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;
28 import java.util.Map.Entry;
30 import org.onap.clamp.clds.model.prop.Global;
31 import org.onap.clamp.clds.model.prop.ModelProperties;
32 import org.onap.clamp.clds.model.prop.ResourceGroup;
33 import org.onap.clamp.clds.model.prop.ServiceConfiguration;
34 import org.onap.clamp.clds.model.prop.StringMatch;
35 import org.onap.clamp.clds.model.refprop.RefProp;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39 import com.fasterxml.jackson.databind.node.ArrayNode;
40 import com.fasterxml.jackson.databind.node.ObjectNode;
43 * Construct a Policy for String Match Micro Service request given CLDS objects.
45 public class StringMatchPolicyReq {
46 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(StringMatchPolicyReq.class);
47 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
50 * Format Policy String Match request.
57 public static String format(RefProp refProp, ModelProperties prop) throws IOException {
58 Global global = prop.getGlobal();
59 String service = global.getService();
61 StringMatch sm = prop.getType(StringMatch.class);
62 prop.setCurrentModelElementId(sm.getId());
63 ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("sm.template", service);
64 rootNode.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
65 ObjectNode content = rootNode.with("content");
66 appendServiceConfigurations(refProp, service, content, sm, prop);
68 String stringMatchPolicyReq = rootNode.toString();
69 logger.info("stringMatchPolicyReq=" + stringMatchPolicyReq);
70 return stringMatchPolicyReq;
74 * Add serviceConfigurations to json
80 public static void appendServiceConfigurations(RefProp refProp, String service, ObjectNode appendToNode,
81 StringMatch sm, ModelProperties prop) throws IOException {
82 // "serviceConfigurations":{
83 ObjectNode scNodes = appendToNode.with("serviceConfigurations");
86 if (sm != null && sm.getResourceGroups() != null) {
87 for (ResourceGroup resourceGroup : sm.getResourceGroups()) {
88 Iterator<ServiceConfiguration> scItr = resourceGroup.getServiceConfigurations().iterator();
90 while (scItr.hasNext()) {
91 ServiceConfiguration sc = scItr.next();
95 String keyValue = "Item" + index;
96 ObjectNode scNode = (ObjectNode) refProp.getJsonTemplate("sm.sc.template", service);
97 scNodes.set(keyValue, scNode);
100 String rulegroupInd = refProp.getStringValue("sm.rulegroup", service);
101 String groupNumber = resourceGroup.getGroupNumber();
102 if (rulegroupInd != null && rulegroupInd.equalsIgnoreCase("true") && groupNumber != null
103 && groupNumber.length() > 0) {
104 scNode.put("rulegroup", groupNumber);
107 // "closedLoopControlName":
108 prop.setPolicyUniqueId(resourceGroup.getPolicyId());
109 scNode.put("closedLoopControlName", prop.getControlNameAndPolicyUniqueId());
111 // "aaiMatchingFields" : ["VM_NAME"],
112 JsonUtil.addArrayField(scNode, "aaiMatchingFields", sc.getaaiMatchingFields());
113 // "aaiSendFields" : ["VMID", "TenantID"],
114 JsonUtil.addArrayField(scNode, "aaiSendFields", sc.getaaiSendFields());
117 ArrayNode ssNode = scNode.putArray("stringSet");
119 for (Entry<String, String> entry : sc.getStringSet().entrySet()) {
120 // exclude eventSourceType
121 if (!entry.getKey().equals("eventSourceType")) {
122 ssNode.add(entry.getKey());
123 ssNode.add(entry.getValue());
128 scNode.put("timeWindow", sc.getTimeWindow());
129 // "ageLimit": "3600",
130 scNode.put("ageLimit", sc.getAgeLimit());
131 // "createClosedLoopEventId" : "Initial",
132 scNode.put("createClosedLoopEventId", sc.getCreateClosedLoopEventId());
133 // "outputEventName": "OnSet"
134 scNode.put("outputEventName", sc.getOutputEventName());