aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-26 15:47:30 -0800
committersebdet <sebastien.determe@intl.att.com>2020-02-27 06:17:02 -0800
commitd2a4df0b62b6a32c42bac45b4bee344016faa8fb (patch)
treea4d49be5501c1016de3af41f7e8935cd5187ec85 /src
parentc11160ecfdce03091917e2728f80848f4d8feb95 (diff)
Add Create loop dialog
Add create loop dialog and backend part associated (this is based on this PR https://gerrit.onap.org/r/c/clamp/+/102156) Issue-ID: CLAMP-587 Change-Id: I58524bc2d5bfbf5ca5a3acf5c59823df06fd4cd9 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java37
-rw-r--r--src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java4
-rw-r--r--src/main/java/org/onap/clamp/clds/config/DefaultUserConfiguration.java4
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java6
-rwxr-xr-xsrc/main/java/org/onap/clamp/clds/util/drawing/Painter.java2
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java23
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopController.java14
-rw-r--r--src/main/java/org/onap/clamp/loop/LoopService.java17
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java11
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModel.java15
-rw-r--r--src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java12
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java24
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java6
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java11
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java2
-rw-r--r--src/main/resources/META-INF/resources/swagger.html2
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml59
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilderTest.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java8
-rw-r--r--src/test/java/org/onap/clamp/loop/DcaeComponentTest.java3
-rw-r--r--src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java3
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java5
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java13
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopToJsonTest.java19
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java32
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java3
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java6
27 files changed, 228 insertions, 115 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
index b3fcb6f1..44abc9dd 100644
--- a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
@@ -25,10 +25,8 @@ package org.onap.clamp.clds.client;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -38,27 +36,21 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
-import org.json.simple.parser.ParseException;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.sdc.controller.installer.BlueprintMicroService;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.loop.template.PolicyModel;
-import org.onap.clamp.loop.template.PolicyModelId;
import org.onap.clamp.loop.template.PolicyModelsService;
import org.onap.clamp.policy.pdpgroup.PdpGroup;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.yaml.snakeyaml.Yaml;
-
-
/**
* The class implements the communication with the Policy Engine to retrieve
* policy models (tosca). It mainly delegates the physical calls to Camel
* engine.
- *
*/
@Component
public class PolicyEngineServices {
@@ -76,16 +68,15 @@ public class PolicyEngineServices {
/**
* Default constructor.
*
- * @param camelContext Camel context bean
- * @param clampProperties ClampProperties bean
- * @param policyModelsSService policyModel repository bean
+ * @param camelContext Camel context bean
+ * @param clampProperties ClampProperties bean
* @param policyModelsService policyModel service
*/
@Autowired
public PolicyEngineServices(CamelContext camelContext, ClampProperties clampProperties,
- PolicyModelsService policyModelsSService) {
+ PolicyModelsService policyModelsService) {
this.camelContext = camelContext;
- this.policyModelsService = policyModelsSService;
+ this.policyModelsService = policyModelsService;
if (clampProperties.getStringValue(POLICY_RETRY_LIMIT) != null) {
retryLimit = Integer.parseInt(clampProperties.getStringValue(POLICY_RETRY_LIMIT));
}
@@ -97,7 +88,7 @@ public class PolicyEngineServices {
/**
* This method query Policy engine and create a PolicyModel object with type and version.
*
- * @param policyType The policyType id
+ * @param policyType The policyType id
* @param policyVersion The policy version of that type
* @return A PolicyModel created from policyEngine data
*/
@@ -130,7 +121,8 @@ public class PolicyEngineServices {
List<LinkedHashMap<String, Object>> policyTypesList = (List<LinkedHashMap<String, Object>>) loadedYaml
.get("policy_types");
policyTypesList.parallelStream().forEach(policyType -> {
- Map.Entry<String, Object> policyTypeEntry = (Map.Entry<String, Object>) new ArrayList(policyType.entrySet()).get(0);
+ Map.Entry<String, Object> policyTypeEntry =
+ (Map.Entry<String, Object>) new ArrayList(policyType.entrySet()).get(0);
policyModelsService.createPolicyInDbIfNeeded(
createPolicyModelFromPolicyEngine(policyTypeEntry.getKey(),
@@ -141,31 +133,34 @@ public class PolicyEngineServices {
/**
* This method can be used to download all policy types + data types defined in
* policy engine.
- *
+ *
* @return A yaml containing all policy Types and all data types
*/
public String downloadAllPolicies() {
- return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models", "Get all policies");
+ return callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-policy-models",
+ "Get all policies");
}
/**
* This method can be used to download a policy tosca model on the engine.
- *
+ *
* @param policyType The policy type (id)
* @param policyVersion The policy version
* @return A string with the whole policy tosca model
*/
public String downloadOnePolicy(String policyType, String policyVersion) {
return callCamelRoute(ExchangeBuilder.anExchange(camelContext).withProperty("policyModelName", policyType)
- .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model", "Get one policy");
+ .withProperty("policyModelVersion", policyVersion).build(), "direct:get-policy-model",
+ "Get one policy");
}
/**
* This method can be used to download all Pdp Groups data from policy engine.
- *
*/
public void downloadPdpGroups() {
- String responseBody = callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-pdp-groups", "Get Pdp Groups");
+ String responseBody =
+ callCamelRoute(ExchangeBuilder.anExchange(camelContext).build(), "direct:get-all-pdp-groups",
+ "Get Pdp Groups");
if (responseBody == null || responseBody.isEmpty()) {
logger.warn("getPdpGroups returned by policy engine could not be decoded, as it's null or empty");
diff --git a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
index 626227e2..a7ef1073 100644
--- a/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
+++ b/src/main/java/org/onap/clamp/clds/config/CldsUserJsonDecoder.java
@@ -26,14 +26,12 @@
package org.onap.clamp.clds.config;
import com.google.gson.JsonParseException;
-
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-
import org.apache.commons.io.IOUtils;
-import org.onap.clamp.clds.exception.CldsUsersException;
import org.onap.clamp.authorization.CldsUser;
+import org.onap.clamp.clds.exception.CldsUsersException;
import org.onap.clamp.clds.util.JsonUtils;
public class CldsUserJsonDecoder {
diff --git a/src/main/java/org/onap/clamp/clds/config/DefaultUserConfiguration.java b/src/main/java/org/onap/clamp/clds/config/DefaultUserConfiguration.java
index a4515860..1261a5e9 100644
--- a/src/main/java/org/onap/clamp/clds/config/DefaultUserConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/DefaultUserConfiguration.java
@@ -27,12 +27,10 @@ package org.onap.clamp.clds.config;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-
import java.io.IOException;
-
+import org.onap.clamp.authorization.CldsUser;
import org.onap.clamp.clds.exception.CldsConfigException;
import org.onap.clamp.clds.exception.CldsUsersException;
-import org.onap.clamp.authorization.CldsUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
index 7edf6c1a..8e3b06a4 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/ClampGraphBuilder.java
@@ -88,12 +88,10 @@ public class ClampGraphBuilder {
public ClampGraphBuilder addLoopElementModel(LoopElementModel loopElementModel) {
if (LoopElementModel.MICRO_SERVICE_TYPE.equals(loopElementModel.getLoopElementType())) {
microServices.add(new MicroServicePolicy(loopElementModel.getName(),
- loopElementModel.getPolicyModels().first(),
- false,
- null));
+ loopElementModel.getPolicyModels().first(), false, loopElementModel));
} else if (LoopElementModel.OPERATIONAL_POLICY_TYPE.equals(loopElementModel.getLoopElementType())) {
policies.add(new OperationalPolicy(loopElementModel.getName(), null, null,
- loopElementModel.getPolicyModels().first()));
+ loopElementModel.getPolicyModels().first(), loopElementModel));
}
return this;
}
diff --git a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
index af62d84a..5ec59dba 100755
--- a/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
+++ b/src/main/java/org/onap/clamp/clds/util/drawing/Painter.java
@@ -83,7 +83,7 @@ public class Painter {
for (MicroServicePolicy ms : microServices) {
ib.arrow().rectangle(ms.getName(),
- RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym());
+ RectTypes.MICROSERVICE, ms.getPolicyModel().getPolicyAcronym()).arrow();
}
for (OperationalPolicy policy : policies) {
ib.arrow().rectangle(policy.getName(), RectTypes.POLICY, policy.getPolicyModel().getPolicyAcronym())
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 676626a1..b3fe58f9 100644
--- a/src/main/java/org/onap/clamp/loop/Loop.java
+++ b/src/main/java/org/onap/clamp/loop/Loop.java
@@ -60,6 +60,7 @@ import org.onap.clamp.loop.components.external.ExternalComponent;
import org.onap.clamp.loop.components.external.PolicyComponent;
import org.onap.clamp.loop.log.LoopLog;
import org.onap.clamp.loop.service.Service;
+import org.onap.clamp.loop.template.LoopElementModel;
import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -155,6 +156,28 @@ public class Loop extends AuditEntity implements Serializable {
initializeExternalComponents();
}
+ /**
+ * This constructor creates a loop from a loop template.
+ *
+ * @param name The loop name
+ * @param loopTemplate The loop template from which a new loop instance must be created
+ */
+ public Loop(String name, LoopTemplate loopTemplate) {
+ this(name,"");
+ this.setLoopTemplate(loopTemplate);
+ this.setModelService(loopTemplate.getModelService());
+ loopTemplate.getLoopElementModelsUsed().forEach(element -> {
+ if (LoopElementModel.MICRO_SERVICE_TYPE.equals(element.getLoopElementModel().getLoopElementType())) {
+ this.addMicroServicePolicy(new MicroServicePolicy(name,
+ element.getLoopElementModel().getPolicyModels().first(), false, element.getLoopElementModel()));
+ } else if (LoopElementModel.OPERATIONAL_POLICY_TYPE
+ .equals(element.getLoopElementModel().getLoopElementType())) {
+ this.addOperationalPolicy(new OperationalPolicy(name, null, new JsonObject(),
+ element.getLoopElementModel().getPolicyModels().first(), element.getLoopElementModel()));
+ }
+ });
+ }
+
public String getName() {
return name;
}
diff --git a/src/main/java/org/onap/clamp/loop/LoopController.java b/src/main/java/org/onap/clamp/loop/LoopController.java
index c161c550..7b037da6 100644
--- a/src/main/java/org/onap/clamp/loop/LoopController.java
+++ b/src/main/java/org/onap/clamp/loop/LoopController.java
@@ -40,16 +40,22 @@ import org.springframework.stereotype.Controller;
public class LoopController {
private final LoopService loopService;
- private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {}
- .getType();
- private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {}
- .getType();
+ private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken<List<OperationalPolicy>>() {
+ }
+ .getType();
+ private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken<List<MicroServicePolicy>>() {
+ }
+ .getType();
@Autowired
public LoopController(LoopService loopService) {
this.loopService = loopService;
}
+ public Loop createLoop(String loopName, String templateName) {
+ return loopService.createLoopFromTemplate(loopName, templateName);
+ }
+
public List<String> getLoopNames() {
return loopService.getClosedLoopNames();
}
diff --git a/src/main/java/org/onap/clamp/loop/LoopService.java b/src/main/java/org/onap/clamp/loop/LoopService.java
index 6ea412c0..34be2038 100644
--- a/src/main/java/org/onap/clamp/loop/LoopService.java
+++ b/src/main/java/org/onap/clamp/loop/LoopService.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Set;
import javax.persistence.EntityNotFoundException;
import org.apache.commons.lang3.RandomStringUtils;
+import org.onap.clamp.loop.template.LoopTemplatesService;
import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.loop.template.PolicyModelsService;
import org.onap.clamp.policy.Policy;
@@ -53,6 +54,9 @@ public class LoopService {
@Autowired
private PolicyModelsService policyModelsService;
+ @Autowired
+ private LoopTemplatesService loopTemplateService;
+
Loop saveOrUpdateLoop(Loop loop) {
return loopsRepository.save(loop);
}
@@ -70,6 +74,17 @@ public class LoopService {
}
/**
+ * Creates a Loop Instance from Loop Template Name.
+ *
+ * @param loopName Name of the Loop to be created
+ * @param templateName Loop Template to used for Loop
+ * @return Loop Instance
+ */
+ public Loop createLoopFromTemplate(String loopName, String templateName) {
+ return loopsRepository.save(new Loop(loopName,loopTemplateService.getLoopTemplate(templateName)));
+ }
+
+ /**
* This method is used to refresh the DCAE deployment status fields.
*
* @param loop The loop instance to be modified
@@ -96,7 +111,7 @@ public class LoopService {
loop.addOperationalPolicy(
new OperationalPolicy(Policy.generatePolicyName("OPERATIONAL", loop.getModelService().getName(),
loop.getModelService().getVersion(), RandomStringUtils.randomAlphanumeric(3),
- RandomStringUtils.randomAlphanumeric(4)), loop, null, policyModel));
+ RandomStringUtils.randomAlphanumeric(4)), loop, null, policyModel, null));
return loopsRepository.save(loop);
}
diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java
index 29382137..09bc80f8 100644
--- a/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java
+++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplatesService.java
@@ -49,6 +49,17 @@ public class LoopTemplatesService {
return loopTemplatesRepository.save(loopTemplate);
}
+
+ /**
+ * Get the SVG representation of the loopTemplate.
+ *
+ * @param templateName The loopTemplate name
+ * @return The SVG representation in xml
+ */
+ public String getSvgRepresentation(String templateName) {
+ return loopTemplatesRepository.findById(templateName).orElse(new LoopTemplate()).getSvgRepresentation();
+ }
+
public List<String> getLoopTemplateNames() {
return loopTemplatesRepository.getAllLoopTemplateNames();
}
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
index 7334eceb..66b05f65 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModel.java
@@ -35,7 +35,6 @@ import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
-
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
@@ -72,7 +71,7 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
*/
@Id
@Expose
- @Column(name = "version",nullable = false)
+ @Column(name = "version", nullable = false)
private String version;
@Column(columnDefinition = "MEDIUMTEXT", name = "policy_tosca")
@@ -198,17 +197,17 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
/**
* Constructor.
*
- * @param policyType The policyType (referenced in the blueprint
+ * @param policyType The policyType (referenced in the blueprint
* @param policyModelTosca The policy tosca model in yaml
- * @param version the version like 1.0.0
- * @param policyAcronym Subtype for policy if it exists (could be used by UI)
+ * @param version the version like 1.0.0
+ * @param policyAcronym Subtype for policy if it exists (could be used by UI)
*/
public PolicyModel(String policyType, String policyModelTosca, String version,
- String policyAcronym) {
+ String policyAcronym) {
this.policyModelType = policyType;
this.policyModelTosca = policyModelTosca;
this.version = version;
- this.policyAcronym=policyAcronym;
+ this.policyAcronym = policyAcronym;
if (this.policyAcronym == null) {
this.policyAcronym = createDefaultPolicyAcronym(policyType);
}
@@ -216,7 +215,7 @@ public class PolicyModel extends AuditEntity implements Serializable, Comparable
/**
* Constructor with acronym generated by default from policyType.
- *
+ *
* @param policyType The policyType (referenced in the blueprint
* @param policyModelTosca The policy tosca model in yaml
* @param version the version like 1.0.0
diff --git a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
index b38be942..7e21cc39 100644
--- a/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
+++ b/src/main/java/org/onap/clamp/loop/template/PolicyModelsService.java
@@ -52,8 +52,7 @@ public class PolicyModelsService {
/**
* Save or Update Policy Model.
*
- * @param policyModel
- * The policyModel
+ * @param policyModel The policyModel
* @return The Policy Model
*/
public PolicyModel saveOrUpdatePolicyModel(PolicyModel policyModel) {
@@ -63,8 +62,7 @@ public class PolicyModelsService {
/**
* Verify whether Policy Model exist by ID.
*
- * @param policyModelId
- * The policyModel Id
+ * @param policyModelId The policyModel Id
* @return The flag indicates whether Policy Model exist
*/
public boolean existsById(PolicyModelId policyModelId) {
@@ -157,14 +155,14 @@ public class PolicyModelsService {
}
}
- /**
+ /**
* Update the Pdp Group info in Policy Model DB.
*
* @param pdpGroupList The list of Pdp Group info received from Policy Engine
*/
public void updatePdpGroupInfo(List<PdpGroup> pdpGroupList) {
List<PolicyModel> policyModelList = policyModelsRepository.findAll();
- for (PolicyModel policyModel : policyModelList) {
+ for (PolicyModel policyModel : policyModelList) {
JsonArray supportedPdpGroups = new JsonArray();
for (PdpGroup pdpGroup : pdpGroupList) {
JsonObject supportedPdpGroup = pdpGroup.getSupportedSubgroups(policyModel.getPolicyModelType(),
@@ -175,7 +173,7 @@ public class PolicyModelsService {
}
if (supportedPdpGroups.size() > 0) {
- JsonObject supportedPdpJson = new JsonObject ();
+ JsonObject supportedPdpJson = new JsonObject();
supportedPdpJson.add("supportedPdpGroups", supportedPdpGroups);
policyModel.setPolicyPdpGroup(supportedPdpJson);
policyModelsRepository.save(policyModel);
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 8d9017ea..75efca76 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java
@@ -51,6 +51,7 @@ import org.onap.clamp.clds.tosca.ToscaYamlToJsonConvertor;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.LoopElementModel;
import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.policy.Policy;
import org.yaml.snakeyaml.Yaml;
@@ -110,23 +111,17 @@ public class MicroServicePolicy extends Policy implements Serializable {
}
/**
- * The constructor that create the json representation from the policyTosca
+ * The constructor that creates the json representation from the policyTosca
* using the ToscaYamlToJsonConvertor.
*
* @param name The name of the MicroService
* @param policyModel The policy model 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, PolicyModel policyModel, Boolean shared,
- Set<Loop> usedByLoops) {
- this.name = name;
- this.policyModel = policyModel;
- this.shared = shared;
- this.setJsonRepresentation(JsonUtils.GSON_JPA_MODEL
+ public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared, LoopElementModel loopElementModel) {
+ this(name,policyModel,shared,JsonUtils.GSON_JPA_MODEL
.fromJson(new ToscaYamlToJsonConvertor().parseToscaYaml(policyModel.getPolicyModelTosca(),
- policyModel.getPolicyModelType()), JsonObject.class));
- this.usedByLoops = usedByLoops;
+ policyModel.getPolicyModelType()), JsonObject.class),loopElementModel);
}
private JsonObject createJsonFromPolicyTosca() {
@@ -138,21 +133,20 @@ public class MicroServicePolicy extends Policy implements Serializable {
/**
* The constructor that does not make use of ToscaYamlToJsonConvertor but take
* the jsonRepresentation instead.
- *
* @param name The name of the MicroService
* @param policyModel The policy model type of the MicroService
* @param shared The flag indicate whether the MicroService is
- * shared
+ * shared
* @param jsonRepresentation The UI representation in json format
- * @param usedByLoops The list of loops that uses this MicroService
+ * @param loopElementModel The loop element model from which this instance should be created
*/
public MicroServicePolicy(String name, PolicyModel policyModel, Boolean shared,
- JsonObject jsonRepresentation, Set<Loop> usedByLoops) {
+ JsonObject jsonRepresentation, LoopElementModel loopElementModel) {
this.name = name;
this.policyModel = policyModel;
this.shared = shared;
- this.usedByLoops = usedByLoops;
this.setJsonRepresentation(jsonRepresentation);
+ this.setLoopElementModel(loopElementModel);
}
@Override
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 b17bf1ac..2af8ec72 100644
--- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicyService.java
@@ -23,12 +23,9 @@
package org.onap.clamp.policy.microservice;
-import com.google.common.collect.Sets;
-
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
-
import org.onap.clamp.loop.Loop;
import org.onap.clamp.policy.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -66,7 +63,7 @@ public class MicroServicePolicyService implements PolicyService<MicroServicePoli
return repository.save(
repository.findById(policy.getName()).map(p -> updateMicroservicePolicyProperties(p, policy, loop))
.orElse(new MicroServicePolicy(policy.getName(), policy.getPolicyModel(),
- policy.getShared(), policy.getJsonRepresentation(), Sets.newHashSet(loop))));
+ policy.getShared(), policy.getJsonRepresentation(),null)));
}
private MicroServicePolicy updateMicroservicePolicyProperties(MicroServicePolicy oldPolicy,
@@ -84,7 +81,6 @@ public class MicroServicePolicyService implements PolicyService<MicroServicePoli
* @param microServicePolicy The micro service policy
* @param deploymentId The deployment ID as returned by DCAE
* @param deploymentUrl The Deployment URL as returned by DCAE
- * @throws MicroServicePolicy doesn't exist in DB
*/
public void updateDcaeDeploymentFields(MicroServicePolicy microServicePolicy, String deploymentId,
String deploymentUrl) {
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 0825ea9e..52b87720 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -55,6 +55,7 @@ import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.onap.clamp.dao.model.jsontype.StringJsonUserType;
import org.onap.clamp.loop.Loop;
+import org.onap.clamp.loop.template.LoopElementModel;
import org.onap.clamp.loop.template.PolicyModel;
import org.onap.clamp.policy.Policy;
import org.yaml.snakeyaml.DumperOptions;
@@ -93,18 +94,20 @@ public class OperationalPolicy extends Policy implements Serializable {
/**
* The constructor.
- *
- * @param name The name of the operational policy
+ * @param name The name of the operational policy
* @param loop The loop that uses this operational policy
* @param configurationsJson The operational policy property in the format of
- * json
+ * json
* @param policyModel The policy model associated if any, can be null
+ * @param loopElementModel The loop element from which this instance is supposed to be created
*/
- public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel) {
+ public OperationalPolicy(String name, Loop loop, JsonObject configurationsJson, PolicyModel policyModel,
+ LoopElementModel loopElementModel) {
this.name = name;
this.loop = loop;
this.setPolicyModel(policyModel);
this.setConfigurationsJson(configurationsJson);
+ this.setLoopElementModel(loopElementModel);
LegacyOperationalPolicy.preloadConfiguration(configurationsJson, loop);
try {
this.setJsonRepresentation(
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
index 174912b2..cc636bab 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicyService.java
@@ -52,7 +52,7 @@ public class OperationalPolicyService implements PolicyService<OperationalPolicy
.map(p -> setConfigurationJson(p, policy.getConfigurationsJson()))
.orElse(new OperationalPolicy(policy.getName(), loop,
policy.getConfigurationsJson(),
- policy.getPolicyModel())))
+ policy.getPolicyModel(), null)))
.collect(Collectors.toSet());
}
diff --git a/src/main/resources/META-INF/resources/swagger.html b/src/main/resources/META-INF/resources/swagger.html
index 0138d9a3..74322f36 100644
--- a/src/main/resources/META-INF/resources/swagger.html
+++ b/src/main/resources/META-INF/resources/swagger.html
@@ -3758,7 +3758,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
</div>
<div id="footer">
<div id="footer-text">
-Last updated 2019-05-27 14:30:20 CEST
+Last updated 2020-02-12 02:20:53 PST
</div>
</div>
</body>
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 1f927267..280b808c 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -612,7 +612,40 @@
</doTry>
</route>
</put>
-
+ <post
+ uri="/v2/loop/create/{loopName}?templateName={templateName}"
+ outType="org.onap.clamp.loop.Loop" consumes="application/json"
+ produces="application/json">
+ <route>
+ <removeHeaders
+ pattern="*"
+ excludePattern="loopName|templateName" />
+ <doTry>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Create Loop')" />
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
+ <to
+ uri="bean:org.onap.clamp.loop.LoopController?method=createLoop(${header.loopName}, ${header.templateName})" />
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <setHeader headerName="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <transform>
+ <simple>ERROR: ${exception.message}</simple>
+ </transform>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" />
+ </doCatch>
+ </doTry>
+ </route>
+ </post>
<get uri="/v2/dictionary"
outType="org.onap.clamp.tosca.Dictionary" produces="application/json">
<route>
@@ -1050,6 +1083,30 @@
</doTry>
</route>
</get>
+ <get uri="/v2/templates/{templateName}/svgRepresentation"
+ outType="java.lang.String" produces="application/xml">
+ <route>
+ <removeHeaders pattern="*" excludePattern="templateName" />
+ <doTry>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Get SVG Representation for Loop template')" />
+ <to
+ uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'template','','read')" />
+ <to
+ uri="bean:org.onap.clamp.loop.template.LoopTemplatesService?method=getSvgRepresentation(${header.templateName})" />
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=endLog()" />
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>false</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=errorLog()" />
+ </doCatch>
+ </doTry>
+ </route>
+ </get>
<get uri="/v2/clampInformation" outType="org.onap.clamp.clds.model.ClampInformation"
produces="application/json">
<to
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 63209e9f..2ccecf3e 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
@@ -70,7 +70,7 @@ public class ClampGraphBuilderTest {
null);
OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
- new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"));
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "opolicy1"), null);
final Set<OperationalPolicy> opPolicies = Set.of(opPolicy);
final Set<MicroServicePolicy> microServices = Set.of(ms1, ms2);
diff --git a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
index aad11adb..7b83a4c3 100644
--- a/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
+++ b/src/test/java/org/onap/clamp/clds/util/drawing/SvgLoopGeneratorTest.java
@@ -24,10 +24,8 @@
package org.onap.clamp.clds.util.drawing;
import static org.assertj.core.api.Assertions.assertThat;
-
import com.google.gson.JsonObject;
import java.io.IOException;
-import java.util.HashSet;
import javax.xml.parsers.ParserConfigurationException;
import org.junit.Test;
import org.onap.clamp.loop.Loop;
@@ -41,12 +39,12 @@ public class SvgLoopGeneratorTest {
MicroServicePolicy ms1 =
new MicroServicePolicy("ms1", new PolicyModel("org.onap.ms1", "", "1.0.0", "short.ms1"),
false,
- new HashSet<Loop>());
+ null);
MicroServicePolicy ms2 =
new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"),
- false, new HashSet<Loop>());
+ false, null);
OperationalPolicy opPolicy = new OperationalPolicy("OperationalPolicy", new Loop(), new JsonObject(),
- new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"));
+ new PolicyModel("org.onap.opolicy", null, "1.0.0", "short.OperationalPolicy"), null);
Loop loop = new Loop();
loop.addMicroServicePolicy(ms1);
loop.addMicroServicePolicy(ms2);
diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
index 57e99a3d..50e2e8d3 100644
--- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
@@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.IOException;
-import java.util.HashSet;
import java.util.List;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
@@ -55,7 +54,7 @@ public class DcaeComponentTest {
MicroServicePolicy microServicePolicy = new MicroServicePolicy("configPolicyTest", new PolicyModel("policy1",
"tosca_definitions_version: tosca_simple_yaml_1_0_0","1.0.0"), true,
- new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), new HashSet<>());
+ new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null);
microServicePolicy.setConfigurationsJson(new Gson().fromJson("{\"param1\":\"value1\"}", JsonObject.class));
loopTest.addMicroServicePolicy(microServicePolicy);
diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
index 4fd78d18..3c2ce17e 100644
--- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
@@ -29,7 +29,6 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
-import java.util.HashSet;
import java.util.Set;
import javax.transaction.Transactional;
import org.apache.camel.CamelContext;
@@ -298,7 +297,7 @@ public class DeployFlowTestItCase {
policyModelsService.saveOrUpdatePolicyModel(policyModel);
MicroServicePolicy microService = new MicroServicePolicy(name, policyModel,
shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ gson.fromJson(jsonRepresentation, JsonObject.class), null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
diff --git a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
index fa4909cb..acde66d9 100644
--- a/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopRepositoriesItCase.java
@@ -31,7 +31,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import java.time.Instant;
-import java.util.HashSet;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.Application;
@@ -91,7 +90,7 @@ public class LoopRepositoriesItCase {
}
private OperationalPolicy getOperationalPolicy(String configJson, String name, PolicyModel policyModel) {
- return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel);
+ return new OperationalPolicy(name, null, new Gson().fromJson(configJson, JsonObject.class), policyModel, null);
}
private LoopElementModel getLoopElementModel(String yaml, String name, String policyType, String createdBy,
@@ -131,7 +130,7 @@ public class LoopRepositoriesItCase {
private MicroServicePolicy getMicroServicePolicy(String name, String jsonRepresentation, String jsonProperties,
boolean shared, PolicyModel policyModel) {
MicroServicePolicy microService = new MicroServicePolicy(name, policyModel, shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ gson.fromJson(jsonRepresentation, JsonObject.class), null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 5eca90c7..849ca5cf 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -46,7 +46,6 @@ import org.onap.clamp.policy.operational.OperationalPolicy;
import org.onap.clamp.policy.operational.OperationalPolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.Commit;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@@ -102,7 +101,7 @@ public class LoopServiceTestItCase {
// given
saveTestLoopToDb();
OperationalPolicy operationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
@@ -233,11 +232,11 @@ public class LoopServiceTestItCase {
JsonObject newJsonConfiguration = JsonUtils.GSON.fromJson("{}", JsonObject.class);
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("secondPolicyName", null,
- newJsonConfiguration, null);
+ newJsonConfiguration, null, null);
// when
firstOperationalPolicy.setConfigurationsJson(newJsonConfiguration);
@@ -264,11 +263,11 @@ public class LoopServiceTestItCase {
saveTestLoopToDb();
OperationalPolicy firstOperationalPolicy = new OperationalPolicy("firstPolicyName", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(firstOperationalPolicy));
OperationalPolicy secondOperationalPolicy = new OperationalPolicy("policyName", null,
- JsonUtils.GSON.fromJson("{}", JsonObject.class), null);
+ JsonUtils.GSON.fromJson("{}", JsonObject.class), null, null);
// when
Loop actualLoop = loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME,
@@ -320,7 +319,7 @@ public class LoopServiceTestItCase {
loop = loopService.saveOrUpdateLoop(loop);
// Add op policy
OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null,
- JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null);
+ JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class), null, null);
loopService.updateAndSaveOperationalPolicies(EXAMPLE_LOOP_NAME, Lists.newArrayList(operationalPolicy));
PolicyModel policyModel = new PolicyModel("org.policies.microPolicy",
diff --git a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
index a2a4536f..34d524a6 100644
--- a/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
+++ b/src/test/java/org/onap/clamp/loop/LoopToJsonTest.java
@@ -33,7 +33,6 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
-import java.util.HashSet;
import java.util.Random;
import org.junit.Test;
import org.onap.clamp.clds.util.JsonUtils;
@@ -55,7 +54,7 @@ public class LoopToJsonTest {
private OperationalPolicy getOperationalPolicy(String configJson, String name) {
return new OperationalPolicy(name, null, gson.fromJson(configJson, JsonObject.class),
- getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"));
+ getPolicyModel("org.onap.policy.drools", "yaml", "1.0.0", "Drools", "type1"), null);
}
private Loop getLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
@@ -73,7 +72,7 @@ public class LoopToJsonTest {
String policyTosca, String jsonProperties, boolean shared) {
MicroServicePolicy microService = new MicroServicePolicy(name, new PolicyModel(modelType, policyTosca, "1.0.0"),
shared,
- gson.fromJson(jsonRepresentation, JsonObject.class), new HashSet<>());
+ gson.fromJson(jsonRepresentation, JsonObject.class), null);
microService.setConfigurationsJson(new Gson().fromJson(jsonProperties, JsonObject.class));
return microService;
}
@@ -106,6 +105,10 @@ public class LoopToJsonTest {
return log;
}
+ /**
+ * This tests a GSON encode/decode.
+ * @throws IOException In case of failure
+ */
@Test
public void loopGsonTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
@@ -146,6 +149,11 @@ public class LoopToJsonTest {
assertThat(loopTestDeserialized.getLoopTemplate()).isEqualTo(loopTemplate);
}
+ /**
+ * This tests the service object GSON encode/decode.
+ *
+ * @throws IOException In case of issues
+ */
@Test
public void loopServiceTest() throws IOException {
Loop loopTest2 = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
@@ -166,6 +174,11 @@ public class LoopToJsonTest {
"blueprint", "components");
}
+ /**
+ * This tests the GSON encode/decode of pdpGroup.
+ *
+ * @throws IOException In case of issues
+ */
@Test
public void createPoliciesPayloadPdpGroupTest() throws IOException {
Loop loopTest = getLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
diff --git a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
index f8aadbad..80545c11 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyModelServiceItCase.java
@@ -25,6 +25,7 @@ package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
+import com.google.gson.JsonObject;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
@@ -46,8 +47,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
-import com.google.gson.JsonObject;
-
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class PolicyModelServiceItCase {
@@ -68,7 +67,7 @@ public class PolicyModelServiceItCase {
private static final String POLICY_MODEL_TYPE_2_VERSION_2 = "2.0.0";
private PolicyModel getPolicyModel(String policyType, String policyModelTosca, String version, String policyAcronym,
- String policyVariant, String createdBy) {
+ String policyVariant, String createdBy) {
PolicyModel policyModel = new PolicyModel();
policyModel.setCreatedBy(createdBy);
policyModel.setPolicyAcronym(policyAcronym);
@@ -110,6 +109,9 @@ public class PolicyModelServiceItCase {
.isEqualToIgnoringGivenFields(policyModel, "createdDate", "updatedDate", "createdBy", "updatedBy");
}
+ /**
+ * This tests a getAllPolicyModelTypes get.
+ */
@Test
@Transactional
public void shouldReturnAllPolicyModelTypes() {
@@ -125,6 +127,9 @@ public class PolicyModelServiceItCase {
assertThat(policyModelTypesList).contains(policyModel1.getPolicyModelType(), policyModel2.getPolicyModelType());
}
+ /**
+ * This tests a getAllPolicyModels get.
+ */
@Test
@Transactional
public void shouldReturnAllPolicyModels() {
@@ -138,6 +143,9 @@ public class PolicyModelServiceItCase {
assertThat(policyModelsService.getAllPolicyModels()).contains(policyModel1, policyModel2);
}
+ /**
+ * This tests a getAllPolicyModelsByType get.
+ */
@Test
@Transactional
public void shouldReturnAllModelsByType() {
@@ -152,6 +160,9 @@ public class PolicyModelServiceItCase {
policyModel2);
}
+ /**
+ * This tests the sorting of policyModel.
+ */
@Test
@Transactional
public void shouldReturnSortedSet() {
@@ -167,14 +178,17 @@ public class PolicyModelServiceItCase {
SortedSet<PolicyModel> sortedSet = new TreeSet<>();
policyModelsService.getAllPolicyModels().forEach(sortedSet::add);
- List<PolicyModel> listToCheck = sortedSet.stream().filter(
- policy -> policy.equals(policyModel3) || policy.equals(policyModel2) || policy.equals(policyModel1))
- .collect(Collectors.toList());
+ List<PolicyModel> listToCheck = sortedSet.stream()
+ .filter(policy -> policy.equals(policyModel3) || policy.equals(policyModel2)
+ || policy.equals(policyModel1)).collect(Collectors.toList());
assertThat(listToCheck.get(0)).isEqualByComparingTo(policyModel2);
assertThat(listToCheck.get(1)).isEqualByComparingTo(policyModel1);
assertThat(listToCheck.get(2)).isEqualByComparingTo(policyModel3);
}
+ /**
+ * This tests the pdpgroup GSON encode/decode and saving.
+ */
@Test
@Transactional
public void shouldAddPdpGroupInfo() {
@@ -229,12 +243,14 @@ public class PolicyModelServiceItCase {
policyModelsService.updatePdpGroupInfo(pdpGroupList);
JsonObject res1 = policyModelsService.getPolicyModel("org.onap.testos", "1.0.0").getPolicyPdpGroup();
- String expectedRes1 = "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}";
+ String expectedRes1 =
+ "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\"]}]}";
JsonObject expectedJson1 = JsonUtils.GSON.fromJson(expectedRes1, JsonObject.class);
assertThat(res1).isEqualTo(expectedJson1);
JsonObject res2 = policyModelsService.getPolicyModel("org.onap.testos2", "2.0.0").getPolicyPdpGroup();
- String expectedRes2 = "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}";
+ String expectedRes2 =
+ "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]},{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\"]}]}";
JsonObject expectedJson2 = JsonUtils.GSON.fromJson(expectedRes2, JsonObject.class);
assertThat(res2).isEqualTo(expectedJson2);
diff --git a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
index 3911494f..ea121820 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/MicroServicePayloadTest.java
@@ -25,7 +25,6 @@ package org.onap.clamp.policy.microservice;
import com.google.gson.JsonObject;
import java.io.IOException;
-import java.util.HashSet;
import org.junit.Test;
import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
@@ -38,7 +37,7 @@ public class MicroServicePayloadTest {
public void testPayloadConstruction() throws IOException {
MicroServicePolicy policy = new MicroServicePolicy("testPolicy", new PolicyModel(
"onap.policies.monitoring.cdap.tca.hi.lo.app",
- ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"),"1.0.0"), false, new HashSet<>());
+ ResourceFileUtil.getResourceAsString("tosca/tosca_example.yaml"),"1.0.0"), false, null);
policy.setConfigurationsJson(JsonUtils.GSON.fromJson(
ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-properties.json"), JsonObject.class));
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/micro-service-policy-payload.json"),
diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
index f42bbc1c..bdc7e80d 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -41,7 +41,7 @@ public class OperationalPolicyPayloadTest {
public void testOperationalPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
assertThat(policy.createPolicyPayloadYaml())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
@@ -63,7 +63,7 @@ public class OperationalPolicyPayloadTest {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"),
JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
assertThat(guardsMap).isEmpty();
assertThat(guardsMap.entrySet()).isEmpty();
@@ -73,7 +73,7 @@ public class OperationalPolicyPayloadTest {
public void testGuardPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
- OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig, null, null);
Map<String, String> guardsMap = policy.createGuardPolicyPayloads();