aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxg353y <xg353y@intl.att.com>2019-03-28 10:05:25 +0100
committerxg353y <xg353y@intl.att.com>2019-03-28 10:05:25 +0100
commita6d09fbe1046057b72247f97ac72a521949409ce (patch)
tree8542f7b7f3afb888bc6c76189b265716be64c83d
parentc62d1b74275b8d5e9d4cef6c308ef16440cfa500 (diff)
Rework the submit operation
Rework the logic to create/delete ms config policies. Issue-ID: CLAMP-303 Change-Id: I317e262ab68280a7518a6e31e82e5fcb0a7f94ed Signed-off-by: xg353y <xg353y@intl.att.com>
-rw-r--r--extra/sql/bulkload/create-tables.sql2
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java2
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java27
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java22
-rw-r--r--src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java4
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java2
-rw-r--r--src/main/java/org/onap/clamp/operation/LoopOperation.java164
-rw-r--r--src/main/java/org/onap/clamp/policy/PolicyOperation.java131
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java30
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java4
-rw-r--r--src/main/java/org/onap/clamp/util/HttpConnectionManager.java36
-rw-r--r--src/main/resources/META-INF/resources/designer/scripts/CldsModelService.js2
-rw-r--r--src/main/resources/application-noaaf.properties3
-rw-r--r--src/main/resources/application.properties3
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml18
-rw-r--r--src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java12
-rw-r--r--src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java10
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java15
-rw-r--r--src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java24
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java8
-rw-r--r--src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java1
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java8
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java18
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java8
-rw-r--r--src/test/resources/application.properties3
-rw-r--r--src/test/resources/clds/blueprint-with-microservice-chain.yaml6
-rw-r--r--src/test/resources/clds/single-microservice-fragment-valid.yaml2
28 files changed, 492 insertions, 77 deletions
diff --git a/extra/sql/bulkload/create-tables.sql b/extra/sql/bulkload/create-tables.sql
index b35606353..29e0facda 100644
--- a/extra/sql/bulkload/create-tables.sql
+++ b/extra/sql/bulkload/create-tables.sql
@@ -35,7 +35,9 @@
create table micro_service_policies (
name varchar(255) not null,
+ blueprint_name varchar(255) not null,
json_representation json not null,
+ model_type varchar(255) not null,
policy_tosca MEDIUMTEXT not null,
properties json,
shared bit not null,
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
index e2a4c2f48..0f4659591 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
@@ -99,7 +99,7 @@ public class DcaeDispatcherServices {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getOperationStatus");
try {
- String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(statusUrl, "GET", null, null, "DCAE");
+ String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(statusUrl, "GET", null, null, "DCAE", null, null);
JSONObject jsonObj = parseResponse(responseStr);
String operationType = (String) jsonObj.get("operationType");
String status = (String) jsonObj.get(DCAE_STATUS_FIELD);
@@ -190,7 +190,7 @@ public class DcaeDispatcherServices {
String nodeAttr) throws IOException, ParseException {
Date startTime = new Date();
try {
- String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(url, requestMethod, payload, contentType, "DCAE");
+ String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(url, requestMethod, payload, contentType, "DCAE", null, null);
JSONObject jsonObj = parseResponse(responseStr);
JSONObject linksObj = (JSONObject) jsonObj.get(node);
String statusUrl = (String) linksObj.get(nodeAttr);
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index 63fdc6187..d8bfeeaec 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -207,7 +207,7 @@ public class DcaeInventoryServices {
}
for (int i = 0; i < retryLimit; i++) {
metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");
- String response = httpConnectionManager.doGeneralHttpQuery(fullUrl, "GET", null, null, "DCAE");
+ String response = httpConnectionManager.doGeneralHttpQuery(fullUrl, "GET", null, null, "DCAE", null, null);
int totalCount = getTotalCountFromDcaeInventoryResponse(response);
metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);
if (totalCount > 0) {
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
index c8de4c589..7447fbae1 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
@@ -27,6 +27,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import java.util.Collections;
import java.util.HashSet;
@@ -51,6 +52,8 @@ public class BlueprintParser {
private static final String TYPE = "type";
private static final String PROPERTIES = "properties";
private static final String NAME = "name";
+ private static final String POLICYID = "policy_id";
+ private static final String POLICY_TYPEID = "policy_type_id";
private static final String RELATIONSHIPS = "relationships";
private static final String CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM = "clamp_node.relationships.gets_input_from";
private static final String TARGET = "target";
@@ -85,7 +88,7 @@ public class BlueprintParser {
}
}
String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA;
- return Collections.singletonList(new MicroService(msName, "", ""));
+ return Collections.singletonList(new MicroService(msName, "", "", "", ""));
}
String getName(Entry<String, JsonElement> entry) {
@@ -114,10 +117,30 @@ public class BlueprintParser {
return "";
}
+ String getModelType(Entry<String, JsonElement> entry) {
+ JsonObject ob = entry.getValue().getAsJsonObject();
+ if (ob.has(PROPERTIES)) {
+ JsonObject properties = ob.get(PROPERTIES).getAsJsonObject();
+ if (properties.has(POLICYID)) {
+ JsonObject policyIdObj = properties.get(POLICYID).getAsJsonObject();
+ if (policyIdObj.has(POLICY_TYPEID)) {
+ return policyIdObj.get(POLICY_TYPEID).getAsString();
+ }
+ }
+ }
+ return "";
+ }
+
+ String getBlueprintName(Entry<String, JsonElement> entry) {
+ return entry.getKey();
+ }
+
MicroService getNodeRepresentation(Entry<String, JsonElement> entry) {
String name = getName(entry);
String getInputFrom = getInput(entry);
- return new MicroService(name, getInputFrom, "");
+ String modelType = getModelType(entry);
+ String blueprintName = getBlueprintName(entry);
+ return new MicroService(name, modelType, getInputFrom, "", blueprintName);
}
private String getTarget(JsonObject elementObject) {
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
index 198bf0ede..a785f41ef 100644
--- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
@@ -27,27 +27,39 @@ import java.util.Objects;
public class MicroService {
private final String name;
+ private final String modelType;
+ private final String blueprintName;
private final String inputFrom;
private String mappedNameJpa;
- public MicroService(String name, String inputFrom, String mappedNameJpa) {
+ public MicroService(String name, String modelType, String inputFrom, String mappedNameJpa, String blueprintName) {
this.name = name;
this.inputFrom = inputFrom;
this.mappedNameJpa = mappedNameJpa;
+ this.modelType = modelType;
+ this.blueprintName = blueprintName;
}
public String getName() {
return name;
}
+ public String getModelType() {
+ return modelType;
+ }
+
public String getInputFrom() {
return inputFrom;
}
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
@Override
public String toString() {
- return "MicroService{" + "name='" + name + '\'' + ", inputFrom='" + inputFrom + '\'' + ", mappedNameJpa='"
- + mappedNameJpa + '\'' + '}';
+ return "MicroService{" + "name='" + name + '\'' + ", modelType='" + modelType + '\'' + ", inputFrom='" + inputFrom + '\'' + ", mappedNameJpa='"
+ + mappedNameJpa + '\'' + ", blueprintName='" + blueprintName + '\'' + '}';
}
public String getMappedNameJpa() {
@@ -67,11 +79,11 @@ public class MicroService {
return false;
}
MicroService that = (MicroService) o;
- return name.equals(that.name) && inputFrom.equals(that.inputFrom) && mappedNameJpa.equals(that.mappedNameJpa);
+ return name.equals(that.name) && modelType.equals(that.modelType) && inputFrom.equals(that.inputFrom) && mappedNameJpa.equals(that.mappedNameJpa) && blueprintName.equals(that.blueprintName);
}
@Override
public int hashCode() {
- return Objects.hash(name, inputFrom, mappedNameJpa);
+ return Objects.hash(name, modelType, inputFrom, mappedNameJpa, blueprintName);
}
}
diff --git a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
index fed2c65b7..05d5c480c 100644
--- a/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
+++ b/src/main/java/org/onap/clamp/loop/CsarInstallerImpl.java
@@ -163,8 +163,8 @@ public class CsarInstallerImpl implements CsarInstaller {
Policy.generatePolicyName(microService.getName(), csar.getSdcNotification().getServiceName(),
csar.getSdcNotification().getServiceVersion(),
blueprintArtifact.getResourceAttached().getResourceInstanceName(),
- blueprintArtifact.getBlueprintArtifactName()),
- csar.getPolicyModelYaml().orElse(""), false, new HashSet<>(Arrays.asList(newLoop)));
+ blueprintArtifact.getBlueprintArtifactName()), microService.getModelType(),
+ csar.getPolicyModelYaml().orElse(""), false, new HashSet<>(Arrays.asList(newLoop)), microService.getBlueprintName());
newSet.add(microServicePolicy);
microService.setMappedNameJpa(microServicePolicy.getName());
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 6dc73e987..cc04ce5d2 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -183,7 +183,7 @@ public class Loop implements Serializable {
this.operationalPolicies = operationalPolicies;
}
- Set<MicroServicePolicy> getMicroServicePolicies() {
+ public Set<MicroServicePolicy> getMicroServicePolicies() {
return microServicePolicies;
}
diff --git a/src/main/java/org/onap/clamp/operation/LoopOperation.java b/src/main/java/org/onap/clamp/operation/LoopOperation.java
index af615af11..bdb4b3f0f 100644
--- a/src/main/java/org/onap/clamp/operation/LoopOperation.java
+++ b/src/main/java/org/onap/clamp/operation/LoopOperation.java
@@ -31,6 +31,7 @@ import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Date;
@@ -40,12 +41,15 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.camel.Exchange;
import org.onap.clamp.clds.client.DcaeDispatcherServices;
+import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.clamp.clds.util.ONAPLogConstants;
import org.onap.clamp.exception.OperationException;
import org.onap.clamp.loop.Loop;
import org.onap.clamp.loop.LoopService;
import org.onap.clamp.loop.LoopState;
+import org.onap.clamp.policy.PolicyOperation;
+import org.onap.clamp.util.HttpConnectionManager;
import org.slf4j.event.Level;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@@ -63,14 +67,17 @@ public class LoopOperation {
private final DcaeDispatcherServices dcaeDispatcherServices;
private final LoopService loopService;
private LoggingUtils util = new LoggingUtils(logger);
+ private PolicyOperation policyOp;
@Autowired
private HttpServletRequest request;
@Autowired
- public LoopOperation(LoopService loopService, DcaeDispatcherServices dcaeDispatcherServices) {
+ public LoopOperation(LoopService loopService, DcaeDispatcherServices dcaeDispatcherServices,
+ ClampProperties refProp, HttpConnectionManager httpConnectionManager, PolicyOperation policyOp) {
this.loopService = loopService;
this.dcaeDispatcherServices = dcaeDispatcherServices;
+ this.policyOp = policyOp;
}
/**
@@ -209,4 +216,159 @@ public class LoopOperation {
// otherwise take it as a string
return new JsonPrimitive(String.valueOf(o));
}
+
+ /**
+ * Submit the Ms policies.
+ *
+ * @param loopName the loop name
+ * @return the updated loop
+ * @throws IOException IO exception
+ * @throws Exceptions during the operation
+ */
+ public Loop submitMsPolicies (String loopName) throws OperationException, IOException {
+ util.entering(request, "LoopOperation: delete microservice policies");
+ Date startTime = new Date();
+ Loop loop = loopService.getLoop(loopName);
+
+ if (loop == null) {
+ String msg = "Submit MS policies exception: Not able to find closed loop:" + loopName;
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // verify the current closed loop state
+ if (loop.getLastComputedState() != LoopState.SUBMITTED && loop.getLastComputedState() != LoopState.DESIGN) {
+ String msg = "Submit MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ + ". It could be deleted only when it is in SUBMITTED state.";
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // Establish the api call to Policy to create the ms services
+ policyOp.createMsPolicy(loop.getMicroServicePolicies());
+
+ // audit log
+ LoggingUtils.setTimeContext(startTime, new Date());
+ auditLogger.info("Deletion of MS policies completed");
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return loop;
+ }
+
+
+ /**
+ * Delete the Ms policies.
+ *
+ * @param loopName the loop name
+ * @return the updated loop
+ * @throws IOException IO exception
+ * @throws Exceptions during the operation
+ */
+ public Loop deleteMsPolicies (Exchange camelExchange, String loopName) throws OperationException, IOException {
+ util.entering(request, "LoopOperation: delete microservice policies");
+ Date startTime = new Date();
+ Loop loop = loopService.getLoop(loopName);
+
+ if (loop == null) {
+ String msg = "Delete MS policies exception: Not able to find closed loop:" + loopName;
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // verify the current closed loop state
+ if (loop.getLastComputedState() != LoopState.SUBMITTED) {
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ + ". It could be deleted only when it is in SUBMITTED state.";
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // Establish the api call to Policy to create the ms services
+ policyOp.deleteMsPolicy(loop.getMicroServicePolicies());
+
+ // audit log
+ LoggingUtils.setTimeContext(startTime, new Date());
+ auditLogger.info("Deletion of MS policies completed");
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return loop;
+ }
+
+ /**
+ * Delete the operational policy.
+ *
+ * @param loopName the loop name
+ * @return the updated loop
+ * @throws Exceptions during the operation
+ */
+ public Loop deleteOpPolicy (Exchange camelExchange, String loopName) throws OperationException {
+ util.entering(request, "LoopOperation: delete guard policy");
+ Date startTime = new Date();
+ Loop loop = loopService.getLoop(loopName);
+
+ if (loop == null) {
+ String msg = "Delete guard policy exception: Not able to find closed loop:" + loopName;
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // verify the current closed loop state
+ if (loop.getLastComputedState() != LoopState.SUBMITTED) {
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ + ". It could be deleted only when it is in SUBMITTED state.";
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // Establish the api call to Policy to delete operational policy
+ //client.deleteOpPolicy();
+
+ // audit log
+ LoggingUtils.setTimeContext(startTime, new Date());
+ auditLogger.info("Deletion of Guard policy completed");
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return loop;
+ }
+
+ /**
+ * Delete the Guard policy.
+ *
+ * @param loopName the loop name
+ * @return the updated loop
+ * @throws Exceptions during the operation
+ */
+ public Loop deleteGuardPolicy (Exchange camelExchange, String loopName) throws OperationException {
+ util.entering(request, "LoopOperation: delete operational policy");
+ Date startTime = new Date();
+ Loop loop = loopService.getLoop(loopName);
+
+ if (loop == null) {
+ String msg = "Delete operational policy exception: Not able to find closed loop:" + loopName;
+ util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // verify the current closed loop state
+ if (loop.getLastComputedState() != LoopState.SUBMITTED) {
+ String msg = "Delete MS policies exception: This closed loop is in state:" + loop.getLastComputedState()
+ + ". It could be deleted only when it is in SUBMITTED state.";
+ util.exiting(HttpStatus.CONFLICT.toString(), msg, Level.INFO,
+ ONAPLogConstants.ResponseStatus.ERROR);
+ throw new OperationException(msg);
+ }
+
+ // Establish the api call to Policy to delete Guard policy
+ //client.deleteOpPolicy();
+
+ // audit log
+ LoggingUtils.setTimeContext(startTime, new Date());
+ auditLogger.info("Deletion of operational policy completed");
+ util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, ONAPLogConstants.ResponseStatus.COMPLETED);
+ return loop;
+ }
}
diff --git a/src/main/java/org/onap/clamp/policy/PolicyOperation.java b/src/main/java/org/onap/clamp/policy/PolicyOperation.java
new file mode 100644
index 000000000..592338c4d
--- /dev/null
+++ b/src/main/java/org/onap/clamp/policy/PolicyOperation.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 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.
+ * 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
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ *
+ */
+
+package org.onap.clamp.policy;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.onap.clamp.clds.config.ClampProperties;
+import org.onap.clamp.policy.microservice.MicroServicePolicy;
+import org.onap.clamp.util.HttpConnectionManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
+@Component
+public class PolicyOperation {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyOperation.class);
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ public static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
+ public static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
+ public static final String POLICY_BASENAME_PREFIX_PROPERTY_NAME = "policy.base.policyNamePrefix";
+ public static final String POLICY_OP_NAME_PREFIX_PROPERTY_NAME = "policy.op.policyNamePrefix";
+ public static final String POLICY_MS_NAME_PREFIX_PROPERTY_NAME = "policy.ms.policyNamePrefix";
+ public static final String POLICY_OP_TYPE_PROPERTY_NAME = "policy.op.type";
+ public static final String POLICY_GUARD_SUFFIX = "_Guard";
+ public static final String POLICY_URL_PROPERTY_NAME = "clamp.config.policy.url";
+ public static final String POLICY_URL_SUFFIX = "/versions/1.0.0/policies";
+ public static final String POLICY_USER_NAME = "clamp.config.policy.userName";
+ public static final String POLICY_PASSWORD = "clamp.config.policy.password";
+
+ public static final String TOSCA_DEF_VERSION = "tosca_definitions_version";
+ public static final String TOSCA_DEF_VERSION_VALUE = "tosca_simple_yaml_1_0_0";
+ public static final String TEMPLATE = "topology_template";
+ public static final String POLICIES = "policies";
+ public static final String MS_TYPE = "type";
+ public static final String MS_VERSION = "version";
+ public static final String MS_VERSION_VALUE = "1.0.0";
+ public static final String MS_METADATA = "metadata";
+ public static final String MS_POLICY_ID = "policy_id";
+ public static final String MS_PROPERTIES = "properties";
+ public static final String MS_policy = "tca_policy";
+
+ private final ClampProperties refProp;
+ private final HttpConnectionManager httpConnectionManager;
+
+ @Autowired
+ public PolicyOperation(ClampProperties refProp, HttpConnectionManager httpConnectionManager) {
+ this.refProp = refProp;
+ this.httpConnectionManager = httpConnectionManager;
+ }
+
+ public void createMsPolicy(Set<MicroServicePolicy> policyList) throws IOException {
+ // Get policy first? if exist delete???
+ // push pdp group
+ for (MicroServicePolicy msPolicy:policyList) {
+ JsonObject payload = createMsPolicyPayload(msPolicy);
+ String policyType = msPolicy.getModelType();
+ String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX;
+ String userName = refProp.getStringValue(POLICY_USER_NAME);
+ String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
+ httpConnectionManager.doGeneralHttpQuery(url, "POST", payload.toString(), "application/json", "POLICY", userName, encodedPass);
+ }
+ }
+
+ public void deleteMsPolicy(Set<MicroServicePolicy> policyList) throws IOException {
+ for (MicroServicePolicy msPolicy:policyList) {
+ String policyType = msPolicy.getModelType();
+ String url = refProp.getStringValue(POLICY_URL_PROPERTY_NAME) + policyType + POLICY_URL_SUFFIX + "/" + msPolicy.getName();
+ String userName = refProp.getStringValue(POLICY_USER_NAME);
+ String encodedPass = refProp.getStringValue(POLICY_PASSWORD);
+ httpConnectionManager.doGeneralHttpQuery(url, "POST", null, null, "POLICY", userName, encodedPass);
+ }
+ }
+
+ private JsonObject createMsPolicyPayload(MicroServicePolicy microService) {
+ JsonObject policyConfig = new JsonObject();
+ policyConfig.add(MS_policy, microService.getProperties());
+
+ JsonObject properties = new JsonObject();
+ properties.add(MS_policy, policyConfig);
+
+ JsonObject msPolicy = new JsonObject();
+ msPolicy.addProperty(MS_TYPE, microService.getModelType());
+ msPolicy.addProperty(MS_VERSION, MS_VERSION_VALUE);
+ JsonObject metaData = new JsonObject();
+ metaData.addProperty(MS_POLICY_ID, microService.getName());
+ msPolicy.add(MS_METADATA, metaData);
+ msPolicy.add(MS_PROPERTIES, properties);
+
+ JsonObject msPolicyWithName = new JsonObject();
+ msPolicyWithName.add(microService.getName(), msPolicy);
+
+ JsonArray policyArray = new JsonArray();
+ policyArray.add(msPolicyWithName);
+
+ JsonObject template = new JsonObject();
+ template.add(POLICIES, policyArray);
+
+ JsonObject configPolicy = new JsonObject();
+ configPolicy.addProperty(TOSCA_DEF_VERSION, TOSCA_DEF_VERSION_VALUE);
+ configPolicy.add(TEMPLATE, template);
+
+ return configPolicy;
+ }
+
+}
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
index 3962a3d4e..c2c60c9c0 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -60,6 +60,14 @@ public class MicroServicePolicy implements Serializable, Policy {
private String name;
@Expose
+ @Column(nullable = false, name = "model_type")
+ private String modelType;
+
+ @Expose
+ @Column(nullable = false, name = "blueprint_name")
+ private String blueprintName;
+
+ @Expose
@Type(type = "json")
@Column(columnDefinition = "json", name = "properties")
private JsonObject properties;
@@ -86,34 +94,42 @@ public class MicroServicePolicy implements Serializable, Policy {
/**
* The constructor.
* @param name The name of the MicroService
+ * @param type The model type of the MicroService
+ * @param blueprintName The name in the blueprint
* @param policyTosca The policy Tosca of the MicroService
* @param shared The flag indicate whether the MicroService is shared
* @param usedByLoops The list of loops that uses this MicroService
*/
- public MicroServicePolicy(String name, String policyTosca, Boolean shared, Set<Loop> usedByLoops) {
+ public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared, Set<Loop> usedByLoops, String blueprintName) {
this.name = name;
+ this.modelType = modelType;
this.policyTosca = policyTosca;
this.shared = shared;
this.jsonRepresentation = JsonUtils.GSON_JPA_MODEL
.fromJson(new ToscaYamlToJsonConvertor(null).parseToscaYaml(policyTosca), JsonObject.class);
this.usedByLoops = usedByLoops;
+ this.blueprintName = blueprintName;
}
/**
* The constructor.
* @param name The name of the MicroService
+ * @param type The model type of the MicroService
+ * @param blueprintName The name in the blueprint
* @param policyTosca The policy Tosca of the MicroService
* @param shared The flag indicate whether the MicroService is shared
* @param jsonRepresentation The UI representation in json format
* @param usedByLoops The list of loops that uses this MicroService
*/
- public MicroServicePolicy(String name, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
- Set<Loop> usedByLoops) {
+ public MicroServicePolicy(String name, String modelType, String policyTosca, Boolean shared, JsonObject jsonRepresentation,
+ Set<Loop> usedByLoops, String blueprintName) {
this.name = name;
+ this.modelType = modelType;
this.policyTosca = policyTosca;
this.shared = shared;
this.usedByLoops = usedByLoops;
this.jsonRepresentation = jsonRepresentation;
+ this.blueprintName = blueprintName;
}
@Override
@@ -121,6 +137,14 @@ public class MicroServicePolicy implements Serializable, Policy {
return name;
}
+ public String getModelType() {
+ return modelType;
+ }
+
+ public String getBlueprintName() {
+ return blueprintName;
+ }
+
public JsonObject getProperties() {
return properties;
}
diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java b/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java
index f473d160f..f95ad3b4e 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroservicePolicyService.java
@@ -66,8 +66,8 @@ public class MicroservicePolicyService implements PolicyService<MicroServicePoli
@Transactional
public MicroServicePolicy getAndUpdateMicroServicePolicy(Loop loop, MicroServicePolicy policy) {
return repository.findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop))
- .orElse(new MicroServicePolicy(policy.getName(), policy.getPolicyTosca(), policy.getShared(),
- policy.getJsonRepresentation(), Sets.newHashSet(loop)));
+ .orElse(new MicroServicePolicy(policy.getName(), policy.getModelType(), policy.getPolicyTosca(), policy.getShared(),
+ policy.getJsonRepresentation(), Sets.newHashSet(loop), policy.getBlueprintName()));
}
private MicroServicePolicy updateMicroservicePolicyProperties(MicroServicePolicy oldPolicy,
diff --git a/src/main/java/org/onap/clamp/util/HttpConnectionManager.java b/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
index 9443301b1..4e97f29b7 100644
--- a/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
+++ b/src/main/java/org/onap/clamp/util/HttpConnectionManager.java
@@ -27,17 +27,22 @@ package org.onap.clamp.util;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import sun.misc.BASE64Encoder;
+
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.security.GeneralSecurityException;
import javax.net.ssl.HttpsURLConnection;
import javax.ws.rs.BadRequestException;
+import org.apache.commons.codec.DecoderException;
import org.apache.commons.io.IOUtils;
+import org.onap.clamp.clds.util.CryptoUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.stereotype.Component;
@@ -50,13 +55,15 @@ public class HttpConnectionManager {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private static final String REQUEST_FAILED_LOG = "Request Failed - response payload=";
- private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType, String target) throws IOException {
+ private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType, String target, String userName, String password) throws IOException {
LoggingUtils utils = new LoggingUtils(logger);
logger.info("Using HTTPS URL:" + url.toString());
HttpsURLConnection secureConnection = (HttpsURLConnection) url.openConnection();
secureConnection = utils.invokeHttps(secureConnection, target, requestMethod);
secureConnection.setRequestMethod(requestMethod);
- secureConnection.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
+ if (userName != null && password != null) {
+ secureConnection.setRequestProperty("Authorization", "Basic " + generateBasicAuth(userName, password));
+ }
if (payload != null && contentType != null) {
secureConnection.setRequestProperty("Content-Type", contentType);
secureConnection.setDoOutput(true);
@@ -84,12 +91,15 @@ public class HttpConnectionManager {
}
}
- private String doHttpQuery(URL url, String requestMethod, String payload, String contentType, String target) throws IOException {
+ private String doHttpQuery(URL url, String requestMethod, String payload, String contentType, String target, String userName, String password) throws IOException {
LoggingUtils utils = new LoggingUtils(logger);
logger.info("Using HTTP URL:" + url);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = utils.invoke(connection, target, requestMethod);
connection.setRequestMethod(requestMethod);
+ if (userName != null && password != null) {
+ connection.setRequestProperty("Authorization", "Basic " + generateBasicAuth(userName, password));
+ }
if (payload != null && contentType != null) {
connection.setRequestProperty("Content-Type", contentType);
connection.setDoOutput(true);
@@ -134,13 +144,27 @@ public class HttpConnectionManager {
* @throws IOException
* In case of issue with the streams
*/
- public String doGeneralHttpQuery(String url, String requestMethod, String payload, String contentType, String target)
+ public String doGeneralHttpQuery(String url, String requestMethod, String payload, String contentType, String target, String userName, String password)
throws IOException {
URL urlObj = new URL(url);
if (url.contains("https://")) { // Support for HTTPS
- return doHttpsQuery(urlObj, requestMethod, payload, contentType, target);
+ return doHttpsQuery(urlObj, requestMethod, payload, contentType, target, userName, password);
} else { // Support for HTTP
- return doHttpQuery(urlObj, requestMethod, payload, contentType, target);
+ return doHttpQuery(urlObj, requestMethod, payload, contentType, target, userName, password);
+ }
+ }
+
+ private String generateBasicAuth(String userName, String encodedPassword) {
+ String password = "";
+ try {
+ password = CryptoUtils.decrypt(encodedPassword);
+ } catch (GeneralSecurityException e) {
+ logger.error("Unable to decrypt the password", e);
+ } catch (DecoderException e) {
+ logger.error("Exception caught when decoding the HEX String Key for encryption", e);
}
+ BASE64Encoder enc = new sun.misc.BASE64Encoder();
+ String userpassword = userName + ":" + password;
+ return enc.encode( userpassword.getBytes() );
}
}
diff --git a/src/main/resources/META-INF/resources/designer/scripts/CldsModelService.js b/src/main/resources/META-INF/resources/designer/scripts/CldsModelService.js
index a71e6caa6..90cdc0d78 100644
--- a/src/main/resources/META-INF/resources/designer/scripts/CldsModelService.js
+++ b/src/main/resources/META-INF/resources/designer/scripts/CldsModelService.js
@@ -96,7 +96,7 @@ app
var def = $q.defer();
var sets = [];
var svcAction = uiAction.toLowerCase();
- var svcUrl = "/restservices/clds/v2/loop/" + "action/" + svcAction + "/" + modelName;
+ var svcUrl = "/restservices/clds/v2/loop/" + svcAction + "/" + modelName;
$http.put(svcUrl).success(
function(data) {
diff --git a/src/main/resources/application-noaaf.properties b/src/main/resources/application-noaaf.properties
index 632856e92..f54cbe096 100644
--- a/src/main/resources/application-noaaf.properties
+++ b/src/main/resources/application-noaaf.properties
@@ -135,6 +135,9 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-
#
#
# Configuration Settings for Policy Engine Components
+clamp.config.policy.url=http://localhost:8085/
+clamp.config.policy.userName=test
+clamp.config.policy.password=test
clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
clamp.config.policy.pdpUrl2=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
clamp.config.policy.papUrl=http://policy.api.simpledemo.onap.org:8081/pap/ , testpap, alpha123
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 91c02ef74..5b47d32de 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -150,6 +150,9 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-
#
#
# Configuration Settings for Policy Engine Components
+clamp.config.policy.url=http://policy.api.simpledemo.onap.org:8081/pdp/
+clamp.config.policy.userName=test
+clamp.config.policy.password=test
clamp.config.policy.pdpUrl1=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
clamp.config.policy.pdpUrl2=http://policy.api.simpledemo.onap.org:8081/pdp/ , testpdp, alpha123
clamp.config.policy.papUrl=http://policy.api.simpledemo.onap.org:8081/pap/ , testpap, alpha123
diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index c5828b284..f339d5d70 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -71,6 +71,24 @@
<to uri="bean:org.onap.clamp.operation.LoopOperation?method=unDeployLoop(${header.loopName})" />
</route>
</put>
+ <put uri="/v2/loop/submit/{loopName}">
+ <route>
+ <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitMsPolicies(${header.loopName})" />
+ <!-- <to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitOpPolicy(${header.loopName})" />-->
+ <!--<to uri="bean:org.onap.clamp.operation.LoopOperation?method=submitGuardPolicy(${header.loopName})" /> -->
+ </route>
+ </put>
+ <put uri="/v2/loop/delete/{loopName}"
+ outType="org.onap.clamp.loop.Loop"
+ produces="application/json">
+ <route>
+ <to uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteMsPolicies(${header.loopName})" />
+ <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteOpPolicy(${header.loopName})" />
+ <to uri="bean:org.onap.clamp.operation.LoopOperation?method=deleteGuardPolicy(${header.loopName})" />
+ </route>
+ </put>
</rest>
</rests>
diff --git a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
index caab61f18..549c2d117 100644
--- a/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/DcaeDispatcherServicesTest.java
@@ -85,7 +85,7 @@ public class DcaeDispatcherServicesTest {
@Test
public void shouldReturnDcaeOperationSataus() throws IOException {
//given
- Mockito.when(httpConnectionManager.doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE"))
+ Mockito.when(httpConnectionManager.doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE", null, null))
.thenReturn(STATUS_RESPONSE_PROCESSING);
//when
String operationStatus = dcaeDispatcherServices.getOperationStatus(DEPLOYMENT_STATUS_URL);
@@ -98,7 +98,7 @@ public class DcaeDispatcherServicesTest {
public void shouldTryMultipleTimesWhenProcessing() throws IOException, InterruptedException {
//given
Mockito.when(httpConnectionManager.doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET",
- null, null, "DCAE"))
+ null, null, "DCAE", null, null))
.thenReturn(STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_ACTIVE);
//when
String operationStatus = dcaeDispatcherServices.getOperationStatusWithRetry(DEPLOYMENT_STATUS_URL);
@@ -106,7 +106,7 @@ public class DcaeDispatcherServicesTest {
//then
Assertions.assertThat(operationStatus).isEqualTo("succeeded");
Mockito.verify(httpConnectionManager, Mockito.times(3))
- .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE");
+ .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE", null, null);
}
@@ -114,7 +114,7 @@ public class DcaeDispatcherServicesTest {
public void shouldTryOnlyAsManyTimesAsConfigured() throws IOException, InterruptedException {
//given
Mockito.when(httpConnectionManager
- .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE"))
+ .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE", null, null))
.thenReturn(STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING,
STATUS_RESPONSE_PROCESSING, STATUS_RESPONSE_PROCESSING);
//when
@@ -123,7 +123,7 @@ public class DcaeDispatcherServicesTest {
//then
Assertions.assertThat(operationStatus).isEqualTo("processing");
Mockito.verify(httpConnectionManager, Mockito.times(3))
- .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE");
+ .doGeneralHttpQuery(DEPLOYMENT_STATUS_URL, "GET", null, null, "DCAE", null, null);
}
@@ -140,7 +140,7 @@ public class DcaeDispatcherServicesTest {
+ "/dcae-deployments/closedLoop_152367c8-b172-47b3-9e58-c53add75d869_deploymentId",
"PUT",
"{\"serviceTypeId\":\"e2ba40f7-bf42-41e7-acd7-48fd07586d90\",\"inputs\":{}}",
- "application/json", "DCAE"))
+ "application/json", "DCAE", null, null))
.thenReturn(DEPLOY_RESPONSE_STRING);
JsonObject blueprintInputJson = new JsonObject();
diff --git a/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java b/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java
index 42e9c7f63..4db0e5c27 100644
--- a/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/HttpConnectionManagerItCase.java
@@ -110,7 +110,7 @@ public class HttpConnectionManagerItCase {
@Test
public void testHttpGet() throws Exception {
String response = httpConnectionManager
- .doGeneralHttpQuery("http://localhost:" + this.httpPort + "/designer/index.html", "GET", null, null, "DCAE");
+ .doGeneralHttpQuery("http://localhost:" + this.httpPort + "/designer/index.html", "GET", null, null, "DCAE", null, null);
assertNotNull(response);
// Should be a redirection so 302, so empty
assertTrue(response.isEmpty());
@@ -119,7 +119,7 @@ public class HttpConnectionManagerItCase {
@Test
public void testHttpsGet() throws Exception {
String response = httpConnectionManager
- .doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index.html", "GET", null, null, "DCAE");
+ .doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index.html", "GET", null, null, "DCAE", null, null);
assertNotNull(response);
// Should contain something
assertTrue(!response.isEmpty());
@@ -128,21 +128,21 @@ public class HttpConnectionManagerItCase {
@Test(expected = BadRequestException.class)
public void testHttpsGet404() throws IOException {
httpConnectionManager.doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html",
- "GET", null, null, "DCAE");
+ "GET", null, null, "DCAE", null, null);
fail("Should have raised an BadRequestException");
}
@Test(expected = BadRequestException.class)
public void testHttpsPost404() throws IOException {
httpConnectionManager.doGeneralHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html",
- "POST", "", "application/json", "DCAE");
+ "POST", "", "application/json", "DCAE", null, null);
fail("Should have raised an BadRequestException");
}
@Test(expected = BadRequestException.class)
public void testHttpException() throws IOException {
httpConnectionManager.doGeneralHttpQuery("http://localhost:" + this.httpsPort + "/designer/index.html", "GET",
- null, null, "DCAE");
+ null, null, "DCAE", null, null);
fail("Should have raised an BadRequestException");
}
}
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
index 551ac1b30..fbe6e63ca 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java
@@ -47,6 +47,9 @@ public class BlueprintParserTest {
private static final String FIRST_APPP = "first_app";
private static final String SECOND_APPP = "second_app";
private static final String THIRD_APPP = "third_app";
+ private static final String MODEL_TYPE1 = "type1";
+ private static final String MODEL_TYPE2 = "type2";
+ private static final String MODEL_TYPE3 = "type3";
private static String microServiceTheWholeBlueprintValid;
private static String microServiceBlueprintOldStyleTCA;
@@ -139,7 +142,7 @@ public class BlueprintParserTest {
public void getNodeRepresentationFromCompleteYaml() {
final JsonObject jsonObject = jsonObjectBlueprintValid;
- MicroService expected = new MicroService(SECOND_APPP, FIRST_APPP, "");
+ MicroService expected = new MicroService(SECOND_APPP, MODEL_TYPE1, FIRST_APPP, "", SECOND_APPP);
Entry<String, JsonElement> entry = jsonObject.entrySet().iterator().next();
MicroService actual = new BlueprintParser().getNodeRepresentation(entry);
@@ -148,9 +151,9 @@ public class BlueprintParserTest {
@Test
public void getMicroServicesFromBlueprintTest() {
- MicroService thirdApp = new MicroService(THIRD_APPP, "", "");
- MicroService firstApp = new MicroService(FIRST_APPP, THIRD_APPP, "");
- MicroService secondApp = new MicroService(SECOND_APPP, FIRST_APPP, "");
+ MicroService thirdApp = new MicroService(THIRD_APPP, MODEL_TYPE3, "", "", THIRD_APPP);
+ MicroService firstApp = new MicroService(FIRST_APPP, MODEL_TYPE1, THIRD_APPP, "", FIRST_APPP);
+ MicroService secondApp = new MicroService(SECOND_APPP, MODEL_TYPE2, FIRST_APPP, "", SECOND_APPP);
Set<MicroService> expected = new HashSet<>(Arrays.asList(firstApp, secondApp, thirdApp));
Set<MicroService> actual = new BlueprintParser().getMicroServices(microServiceTheWholeBlueprintValid);
@@ -160,7 +163,7 @@ public class BlueprintParserTest {
@Test
public void fallBackToOneMicroServiceTCATest() {
- MicroService tcaMS = new MicroService(BlueprintParser.TCA, "", "");
+ MicroService tcaMS = new MicroService(BlueprintParser.TCA, "", "", "", "");
List<MicroService> expected = Collections.singletonList(tcaMS);
List<MicroService> actual = new BlueprintParser().fallbackToOneMicroService(microServiceBlueprintOldStyleTCA);
@@ -170,7 +173,7 @@ public class BlueprintParserTest {
@Test
public void fallBackToOneMicroServiceHolmesTest() {
- MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "", "");
+ MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "", "", "", "");
List<MicroService> expected = Collections.singletonList(holmesMS);
List<MicroService> actual = new BlueprintParser()
diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
index 2ec508799..1eb66eadd 100644
--- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
+++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/ChainGeneratorTest.java
@@ -38,10 +38,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, FIRST_APPP, "");
- MicroService ms3 = new MicroService(THIRD_APPP, SECOND_APPP, "");
- MicroService ms4 = new MicroService(FOURTH_APPP, THIRD_APPP, "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", THIRD_APPP, "", "");
List<MicroService> expectedList = Arrays.asList(ms1, ms2, ms3, ms4);
Set<MicroService> inputSet = new HashSet<>(expectedList);
@@ -52,10 +52,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesTwiceNoInputTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, "", "");
- MicroService ms3 = new MicroService(THIRD_APPP, SECOND_APPP, "");
- MicroService ms4 = new MicroService(FOURTH_APPP, FIRST_APPP, "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", "", "", "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", SECOND_APPP, "", "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
@@ -64,10 +64,10 @@ public class ChainGeneratorTest {
@Test
public void getChainOfMicroServicesBranchingTest() {
- MicroService ms1 = new MicroService(FIRST_APPP, "", "");
- MicroService ms2 = new MicroService(SECOND_APPP, FIRST_APPP, "");
- MicroService ms3 = new MicroService(THIRD_APPP, FIRST_APPP, "");
- MicroService ms4 = new MicroService(FOURTH_APPP, FIRST_APPP, "");
+ MicroService ms1 = new MicroService(FIRST_APPP, "", "", "", "");
+ MicroService ms2 = new MicroService(SECOND_APPP, "", FIRST_APPP, "", "");
+ MicroService ms3 = new MicroService(THIRD_APPP, "", FIRST_APPP, "", "");
+ MicroService ms4 = new MicroService(FOURTH_APPP, "", FIRST_APPP, "", "");
Set<MicroService> inputSet = new HashSet<>(Arrays.asList(ms1, ms2, ms3, ms4));
List<MicroService> actualList = new ChainGenerator().getChainOfMicroServices(inputSet);
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
index 459a701fe..f7d2fe76e 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java
@@ -56,8 +56,8 @@ public class ClampGraphBuilderTest {
@Test
public void clampGraphBuilderCompleteChainTest() {
String collector = "VES";
- MicroService ms1 = new MicroService("ms1", "", "ms1_jpa_id");
- MicroService ms2 = new MicroService("ms2", "", "ms2_jpa_id");
+ MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id", "");
+ MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id", "");
;
String policy = "Policy";
List<MicroService> microServices = Arrays.asList(ms1, ms2);
@@ -76,8 +76,8 @@ public class ClampGraphBuilderTest {
@Test(expected = InvalidStateException.class)
public void clampGraphBuilderNoPolicyGivenTest() {
String collector = "VES";
- MicroService ms1 = new MicroService("ms1", "", "ms1_jpa_id");
- MicroService ms2 = new MicroService("ms2", "", "ms2_jpa_id");
+ MicroService ms1 = new MicroService("ms1", "", "", "ms1_jpa_id", "");
+ MicroService ms2 = new MicroService("ms2", "", "", "ms2_jpa_id", "");
ClampGraphBuilder clampGraphBuilder = new ClampGraphBuilder(mockPainter);
clampGraphBuilder.collector(collector).addMicroService(ms1).addMicroService(ms2).build();
diff --git a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
index fcef5b79e..2578f68ed 100644
--- a/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
+++ b/src/test/java/org/onap/clamp/loop/CsarInstallerItCase.java
@@ -173,7 +173,6 @@ public class CsarInstallerItCase {
assertThat(loop.getSvgRepresentation()).startsWith("<svg ");
assertThat(loop.getGlobalPropertiesJson().get("dcaeDeployParameters")).isNotNull();
assertThat(loop.getMicroServicePolicies()).hasSize(1);
-
assertThat(loop.getOperationalPolicies()).hasSize(1);
assertThat(loop.getModelPropertiesJson().get("serviceDetails")).isNotNull();
assertThat(loop.getModelPropertiesJson().get("resourceDetails")).isNotNull();
diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
index c524eec39..9d07415bc 100644
--- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
@@ -83,10 +83,10 @@ public class LoopRepositoriesItCase {
return loop;
}
- private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String policyTosca,
+ private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation, String policyTosca,
String jsonProperties, boolean shared) {
- MicroServicePolicy µService = new MicroServicePolicy(name, policyTosca, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ MicroServicePolicy µService = new MicroServicePolicy(name, modelType, policyTosca, shared,
+ gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>(), "");
µService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class));
return µService;
}
@@ -105,7 +105,7 @@ public class LoopRepositoriesItCase {
"123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
- MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "{\"configtype\":\"json\"}",
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "", "{\"configtype\":\"json\"}",
"YamlContent", "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
LoopLog loopLog = getLoopLog(LogType.INFO, "test message");
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 4011a7867..9a44d41bc 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -114,7 +114,7 @@ public class LoopServiceTestItCase {
JsonObject confJson = JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class);
String policyName = "policyName";
String policyTosca = "policyTosca";
- MicroServicePolicy microServicePolicy = new MicroServicePolicy(policyName, policyTosca, false, confJson, null);
+ MicroServicePolicy microServicePolicy = new MicroServicePolicy(policyName, "", policyTosca, false, confJson, null, "");
//when
Loop actualLoop = loopService
@@ -141,12 +141,12 @@ public class LoopServiceTestItCase {
JsonObject newJsonRepresentation = JsonUtils.GSON.fromJson("{}", JsonObject.class);
String secondPolicyName = "secondPolicyName";
String secondPolicyTosca = "secondPolicyTosca";
- MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "", "policyTosca",
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, "");
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
- MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
- newJsonRepresentation, null);
+ MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, "", secondPolicyTosca, true,
+ newJsonRepresentation, null, "");
//when
firstMicroServicePolicy.setProperties(JsonUtils.GSON.fromJson("{\"name1\":\"value1\"}", JsonObject.class));
@@ -178,12 +178,12 @@ public class LoopServiceTestItCase {
String firstPolicyName = "firstPolicyName";
String secondPolicyName = "policyName";
String secondPolicyTosca = "secondPolicyTosca";
- MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "policyTosca",
- false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ MicroServicePolicy firstMicroServicePolicy = new MicroServicePolicy(firstPolicyName, "", "policyTosca",
+ false, JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, "");
loopService.updateAndSaveMicroservicePolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstMicroServicePolicy));
- MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, secondPolicyTosca, true,
- jsonRepresentation, null);
+ MicroServicePolicy secondMicroServicePolicy = new MicroServicePolicy(secondPolicyName, "", secondPolicyTosca, true,
+ jsonRepresentation, null, "");
//when
Loop actualLoop = loopService
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index 92a0e14cf..1c218977d 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -58,10 +58,10 @@ public class LoopToJsonTest {
return loop;
}
- private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String policyTosca,
+ private MicroServicePolicy getMicroServicePolicy(String name, String modelType, String jsonRepresentation, String policyTosca,
String jsonProperties, boolean shared) {
- MicroServicePolicy µService = new MicroServicePolicy(name, policyTosca, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ MicroServicePolicy µService = new MicroServicePolicy(name, modelType, policyTosca, shared,
+ gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>(), "");
µService.setProperties(new Gson().fromJson(jsonProperties, JsonObject.class));
return µService;
@@ -81,7 +81,7 @@ public class LoopToJsonTest {
"123456789", "https://dcaetest.org", "UUID-blueprint");
OperationalPolicy opPolicy = this.getOperationalPolicy("{\"type\":\"GUARD\"}", "GuardOpPolicyTest");
loopTest.addOperationalPolicy(opPolicy);
- MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "{\"configtype\":\"json\"}",
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "", "{\"configtype\":\"json\"}",
"YamlContent", "{\"param1\":\"value1\"}", true);
loopTest.addMicroServicePolicy(microServicePolicy);
LoopLog loopLog = getLoopLog(LogType.INFO, "test message");
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
index e15b8737a..99d5da8b3 100644
--- a/src/test/resources/application.properties
+++ b/src/test/resources/application.properties
@@ -141,6 +141,9 @@ clamp.config.dcae.deployment.template=classpath:/clds/templates/dcae-deployment-
#
#
# Configuration Settings for Policy Engine Components
+clamp.config.policy.url=http://localhost:${docker.http-cache.port.host}
+clamp.config.policy.userName=test
+clamp.config.policy.password=test
clamp.config.policy.pdpUrl1=http://localhost:${docker.http-cache.port.host}/pdp/ , testpdp, alpha123
clamp.config.policy.pdpUrl2=http://localhost:${docker.http-cache.port.host}/pdp/ , testpdp, alpha123
clamp.config.policy.papUrl=http://localhost:${docker.http-cache.port.host}/pap/ , testpap, alpha123
diff --git a/src/test/resources/clds/blueprint-with-microservice-chain.yaml b/src/test/resources/clds/blueprint-with-microservice-chain.yaml
index 7b7148d54..4a7e5d7aa 100644
--- a/src/test/resources/clds/blueprint-with-microservice-chain.yaml
+++ b/src/test/resources/clds/blueprint-with-microservice-chain.yaml
@@ -30,6 +30,8 @@ node_templates:
service_component_type: dcaegen2-analytics-tca
service_component_name_override: second_app
image: { get_input: second_app_docker_image }
+ policy_id:
+ policy_type_id: type2
interfaces:
cloudify.interfaces.lifecycle:
start:
@@ -53,6 +55,8 @@ node_templates:
dns_name: "first_app"
image: { get_input: first_app_docker_image }
container_port: 6565
+ policy_id:
+ policy_type_id: type1
interfaces:
cloudify.interfaces.lifecycle:
start:
@@ -76,6 +80,8 @@ node_templates:
dns_name: "third_app"
image: { get_input: third_app_docker_image }
container_port: 443
+ policy_id:
+ policy_type_id: type3
interfaces:
cloudify.interfaces.lifecycle:
start:
diff --git a/src/test/resources/clds/single-microservice-fragment-valid.yaml b/src/test/resources/clds/single-microservice-fragment-valid.yaml
index abaae20b3..269ee5062 100644
--- a/src/test/resources/clds/single-microservice-fragment-valid.yaml
+++ b/src/test/resources/clds/single-microservice-fragment-valid.yaml
@@ -5,6 +5,8 @@ second_app:
service_component_name_override: second_app
image: { get_input: second_app_docker_image }
name: second_app
+ policy_id:
+ policy_type_id: type1
interfaces:
cloudify.interfaces.lifecycle:
start: