use of org.codehaus.jackson.node.ObjectNode in project helix by apache.
the class WorkflowAccessor method getWorkflowConfig.
@GET
@Path("{workflowId}/configs")
public Response getWorkflowConfig(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
TaskDriver taskDriver = getTaskDriver(clusterId);
WorkflowConfig workflowConfig = taskDriver.getWorkflowConfig(workflowId);
ObjectNode workflowConfigNode = JsonNodeFactory.instance.objectNode();
if (workflowConfig != null) {
getWorkflowConfigNode(workflowConfigNode, workflowConfig.getRecord());
}
return JSONRepresentation(workflowConfigNode);
}
use of org.codehaus.jackson.node.ObjectNode in project helix by apache.
the class InstanceAccessor method getInstances.
@GET
public Response getInstances(@PathParam("clusterId") String clusterId) {
HelixDataAccessor accessor = getDataAccssor(clusterId);
ObjectNode root = JsonNodeFactory.instance.objectNode();
root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
ArrayNode instancesNode = root.putArray(InstanceProperties.instances.name());
ArrayNode onlineNode = root.putArray(InstanceProperties.online.name());
ArrayNode disabledNode = root.putArray(InstanceProperties.disabled.name());
List<String> instances = accessor.getChildNames(accessor.keyBuilder().instanceConfigs());
if (instances != null) {
instancesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(instances));
} else {
return notFound();
}
List<String> liveInstances = accessor.getChildNames(accessor.keyBuilder().liveInstances());
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
for (String instanceName : instances) {
InstanceConfig instanceConfig = accessor.getProperty(accessor.keyBuilder().instanceConfig(instanceName));
if (instanceConfig != null) {
if (!instanceConfig.getInstanceEnabled() || (clusterConfig.getDisabledInstances() != null && clusterConfig.getDisabledInstances().containsKey(instanceName))) {
disabledNode.add(JsonNodeFactory.instance.textNode(instanceName));
}
if (liveInstances.contains(instanceName)) {
onlineNode.add(JsonNodeFactory.instance.textNode(instanceName));
}
}
}
return JSONRepresentation(root);
}
use of org.codehaus.jackson.node.ObjectNode in project helix by apache.
the class JobAccessor method getJobs.
@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);
}
use of org.codehaus.jackson.node.ObjectNode in project helix by apache.
the class InstanceAccessor method getMessagesOnInstance.
@GET
@Path("{instanceName}/messages")
public Response getMessagesOnInstance(@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 newMessages = root.putArray(InstanceProperties.new_messages.name());
ArrayNode readMessages = root.putArray(InstanceProperties.read_messages.name());
List<String> messages = accessor.getChildNames(accessor.keyBuilder().messages(instanceName));
if (messages == null || messages.size() == 0) {
return notFound();
}
for (String messageName : messages) {
Message message = accessor.getProperty(accessor.keyBuilder().message(instanceName, messageName));
if (message.getMsgState() == Message.MessageState.NEW) {
newMessages.add(messageName);
}
if (message.getMsgState() == Message.MessageState.READ) {
readMessages.add(messageName);
}
}
root.put(InstanceProperties.total_message_count.name(), newMessages.size() + readMessages.size());
root.put(InstanceProperties.read_message_count.name(), readMessages.size());
return JSONRepresentation(root);
}
use of org.codehaus.jackson.node.ObjectNode in project apex-core by apache.
the class InjectConfigTest method merge.
public static JsonNode merge(JsonNode mainNode, JsonNode updateNode) {
Iterator<String> fieldNames = updateNode.getFieldNames();
while (fieldNames.hasNext()) {
String fieldName = fieldNames.next();
JsonNode jsonNode = mainNode.get(fieldName);
// if field doesn't exist or is an embedded object
if (jsonNode != null && jsonNode.isObject()) {
merge(jsonNode, updateNode.get(fieldName));
} else {
if (mainNode instanceof ObjectNode) {
// Overwrite field
JsonNode value = updateNode.get(fieldName);
((ObjectNode) mainNode).put(fieldName, value);
}
}
}
return mainNode;
}
Aggregations