public void addDisplayMeta(ArrayNode displayNode) { if (displayMeta == null) { displayMeta = JsonNodeFactory.instance.arrayNode(); } displayMeta.addAll(displayNode); }
private static JsonNode toJsonNode(final List<JsonNode> matching) { switch (matching.size()) { case 0: return NullNode.getInstance(); case 1: return matching.get(0); default: final ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance); arrayNode.addAll(matching); return arrayNode; } }
private static JsonNode toJsonNode(final List<JsonNode> matching) { switch (matching.size()) { case 0: return NullNode.getInstance(); case 1: return matching.get(0); default: final ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance); arrayNode.addAll(matching); return arrayNode; } }
public static ArrayNode toJsonArray(final JsonNode... values){ final ArrayNode result = ThreadLocalJsonFactory.getFactory().arrayNode(); result.addAll(Arrays.asList(values)); return result; }
@GET @Path("{instanceName}/healthreports") public Response getHealthReportsOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException { HelixDataAccessor accessor = getDataAccssor(clusterId); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(Properties.id.name(), instanceName); ArrayNode healthReportsNode = root.putArray(InstanceProperties.healthreports.name()); List<String> healthReports = accessor.getChildNames(accessor.keyBuilder().healthReports(instanceName)); if (healthReports != null && healthReports.size() > 0) { healthReportsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(healthReports)); } return JSONRepresentation(root); }
@GET @Path("{instanceName}/resources") public Response getResourcesOnInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName) throws IOException { HelixDataAccessor accessor = getDataAccssor(clusterId); ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(Properties.id.name(), instanceName); ArrayNode resourcesNode = root.putArray(InstanceProperties.resources.name()); List<String> sessionIds = accessor.getChildNames(accessor.keyBuilder().sessions(instanceName)); if (sessionIds == null || sessionIds.size() == 0) { return null; } // Only get resource list from current session id String currentSessionId = sessionIds.get(0); List<String> resources = accessor.getChildNames(accessor.keyBuilder().currentStates(instanceName, currentSessionId)); if (resources != null && resources.size() > 0) { resourcesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(resources)); } return JSONRepresentation(root); }
@GET public Response getJobs(@PathParam("clusterId") String clusterId, @PathParam("workflowName") String workflowName) { TaskDriver driver = getTaskDriver(clusterId); WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName); ObjectNode root = JsonNodeFactory.instance.objectNode(); if (workflowConfig == null) { return badRequest(String.format("Workflow %s is not found!", workflowName)); } Set<String> jobs = workflowConfig.getJobDag().getAllNodes(); root.put(Properties.id.name(), JobProperties.Jobs.name()); ArrayNode jobsNode = root.putArray(JobProperties.Jobs.name()); if (jobs != null) { jobsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(jobs)); } return JSONRepresentation(root); }
@GET public Response getResources(@PathParam("clusterId") String clusterId) { ObjectNode root = JsonNodeFactory.instance.objectNode(); root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId)); HelixZkClient zkClient = getHelixZkClient(); ArrayNode idealStatesNode = root.putArray(ResourceProperties.idealStates.name()); ArrayNode externalViewsNode = root.putArray(ResourceProperties.externalViews.name()); List<String> idealStates = zkClient.getChildren(PropertyPathBuilder.idealState(clusterId)); List<String> externalViews = zkClient.getChildren(PropertyPathBuilder.externalView(clusterId)); if (idealStates != null) { idealStatesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(idealStates)); } else { return notFound(); } if (externalViews != null) { externalViewsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(externalViews)); } return JSONRepresentation(root); }
if (partitions != null) { ArrayNode partitionsNode = resourcesNode.putArray(resourceName); partitionsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(partitions));
instancesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(instances)); } else { return notFound();