Search in sources :

Example 21 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project helix by apache.

the class ResourceAccessor method getResources.

@GET
public Response getResources(@PathParam("clusterId") String clusterId) {
    ObjectNode root = JsonNodeFactory.instance.objectNode();
    root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
    ZkClient zkClient = getZkClient();
    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);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ObjectNode(org.codehaus.jackson.node.ObjectNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) GET(javax.ws.rs.GET)

Example 22 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.

the class WebAdminHostPageServletTest method setUpMockRequest.

@Before
public void setUpMockRequest() {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode mockPluginDef = mapper.createObjectNode();
    // $NON-NLS-1$ //$NON-NLS-2$
    mockPluginDef.put("foo", "bar");
    mockPluginDefinitionsArray = mapper.createArrayNode();
    mockPluginDefinitionsArray.add(mockPluginDef);
    when(mockApplicationModeObject.toString()).thenReturn(APPLICATION_MODE);
    when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_APPLICATION_MODE)).thenReturn(mockApplicationModeObject);
    when(mockRequest.getAttribute(WebAdminHostPageServlet.ATTR_PLUGIN_DEFS)).thenReturn(mockPluginDefinitionsArray);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Before(org.junit.Before)

Example 23 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.

the class WebAdminHostPageServletTest method testGetPluginDefinitionsArray.

@Test
public void testGetPluginDefinitionsArray() {
    int mockDataCount = 10;
    List<PluginData> pluginData = new ArrayList<>();
    for (int i = 0; i < mockDataCount; i++) {
        PluginData mockData = mock(PluginData.class);
        // $NON-NLS-1$
        when(mockData.getName()).thenReturn("name" + i);
        // $NON-NLS-1$
        when(mockData.getUrl()).thenReturn("url" + i);
        when(mockData.mergeConfiguration()).thenReturn(mock(ObjectNode.class));
        when(mockData.isEnabled()).thenReturn(true);
        pluginData.add(mockData);
    }
    ArrayNode result = testServlet.getPluginDefinitionsArray(pluginData);
    assertEquals(mockDataCount, result.size());
    for (int i = 0; i < mockDataCount; i++) {
        JsonNode item = result.get(i);
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(item.get("name").asText(), "name" + i);
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals(item.get("url").asText(), "url" + i);
        // $NON-NLS-1$
        assertTrue(item.get("config") instanceof ObjectNode);
        // $NON-NLS-1$
        assertTrue(item.get("enabled").asBoolean());
    }
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) PluginData(org.ovirt.engine.ui.frontend.server.gwt.plugin.PluginData) ArrayList(java.util.ArrayList) JsonNode(org.codehaus.jackson.JsonNode) ArrayNode(org.codehaus.jackson.node.ArrayNode) Test(org.junit.Test)

Example 24 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.

the class WebAdminHostPageServlet method getPluginDefinitionsArray.

protected ArrayNode getPluginDefinitionsArray(List<PluginData> pluginData) {
    ArrayNode arr = createArrayNode();
    for (PluginData data : pluginData) {
        ObjectNode dataObj = createObjectNode();
        // $NON-NLS-1$
        dataObj.put("name", data.getName());
        // $NON-NLS-1$
        dataObj.put("url", data.getUrl());
        // $NON-NLS-1$
        dataObj.put("config", data.mergeConfiguration());
        // $NON-NLS-1$
        dataObj.put("lazyLoad", data.isLazyLoad());
        // $NON-NLS-1$
        dataObj.put("enabled", data.isEnabled());
        arr.add(dataObj);
    }
    return arr;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) PluginData(org.ovirt.engine.ui.frontend.server.gwt.plugin.PluginData) ArrayNode(org.codehaus.jackson.node.ArrayNode)

Example 25 with ObjectNode

use of org.codehaus.jackson.node.ObjectNode in project ovirt-engine by oVirt.

the class WebAdminHostPageServlet method getApplicationModeObject.

protected ObjectNode getApplicationModeObject(Integer applicationMode) {
    ObjectNode obj = createObjectNode();
    // $NON-NLS-1$
    obj.put("value", String.valueOf(applicationMode));
    return obj;
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode)

Aggregations

ObjectNode (org.codehaus.jackson.node.ObjectNode)97 ArrayNode (org.codehaus.jackson.node.ArrayNode)29 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)28 JsonNode (org.codehaus.jackson.JsonNode)22 GET (javax.ws.rs.GET)21 Path (javax.ws.rs.Path)18 Test (org.junit.Test)17 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)7 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