From d2a4df0b62b6a32c42bac45b4bee344016faa8fb Mon Sep 17 00:00:00 2001 From: sebdet Date: Wed, 26 Feb 2020 15:47:30 -0800 Subject: [PATCH] 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 --- docs/swagger/swagger.pdf | 4 +- .../clamp/clds/client/PolicyEngineServices.java | 37 +++--- .../clamp/clds/config/CldsUserJsonDecoder.java | 4 +- .../clds/config/DefaultUserConfiguration.java | 4 +- .../clamp/clds/util/drawing/ClampGraphBuilder.java | 6 +- .../org/onap/clamp/clds/util/drawing/Painter.java | 2 +- src/main/java/org/onap/clamp/loop/Loop.java | 23 ++++ .../java/org/onap/clamp/loop/LoopController.java | 14 ++- src/main/java/org/onap/clamp/loop/LoopService.java | 17 ++- .../clamp/loop/template/LoopTemplatesService.java | 11 ++ .../org/onap/clamp/loop/template/PolicyModel.java | 15 ++- .../clamp/loop/template/PolicyModelsService.java | 12 +- .../policy/microservice/MicroServicePolicy.java | 24 ++-- .../microservice/MicroServicePolicyService.java | 6 +- .../policy/operational/OperationalPolicy.java | 11 +- .../operational/OperationalPolicyService.java | 2 +- src/main/resources/META-INF/resources/swagger.html | 2 +- .../resources/clds/camel/rest/clamp-api-v2.xml | 59 ++++++++- .../clds/util/drawing/ClampGraphBuilderTest.java | 2 +- .../clds/util/drawing/SvgLoopGeneratorTest.java | 8 +- .../org/onap/clamp/loop/DcaeComponentTest.java | 3 +- .../org/onap/clamp/loop/DeployFlowTestItCase.java | 3 +- .../onap/clamp/loop/LoopRepositoriesItCase.java | 5 +- .../org/onap/clamp/loop/LoopServiceTestItCase.java | 13 +- .../java/org/onap/clamp/loop/LoopToJsonTest.java | 19 ++- .../onap/clamp/loop/PolicyModelServiceItCase.java | 32 +++-- .../microservice/MicroServicePayloadTest.java | 3 +- .../microservice/OperationalPolicyPayloadTest.java | 6 +- ui-react/src/LoopUI.js | 3 + ui-react/src/__snapshots__/LoopUI.test.js.snap | 4 + ui-react/src/__snapshots__/OnapClamp.test.js.snap | 4 + ui-react/src/api/LoopService.js | 18 +++ ui-react/src/api/TemplateService.js | 16 +++ .../src/components/dialogs/Loop/CreateLoopModal.js | 133 +++++++++++++++++++++ .../src/components/dialogs/Policy/PolicyModal.js | 8 +- ui-react/src/components/menu/MenuBar.js | 5 +- .../menu/__snapshots__/MenuBar.test.js.snap | 55 ++++++++- 37 files changed, 468 insertions(+), 125 deletions(-) create mode 100644 ui-react/src/components/dialogs/Loop/CreateLoopModal.js diff --git a/docs/swagger/swagger.pdf b/docs/swagger/swagger.pdf index d9acf9d7..18a6316d 100644 --- a/docs/swagger/swagger.pdf +++ b/docs/swagger/swagger.pdf @@ -4,8 +4,8 @@ << /Title (Clamp Rest API) /Creator (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0) /Producer (Asciidoctor PDF 1.5.0.alpha.10, based on Prawn 1.3.0) -/CreationDate (D:20200226131758+01'00') -/ModDate (D:20200226131758+01'00') +/CreationDate (D:20200226154251-08'00') +/ModDate (D:20200226154251-08'00') >> endobj 2 0 obj 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> policyTypesList = (List>) loadedYaml .get("policy_types"); policyTypesList.parallelStream().forEach(policyType -> { - Map.Entry policyTypeEntry = (Map.Entry) new ArrayList(policyType.entrySet()).get(0); + Map.Entry policyTypeEntry = + (Map.Entry) 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>() {} - .getType(); - private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken>() {} - .getType(); + private static final Type OPERATIONAL_POLICY_TYPE = new TypeToken>() { + } + .getType(); + private static final Type MICROSERVICE_POLICY_TYPE = new TypeToken>() { + } + .getType(); @Autowired public LoopController(LoopService loopService) { this.loopService = loopService; } + public Loop createLoop(String loopName, String templateName) { + return loopService.createLoopFromTemplate(loopName, templateName); + } + public List 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); } @@ -69,6 +73,17 @@ public class LoopService { loopsRepository.deleteById(loopName); } + /** + * 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. * @@ -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 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 pdpGroupList) { List 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 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 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 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 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 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 @@ - + + + + + + + + + + java.lang.Exception + + true + + + 500 + + + ERROR: ${exception.message} + + + + + + @@ -1050,6 +1083,30 @@ + + + + + + + + + + java.lang.Exception + + false + + + + + + opPolicies = Set.of(opPolicy); final Set 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()); + null); MicroServicePolicy ms2 = new MicroServicePolicy("ms2", new PolicyModel("org.onap.ms2", "", "1.0.0", "short.ms2"), - false, new HashSet()); + 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", "", "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", "", "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", "", "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 sortedSet = new TreeSet<>(); policyModelsService.getAllPolicyModels().forEach(sortedSet::add); - List listToCheck = sortedSet.stream().filter( - policy -> policy.equals(policyModel3) || policy.equals(policyModel2) || policy.equals(policyModel1)) - .collect(Collectors.toList()); + List 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 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 guardsMap = policy.createGuardPolicyPayloads(); diff --git a/ui-react/src/LoopUI.js b/ui-react/src/LoopUI.js index 95106702..471e8720 100644 --- a/ui-react/src/LoopUI.js +++ b/ui-react/src/LoopUI.js @@ -37,10 +37,12 @@ import LoopCache from './api/LoopCache'; import LoopActionService from './api/LoopActionService'; import { Route } from 'react-router-dom' +import CreateLoopModal from './components/dialogs/Loop/CreateLoopModal'; import OpenLoopModal from './components/dialogs/Loop/OpenLoopModal'; import ModifyLoopModal from './components/dialogs/Loop/ModifyLoopModal'; import OperationalPolicyModal from './components/dialogs/OperationalPolicy/OperationalPolicyModal'; import ConfigurationPolicyModal from './components/dialogs/ConfigurationPolicy/ConfigurationPolicyModal'; +import PolicyModal from './components/dialogs/Policy/PolicyModal'; import LoopPropertiesModal from './components/dialogs/Loop/LoopPropertiesModal'; import UserInfoModal from './components/dialogs/UserInfoModal'; import LoopService from './api/LoopService'; @@ -257,6 +259,7 @@ export default class LoopUI extends React.Component { render={(routeProps) => ()} /> ()} /> ()} /> + ()} /> ()} /> ()} /> ()} /> diff --git a/ui-react/src/__snapshots__/LoopUI.test.js.snap b/ui-react/src/__snapshots__/LoopUI.test.js.snap index 3d0137c1..7d2c4467 100644 --- a/ui-react/src/__snapshots__/LoopUI.test.js.snap +++ b/ui-react/src/__snapshots__/LoopUI.test.js.snap @@ -28,6 +28,10 @@ exports[`Verify LoopUI Test the render method 1`] = ` path="/configurationPolicyModal/:policyName" render={[Function]} /> + + { + const templateOptions = templateNames.map((templateName) => { return { label: templateName, value: templateName } }); + this.setState({ templateNames: templateOptions }) + }); + } + + handleCreate() { + if (!this.state.modelName) { + alert("A model name is required"); + return; + } + console.info("Create Model " + this.state.modelName + ", Template " + this.state.chosenTemplateName + " is chosen"); + this.setState({ show: false }); + LoopService.createLoop("LOOP_" + this.state.modelName, this.state.chosenTemplateName).then(text => { + console.debug("CreateLoop response received: ", text); + try { + this.props.history.push('/'); + this.props.loadLoopFunction("LOOP_" + this.state.modelName); + } catch(err) { + alert(text); + this.props.history.push('/'); + } + }) + .catch(error => { + console.debug("Create Loop failed"); + }); + + } + + handleModelName = event => { + this.setState({ + modelName: event.target.value + }) + } + + render() { + return ( + + + Create Model + + + + Template Name + + + + + + + + + + + ); + } +} \ No newline at end of file diff --git a/ui-react/src/components/dialogs/Policy/PolicyModal.js b/ui-react/src/components/dialogs/Policy/PolicyModal.js index 75ac2c49..51a6464c 100644 --- a/ui-react/src/components/dialogs/Policy/PolicyModal.js +++ b/ui-react/src/components/dialogs/Policy/PolicyModal.js @@ -61,14 +61,14 @@ export default class PolicyModal extends React.Component { } else { console.info("NO validation errors found in policy data"); - if (policyInstanceType === 'MICRO-SERVICE-POLICY') { + if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') { this.state.loopCache.updateMicroServiceProperties(this.state.policyName, editorData[0]); LoopService.setMicroServiceProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getMicroServiceForName(this.state.policyName)).then(resp => { this.setState({ show: false }); this.props.history.push('/'); this.props.loadLoopFunction(this.state.loopCache.getLoopName()); }); - } else if (policyInstanceType === 'OPERATIONAL-POLICY') { + } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') { this.state.loopCache.updateOperationalPolicyProperties(editorData); LoopService.setOperationalPolicyProperties(this.state.loopCache.getLoopName(), this.state.loopCache.getOperationalPolicyForName(this.state.policyName)).then(resp => { this.setState({ show: false }); @@ -92,10 +92,10 @@ export default class PolicyModal extends React.Component { console.debug("Rendering PolicyModal ", this.state.policyName); var toscaModel = {}; var editorData = {}; - if (policyInstanceType === 'MICRO-SERVICE-POLICY') { + if (this.state.policyInstanceType === 'MICRO-SERVICE-POLICY') { toscaModel = this.state.loopCache.getMicroServiceJsonRepresentationForName(this.state.policyName); editorData = this.state.loopCache.getMicroServicePropertiesForName(this.state.policyName); - } else if (policyInstanceType === 'OPERATIONAL-POLICY') { + } else if (this.state.policyInstanceType === 'OPERATIONAL-POLICY') { toscaModel = this.state.loopCache.getOperationalPolicyJsonRepresentationForName(this.state.policyName); editorData = this.state.loopCache.getOperationalPolicyPropertiesForName(this.state.policyName); } diff --git a/ui-react/src/components/menu/MenuBar.js b/ui-react/src/components/menu/MenuBar.js index c1a7ac3b..2f13cfe3 100644 --- a/ui-react/src/components/menu/MenuBar.js +++ b/ui-react/src/components/menu/MenuBar.js @@ -95,10 +95,11 @@ export default class MenuBar extends React.Component { View Tosca Models - Open Loop + Create + Open Properties Close - Modify + Modify Refresh Status diff --git a/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap b/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap index a7e66edd..63d3f654 100644 --- a/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap +++ b/ui-react/src/components/menu/__snapshots__/MenuBar.test.js.snap @@ -199,6 +199,57 @@ exports[`Verify MenuBar Test the render method 1`] = ` [Function], "; } +", + ], + }, + "displayName": "Styled(Link)", + "foldedComponentIds": Array [], + "render": [Function], + "styledComponentId": "sc-bdVaJa", + "target": [Function], + "toString": [Function], + "warnTooManyClasses": [Function], + "withComponent": [Function], + } + } + disabled={false} + to="/createLoop" + > + Create + + - Open Loop + Open Modify -- 2.16.6