1 package org.onap.clamp.clds.client.req;
3 import java.io.IOException;
4 import java.util.Iterator;
5 import java.util.logging.Logger;
7 import org.onap.clamp.clds.model.prop.Global;
8 import org.onap.clamp.clds.model.prop.ModelProperties;
9 import org.onap.clamp.clds.model.prop.Tca;
10 import org.onap.clamp.clds.model.prop.TcaItem;
11 import org.onap.clamp.clds.model.prop.TcaThreshhold;
12 import org.onap.clamp.clds.model.refprop.RefProp;
13 import com.fasterxml.jackson.core.JsonParseException;
14 import com.fasterxml.jackson.databind.JsonMappingException;
15 import com.fasterxml.jackson.databind.node.ArrayNode;
16 import com.fasterxml.jackson.databind.node.ObjectNode;
19 * Construct a Policy for Tca/MTca Service request given CLDS objects.
23 public class TcaMPolicyReq {
24 private static final Logger logger = Logger.getLogger(StringMatchPolicyReq.class.getName());
27 * Format Tca Policy request
32 * @throws JsonParseException
33 * @throws JsonMappingException
36 public static String formatTca(RefProp refProp, ModelProperties prop) throws JsonParseException, JsonMappingException, IOException {
37 Global global = prop.getGlobal();
38 String service = global.getService();
40 Tca tca = prop.getTca();
41 prop.setCurrentModelElementId(tca.getId());
42 ObjectNode rootNode = (ObjectNode)refProp.getJsonTemplate("tca.template", service);
43 rootNode.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
44 ObjectNode content = rootNode.with("content");
45 appendSignatures(refProp, service, content, tca, prop);
47 String tcaPolicyReq = rootNode.toString();
48 logger.info("tcaPolicyReq=" + tcaPolicyReq);
53 * Add appendSignatures to json
60 * @throws JsonParseException
61 * @throws JsonMappingException
64 public static void appendSignatures(RefProp refProp, String service, ObjectNode appendToNode, Tca tca, ModelProperties prop) throws JsonParseException, JsonMappingException, IOException {
66 ArrayNode tcaNodes = appendToNode.withArray("signatures");
67 for(TcaItem tcaItem : tca.getTcaItems()){
68 ObjectNode tcaNode = (ObjectNode)refProp.getJsonTemplate("tca.signature.template", service);
69 tcaNode.put("useCaseName", tcaItem.getTcaName());
70 tcaNode.put("signatureName", tcaItem.getTcaName()+ "_" + tcaItem.getTcaUuId());
71 tcaNode.put("signatureUuid", tcaItem.getTcaUuId());
72 prop.setPolicyUniqueId(tcaItem.getPolicyId());
73 tcaNode.put("closedLoopControlName", prop.getControlNameAndPolicyUniqueId());
74 tcaNode.put("severity", tcaItem.getSeverity());
75 tcaNode.put("maxInterval", tcaItem.getInterval());
76 tcaNode.put("minMessageViolations", tcaItem.getViolations());
78 tcaNodes.add(tcaNode);
79 Iterator<TcaThreshhold> scItr = tcaItem.getTcaThreshholds().iterator();
80 while(scItr.hasNext()) {
81 TcaThreshhold tcaThreshhold = scItr.next();
83 ArrayNode thNodes = tcaNode.withArray("thresholds");
84 ObjectNode thNode = thNodes.addObject();
85 thNode.put("fieldPath", tcaThreshhold.getFieldPath());
86 thNode.put("thresholdName", tcaThreshhold.getMetric());
87 thNode.put("thresholdValue", tcaThreshhold.getThreshhold());
88 thNode.put("direction", tcaThreshhold.getOperator());