use of org.codehaus.jackson.node.ArrayNode in project motech by motech.
the class TaskServiceImpl method removeIgnoredFields.
private void removeIgnoredFields(JsonNode node) {
if (null == node || node.isValueNode()) {
return;
}
if (node.isObject()) {
ObjectNode obj = (ObjectNode) node;
obj.remove(IGNORED_FIELDS);
}
if (node.isArray()) {
ArrayNode array = (ArrayNode) node;
for (JsonNode item : array) {
removeIgnoredFields(item);
}
}
Iterator<Map.Entry<String, JsonNode>> elements = node.getFields();
while (elements.hasNext()) {
Map.Entry<String, JsonNode> entry = elements.next();
if (!"values".equals(entry.getKey())) {
removeIgnoredFields(entry.getValue());
}
}
}
use of org.codehaus.jackson.node.ArrayNode in project helix by apache.
the class InstanceAccessor method getHealthReportsOnInstance.
@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);
}
use of org.codehaus.jackson.node.ArrayNode in project helix by apache.
the class InstanceAccessor method getResourcesOnInstance.
@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);
}
use of org.codehaus.jackson.node.ArrayNode 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.ArrayNode 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());
}
}
Aggregations