Search in sources :

Example 1 with GroupedTasks

use of com.mesosphere.sdk.http.types.GroupedTasks in project dcos-commons by mesosphere.

the class PodQueries method getStatuses.

/**
 * Produces the summary statuses of all pod instances.
 */
public static Response getStatuses(StateStore stateStore, String serviceName) {
    try {
        // Group the tasks by pod:
        GroupedTasks groupedTasks = GroupedTasks.create(stateStore);
        // Output statuses for all tasks in each pod:
        JSONObject responseJson = new JSONObject();
        responseJson.put("service", serviceName);
        for (Map.Entry<String, Map<Integer, List<TaskInfoAndStatus>>> podType : groupedTasks.byPodTypeAndIndex.entrySet()) {
            JSONObject podJson = new JSONObject();
            podJson.put("name", podType.getKey());
            for (Map.Entry<Integer, List<TaskInfoAndStatus>> podInstance : podType.getValue().entrySet()) {
                podJson.append("instances", getPodInstanceStatusJson(stateStore, PodInstance.getName(podType.getKey(), podInstance.getKey()), podInstance.getValue()));
            }
            responseJson.append("pods", podJson);
        }
        // Output an 'unknown pod' instance for any tasks which didn't have a resolvable pod:
        if (!groupedTasks.unknownPod.isEmpty()) {
            JSONObject podTypeJson = new JSONObject();
            podTypeJson.put("name", UNKNOWN_POD_LABEL);
            podTypeJson.append("instances", getPodInstanceStatusJson(stateStore, PodInstance.getName(UNKNOWN_POD_LABEL, 0), groupedTasks.unknownPod));
            responseJson.append("pods", podTypeJson);
        }
        return jsonOkResponse(responseJson);
    } catch (Exception e) {
        LOGGER.error("Failed to fetch collated list of task statuses by pod", e);
        return Response.serverError().build();
    }
}
Also used : JSONObject(org.json.JSONObject) TaskInfoAndStatus(com.mesosphere.sdk.http.types.TaskInfoAndStatus) GroupedTasks(com.mesosphere.sdk.http.types.GroupedTasks) JSONException(org.json.JSONException) TaskException(com.mesosphere.sdk.offer.TaskException)

Aggregations

GroupedTasks (com.mesosphere.sdk.http.types.GroupedTasks)1 TaskInfoAndStatus (com.mesosphere.sdk.http.types.TaskInfoAndStatus)1 TaskException (com.mesosphere.sdk.offer.TaskException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1