Java Code Examples for org.codehaus.jackson.JsonNode#iterator()

The following examples show how to use org.codehaus.jackson.JsonNode#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonUtils.java    From urule with Apache License 2.0 6 votes vote down vote up
public static List<Parameter> parseParameters(JsonNode node){
	JsonNode parametersNode=node.get("parameters");
	if(parametersNode==null){
		return null;
	}
	Iterator<JsonNode> iter=parametersNode.iterator();
	List<Parameter> parameters=new ArrayList<Parameter>();
	while(iter.hasNext()){
		JsonNode parameterNode=iter.next();
		Parameter param=new Parameter();
		param.setName(getJsonValue(parameterNode, "name"));
		String type=getJsonValue(parameterNode, "type");
		if(type!=null){
			param.setType(Datatype.valueOf(type));
		}
		String valueTypeText=getJsonValue(parameterNode, "valueType");
		if(valueTypeText!=null){
			param.setValue(parseValue(parameterNode));
		}
		param.setValue(parseValue(parameterNode));
		parameters.add(param);
	}
	return parameters;
}
 
Example 2
Source File: ReteNodeJsonDeserializer.java    From urule with Apache License 2.0 6 votes vote down vote up
private List<Line> parseLines(JsonNode node){
	JsonNode lineNodes=node.get("lines");
	if(lineNodes==null){
		return null;
	}
	List<Line> lines=new ArrayList<Line>();
	Iterator<JsonNode> iter=lineNodes.iterator();
	while(iter.hasNext()){
		JsonNode jsonNode=iter.next();
		Line line=new Line();
		line.setFromNodeId(jsonNode.get("fromNodeId").getIntValue());
		line.setToNodeId(jsonNode.get("toNodeId").getIntValue());
		lines.add(line);
	}
	return lines;
}
 
Example 3
Source File: ReteNodeJsonDeserializer.java    From urule with Apache License 2.0 6 votes vote down vote up
private CriteriaUnit parseCriteriaUnit(JsonNode unitNode) {
	CriteriaUnit unit=new CriteriaUnit();
	JsonNode criteriaNode=unitNode.get("criteria");
	if(criteriaNode!=null){
		unit.setCriteria(parseCriteria(criteriaNode));
	}
	JsonNode junctionTypeNode=unitNode.get("junctionType");
	if(junctionTypeNode!=null){
		unit.setJunctionType(JunctionType.valueOf(junctionTypeNode.getTextValue()));
	}
	JsonNode nextUnitNodes=unitNode.get("nextUnits");
	if(nextUnitNodes!=null){
		List<CriteriaUnit> nextUnits=new ArrayList<CriteriaUnit>();
		Iterator<JsonNode> iter=nextUnitNodes.iterator();
		while(iter.hasNext()){
			JsonNode nextNode=iter.next();
			nextUnits.add(parseCriteriaUnit(nextNode));
		}
		unit.setNextUnits(nextUnits);
	}
	return unit;
}
 
Example 4
Source File: GenericDataTSV.java    From iow-hadoop-streaming with Apache License 2.0 6 votes vote down vote up
private Array<java.io.Serializable> createArray(Schema type, String t)
        throws IOException, JsonProcessingException {

    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(t);
    Iterator <JsonNode> i = node.iterator();
    Array<java.io.Serializable> arr = new GenericData.Array<java.io.Serializable>(node.size(), Schema.createArray(type));
    while(i.hasNext()) {
        switch (type.getType()) {
            case INT:
                arr.add(i.next().getIntValue());
                break;
            case FLOAT:
            case DOUBLE:
                arr.add(i.next().getDoubleValue());
                break;
            default:
                arr.add(i.next().getTextValue());  // No array-of-objects!
        }
    }

    return arr;
}
 
Example 5
Source File: TestRMNMInfo.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMNMInfo() throws Exception {
  if (!(new File(MiniMRYarnCluster.APPJAR)).exists()) {
    LOG.info("MRAppJar " + MiniMRYarnCluster.APPJAR
         + " not found. Not running test.");
    return;
  }
  
  RMContext rmc = mrCluster.getResourceManager().getRMContext();
  ResourceScheduler rms = mrCluster.getResourceManager()
                                                 .getResourceScheduler();
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             NUMNODEMANAGERS, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNotNull(n.get("NumContainers"));
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected number of used containers",
            0, n.get("NumContainers").asInt());
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected amount of used memory",
            0, n.get("UsedMemoryMB").asInt());
    Assert.assertNotNull(n.get("AvailableMemoryMB"));
  }
}
 
Example 6
Source File: TestRMNMInfo.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMNMInfoMissmatch() throws Exception {
  RMContext rmc = mock(RMContext.class);
  ResourceScheduler rms = mock(ResourceScheduler.class);
  ConcurrentMap<NodeId, RMNode> map = new ConcurrentHashMap<NodeId, RMNode>();
  RMNode node = MockNodes.newNodeInfo(1, MockNodes.newResource(4 * 1024));
  map.put(node.getNodeID(), node);
  when(rmc.getRMNodes()).thenReturn(map);
  
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             1, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNull(n.get("NumContainers"));
    Assert.assertNull(n.get("UsedMemoryMB"));
    Assert.assertNull(n.get("AvailableMemoryMB"));
  }
}
 
Example 7
Source File: TestRMNMInfo.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMNMInfo() throws Exception {
  if (!(new File(MiniMRYarnCluster.APPJAR)).exists()) {
    LOG.info("MRAppJar " + MiniMRYarnCluster.APPJAR
         + " not found. Not running test.");
    return;
  }
  
  RMContext rmc = mrCluster.getResourceManager().getRMContext();
  ResourceScheduler rms = mrCluster.getResourceManager()
                                                 .getResourceScheduler();
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             NUMNODEMANAGERS, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNotNull(n.get("NumContainers"));
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected number of used containers",
            0, n.get("NumContainers").asInt());
    Assert.assertEquals(
            n.get("NodeId") + ": Unexpected amount of used memory",
            0, n.get("UsedMemoryMB").asInt());
    Assert.assertNotNull(n.get("AvailableMemoryMB"));
  }
}
 
Example 8
Source File: TestRMNMInfo.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testRMNMInfoMissmatch() throws Exception {
  RMContext rmc = mock(RMContext.class);
  ResourceScheduler rms = mock(ResourceScheduler.class);
  ConcurrentMap<NodeId, RMNode> map = new ConcurrentHashMap<NodeId, RMNode>();
  RMNode node = MockNodes.newNodeInfo(1, MockNodes.newResource(4 * 1024));
  map.put(node.getNodeID(), node);
  when(rmc.getRMNodes()).thenReturn(map);
  
  RMNMInfo rmInfo = new RMNMInfo(rmc,rms);
  String liveNMs = rmInfo.getLiveNodeManagers();
  ObjectMapper mapper = new ObjectMapper();
  JsonNode jn = mapper.readTree(liveNMs);
  Assert.assertEquals("Unexpected number of live nodes:",
                                             1, jn.size());
  Iterator<JsonNode> it = jn.iterator();
  while (it.hasNext()) {
    JsonNode n = it.next();
    Assert.assertNotNull(n.get("HostName"));
    Assert.assertNotNull(n.get("Rack"));
    Assert.assertTrue("Node " + n.get("NodeId") + " should be RUNNING",
            n.get("State").asText().contains("RUNNING"));
    Assert.assertNotNull(n.get("NodeHTTPAddress"));
    Assert.assertNotNull(n.get("LastHealthUpdate"));
    Assert.assertNotNull(n.get("HealthReport"));
    Assert.assertNotNull(n.get("NodeManagerVersion"));
    Assert.assertNull(n.get("NumContainers"));
    Assert.assertNull(n.get("UsedMemoryMB"));
    Assert.assertNull(n.get("AvailableMemoryMB"));
  }
}
 
Example 9
Source File: AbstractJsonDeserializer.java    From urule with Apache License 2.0 4 votes vote down vote up
private List<Action> parseActions(JsonNode node){
	List<Action> actions=new ArrayList<Action>();
	JsonNode nodes=node.get("actions");
	if(nodes==null)return actions;
	Iterator<JsonNode> iter=nodes.iterator();
	while(iter.hasNext()){
		JsonNode jsonNode=iter.next();
		ActionType actionType=ActionType.valueOf(JsonUtils.getJsonValue(jsonNode, "actionType"));
		switch(actionType){
		case ConsolePrint:
			ConsolePrintAction console=new ConsolePrintAction();
			console.setValue(JsonUtils.parseValue(jsonNode));
			console.setPriority(Integer.valueOf(JsonUtils.getJsonValue(jsonNode, "priority")));
			actions.add(console);
			break;
		case ExecuteMethod:
			ExecuteMethodAction method=new ExecuteMethodAction();
			method.setBeanId(JsonUtils.getJsonValue(jsonNode, "beanId"));
			method.setBeanLabel(JsonUtils.getJsonValue(jsonNode, "beanLabel"));
			method.setMethodLabel(JsonUtils.getJsonValue(jsonNode, "methodLabel"));
			method.setPriority(Integer.valueOf(JsonUtils.getJsonValue(jsonNode, "priority")));
			method.setMethodName(JsonUtils.getJsonValue(jsonNode, "methodName"));
			method.setParameters(JsonUtils.parseParameters(jsonNode));
			actions.add(method);
			break;
		case VariableAssign:
			VariableAssignAction assign=new VariableAssignAction();
			String type=JsonUtils.getJsonValue(jsonNode, "type");
			if(type!=null){					
				assign.setType(LeftType.valueOf(type)); 
			}
			assign.setReferenceName(JsonUtils.getJsonValue(jsonNode, "referenceName"));
			assign.setDatatype(Datatype.valueOf(JsonUtils.getJsonValue(jsonNode, "datatype")));
			assign.setVariableCategory(JsonUtils.getJsonValue(jsonNode, "variableCategory"));
			assign.setVariableLabel(JsonUtils.getJsonValue(jsonNode, "variableLabel"));
			assign.setVariableName(JsonUtils.getJsonValue(jsonNode, "variableName"));
			assign.setPriority(Integer.valueOf(JsonUtils.getJsonValue(jsonNode, "priority")));
			assign.setValue(JsonUtils.parseValue(jsonNode));
			actions.add(assign);
			break;
		case ExecuteCommonFunction:
			ExecuteCommonFunctionAction ca=new ExecuteCommonFunctionAction();
			ca.setLabel(JsonUtils.getJsonValue(jsonNode, "label"));
			ca.setName(JsonUtils.getJsonValue(jsonNode, "name"));
			ca.setParameter(JsonUtils.parseCommonFunctionParameter(jsonNode));
			ca.setPriority(Integer.valueOf(JsonUtils.getJsonValue(jsonNode, "priority")));
			actions.add(ca);
			break;
		case Scoring:
			int rowNumber=Integer.valueOf(JsonUtils.getJsonValue(jsonNode, "rowNumber"));
			String name=JsonUtils.getJsonValue(jsonNode, "name");
			String weight=JsonUtils.getJsonValue(jsonNode, "weight");
			ScoringAction sa=new ScoringAction(rowNumber, name, weight);
			sa.setValue(JsonUtils.parseValue(jsonNode));
			actions.add(sa);
			break;
		}
	}
	return actions;
}