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

The following examples show how to use org.codehaus.jackson.JsonNode#getTextValue() . 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 Cubert with Apache License 2.0 6 votes vote down vote up
public static String[] asArray(JsonNode node)
{
    if (node == null)
        throw new IllegalArgumentException("Specified JsonNode is null");

    if (node.isArray())
    {
        ArrayNode anode = (ArrayNode) node;
        int nelements = anode.size();
        String[] array = new String[nelements];
        for (int i = 0; i < nelements; i++)
        {
            array[i] = anode.get(i).getTextValue();
        }
        return array;
    }
    else
    {
        return new String[] { node.getTextValue() };
    }
}
 
Example 2
Source File: MLOBIOutboundTransport.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private String getTrackIdAsString(JsonNode trackIDNode)
{
	String output = null;
	if (trackIDNode.isTextual())
		output = trackIDNode.getTextValue();
	else if (trackIDNode.isInt())
		output = Integer.toString(trackIDNode.getIntValue());
	else if (trackIDNode.isLong())
		output = Long.toString(trackIDNode.getLongValue());
	else if (trackIDNode.isDouble())
		output = Double.toString(trackIDNode.getDoubleValue());
	else if (trackIDNode.isFloatingPointNumber())
		output = trackIDNode.getDecimalValue().toString();

	if (!Validator.isEmpty(output))
	{
		output = output.replace("'", "''");
	}
	return output;
}
 
Example 3
Source File: GenericEntityDeserializer.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private Object processPrimitive(final JsonNode prim) {
    Object val;
    
    if (prim instanceof BooleanNode) {
        val = prim.getBooleanValue();
    } else if (prim instanceof DoubleNode) {
        val = prim.getDoubleValue();
    } else if (prim instanceof IntNode) {
        val = prim.getIntValue();
    } else if (prim instanceof LongNode) {
        val = prim.getLongValue();
    } else {
        val = prim.getTextValue();
    }
    return val;
}
 
Example 4
Source File: LineageHelper.java    From Cubert with Apache License 2.0 5 votes vote down vote up
public static String getPathRoot(JsonNode pathNode)
{
    if (pathNode instanceof ObjectNode
            && ((ObjectNode) pathNode).get("startDate") != null)
        return (pathNode.get("root").getTextValue());
    else
        return (pathNode.getTextValue());

}
 
Example 5
Source File: FlattenBagOperator.java    From Cubert with Apache License 2.0 5 votes vote down vote up
private void init(JsonNode operatorJson, BlockSchema inputSchema)
{
    JsonNode exprListNode = operatorJson.get("genExpressions");
    Iterator<JsonNode> it = exprListNode.getElements();
    while (it.hasNext())
    {
        JsonNode e = it.next();
        String colName = e.get("col").getTextValue();
        int columnId = inputSchema.getIndex(colName);
        flattenColumnNameSet.add(colName);
        columnIndexArray.add(columnId);

        JsonNode flattenNode = e.get("flatten");
        if (flattenNode != null)
        {
            String ftypestr = flattenNode.getTextValue();

            flattenPositions.put(inputSchema.getIndex(colName),
                                 FlattenType.fromString(ftypestr));
            // System.out.println("Flatten column  =" + colName + " position = " +
            // inputSchema.getIndex(colName) + " type= " + ftypestr);

            odometerIterators.add(null);

            // out put column definitions:
            List<ColumnType> outputColumTypeList = new ArrayList<ColumnType>();
            outputColumnTypeMap.put(colName, outputColumTypeList);
            JsonNode outputNode = e.get("output");
            for (JsonNode j : outputNode)
            {
                String outColName = j.get("col").getTextValue();
                DataType outType = DataType.valueOf(j.get("type").getTextValue());
                outputColumTypeList.add(new ColumnType(outColName, outType));
            }

        }
    }

    this.outSchema = generateOutSchema(inputSchema);
}
 
Example 6
Source File: JobExecutor.java    From Cubert with Apache License 2.0 5 votes vote down vote up
protected void cacheFiles() throws URISyntaxException,
        IOException
{
    if (!root.has("cachedFiles") || root.get("cachedFiles").isNull()
            || root.get("cachedFiles").size() == 0)
        return;

    for (JsonNode cachedFile : root.path("cachedFiles"))
    {
        URI uri = new URI(cachedFile.getTextValue());
        print.f("CACHING file %s", uri);
        DistributedCache.addCacheFile(uri, conf);
    }
}
 
Example 7
Source File: ShuffleRewriter.java    From Cubert with Apache License 2.0 5 votes vote down vote up
private void rewriteGroupByAggregateForCube(JsonNode aggregates)
{
    // modify the aggregates JsonNode object (to be used in SHUFFLE, and GBY in
    // reducer):
    // a) if it is dual agg, use the outer aggregator
    // b) if it is COUNT or COUNT_DISTINCT agg, switch it to SUM
    // c) use the original output column name as input column name
    for (JsonNode aggNode : aggregates)
    {
        String type;
        JsonNode typeJson = aggNode.get("type");
        if (typeJson.isArray())
            type = typeJson.get(0).getTextValue();
        else
            type = typeJson.getTextValue();

        String outputColName = getText(aggNode, "output");

        ObjectNode onode = (ObjectNode) aggNode;
        // see if the aggregation type has to be changed
        if (type.equals("COUNT") || type.equals("COUNT_DISTINCT"))
            onode.put("type", "SUM");
        else
            onode.put("type", type);

        // change the input column name
        onode.put("input", outputColName);
    }
}
 
Example 8
Source File: JsonControlGroup.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Override
public JsonControlGroup deserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode rootNode = obj.readTree(jp);
    final JsonNode operation = rootNode.get("controlOperation");

    return new JsonControlGroup(operation.getTextValue());
}
 
Example 9
Source File: JsonControlJvm.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Override
public JsonControlJvm deserialize(final JsonParser jp,
                                  final DeserializationContext ctxt) throws IOException {

    final ObjectCodec obj = jp.getCodec();
    final JsonNode rootNode = obj.readTree(jp);
    final JsonNode operation = rootNode.get("controlOperation");

    return new JsonControlJvm(operation.getTextValue());
}
 
Example 10
Source File: TestLog4Json.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testNestedException() throws Throwable {
  Exception e =
      new NoRouteToHostException("that box caught fire 3 years ago");
  Exception ioe = new IOException("Datacenter problems", e);
  ThrowableInformation ti = new ThrowableInformation(ioe);
  Log4Json l4j = new Log4Json();
  long timeStamp = Time.now();
  String outcome = l4j.toJson(new StringWriter(),
      "testNestedException",
      timeStamp,
      "INFO",
      "quoted\"",
      "new line\n and {}",
      ti)
      .toString();
  println("testNestedException", outcome);
  ContainerNode rootNode = Log4Json.parse(outcome);
  assertEntryEquals(rootNode, Log4Json.LEVEL, "INFO");
  assertEntryEquals(rootNode, Log4Json.NAME, "testNestedException");
  assertEntryEquals(rootNode, Log4Json.TIME, timeStamp);
  assertEntryEquals(rootNode, Log4Json.EXCEPTION_CLASS,
      ioe.getClass().getName());
  JsonNode node = assertNodeContains(rootNode, Log4Json.STACK);
  assertTrue("Not an array: " + node, node.isArray());
  node = assertNodeContains(rootNode, Log4Json.DATE);
  assertTrue("Not a string: " + node, node.isTextual());
  //rather than try and make assertions about the format of the text
  //message equalling another ISO date, this test asserts that the hypen
  //and colon characters are in the string.
  String dateText = node.getTextValue();
  assertTrue("No '-' in " + dateText, dateText.contains("-"));
  assertTrue("No '-' in " + dateText, dateText.contains(":"));

}
 
Example 11
Source File: Lineage.java    From Cubert with Apache License 2.0 5 votes vote down vote up
private static String findNamedColumn(ArrayNode argsNode)
{
    for (JsonNode arg : argsNode)
    {
      if (!arg.isTextual())
        continue;
      return arg.getTextValue();
    }
    return null;
}
 
Example 12
Source File: KubernetesBackUpTask.java    From kardio with Apache License 2.0 5 votes vote down vote up
/**
 * This function returns the host url.
 * If the app is using path based routing, then path is appended to end of the host url 
 * @param specIngNode
 * @param healthCheckPort
 * @param isPathNeeded
 * @return
 */
private static String getHostUrlAndPath(JsonNode specIngNode, String healthCheckPort, boolean isPathNeeded) {
	// TODO Auto-generated method stub
	ArrayNode rulesArrayNode = (ArrayNode)specIngNode.get("rules");
   	Iterator<JsonNode> rulesNodeItr = rulesArrayNode.getElements();
   	while(rulesNodeItr.hasNext()){
   		JsonNode rulesNode = rulesNodeItr.next();
   		JsonNode hostNode = rulesNode.get("host");
   		if(hostNode == null){
   			return null;
   		}
   		String host = hostNode.asText();
   		if(!isPathNeeded){
   			return host;
   		}
   		JsonNode httpRuleNode = rulesNode.get("http");
   		ArrayNode pathsArrayNode = (ArrayNode)httpRuleNode.get("paths");
   		Iterator<JsonNode> pathsNodeItr = pathsArrayNode.getElements();
   		while(pathsNodeItr.hasNext()){
   			JsonNode pathsRootNode = pathsNodeItr.next();
   			JsonNode backendNode = pathsRootNode.get("backend");
   			JsonNode servicePortNode = backendNode.get("servicePort");
   			if(servicePortNode.asText().equals(healthCheckPort)){
   				JsonNode pathNode = pathsRootNode.get("path");
   				return host+pathNode.getTextValue();
   			}
   		}
   	}
   	return null;
}
 
Example 13
Source File: TPSDataLoadTask.java    From kardio with Apache License 2.0 4 votes vote down vote up
/**
 * A common method to Call the prometheous based on the queries passed (TPS/Latency query).
 * Iterate the prometheous output json, the response of this method is a Map with componentID as key and
 * TPS/Latency value as value of the Map.
 * @param promUrl
 * @param EnvName
 * @param promLookMap
 * @param platform
 * @return
 * @throws Exception
 */
private static Map<Integer, Float> getMatrxValuesFromPrometeous(String promUrl, String EnvName, Map<String, Integer> promLookMap, String platform) throws Exception{
	String lookUpPath = null;
	if(platform.equals("Mesos")){
		lookUpPath = "proxyname";
	}else if(platform.equals("K8s")){
		lookUpPath = "service";
	}else{
		logger.error("Not a valid platform");
	}
	String prometheusResponse = RestCommunicationHandler.getResponse(promUrl, false, null, null);
	ObjectMapper mapper = new ObjectMapper();
       JsonNode rootNode = mapper.readTree(prometheusResponse);
       if(rootNode.get("status") == null || !rootNode.get("status").getTextValue().equalsIgnoreCase("success")){
       	logger.error("Prometheus : Status Check Failed For Environment " + EnvName );
       	logger.error("Prometheus Response : \n" + prometheusResponse);
       	throw new GeneralException("Prometheus : Status Check Failed. Environment name " + EnvName);
       }
       if(rootNode.get("data") == null
       		|| rootNode.get("data").get("result") == null
       		|| !rootNode.get("data").get("result").isArray()){
       	logger.error("/data/result Node is missing in prometheus response. Environment name " + EnvName );
       	logger.error("Prometheus Response : \n" + prometheusResponse);
       	throw new GeneralException("/data/result Node is missing in prometheus response. Environment name " + EnvName);
       }
       
       Map<Integer, Float> valueMap = new HashMap<Integer, Float>();
       JsonNode valueNode = null;
       JsonNode metricNode = null;
       for (final JsonNode arrayNode : rootNode.get("data").get("result")) {
       	metricNode = arrayNode.get("metric");
       	if(metricNode == null){
       		logger.error("Metric Node cannot be null");
       		continue;
       	}
       	valueNode = arrayNode.get("value");
       	if(valueNode == null){
       		logger.error("/data/result/value Node is missing in prometheus response. Environment name " + EnvName);
               logger.error("Prometheus Response : \n" + prometheusResponse);
               throw new GeneralException("/data/result/value Node is missing in prometheus response. Environment name " + EnvName);
           }
       	String tpsValueString = valueNode.get(1).getTextValue();
           float tpsValue = Float.parseFloat(tpsValueString);
           if(metricNode.get(lookUpPath) == null){
           	logger.error("Metric Node without lookUpPath");
       		continue;
           }
           JsonNode lookupPathNode = metricNode.get(lookUpPath);
           String metricLookup = lookupPathNode.getTextValue();
       	if(promLookMap.containsKey(metricLookup)){
       		
       		int compId = promLookMap.get(metricLookup);
       		if(valueMap == null || valueMap.isEmpty()){
       			valueMap.put(compId, tpsValue);
       		}else if(valueMap.containsKey(compId)){
       			valueMap.put(compId, valueMap.get(compId)+tpsValue);
       		}else{
       			valueMap.put(compId, tpsValue);
       		}
       	}
       }
	return valueMap;
}
 
Example 14
Source File: JSONRPCParser.java    From bitcoin-transaction-explorer with MIT License 4 votes vote down vote up
public static String getString(final InputStream jsonData) throws JsonProcessingException, IOException {
  final JsonNode tree = JsonParser.mapper.readTree(jsonData);

  return tree.getTextValue();
}
 
Example 15
Source File: SamzaObjectMapper.java    From samza with Apache License 2.0 4 votes vote down vote up
@Override
public TaskName deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException, JsonProcessingException {
  ObjectCodec oc = jsonParser.getCodec();
  JsonNode node = oc.readTree(jsonParser);
  return new TaskName(node.getTextValue());
}
 
Example 16
Source File: KubernetesBackUpTask.java    From kardio with Apache License 2.0 4 votes vote down vote up
/**
 * The function returns all Ingress as a Map, with key as service name & Ingress root node
 * @param ingressJson
 * @param eVo
 * @return
 * @throws Exception 
 */
private static Map<String, JsonNode> getIngressLookupMap(String authToken, EnvironmentVO eVo) throws Exception {
	// TODO Auto-generated method stub
	String ingressApiUrl = eVo.getK8sUrl() + PropertyUtil.getInstance().getValue(SurveillerConstants.K8S_API_INGRESS_PATH);
	String ingressJson = RestCommunicationHandler.getResponse(ingressApiUrl, true, SurveillerConstants.BEARER_TOKEN, authToken);
	ObjectMapper mapper = new ObjectMapper();
	JsonNode ingRootNode = mapper.readTree(ingressJson);
       ArrayNode ingressArrayNode = (ArrayNode) ingRootNode.get("items");
       if(ingressArrayNode == null || ingressArrayNode.size() == 0){
       	logger.info("No Ingress is available for the environment : "+eVo.getEnvironmentName());
		return null;
       }
       Iterator<JsonNode> ingressIterator = ingressArrayNode.getElements();
       Map<String, JsonNode> ingressMap = new HashMap<String, JsonNode>();
       while (ingressIterator.hasNext()) {
       	
       	JsonNode ingressInNode = ingressIterator.next();
       	JsonNode metadataNode = ingressInNode.get("metadata");
       	JsonNode nameNode = metadataNode.get("name");
       	String ingressName = nameNode.getValueAsText();
       	JsonNode namespaceNode = metadataNode.get("namespace");
       	String namespace = namespaceNode.getValueAsText();
       	if (!namespace.contains("-")) {
			logger.info("Excluding Ingress - " + ingressName + " in the namespace - " + namespace);
			continue;
		}
       	/*This particular block of code is to avoid code executions for the applications with multiple ingress
       	 * FIXME: Remove if this logic is not necessary
       	 * CASE: Services with multiple Ingress 
       	 * In our case the annotation "kubernetes.io/ingress.class" contains values "nginx-internal" or "nginx-external"
       	 * */
       	JsonNode annotNode = metadataNode.get("annotations");
       	if(annotNode == null){
       		logger.info("The annotations node is null for the Ingress - "+ingressName+" in the namespace - "+ namespace);
       	}else{
	        JsonNode ingClasstNode = annotNode.get("kubernetes.io/ingress.class");
            if(ingClasstNode == null || !ingClasstNode.getTextValue().equals("nginx-internal")){
            	logger.info("The hostname node is "+ingClasstNode+ "for the Ingress - "+ingressName+" in the namespace - "+ namespace);
            	continue;
            }
       	}   
           /******/
       	JsonNode specNode = ingressInNode.get("spec");
           if (specNode == null) {
			logger.info("The specNode is null for the ingress - " + ingressName + " in the namespace - "+ namespace);
			continue;
		}
           String serviceName = null;
           ArrayNode ruleArrayNode = (ArrayNode)specNode.get("rules");
           Iterator<JsonNode> ruleNodeItr = ruleArrayNode.getElements();
           while (ruleNodeItr.hasNext()) {
               JsonNode ruleNode = ruleNodeItr.next();
               JsonNode httpNode = ruleNode.get("http");
               if(httpNode == null){
               	logger.info("The httpNode is null for the ingress - " + ingressName + " in the namespace - "+ namespace);
               	continue;
               }
               ArrayNode pathArrayNode = (ArrayNode)httpNode.get("paths");
               Iterator<JsonNode> pathNodeItr = pathArrayNode.getElements();
               while (pathNodeItr.hasNext()) {
                JsonNode pathNode = pathNodeItr.next();
                JsonNode backendNode = pathNode.get("backend");
                JsonNode serviceNode = backendNode.get("serviceName");
                if (serviceNode == null) {
					logger.info("The serviceNode is null for the ingress - " + ingressName + " in the namespace - "+ namespace);
					continue;
				}
                serviceName = serviceNode.getTextValue();
                ingressMap.put(namespace+"/"+serviceName, ingressInNode);
               }    
          }	
       }
	return ingressMap;
}
 
Example 17
Source File: JsonSchemaInference.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected DataType getDataType(final JsonNode jsonNode) {
    if (jsonNode.isTextual()) {
        final String text = jsonNode.getTextValue();
        if (text == null) {
            return RecordFieldType.STRING.getDataType();
        }

        final Optional<DataType> timeDataType = timeValueInference.getDataType(text);
        return timeDataType.orElse(RecordFieldType.STRING.getDataType());
    }

    if (jsonNode.isObject()) {
        final RecordSchema schema = createSchema(jsonNode);
        return RecordFieldType.RECORD.getRecordDataType(schema);
    }

    if (jsonNode.isIntegralNumber()) {
        if (jsonNode.isBigInteger()) {
            return RecordFieldType.BIGINT.getDataType();
        }
        return RecordFieldType.LONG.getDataType();
    }

    if (jsonNode.isBigDecimal()) {
        final DecimalNode decimalNode = (DecimalNode) jsonNode;
        final BigDecimal value = decimalNode.getDecimalValue();
        return RecordFieldType.DECIMAL.getDecimalDataType(value.precision(), value.scale());
    }

    if (jsonNode.isFloatingPointNumber()) {
        return RecordFieldType.DOUBLE.getDataType();
    }
    if (jsonNode.isBinary()) {
        return RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BYTE.getDataType());
    }
    if (jsonNode.isBoolean()) {
        return RecordFieldType.BOOLEAN.getDataType();
    }

    return null;
}
 
Example 18
Source File: AbstractSiteToSiteReportingTask.java    From nifi with Apache License 2.0 4 votes vote down vote up
protected Object getRawNodeValue(final JsonNode fieldNode, final DataType dataType) throws IOException {
    if (fieldNode == null || fieldNode.isNull()) {
        return null;
    }

    if (fieldNode.isNumber()) {
        return fieldNode.getNumberValue();
    }

    if (fieldNode.isBinary()) {
        return fieldNode.getBinaryValue();
    }

    if (fieldNode.isBoolean()) {
        return fieldNode.getBooleanValue();
    }

    if (fieldNode.isTextual()) {
        return fieldNode.getTextValue();
    }

    if (fieldNode.isArray()) {
        final ArrayNode arrayNode = (ArrayNode) fieldNode;
        final int numElements = arrayNode.size();
        final Object[] arrayElements = new Object[numElements];
        int count = 0;

        final DataType elementDataType;
        if (dataType != null && dataType.getFieldType() == RecordFieldType.ARRAY) {
            final ArrayDataType arrayDataType = (ArrayDataType) dataType;
            elementDataType = arrayDataType.getElementType();
        } else {
            elementDataType = null;
        }

        for (final JsonNode node : arrayNode) {
            final Object value = getRawNodeValue(node, elementDataType);
            arrayElements[count++] = value;
        }

        return arrayElements;
    }

    if (fieldNode.isObject()) {
        RecordSchema childSchema;
        if (dataType != null && RecordFieldType.RECORD == dataType.getFieldType()) {
            final RecordDataType recordDataType = (RecordDataType) dataType;
            childSchema = recordDataType.getChildSchema();
        } else {
            childSchema = null;
        }

        if (childSchema == null) {
            childSchema = new SimpleRecordSchema(Collections.emptyList());
        }

        final Iterator<String> fieldNames = fieldNode.getFieldNames();
        final Map<String, Object> childValues = new HashMap<>();
        while (fieldNames.hasNext()) {
            final String childFieldName = fieldNames.next();
            final Object childValue = getRawNodeValue(fieldNode.get(childFieldName), dataType);
            childValues.put(childFieldName, childValue);
        }

        final MapRecord record = new MapRecord(childSchema, childValues);
        return record;
    }

    return null;
}
 
Example 19
Source File: K8sAPIDashboardTask.java    From kardio with Apache License 2.0 4 votes vote down vote up
/**
 * Method to get all Pods and Containers associated to the deployment.
 * 
 * @param authToken
 * @param eVo
 * @param depLabelMap
 * @param externalPodsMap
 *
 */
private static void getPodsAndContainersOfDeployments(String authToken, EnvironmentVO eVo,
		Map<String, List<ServiceLabelVO>> depLabelMap, Map<String, ArrayList<Integer>> externalPodsMap) throws IOException {
	String podApiUrl = eVo.getK8sUrl() + PropertyUtil.getInstance().getValue(SurveillerConstants.K8S_API_PODS_PATH);
	/* Call - the Kube Pod api to get all the Pods in the Cluster */
	String podJson = RestCommunicationHandler.getResponse(podApiUrl, true, SurveillerConstants.BEARER_TOKEN, authToken);
	ObjectMapper mapper = new ObjectMapper();
	JsonNode podRootNode = mapper.readTree(podJson);
	ArrayNode appsNode = (ArrayNode) podRootNode.get("items");
	Iterator<JsonNode> podsIterator = appsNode.getElements();
	while (podsIterator.hasNext()) {
		JsonNode appsInNode = podsIterator.next();
		JsonNode metadataNode = appsInNode.get("metadata");
		JsonNode nameNode = metadataNode.get("name");
		String podName = nameNode.getValueAsText();
		JsonNode namespaceNode = metadataNode.get("namespace");
		String namespace = namespaceNode.getValueAsText();
		if (namespace.equals("default") || !namespace.contains("-")) {
			logger.info("Excluding Pods - " + podName + " in the namespace - " + namespace);
			continue;
		}
		JsonNode specNode = appsInNode.get("spec");
		ArrayNode contArrayNode = (ArrayNode) specNode.get("containers");
		/* Number of containers in Pod */
		int numCount = contArrayNode.size();
		//JsonNode ownerReferencesNode = 
		ArrayNode ownerReferencesArray = (ArrayNode) metadataNode.get("ownerReferences");
		if(ownerReferencesArray == null){
			loadPodsAndContainer("Kube-Systems",namespace, externalPodsMap, numCount);
			continue;
		}
		JsonNode ownerReferencesNode = ownerReferencesArray.get(0);
		JsonNode kindNode = ownerReferencesNode.get("kind");
		String kind = kindNode.getTextValue();
		if(!kind.equalsIgnoreCase("ReplicaSet")){
			loadPodsAndContainer(kind,namespace , externalPodsMap, numCount);
			continue;
		}
		
		JsonNode labelsNode = metadataNode.get("labels");
		if (labelsNode == null) {
			logger.info("The labelsNode is null for the pod - " + podName + " in the namespace - " + namespace);
			continue;
		}
		Map<String, String> podLabelMap = mapper.convertValue(labelsNode, Map.class);
		List<ServiceLabelVO> servLblList = depLabelMap.get(namespace);
		if(servLblList == null){
			continue;
		}
		serviceLabelLoop: for (ServiceLabelVO servLabelVo : servLblList) {
			int labelCount = 0;
			for (Entry<String, String> labelInfo : servLabelVo.getLabel().entrySet()) {
				if (podLabelMap.containsKey(labelInfo.getKey())) {
					if (podLabelMap.get(labelInfo.getKey()).equals(labelInfo.getValue())) {
						labelCount = labelCount + 1;
					} else {
						continue serviceLabelLoop;
					}
				} else {
					continue serviceLabelLoop;
				}
			}
			if (servLabelVo.getLabel().size() == labelCount) {
				
				servLabelVo.setNumOfContainers(servLabelVo.getNumOfContainers() + numCount);
				servLabelVo.setNumOfPods(servLabelVo.getNumOfPods() + 1);
				break;
			}
		}
	}
	
}
 
Example 20
Source File: ColumnTypeUtil.java    From Cubert with Apache License 2.0 3 votes vote down vote up
/**
 * Generates the ColumnType array for the specified JsonNode.
 * <p>
 * The JsonNode can be:
 * <ul>
 * <li>a string of form "{@literal <data type> <column name>, ...}"</li>
 * 
 * <li>a json node that conforms to the ColumnType.json schema</li>
 * </ul>
 * 
 * @param node
 *            the json node
 * @return the ColumnType array
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
public static ColumnType[] getColumnTypes(JsonNode node) throws IOException
{
    if (node.isTextual())
    {
        String str = node.getTextValue();
        return getColumnTypes(str);
    }
    else
    {
        return getMapper().readValue(node.toString(), ColumnType[].class);
    }
}