aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extra/sql/bulkload/create-tables.sql3
-rw-r--r--src/main/java/org/onap/clamp/loop/Loop.java19
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/DcaeComponent.java13
-rw-r--r--src/main/java/org/onap/clamp/loop/template/LoopTemplate.java25
-rw-r--r--src/main/resources/clds/camel/routes/dcae-flows.xml47
-rw-r--r--src/main/resources/clds/camel/routes/loop-flows.xml103
-rw-r--r--src/test/java/org/onap/clamp/loop/DcaeComponentTest.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java86
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java4
-rw-r--r--src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java7
-rw-r--r--src/test/resources/clds/camel/routes/dcae-flows.xml26
-rw-r--r--src/test/resources/clds/camel/routes/loop-flows.xml104
12 files changed, 328 insertions, 113 deletions
diff --git a/extra/sql/bulkload/create-tables.sql b/extra/sql/bulkload/create-tables.sql
index 10327650..819d9259 100644
--- a/extra/sql/bulkload/create-tables.sql
+++ b/extra/sql/bulkload/create-tables.sql
@@ -62,6 +62,7 @@
dcae_blueprint_id varchar(255),
maximum_instances_allowed integer,
svg_representation MEDIUMTEXT,
+ unique_blueprint boolean default false,
service_uuid varchar(255),
primary key (name)
) engine=InnoDB;
@@ -84,7 +85,7 @@
global_properties_json json,
last_computed_state varchar(255) not null,
svg_representation MEDIUMTEXT,
- loop_template_name varchar(255),
+ loop_template_name varchar(255) not null,
service_uuid varchar(255),
primary key (name)
) engine=InnoDB;
diff --git a/src/main/java/org/onap/clamp/loop/Loop.java b/src/main/java/org/onap/clamp/loop/Loop.java
index 33981267..0ac8030d 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<String, ExternalComponent> 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 21960e38..7c0e3ccb 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 b8adebae..3e90c1e5 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;
+ }
}
/**
@@ -245,6 +253,15 @@ public class LoopTemplate extends AuditEntity implements Serializable {
}
/**
+ * uniqueBlueprint getter.
+ *
+ * @return the uniqueBlueprint
+ */
+ public boolean getUniqueBlueprint() {
+ return uniqueBlueprint;
+ }
+
+ /**
* Default constructor for serialization.
*/
public LoopTemplate() {
@@ -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 7137bab9..8088c2a4 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 @@
<from uri="direct:deploy-loop" />
<choice>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
</simple>
<to uri="direct:deploy-loop-single-blueprint" />
</when>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
</simple>
<to uri="direct:deploy-loop-multi-blueprint" />
</when>
@@ -74,18 +74,14 @@
</setProperty>
<to
uri="bean:org.onap.clamp.policy.microservice.MicroServicePolicyService?method=updateDcaeDeploymentFields(${exchangeProperty[microServicePolicy]},${exchangeProperty[dcaeDeploymentId]},${exchangeProperty[dcaeStatusUrl]})" />
- <setProperty propertyName="logMessage">
- <simple>DEPLOY loop status
- (Dep-id:${exchangeProperty[dcaeDeploymentId]},
- StatusUrl:${exchangeProperty[dcaeStatusUrl]})
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>DCAE</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Deploy for the micro service: ${exchangeProperty[microServicePolicy].getName()} - ${header.CamelHttpResponseCode} : ${header.CamelHttpResponseText}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</split>
<doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>false</constant>
+ </handled>
<setProperty propertyName="logMessage">
<simple>DEPLOY micro service failed
(MicroService name:${exchangeProperty[microServicePolicy].getName()}),
@@ -176,12 +172,12 @@
<from uri="direct:undeploy-loop" />
<choice>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
</simple>
<to uri="direct:undeploy-loop-single-blueprint" />
</when>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
</simple>
<to uri="direct:undeploy-loop-multi-blueprint" />
</when>
@@ -244,25 +240,22 @@
</setProperty>
<to
uri="bean:org.onap.clamp.policy.microservice.MicroServicePolicyService?method=updateDcaeDeploymentFields(${exchangeProperty[microServicePolicy]},${exchangeProperty[microServicePolicy].getDcaeDeploymentId()},${exchangeProperty[dcaeStatusUrl]})" />
- <setProperty propertyName="logMessage">
- <simple>UNDEPLOY micro service successful
- (MicroService name:${exchangeProperty[microServicePolicy].getName()})
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>DCAE</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()} - ${header.CamelHttpResponseCode} : ${header.CamelHttpResponseText}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</when>
<otherwise>
<log loggingLevel="WARNING"
message="Cannot Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()}, the Deployment ID does not exist !" />
<to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Cannot Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()}, the Deployment ID does not exist !','WARNING',${exchangeProperty[loopObject]})" />
+ 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]})" />
</otherwise>
</choice>
</split>
<doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>false</constant>
+ </handled>
<setProperty propertyName="logMessage">
<simple>UNDEPLOY micro service failed
(MicroService name:${exchangeProperty[microServicePolicy].getName()})
@@ -355,7 +348,7 @@
<route id="get-dcae-deployment-status">
<from uri="direct:get-dcae-deployment-status" />
<log loggingLevel="INFO"
- message="Getting DCAE deployment status for loop: ${exchangeProperty[loopObject].getName()}" />
+ message="Getting DCAE deployment status for loop: ${exchangeProperty[loopObject].getName()} - ${exchangeProperty[dcaeComponent].getComponentName()}" />
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('DCAE', 'Getting Deployment status')" />
<doTry>
@@ -375,9 +368,9 @@
</simple>
</setHeader>
<log loggingLevel="INFO"
- message="Endpoint to query Closed Loop status: ${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}"></log>
+ message="Endpoint to query Closed Loop status: ${exchangeProperty[getStatusUrl]}"></log>
<toD
- uri="${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.dcae.deployment.userName}}&amp;authPassword={{clamp.config.dcae.deployment.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=30000&amp;authenticationPreemptive=true&amp;connectionClose=true" />
+ uri="${exchangeProperty[getStatusUrl]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.dcae.deployment.userName}}&amp;authPassword={{clamp.config.dcae.deployment.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=30000&amp;authenticationPreemptive=true&amp;connectionClose=true" />
<doFinally>
<to uri="direct:reset-raise-http-exception-flag" />
<to
diff --git a/src/main/resources/clds/camel/routes/loop-flows.xml b/src/main/resources/clds/camel/routes/loop-flows.xml
index 57d32f0f..c4e9fee6 100644
--- a/src/main/resources/clds/camel/routes/loop-flows.xml
+++ b/src/main/resources/clds/camel/routes/loop-flows.xml
@@ -108,37 +108,84 @@
<from uri="direct:update-dcae-status-for-loop" />
<log loggingLevel="INFO"
message="Updating DCAE status for loop: ${exchangeProperty[loopObject].getName()}" />
- <setProperty propertyName="dcaeComponent">
- <simple>${exchangeProperty[loopObject].getComponent('DCAE')}</simple>
- </setProperty>
- <when>
- <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}
- != null
- </simple>
- <setProperty propertyName="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <to uri="direct:get-dcae-deployment-status" />
+ <choice>
<when>
- <simple> ${header.CamelHttpResponseCode} == 200 </simple>
- <convertBodyTo type="java.lang.String" />
- <setProperty propertyName="dcaeResponse">
- <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
- method="convertDcaeResponse(${body})" />
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
+ </simple>
+ <setProperty propertyName="dcaeComponent">
+ <simple>${exchangeProperty[loopObject].getComponent('DCAE')}</simple>
+ </setProperty>
+ <when>
+ <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()} != null
+ </simple>
+ <setProperty propertyName="getStatusUrl">
+ <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}</simple>
+ </setProperty>
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-dcae-deployment-status" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} == 200 </simple>
+ <convertBodyTo type="java.lang.String" />
+ <setProperty propertyName="dcaeResponse">
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ method="convertDcaeResponse(${body})" />
+ </setProperty>
+ </when>
+ </when>
+ <setProperty propertyName="dcaeState">
+ <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
+ </simple>
</setProperty>
+ <log loggingLevel="INFO"
+ message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</when>
- </when>
-
- <setProperty propertyName="dcaeState">
- <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
- </simple>
- </setProperty>
- <log loggingLevel="INFO"
- message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
- <to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[loopObject]})" />
-
- </route>
+ <when>
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
+ </simple>
+ <split>
+ <simple>${exchangeProperty[loopObject].getMicroServicePolicies()}
+ </simple>
+ <setProperty propertyName="microServicePolicy">
+ <simple>${body}</simple>
+ </setProperty>
+ <setProperty propertyName="dcaeComponent">
+ <simple>${exchangeProperty[loopObject].getComponent('DCAE_' + ${exchangeProperty[microServicePolicy].getName())}</simple>
+ </setProperty>
+ <when>
+ <simple>${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()} != null
+ </simple>
+ <setProperty propertyName="getStatusUrl">
+ <simple>${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()}</simple>
+ </setProperty>
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-dcae-deployment-status" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} == 200 </simple>
+ <convertBodyTo type="java.lang.String" />
+ <setProperty propertyName="dcaeResponse">
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ method="convertDcaeResponse(${body})" />
+ </setProperty>
+ </when>
+ </when>
+ <setProperty propertyName="dcaeState">
+ <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
+ </simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[microServicePolicy]})" />
+ </split>>
+ </when>
+ </choice>
+ </route>
<route id="direct:update-loop-state">
<from uri="direct:update-loop-state" />
<log loggingLevel="INFO"
diff --git a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
index 03b35f1b..fa9cc063 100644
--- a/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/DcaeComponentTest.java
@@ -69,8 +69,8 @@ public class DcaeComponentTest {
@Test
public void convertDcaeResponseTest() throws IOException {
- String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state','error':'errorMessage', "
- + "'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}";
+ String dcaeFakeResponse = "{'requestId':'testId','operationType':'install','status':'state',"
+ + "'error':'errorMessage', 'links':{'self':'selfUrl','uninstall':'uninstallUrl'}}";
DcaeOperationStatusResponse responseObject = DcaeComponent.convertDcaeResponse(dcaeFakeResponse);
assertThat(responseObject.getRequestId()).isEqualTo("testId");
assertThat(responseObject.getOperationType()).isEqualTo("install");
diff --git a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
index e1cee341..c85d5a57 100644
--- a/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/DeployFlowTestItCase.java
@@ -58,6 +58,9 @@ public class DeployFlowTestItCase {
@Autowired
LoopService loopService;
+ @Autowired
+ LoopsRepository loopsRepository;
+
@Test
@Transactional
public void deployWithSingleBlueprintTest() throws JsonSyntaxException, IOException {
@@ -86,8 +89,8 @@ public class DeployFlowTestItCase {
@Transactional
public void deployWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
Loop loopTest2 = createLoop("ControlLoopTest2", "<xml></xml>", "yamlcontent", "{\"dcaeDeployParameters\": {"
- + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName1_tca\"},"
- + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName2_tca\"}"
+ + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName1_tca\"},"
+ + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName2_tca\"}"
+ "}}", "UUID-blueprint");
LoopTemplate template = new LoopTemplate();
template.setName("templateName");
@@ -98,7 +101,7 @@ public class DeployFlowTestItCase {
"tosca_definitions_version: tosca_simple_yaml_1_0_0", "{\"param1\":\"value1\"}", true);
loopTest2.addMicroServicePolicy(microServicePolicy1);
loopTest2.addMicroServicePolicy(microServicePolicy2);
- loopService.saveOrUpdateLoop(loopTest2);
+ loopsRepository.saveAndFlush(loopTest2);
Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest2)
.build();
@@ -143,8 +146,8 @@ public class DeployFlowTestItCase {
@Transactional
public void undeployWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
Loop loopTest2 = createLoop("ControlLoopTest2", "<xml></xml>", "yamlcontent", "{\"dcaeDeployParameters\": {"
- + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName1_tca\"},"
- + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_h2NMX_v1_0_ResourceInstanceName2_tca\"}"
+ + "\"microService1\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName1_tca\"},"
+ + "\"microService2\": {\"location_id\": \"\", \"policy_id\": \"TCA_ResourceInstanceName2_tca\"}"
+ "}}", "UUID-blueprint");
LoopTemplate template = new LoopTemplate();
template.setName("templateName");
@@ -157,7 +160,7 @@ public class DeployFlowTestItCase {
"testDeploymentId2", "testDeploymentStatusUrl2");
loopTest2.addMicroServicePolicy(microServicePolicy1);
loopTest2.addMicroServicePolicy(microServicePolicy2);
- loopService.saveOrUpdateLoop(loopTest2);
+ loopsRepository.saveAndFlush(loopTest2);
Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest2)
.build();
@@ -172,6 +175,77 @@ public class DeployFlowTestItCase {
assertThat(loopAfterTest.getDcaeDeploymentId()).isNull();
}
+
+ @Test
+ @Transactional
+ public void getStatusWithSingleBlueprintTest() throws JsonSyntaxException, IOException {
+ Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+ "UUID-blueprint");
+ LoopTemplate template = new LoopTemplate();
+ template.setName("templateName");
+ template.setBlueprint("yamlcontent");
+ loopTest.setLoopTemplate(template);
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ loopTest.addMicroServicePolicy(microServicePolicy);
+ loopService.saveOrUpdateLoop(loopTest);
+ assertThat(loopTest.getComponents().size()).isEqualTo(2);
+ assertThat(loopTest.getComponent("DCAE")).isNotNull();
+ assertThat(loopTest.getComponent("POLICY")).isNotNull();
+ Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest)
+ .build();
+
+ camelContext.createProducerTemplate().send("direct:update-dcae-status-for-loop", myCamelExchange);
+
+ assertThat(loopTest.getComponent("DCAE").getState().getStateName()).isEqualTo("BLUEPRINT_DEPLOYED");
+
+ Loop loopAfterTest = loopService.getLoop("ControlLoopTest");
+ assertThat(loopAfterTest.getComponents().size()).isEqualTo(2);
+ assertThat(loopAfterTest.getComponent("DCAE")).isNotNull();
+ assertThat(loopAfterTest.getComponent("POLICY")).isNotNull();
+ }
+
+ @Test
+ @Transactional
+ public void getStatusWithMultipleBlueprintTest() throws JsonSyntaxException, IOException {
+ Loop loopTest = createLoop("ControlLoopTest", "<xml></xml>", "yamlcontent", "{\"testname\":\"testvalue\"}",
+ "UUID-blueprint");
+ LoopTemplate template = new LoopTemplate();
+ template.setName("templateName");
+ loopTest.setLoopTemplate(template);
+ MicroServicePolicy microServicePolicy = getMicroServicePolicy("configPolicyTest", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ MicroServicePolicy microServicePolicy2 = getMicroServicePolicy("configPolicyTest2", "",
+ "{\"configtype\":\"json\"}", "tosca_definitions_version: tosca_simple_yaml_1_0_0",
+ "{\"param1\":\"value1\"}", true);
+ loopTest.addMicroServicePolicy(microServicePolicy);
+ loopTest.addMicroServicePolicy(microServicePolicy2);
+ loopService.saveOrUpdateLoop(loopTest);
+ assertThat(loopTest.getComponents().size()).isEqualTo(3);
+ assertThat(loopTest.getComponent("DCAE")).isNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2")).isNotNull();
+ assertThat(loopTest.getComponent("POLICY")).isNotNull();
+ Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext).withProperty("loopObject", loopTest)
+ .build();
+
+ camelContext.createProducerTemplate().send("direct:update-dcae-status-for-loop", myCamelExchange);
+
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest").getState().getStateName())
+ .isEqualTo("BLUEPRINT_DEPLOYED");
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2").getState().getStateName())
+ .isEqualTo("BLUEPRINT_DEPLOYED");
+
+ Loop loopAfterTest = loopService.getLoop("ControlLoopTest");
+ assertThat(loopAfterTest.getComponents().size()).isEqualTo(3);
+ assertThat(loopAfterTest.getComponent("DCAE")).isNull();
+ assertThat(loopAfterTest.getComponent("POLICY")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest")).isNotNull();
+ assertThat(loopTest.getComponent("DCAE_configPolicyTest2")).isNotNull();
+ }
+
private Loop createLoop(String name, String svgRepresentation, String blueprint, String globalPropertiesJson,
String dcaeBlueprintId) throws JsonSyntaxException, IOException {
Loop loop = new Loop(name, svgRepresentation);
diff --git a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
index ad37bcc8..f1e5c092 100644
--- a/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopControllerTestItCase.java
@@ -39,6 +39,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.Application;
import org.onap.clamp.clds.util.JsonUtils;
+import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -68,6 +69,9 @@ public class LoopControllerTestItCase {
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ testLoop.setLoopTemplate(template);
loopService.saveOrUpdateLoop(testLoop);
}
diff --git a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
index 615826ed..8089bf1a 100644
--- a/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
+++ b/src/test/java/org/onap/clamp/loop/LoopServiceTestItCase.java
@@ -40,6 +40,7 @@ import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.loop.log.LogType;
import org.onap.clamp.loop.log.LoopLog;
import org.onap.clamp.loop.log.LoopLogService;
+import org.onap.clamp.loop.template.LoopTemplate;
import org.onap.clamp.policy.microservice.MicroServicePolicy;
import org.onap.clamp.policy.microservice.MicroServicePolicyService;
import org.onap.clamp.policy.operational.OperationalPolicy;
@@ -175,6 +176,9 @@ public class LoopServiceTestItCase {
private void saveTestLoopToDb() {
Loop testLoop = createTestLoop(EXAMPLE_LOOP_NAME, "blueprint", "representation");
testLoop.setGlobalPropertiesJson(JsonUtils.GSON.fromJson(EXAMPLE_JSON, JsonObject.class));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ testLoop.setLoopTemplate(template);
loopService.saveOrUpdateLoop(testLoop);
}
@@ -296,6 +300,9 @@ public class LoopServiceTestItCase {
// Add log
Loop loop = loopsRepository.findById(EXAMPLE_LOOP_NAME).orElse(null);
loop.addLog(new LoopLog("test", LogType.INFO, "CLAMP", loop));
+ LoopTemplate template = new LoopTemplate();
+ template.setName("testTemplate");
+ loop.setLoopTemplate(template);
loop = loopService.saveOrUpdateLoop(loop);
// Add op policy
OperationalPolicy operationalPolicy = new OperationalPolicy("opPolicy", null,
diff --git a/src/test/resources/clds/camel/routes/dcae-flows.xml b/src/test/resources/clds/camel/routes/dcae-flows.xml
index 48cda7a0..8088c2a4 100644
--- a/src/test/resources/clds/camel/routes/dcae-flows.xml
+++ b/src/test/resources/clds/camel/routes/dcae-flows.xml
@@ -3,12 +3,12 @@
<from uri="direct:deploy-loop" />
<choice>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
</simple>
<to uri="direct:deploy-loop-single-blueprint" />
</when>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
</simple>
<to uri="direct:deploy-loop-multi-blueprint" />
</when>
@@ -74,6 +74,8 @@
</setProperty>
<to
uri="bean:org.onap.clamp.policy.microservice.MicroServicePolicyService?method=updateDcaeDeploymentFields(${exchangeProperty[microServicePolicy]},${exchangeProperty[dcaeDeploymentId]},${exchangeProperty[dcaeStatusUrl]})" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Deploy for the micro service: ${exchangeProperty[microServicePolicy].getName()} - ${header.CamelHttpResponseCode} : ${header.CamelHttpResponseText}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</split>
<doCatch>
<exception>java.lang.Exception</exception>
@@ -170,12 +172,12 @@
<from uri="direct:undeploy-loop" />
<choice>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} != null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
</simple>
<to uri="direct:undeploy-loop-single-blueprint" />
</when>
<when>
- <simple>${exchangeProperty['loopObject'].getLoopTemplate().getBlueprint()} == null
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
</simple>
<to uri="direct:undeploy-loop-multi-blueprint" />
</when>
@@ -238,12 +240,14 @@
</setProperty>
<to
uri="bean:org.onap.clamp.policy.microservice.MicroServicePolicyService?method=updateDcaeDeploymentFields(${exchangeProperty[microServicePolicy]},${exchangeProperty[microServicePolicy].getDcaeDeploymentId()},${exchangeProperty[dcaeStatusUrl]})" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()} - ${header.CamelHttpResponseCode} : ${header.CamelHttpResponseText}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</when>
<otherwise>
<log loggingLevel="WARNING"
message="Cannot Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()}, the Deployment ID does not exist !" />
<to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Cannot Undeploy for the micro service: ${exchangeProperty[microServicePolicy].getName()}, the Deployment ID does not exist !','WARNING',${exchangeProperty[loopObject]})" />
+ 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]})" />
</otherwise>
</choice>
</split>
@@ -344,7 +348,7 @@
<route id="get-dcae-deployment-status">
<from uri="direct:get-dcae-deployment-status" />
<log loggingLevel="INFO"
- message="Getting DCAE deployment status for loop: ${exchangeProperty[loopObject].getName()}" />
+ message="Getting DCAE deployment status for loop: ${exchangeProperty[loopObject].getName()} - ${exchangeProperty[dcaeComponent].getComponentName()}" />
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('DCAE', 'Getting Deployment status')" />
<doTry>
@@ -364,9 +368,9 @@
</simple>
</setHeader>
<log loggingLevel="INFO"
- message="Endpoint to query Closed Loop status: ${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}"></log>
+ message="Endpoint to query Closed Loop status: ${exchangeProperty[getStatusUrl]}"></log>
<toD
- uri="${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.dcae.deployment.userName}}&amp;authPassword={{clamp.config.dcae.deployment.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=30000&amp;authenticationPreemptive=true&amp;connectionClose=true" />
+ uri="${exchangeProperty[getStatusUrl]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.dcae.deployment.userName}}&amp;authPassword={{clamp.config.dcae.deployment.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=30000&amp;authenticationPreemptive=true&amp;connectionClose=true" />
<doFinally>
<to uri="direct:reset-raise-http-exception-flag" />
<to
@@ -448,9 +452,9 @@
<split>
<simple>${exchangeProperty[dcaeResponseList]}</simple>
<convertBodyTo type="org.onap.clamp.clds.model.dcae.DcaeInventoryResponse" />
- <setProperty propertyName="dcaeResponse">
- <simple>${body}</simple>
- </setProperty>
+ <setProperty propertyName="dcaeResponse">
+ <simple>${body}</simple>
+ </setProperty>
<to uri="bean:org.onap.clamp.clds.model.dcae.DcaeInventoryCache?method=addDcaeInventoryResponse(${exchangeProperty[dcaeResponse]})" />
</split>
<doFinally>
diff --git a/src/test/resources/clds/camel/routes/loop-flows.xml b/src/test/resources/clds/camel/routes/loop-flows.xml
index 036e8efc..c4e9fee6 100644
--- a/src/test/resources/clds/camel/routes/loop-flows.xml
+++ b/src/test/resources/clds/camel/routes/loop-flows.xml
@@ -17,7 +17,6 @@
<stop />
</when>
</route>
-
<route id="update-policy-status-for-loop">
<from uri="direct:update-policy-status-for-loop" />
<setProperty propertyName="policyComponent">
@@ -109,37 +108,84 @@
<from uri="direct:update-dcae-status-for-loop" />
<log loggingLevel="INFO"
message="Updating DCAE status for loop: ${exchangeProperty[loopObject].getName()}" />
- <setProperty propertyName="dcaeComponent">
- <simple>${exchangeProperty[loopObject].getComponent('DCAE')}</simple>
- </setProperty>
- <when>
- <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}
- != null
- </simple>
- <setProperty propertyName="raiseHttpExceptionFlag">
- <simple resultType="java.lang.Boolean">false</simple>
- </setProperty>
- <to uri="direct:get-dcae-deployment-status" />
+ <choice>
<when>
- <simple> ${header.CamelHttpResponseCode} == 200 </simple>
- <convertBodyTo type="java.lang.String" />
- <setProperty propertyName="dcaeResponse">
- <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
- method="convertDcaeResponse(${body})" />
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == true
+ </simple>
+ <setProperty propertyName="dcaeComponent">
+ <simple>${exchangeProperty[loopObject].getComponent('DCAE')}</simple>
+ </setProperty>
+ <when>
+ <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()} != null
+ </simple>
+ <setProperty propertyName="getStatusUrl">
+ <simple>${exchangeProperty[loopObject].getDcaeDeploymentStatusUrl()}</simple>
+ </setProperty>
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-dcae-deployment-status" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} == 200 </simple>
+ <convertBodyTo type="java.lang.String" />
+ <setProperty propertyName="dcaeResponse">
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ method="convertDcaeResponse(${body})" />
+ </setProperty>
+ </when>
+ </when>
+ <setProperty propertyName="dcaeState">
+ <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
+ </simple>
</setProperty>
+ <log loggingLevel="INFO"
+ message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[loopObject]})" />
</when>
- </when>
-
- <setProperty propertyName="dcaeState">
- <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
- </simple>
- </setProperty>
- <log loggingLevel="INFO"
- message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
- <to
- uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[loopObject]})" />
-
- </route>
+ <when>
+ <simple>${exchangeProperty['loopObject'].getLoopTemplate().getUniqueBlueprint()} == false
+ </simple>
+ <split>
+ <simple>${exchangeProperty[loopObject].getMicroServicePolicies()}
+ </simple>
+ <setProperty propertyName="microServicePolicy">
+ <simple>${body}</simple>
+ </setProperty>
+ <setProperty propertyName="dcaeComponent">
+ <simple>${exchangeProperty[loopObject].getComponent('DCAE_' + ${exchangeProperty[microServicePolicy].getName())}</simple>
+ </setProperty>
+ <when>
+ <simple>${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()} != null
+ </simple>
+ <setProperty propertyName="getStatusUrl">
+ <simple>${exchangeProperty[microServicePolicy].getDcaeDeploymentStatusUrl()}</simple>
+ </setProperty>
+ <setProperty propertyName="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-dcae-deployment-status" />
+ <when>
+ <simple> ${header.CamelHttpResponseCode} == 200 </simple>
+ <convertBodyTo type="java.lang.String" />
+ <setProperty propertyName="dcaeResponse">
+ <method ref="org.onap.clamp.loop.components.external.DcaeComponent"
+ method="convertDcaeResponse(${body})" />
+ </setProperty>
+ </when>
+ </when>
+ <setProperty propertyName="dcaeState">
+ <simple> ${exchangeProperty[dcaeComponent].computeState(*)}
+ </simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - DCAE message: ${exchangeProperty[dcaeResponse].getError()}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLogForComponent('DCAE state set to: ${exchangeProperty[dcaeState].getStateName()} - message: ${exchangeProperty[dcaeResponse].getError()}','INFO','DCAE',${exchangeProperty[microServicePolicy]})" />
+ </split>>
+ </when>
+ </choice>
+ </route>
<route id="direct:update-loop-state">
<from uri="direct:update-loop-state" />
<log loggingLevel="INFO"