* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* limitations under the License.
* ============LICENSE_END============================================
* ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.clamp.clds.client.req.tca;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml;
import java.io.IOException;
import java.util.Map;
+import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.exception.TcaRequestFormatterException;
-import org.onap.clamp.clds.model.prop.ModelProperties;
-import org.onap.clamp.clds.model.prop.Tca;
-import org.onap.clamp.clds.model.prop.TcaItem;
-import org.onap.clamp.clds.model.prop.TcaThreshold;
-import org.onap.clamp.clds.model.refprop.RefProp;
+import org.onap.clamp.clds.model.properties.ModelProperties;
+import org.onap.clamp.clds.model.properties.Tca;
+import org.onap.clamp.clds.model.properties.TcaItem;
+import org.onap.clamp.clds.model.properties.TcaThreshold;
+import org.yaml.snakeyaml.Yaml;
/**
* Construct the requests for TCA policy and SDC.
- *
*/
public class TcaRequestFormatter {
- protected static final EELFLogger logger = EELFManager.getInstance().getLogger(TcaRequestFormatter.class);
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(TcaRequestFormatter.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
/**
* The Model Prop created from BPMN JSON and BPMN properties JSON
* @return The Json string containing that should be sent to policy
*/
- public static String createPolicyJson(RefProp refProp, ModelProperties modelProperties) {
+ public static String createPolicyJson(ClampProperties refProp, ModelProperties modelProperties) {
try {
String service = modelProperties.getGlobal().getService();
Tca tca = modelProperties.getType(Tca.class);
modelProperties.setCurrentModelElementId(tca.getId());
+ // Always one tcaItem so must be set to id 0
+ modelProperties.setPolicyUniqueId("0");
ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.policy.template", service);
String policyName = modelProperties.getCurrentPolicyScopeAndPolicyName();
rootNode.put("policyName", policyName);
- rootNode.put("description", "MicroService vCPE Policy");
((ObjectNode) rootNode.get("content")).replace("tca_policy",
createPolicyContent(refProp, modelProperties, service, policyName, tca));
String tcaPolicyReq = rootNode.toString();
* modelProperties.setCurrentModelElementId will be used
* @return The Json node containing what should be sent to policy
*/
- public static JsonNode createPolicyContent(RefProp refProp, ModelProperties modelProperties, String service,
+ public static JsonNode createPolicyContent(ClampProperties refProp, ModelProperties modelProperties, String service,
String policyName, Tca tca) {
try {
String serviceToUse = service;
* The Model Properties created from BPMN JSON and BPMN
* properties JSON
*/
- private static void addThresholds(RefProp refProp, String service, ObjectNode appendToNode, TcaItem tcaItem,
+ private static void addThresholds(ClampProperties refProp, String service, ObjectNode appendToNode, TcaItem tcaItem,
ModelProperties modelProperties) {
ArrayNode tcaNodes = appendToNode.withArray("thresholds");
- ObjectNode tcaNode;
try {
- tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
for (TcaThreshold tcaThreshold : tcaItem.getTcaThresholds()) {
+ ObjectNode tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
tcaNode.put("closedLoopControlName", modelProperties.getControlNameAndPolicyUniqueId());
tcaNode.put("fieldPath", tcaThreshold.getFieldPath());
tcaNode.put("thresholdValue", tcaThreshold.getThreshold());
* The yaml string received from the UI
* @return The updated YAML as a string
*/
- public static String updatedBlueprintWithConfiguration(RefProp refProp, ModelProperties modelProperties,
+ public static String updatedBlueprintWithConfiguration(ClampProperties refProp, ModelProperties modelProperties,
String yamlValue) {
String jsonPolicy = ((ObjectNode) createPolicyContent(refProp, modelProperties, null, null, null)).toString();
logger.info("Yaml that will be updated:" + yamlValue);