pbacsko commented on code in PR #750:
URL: https://github.com/apache/yunikorn-core/pull/750#discussion_r1427984696
##########
pkg/webservice/handlers.go:
##########
@@ -619,6 +625,41 @@ func getQueueApplications(w http.ResponseWriter, r
*http.Request) {
}
}
+func getPartitionApplicationIDsByState(w http.ResponseWriter, r *http.Request)
{
+ writeHeaders(w)
+ vars := httprouter.ParamsFromContext(r.Context())
+ if vars == nil {
+ buildJSONErrorResponse(w, MissingParamsName,
http.StatusBadRequest)
+ return
+ }
+ partition := vars.ByName("partition")
+ appState := vars.ByName("state")
+
+ partitionContext :=
schedulerContext.GetPartitionWithoutClusterID(partition)
+ if partitionContext == nil {
+ buildJSONErrorResponse(w, PartitionDoesNotExists,
http.StatusNotFound)
+ return
+ }
+ if !allowedAppStates[appState] {
+ buildJSONErrorResponse(w, fmt.Sprintf("Only %s,%s,%s state is
allowed",
+ objects.Running.String(), objects.Rejected.String(),
objects.Completed.String()), http.StatusBadRequest)
+ return
+ }
Review Comment:
I don't want to overengineer things, but it's safer to auto-construct this:
```
var allowedStatesMsg string
var allowedAppStates map[string]bool
func init() {
allowedAppStates[objects.Running.String()] = true
allowedAppStates[objects.Rejected.String()] = true
allowedAppStates[objects.Completed.String()] = true
var states []string
for k := range allowedAppStates {
states = append(states, k)
}
allowedStatesMsg = fmt.Sprintf("Only following application states are
allowed: %s", strings.Join(states, ","))
}
...
if !allowedAppStates[appState] {
buildJSONErrorResponse(w, allowedStatesMsg,
http.StatusBadRequest)
return
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]