aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyClient.java12
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java56
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java10
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/TcaThreshold.java14
4 files changed, 58 insertions, 34 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
index cb86acbd..54b3fbb4 100644
--- a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
@@ -37,6 +37,7 @@ import java.util.UUID;
import javax.ws.rs.BadRequestException;
+import org.onap.clamp.clds.client.req.TcaRequestFormatter;
import org.onap.clamp.clds.exception.policy.PolicyClientException;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
@@ -62,7 +63,6 @@ import org.springframework.context.ApplicationContext;
* Policy utility methods - specifically, send the policy.
*/
public class PolicyClient {
-
protected static final String POLICY_PREFIX_BASE = "Config_";
protected static final String POLICY_PREFIX_BRMS_PARAM = "Config_BRMS_Param_";
protected static final String POLICY_PREFIX_MICROSERVICE = "Config_MS_";
@@ -110,8 +110,6 @@ public class PolicyClient {
// Data Issue: No policyDescription given.
policyParameters.setPolicyDescription(refProp.getStringValue("op.policyDescription"));
- policyParameters.setAttributes(attributes);
-
// Set a random UUID(Mandatory)
policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
String policyNamePrefix = refProp.getStringValue("policy.op.policyNamePrefix");
@@ -213,16 +211,12 @@ public class PolicyClient {
public String sendMicroServiceInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
-
- // Set Policy Type
+ // Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
+ policyParameters.setOnapName("DCAE");
policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
-
policyParameters.setConfigBody(configBody);
- policyParameters.setConfigBodyType(PolicyType.OTHER);
-
- policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
// Adding this line to clear the policy id from policy name while
diff --git a/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java
index c2590d76..a71a5f37 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java
@@ -27,6 +27,7 @@ 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;
+import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml;
import java.util.HashMap;
@@ -70,16 +71,11 @@ public class TcaRequestFormatter {
Tca tca = modelProperties.getType(Tca.class);
modelProperties.setCurrentModelElementId(tca.getId());
- ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service);
- ((ObjectNode) rootNode.get("cdap-tca-hi-lo_policy").get("metricsPerEventName").get(0)).put("policyName",
- modelProperties.getCurrentPolicyScopeAndPolicyName());
- ((ObjectNode) rootNode.get("cdap-tca-hi-lo_policy").get("metricsPerEventName").get(0)).put("eventName",
- tca.getTcaItem().getEventName());
-
- ObjectNode thresholdsParent = ((ObjectNode) rootNode.get("cdap-tca-hi-lo_policy").get("metricsPerEventName")
- .get(0));
-
- addThresholds(refProp, service, thresholdsParent, tca.getTcaItem(), modelProperties);
+ ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.policy.template", service);
+ String policyName = refProp.getStringValue("tca.policyid.prefix") + modelProperties.getCurrentPolicyScopeAndPolicyName();
+ ((ObjectNode) rootNode).put("policyName", policyName);
+ ((ObjectNode) rootNode).put("description", "MicroService vCPE Policy");
+ ((ObjectNode) rootNode).replace("content", createPolicyContent(refProp, modelProperties, service, policyName, tca));
String tcaPolicyReq = rootNode.toString();
logger.info("tcaPolicyReq=" + tcaPolicyReq);
@@ -90,6 +86,43 @@ public class TcaRequestFormatter {
}
/**
+ * Format Tca Policy Content JSON
+ *
+ * @param refProp
+ * The refProp generally created by Spring, it's an access on the
+ * clds-references.properties file
+ * @param modelProperties
+ * The Model Prop created from BPMN JSON and BPMN properties JSON
+ * @return The Json string containing that should be sent to policy
+ */
+ public static JsonNode createPolicyContent(RefProp refProp, ModelProperties modelProperties, String service, String policyName, Tca tca) {
+ try {
+ if (null == service) {
+ service = modelProperties.getGlobal().getService();
+ }
+ if (null == tca){
+ tca = modelProperties.getType(Tca.class);
+ modelProperties.setCurrentModelElementId(tca.getId());
+ }
+ if (null == policyName) {
+ policyName = refProp.getStringValue("tca.policyid.prefix") + modelProperties.getCurrentPolicyScopeAndPolicyName();
+ }
+ ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service);
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("eventName", tca.getTcaItem().getEventName());
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("policyName", policyName);
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("controlLoopSchemaType", tca.getTcaItem().getControlLoopSchemaType());
+ ObjectNode thresholdsParent = ((ObjectNode) rootNode.get("metricsPerEventName").get(0));
+
+ addThresholds(refProp, service, thresholdsParent, tca.getTcaItem(), modelProperties);
+
+ logger.info("tcaPolicyContent=" + rootNode.toString());
+ return (JsonNode) rootNode;
+ } catch (Exception e) {
+ throw new TcaRequestFormatterException("Exception caught when attempting to create the policy content JSON", e);
+ }
+ }
+
+ /**
* Add threshold values to the existing policy JSON.
*
* @param refProp
@@ -114,7 +147,6 @@ public class TcaRequestFormatter {
ObjectNode tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
for (TcaThreshold tcaThreshold : tcaItem.getTcaThresholds()) {
- tcaNode.put("controlLoopSchema", tcaThreshold.getControlLoopSchema());
tcaNode.put("closedLoopControlName", modelProperties.getControlNameAndPolicyUniqueId());
tcaNode.put("fieldPath", tcaThreshold.getFieldPath());
tcaNode.put("thresholdValue", tcaThreshold.getThreshold());
@@ -143,7 +175,7 @@ public class TcaRequestFormatter {
public static String updatedBlueprintWithConfiguration(RefProp refProp, ModelProperties modelProperties,
String yamlValue) {
try {
- String jsonPolicy = createPolicyJson(refProp, modelProperties);
+ String jsonPolicy = ((ObjectNode) createPolicyContent(refProp, modelProperties, null, null, null)).toString();
logger.info("Yaml that will be updated:" + yamlValue);
Yaml yaml = new Yaml();
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java b/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
index 79da2db0..13bff002 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/TcaItem.java
@@ -44,6 +44,7 @@ public class TcaItem {
private String tcaUuId;
private String policyId;
private String eventName;
+ private String controlLoopSchemaType;
private List<TcaThreshold> tcaThresholds;
/**
@@ -57,6 +58,7 @@ public class TcaItem {
tcaUuId = AbstractModelElement.getValueByName(node, "tuuid");
policyId = AbstractModelElement.getValueByName(node, "tcaPolId");
eventName = AbstractModelElement.getValueByName(node, "eventName");
+ controlLoopSchemaType = AbstractModelElement.getValueByName(node, "controlLoopSchemaType");
// process service Configurations
JsonNode serviceConfigurationsNode = node.get(node.size() - 1).get("serviceConfigurations");
Iterator<JsonNode> itr = serviceConfigurationsNode.elements();
@@ -66,6 +68,14 @@ public class TcaItem {
}
}
+ public String getControlLoopSchemaType() {
+ return controlLoopSchemaType;
+ }
+
+ public void setControlLoopSchemaType(String controlLoopSchemaType) {
+ this.controlLoopSchemaType = controlLoopSchemaType;
+ }
+
public String getTcaName() {
return tcaName;
}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/TcaThreshold.java b/src/main/java/org/onap/clamp/clds/model/prop/TcaThreshold.java
index 43bdb5c1..d278c254 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/TcaThreshold.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/TcaThreshold.java
@@ -40,7 +40,6 @@ public class TcaThreshold {
private String operator;
private Integer threshold;
private String closedLoopEventStatus;
- private String controlLoopSchema;
/**
* Parse Tca Threshhold given json node
@@ -59,10 +58,7 @@ public class TcaThreshold {
threshold = Integer.valueOf(node.get(2).asText());
}
if (node.get(3) != null) {
- controlLoopSchema = node.get(3).asText();
- }
- if (node.get(4) != null) {
- closedLoopEventStatus = node.get(4).asText();
+ closedLoopEventStatus = node.get(3).asText();
}
}
@@ -97,12 +93,4 @@ public class TcaThreshold {
public void setClosedLoopEventStatus(String closedLoopEventStatus) {
this.closedLoopEventStatus = closedLoopEventStatus;
}
-
- public String getControlLoopSchema() {
- return controlLoopSchema;
- }
-
- public void setControlLoopSchema(String controlLoopSchema) {
- this.controlLoopSchema = controlLoopSchema;
- }
}