2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.client.req;
26 import java.io.IOException;
27 import java.util.Iterator;
29 import org.onap.clamp.clds.model.prop.Global;
30 import org.onap.clamp.clds.model.prop.ModelProperties;
31 import org.onap.clamp.clds.model.prop.Tca;
32 import org.onap.clamp.clds.model.prop.TcaItem;
33 import org.onap.clamp.clds.model.prop.TcaThreshhold;
34 import org.onap.clamp.clds.model.refprop.RefProp;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import com.fasterxml.jackson.core.JsonParseException;
39 import com.fasterxml.jackson.databind.JsonMappingException;
40 import com.fasterxml.jackson.databind.node.ArrayNode;
41 import com.fasterxml.jackson.databind.node.ObjectNode;
44 * Construct a Policy for Tca/MTca Service request given CLDS objects.
48 public class TcaMPolicyReq {
49 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(TcaMPolicyReq.class);
50 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
53 * Format Tca Policy request
58 * @throws JsonParseException
59 * @throws JsonMappingException
62 public static String formatTca(RefProp refProp, ModelProperties prop)
63 throws JsonParseException, JsonMappingException, IOException {
64 Global global = prop.getGlobal();
65 String service = global.getService();
67 Tca tca = prop.getType(Tca.class);
68 prop.setCurrentModelElementId(tca.getId());
69 ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service);
70 rootNode.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
71 ObjectNode content = rootNode.with("content");
72 appendSignatures(refProp, service, content, tca, prop);
74 String tcaPolicyReq = rootNode.toString();
75 logger.info("tcaPolicyReq=" + tcaPolicyReq);
80 * Add appendSignatures to json
87 * @throws JsonParseException
88 * @throws JsonMappingException
91 public static void appendSignatures(RefProp refProp, String service, ObjectNode appendToNode, Tca tca,
92 ModelProperties prop) throws JsonParseException, JsonMappingException, IOException {
94 ArrayNode tcaNodes = appendToNode.withArray("signatures");
95 for (TcaItem tcaItem : tca.getTcaItems()) {
96 ObjectNode tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.signature.template", service);
97 tcaNode.put("useCaseName", tcaItem.getTcaName());
98 tcaNode.put("signatureName", tcaItem.getTcaName() + "_" + tcaItem.getTcaUuId());
99 tcaNode.put("signatureUuid", tcaItem.getTcaUuId());
100 prop.setPolicyUniqueId(tcaItem.getPolicyId());
101 tcaNode.put("closedLoopControlName", prop.getControlNameAndPolicyUniqueId());
102 tcaNode.put("severity", tcaItem.getSeverity());
103 tcaNode.put("maxInterval", tcaItem.getInterval());
104 tcaNode.put("minMessageViolations", tcaItem.getViolations());
106 tcaNodes.add(tcaNode);
107 Iterator<TcaThreshhold> scItr = tcaItem.getTcaThreshholds().iterator();
108 while (scItr.hasNext()) {
109 TcaThreshhold tcaThreshhold = scItr.next();
111 ArrayNode thNodes = tcaNode.withArray("thresholds");
112 ObjectNode thNode = thNodes.addObject();
113 thNode.put("fieldPath", tcaThreshhold.getFieldPath());
114 thNode.put("thresholdName", tcaThreshhold.getMetric());
115 thNode.put("thresholdValue", tcaThreshhold.getThreshhold());
116 thNode.put("direction", tcaThreshhold.getOperator());