From 81c1344c018e995e4f6f906435d0faab3480e13b Mon Sep 17 00:00:00 2001 From: xuegao Date: Tue, 4 Feb 2020 15:22:00 +0100 Subject: Update get Dcae Status flow Update the flow to get Dcae Status, supporting multiple blue print. Issue-ID: CLAMP-590 Change-Id: I6a05a40d4879082413d3ed83159467ea616c5d37 Signed-off-by: xuegao --- src/main/java/org/onap/clamp/loop/Loop.java | 19 +++- .../loop/components/external/DcaeComponent.java | 13 ++- .../org/onap/clamp/loop/template/LoopTemplate.java | 25 ++++- .../resources/clds/camel/routes/dcae-flows.xml | 47 ++++------ .../resources/clds/camel/routes/loop-flows.xml | 103 +++++++++++++++------ 5 files changed, 143 insertions(+), 64 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java index 339812672..0ac8030d3 100644 --- a/src/main/java/org/onap/clamp/loop/Loop.java +++ b/src/main/java/org/onap/clamp/loop/Loop.java @@ -131,7 +131,7 @@ public class Loop extends AuditEntity implements Serializable { @Expose @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.EAGER) - @JoinColumn(name = "loop_template_name") + @JoinColumn(name = "loop_template_name", nullable=false) private LoopTemplate loopTemplate; private void initializeExternalComponents() { @@ -253,10 +253,12 @@ public class Loop extends AuditEntity implements Serializable { } public Map getComponents() { + refreshDcaeComponents(); return components; } public ExternalComponent getComponent(String componentName) { + refreshDcaeComponents(); return this.components.get(componentName); } @@ -272,6 +274,17 @@ public class Loop extends AuditEntity implements Serializable { this.loopTemplate = loopTemplate; } + private void refreshDcaeComponents() { + if (!this.loopTemplate.getUniqueBlueprint()) { + this.components.remove("DCAE"); + for (MicroServicePolicy policy : this.microServicePolicies) { + if (!this.components.containsKey("DCAE_" + policy.getName())) { + this.addComponent(new DcaeComponent(policy.getName())); + } + } + } + } + /** * Generate the loop name. * @@ -282,9 +295,9 @@ public class Loop extends AuditEntity implements Serializable { * @return The generated loop name */ public static String generateLoopName(String serviceName, String serviceVersion, String resourceName, - String blueprintFilename) { + String blueprintFileName) { StringBuilder buffer = new StringBuilder("LOOP_").append(serviceName).append("_v").append(serviceVersion) - .append("_").append(resourceName).append("_").append(blueprintFilename.replaceAll(".yaml", "")); + .append("_").append(resourceName).append("_").append(blueprintFileName.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } diff --git a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java index 21960e387..7c0e3ccbb 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java @@ -48,6 +48,8 @@ public class DcaeComponent extends ExternalComponent { private static final String DCAE_SERVICETYPE_ID = "serviceTypeId"; private static final String DCAE_INPUTS = "inputs"; + private String name; + public static final ExternalComponentState BLUEPRINT_DEPLOYED = new ExternalComponentState("BLUEPRINT_DEPLOYED", "The DCAE blueprint has been found in the DCAE inventory but not yet instancianted for this loop"); public static final ExternalComponentState PROCESSING_MICROSERVICE_INSTALLATION = new ExternalComponentState( @@ -73,13 +75,20 @@ public class DcaeComponent extends ExternalComponent { public DcaeComponent() { super(BLUEPRINT_DEPLOYED); + this.name = "DCAE"; + } + + public DcaeComponent(String name) { + super(BLUEPRINT_DEPLOYED); + this.name = "DCAE_" + name; } @Override public String getComponentName() { - return "DCAE"; + return name; } + /** * Convert the json response to a DcaeOperationStatusResponse. * @@ -170,7 +179,7 @@ public class DcaeComponent extends ExternalComponent { /** * Return the uninstallation payload for DCAE. * - * @param microServicePolicy The microServicePolicy object + * @param policy The microServicePolicy object * @return The payload in string (json) */ public static String getUndeployPayload(MicroServicePolicy policy) { diff --git a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java index b8adebae9..3e90c1e5b 100644 --- a/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java +++ b/src/main/java/org/onap/clamp/loop/template/LoopTemplate.java @@ -70,7 +70,6 @@ public class LoopTemplate extends AuditEntity implements Serializable { @Column(columnDefinition = "MEDIUMTEXT", name = "blueprint_yaml") private String blueprint; - @Expose @Column(columnDefinition = "MEDIUMTEXT", name = "svg_representation") private String svgRepresentation; @@ -88,6 +87,10 @@ public class LoopTemplate extends AuditEntity implements Serializable { @Column(name = "maximum_instances_allowed") private Integer maximumInstancesAllowed; + @Expose + @Column(name = "unique_blueprint", columnDefinition = "boolean default false") + private boolean uniqueBlueprint; + /** * name getter. * @@ -140,6 +143,11 @@ public class LoopTemplate extends AuditEntity implements Serializable { */ public void setBlueprint(String blueprint) { this.blueprint = blueprint; + if (blueprint == null) { + this.uniqueBlueprint = false; + } else { + this.uniqueBlueprint = true; + } } /** @@ -244,6 +252,15 @@ public class LoopTemplate extends AuditEntity implements Serializable { this.modelService = modelService; } + /** + * uniqueBlueprint getter. + * + * @return the uniqueBlueprint + */ + public boolean getUniqueBlueprint() { + return uniqueBlueprint; + } + /** * Default constructor for serialization. */ @@ -265,7 +282,7 @@ public class LoopTemplate extends AuditEntity implements Serializable { public LoopTemplate(String name, String blueprint, String svgRepresentation, Integer maxInstancesAllowed, Service service) { this.name = name; - this.blueprint = blueprint; + this.setBlueprint(blueprint); this.svgRepresentation = svgRepresentation; this.maximumInstancesAllowed = maxInstancesAllowed; @@ -312,10 +329,10 @@ public class LoopTemplate extends AuditEntity implements Serializable { * @return The generated loop template name */ public static String generateLoopTemplateName(String serviceName, String serviceVersion, String resourceName, - String blueprintFilename) { + String blueprintFileName) { StringBuilder buffer = new StringBuilder("LOOP_TEMPLATE_").append(serviceName).append("_v") .append(serviceVersion).append("_").append(resourceName).append("_") - .append(blueprintFilename.replaceAll(".yaml", "")); + .append(blueprintFileName.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } } diff --git a/src/main/resources/clds/camel/routes/dcae-flows.xml b/src/main/resources/clds/camel/routes/dcae-flows.xml index 7137bab92..8088c2a40 100644 --- a/src/main/resources/clds/camel/routes/dcae-flows.xml +++ b/src/main/resources/clds/camel/routes/dcae-flows.xml @@ -3,12 +3,12 @@ - ${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true - ${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false @@ -74,18 +74,14 @@ - - DEPLOY loop status - (Dep-id:${exchangeProperty[dcaeDeploymentId]}, - StatusUrl:${exchangeProperty[dcaeStatusUrl]}) - - - - DCAE - - + + java.lang.Exception + + false + DEPLOY micro service failed (MicroService name:${exchangeProperty[microServicePolicy].getName()}), @@ -176,12 +172,12 @@ - ${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true - ${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false @@ -244,25 +240,22 @@ - - UNDEPLOY micro service successful - (MicroService name:${exchangeProperty[microServicePolicy].getName()}) - - - - DCAE - - + + uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Cannot Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()}, the Deployment ID does not exist !','WARNING','DCAE',${exchangeProperty[loopObject]})" /> + java.lang.Exception + + false + UNDEPLOY micro service failed (MicroService name:${exchangeProperty[microServicePolicy].getName()}) @@ -355,7 +348,7 @@ + message="Getting DCAE deployment status for loop: ${exchangeProperty[loopObject].getName()} - ${exchangeProperty[dcaeComponent].getComponentName()}" /> @@ -375,9 +368,9 @@ + message="Endpoint to query Closed Loop status: ${exchangeProperty[getStatusUrl]}"> + uri="${exchangeProperty[getStatusUrl]}?bridgeEndpoint=true&useSystemProperties=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&authMethod=Basic&authUsername={{clamp.config.dcae.deployment.userName}}&authPassword={{clamp.config.dcae.deployment.password}}&connectionTimeToLive=5000&httpClient.connectTimeout=10000&httpClient.socketTimeout=30000&authenticationPreemptive=true&connectionClose=true" /> - - ${exchangeProperty[loopObject].getComponent('DCAE')} - - - ${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()} - != null - - - false - - + - ${header.CamelHttpResponseCode} == 200 - - - + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true + + + ${exchangeProperty[loopObject].getComponent('DCAE')} + + + ${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()} != null + + + ${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()} + + + false + + + + ${header.CamelHttpResponseCode} == 200 + + + + + + + + ${exchangeProperty[dcaeComponent].computeState(*)} + + + - - - - ${exchangeProperty[dcaeComponent].computeState(*)} - - - - - - + + ${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false + + + ${exchangeProperty[loopObject].getMicroServicePolicies()} + + + ${body} + + + ${exchangeProperty[loopObject].getComponent('DCAE_' + ${exchangeProperty[microServicePolicy].getName())} + + + ${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()} != null + + + ${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()} + + + false + + + + ${header.CamelHttpResponseCode} == 200 + + + + + + + + ${exchangeProperty[dcaeComponent].computeState(*)} + + + + + > + + +