* Copyright (C) 2017 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
package org.onap.clamp.clds.client.req;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
import org.onap.clamp.clds.model.prop.Global;
import org.onap.clamp.clds.model.prop.ModelProperties;
+import org.onap.clamp.clds.model.prop.ResourceGroup;
import org.onap.clamp.clds.model.prop.ServiceConfiguration;
import org.onap.clamp.clds.model.prop.StringMatch;
import org.onap.clamp.clds.model.refprop.RefProp;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.logging.Logger;
-
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* Construct a Policy for String Match Micro Service request given CLDS objects.
*/
public class StringMatchPolicyReq {
- // currently uses the java.util.logging.Logger like the Camunda engine
- private static final Logger logger = Logger.getLogger(StringMatchPolicyReq.class.getName());
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(StringMatchPolicyReq.class);
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
/**
* Format Policy String Match request.
Global global = prop.getGlobal();
String service = global.getService();
- StringMatch sm = prop.getStringMatch();
+ StringMatch sm = prop.getType(StringMatch.class);
prop.setCurrentModelElementId(sm.getId());
ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("sm.template", service);
-
- // "policyName":
rootNode.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
-
- // "content":{
ObjectNode content = rootNode.with("content");
-
- // "closedLoopControlName":
- content.put("closedLoopControlName", prop.getControlName());
-
- // "serviceConfigurations":[
- appendServiceConfigurations(refProp, service, content, sm);
+ appendServiceConfigurations(refProp, service, content, sm, prop);
String stringMatchPolicyReq = rootNode.toString();
logger.info("stringMatchPolicyReq=" + stringMatchPolicyReq);
* @param sm
* @throws IOException
*/
- public static void appendServiceConfigurations(RefProp refProp, String service, ObjectNode appendToNode, StringMatch sm) throws IOException {
- // "serviceConfigurations":{
+ public static void appendServiceConfigurations(RefProp refProp, String service, ObjectNode appendToNode,
+ StringMatch sm, ModelProperties prop) throws IOException {
+ // "serviceConfigurations":{
ObjectNode scNodes = appendToNode.with("serviceConfigurations");
- Iterator<ServiceConfiguration> scItr = sm.getServiceConfigurations().iterator();
int index = 0;
- while (scItr.hasNext()) {
- ServiceConfiguration sc = scItr.next();
-
- //"ItemX":{
- index++;
- String keyValue = "Item" + index;
- ObjectNode scNode = (ObjectNode) refProp.getJsonTemplate("sm.sc.template", service);
- scNodes.set(keyValue, scNode);
-
- // "rulegroup":"abc",
- String rulegroupInd = refProp.getStringValue("sm.rulegroup", service);
- String groupNumber = sc.getGroupNumber();
- if (rulegroupInd != null && rulegroupInd.equalsIgnoreCase("true") && groupNumber != null && groupNumber.length() > 0) {
-
- //String rulegroup = (sc.getResourceVf() == null ? "" : String.join(" ", sc.getResourceVf())) + " - " + (sc.getResourceVfc() == null ? "" : String.join(" ", sc.getResourceVfc()));
- scNode.put("rulegroup", groupNumber);
- }
-
- // "aaiMatchingFields" : ["VM_NAME"],
- JsonUtil.addArrayField(scNode, "aaiMatchingFields", sc.getaaiMatchingFields());
- // "aaiSendFields" : ["VMID", "TenantID"],
- JsonUtil.addArrayField(scNode, "aaiSendFields", sc.getaaiSendFields());
-
- // "stringSet": [
- ArrayNode ssNode = scNode.putArray("stringSet");
- // ObjectNode ssNode = scNode.with("stringSet");
- for (Entry<String, String> entry : sc.getStringSet().entrySet()) {
- // exclude eventSourceType
- if (!entry.getKey().equals("eventSourceType")) {
- ssNode.add(entry.getKey());
- ssNode.add(entry.getValue());
+ if (sm != null && sm.getResourceGroups() != null) {
+ for (ResourceGroup resourceGroup : sm.getResourceGroups()) {
+ Iterator<ServiceConfiguration> scItr = resourceGroup.getServiceConfigurations().iterator();
+
+ while (scItr.hasNext()) {
+ ServiceConfiguration sc = scItr.next();
+
+ // "ItemX":{
+ index++;
+ String keyValue = "Item" + index;
+ ObjectNode scNode = (ObjectNode) refProp.getJsonTemplate("sm.sc.template", service);
+ scNodes.set(keyValue, scNode);
+
+ // "rulegroup":"abc",
+ String rulegroupInd = refProp.getStringValue("sm.rulegroup", service);
+ String groupNumber = resourceGroup.getGroupNumber();
+ if (rulegroupInd != null && rulegroupInd.equalsIgnoreCase("true") && groupNumber != null
+ && groupNumber.length() > 0) {
+ scNode.put("rulegroup", groupNumber);
+ }
+
+ // "closedLoopControlName":
+ prop.setPolicyUniqueId(resourceGroup.getPolicyId());
+ scNode.put("closedLoopControlName", prop.getControlNameAndPolicyUniqueId());
+
+ // "aaiMatchingFields" : ["VM_NAME"],
+ JsonUtil.addArrayField(scNode, "aaiMatchingFields", sc.getaaiMatchingFields());
+ // "aaiSendFields" : ["VMID", "TenantID"],
+ JsonUtil.addArrayField(scNode, "aaiSendFields", sc.getaaiSendFields());
+
+ // "stringSet": [
+ ArrayNode ssNode = scNode.putArray("stringSet");
+
+ for (Entry<String, String> entry : sc.getStringSet().entrySet()) {
+ // exclude eventSourceType
+ if (!entry.getKey().equals("eventSourceType")) {
+ ssNode.add(entry.getKey());
+ ssNode.add(entry.getValue());
+ }
+ }
+
+ // timeWindow": "0",
+ scNode.put("timeWindow", sc.getTimeWindow());
+ // "ageLimit": "3600",
+ scNode.put("ageLimit", sc.getAgeLimit());
+ // "createClosedLoopEventId" : "Initial",
+ scNode.put("createClosedLoopEventId", sc.getCreateClosedLoopEventId());
+ // "outputEventName": "OnSet"
+ scNode.put("outputEventName", sc.getOutputEventName());
}
}
-
- // timeWindow": "0",
- scNode.put("timeWindow", sc.getTimeWindow());
- // "ageLimit": "3600",
- scNode.put("ageLimit", sc.getAgeLimit());
- // "createClosedLoopEventId" : "Initial",
- scNode.put("createClosedLoopEventId", sc.getCreateClosedLoopEventId());
- // "outputEventName": "OnSet"
- scNode.put("outputEventName", sc.getOutputEventName());
}
}
-
}