Search in sources :

Example 91 with ObjectNode

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);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 92 with ObjectNode

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);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayNode(org.codehaus.jackson.node.ArrayNode) ClusterConfig(org.apache.helix.model.ClusterConfig) GET(javax.ws.rs.GET)

Example 93 with ObjectNode

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);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) ArrayNode(org.codehaus.jackson.node.ArrayNode) GET(javax.ws.rs.GET)

Example 94 with ObjectNode

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);
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) ObjectNode(org.codehaus.jackson.node.ObjectNode) Message(org.apache.helix.model.Message) ArrayNode(org.codehaus.jackson.node.ArrayNode) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 95 with ObjectNode

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;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) JsonNode(org.codehaus.jackson.JsonNode)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)29 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)16 Produces (javax.ws.rs.Produces)12 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)9 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)5 JsonFactory (org.codehaus.jackson.JsonFactory)5 HelixDataAccessor (org.apache.helix.HelixDataAccessor)4 Span (org.apache.stanbol.enhancer.nlp.model.Span)4 DatasetImpl (org.eol.globi.service.DatasetImpl)4 Date (java.util.Date)3 TaskDriver (org.apache.helix.task.TaskDriver)3 WorkflowConfig (org.apache.helix.task.WorkflowConfig)3