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);
}
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);
}
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());
}
}
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;
}
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;
}
Aggregations