diff options
author | 2020-02-26 15:47:30 -0800 | |
---|---|---|
committer | 2020-02-27 06:17:02 -0800 | |
commit | d2a4df0b62b6a32c42bac45b4bee344016faa8fb (patch) | |
tree | a4d49be5501c1016de3af41f7e8935cd5187ec85 /src/main | |
parent | c11160ecfdce03091917e2728f80848f4d8feb95 (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/main')
17 files changed, 170 insertions, 79 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 |