chia7712 commented on code in PR #750:
URL: https://github.com/apache/yunikorn-core/pull/750#discussion_r1440735232


##########
pkg/webservice/handlers.go:
##########
@@ -619,6 +640,58 @@ func getQueueApplications(w http.ResponseWriter, r 
*http.Request) {
        }
 }
 
+func getPartitionApplicationsByState(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 := strings.ToLower(vars.ByName("state"))
+
+       partitionContext := 
schedulerContext.GetPartitionWithoutClusterID(partition)
+       if partitionContext == nil {
+               buildJSONErrorResponse(w, PartitionDoesNotExists, 
http.StatusNotFound)
+               return
+       }
+       if appState != "active" && appState != "rejected" && appState != 
"completed" {
+               buildJSONErrorResponse(w, "Only following application states 
are allowed: active, rejected, completed", http.StatusBadRequest)
+               return
+       }
+       var appList []*objects.Application
+       switch appState {
+       case "active":
+               if status := strings.ToLower(r.URL.Query().Get("status")); 
status != "" {
+                       if !allowedAppActiveStates[status] {
+                               buildJSONErrorResponse(w, 
allowedActiveStatesMsg, http.StatusBadRequest)

Review Comment:
   Should `allowedActiveStatesMsg` be renamed to `allowedActiveStatusMsg` if 
the query key is called "statue"?



##########
pkg/webservice/handlers.go:
##########
@@ -619,6 +640,58 @@ func getQueueApplications(w http.ResponseWriter, r 
*http.Request) {
        }
 }
 
+func getPartitionApplicationsByState(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 := strings.ToLower(vars.ByName("state"))
+
+       partitionContext := 
schedulerContext.GetPartitionWithoutClusterID(partition)
+       if partitionContext == nil {
+               buildJSONErrorResponse(w, PartitionDoesNotExists, 
http.StatusNotFound)
+               return
+       }
+       if appState != "active" && appState != "rejected" && appState != 
"completed" {
+               buildJSONErrorResponse(w, "Only following application states 
are allowed: active, rejected, completed", http.StatusBadRequest)

Review Comment:
   Could we move this line to line#683? for example:
   ```go
        case "active":
                if status := strings.ToLower(r.URL.Query().Get("status")); 
status != "" {
                        if !allowedAppActiveStates[status] {
                                buildJSONErrorResponse(w, 
allowedActiveStatesMsg, http.StatusBadRequest)
                                return
                        }
                        for _, app := range partitionContext.GetApplications() {
                                if strings.ToLower(app.CurrentState()) == 
status {
                                        appList = append(appList, app)
                                }
                        }
                } else {
                        appList = partitionContext.GetApplications()
                }
        case "rejected":
                appList = partitionContext.GetRejectedApplications()
        case "completed":
                appList = partitionContext.GetCompletedApplications()
        default:
                buildJSONErrorResponse(w, "Only following application states 
are allowed: active, rejected, completed", 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]

Reply via email to