[SO] CNF Invoke AS instance updates 33/129633/2
authorSagarS <sagar.shetty@est.tech>
Thu, 16 Jun 2022 12:22:13 +0000 (13:22 +0100)
committerSagarS <sagar.shetty@est.tech>
Thu, 16 Jun 2022 14:35:44 +0000 (15:35 +0100)
Change-Id: I221df282a8cf1b9b4b0c579517393d2818eafaf2
Signed-off-by: SagarS <sagar.shetty@est.tech>
Issue-ID: SO-3905

bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java

index 1ed80ee..a94e6aa 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0x13ohc" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0x13ohc" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0">
   <bpmn:process id="CnfInstantiateBB" name="&#10;Invoke CNFM" isExecutable="true">
     <bpmn:startEvent id="StartEvent_0ru3x55">
       <bpmn:outgoing>SequenceFlow_016sgof</bpmn:outgoing>
     </bpmn:startEvent>
     <bpmn:sequenceFlow id="SequenceFlow_016sgof" sourceRef="StartEvent_0ru3x55" targetRef="ServiceTask_11" />
     <bpmn:endEvent id="EndEvent_001k15i">
-      <bpmn:incoming>Flow_1luy180</bpmn:incoming>
+      <bpmn:incoming>Flow_1xcu3yl</bpmn:incoming>
     </bpmn:endEvent>
     <bpmn:serviceTask id="ServiceTask_11" name="Create &#10;CreateAsRequest" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.createCreateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
       <bpmn:incoming>SequenceFlow_016sgof</bpmn:incoming>
       <bpmn:outgoing>Flow_1luy180</bpmn:outgoing>
     </bpmn:serviceTask>
     <bpmn:sequenceFlow id="Flow_1s7gtbc" sourceRef="ServiceTask_11" targetRef="Activity_1y5x7jl" />
-    <bpmn:sequenceFlow id="Flow_1luy180" sourceRef="Activity_1y5x7jl" targetRef="EndEvent_001k15i" />
+    <bpmn:sequenceFlow id="Flow_1luy180" sourceRef="Activity_1y5x7jl" targetRef="Activity_0oa5fst" />
+    <bpmn:serviceTask id="Activity_00w0lnj" name="Invoke CNFM Instance Request" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.invokeCnfmWithInstantiateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+      <bpmn:incoming>Flow_0xq0uda</bpmn:incoming>
+      <bpmn:outgoing>Flow_1xcu3yl</bpmn:outgoing>
+    </bpmn:serviceTask>
+    <bpmn:serviceTask id="Activity_0oa5fst" name="Create&#10;AsInstance Request" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.createAsInstanceRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+      <bpmn:incoming>Flow_1luy180</bpmn:incoming>
+      <bpmn:outgoing>Flow_0xq0uda</bpmn:outgoing>
+    </bpmn:serviceTask>
+    <bpmn:sequenceFlow id="Flow_0xq0uda" sourceRef="Activity_0oa5fst" targetRef="Activity_00w0lnj" />
+    <bpmn:sequenceFlow id="Flow_1xcu3yl" sourceRef="Activity_00w0lnj" targetRef="EndEvent_001k15i" />
   </bpmn:process>
   <bpmndi:BPMNDiagram id="BPMNDiagram_1">
     <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CnfInstantiateBB">
-      <bpmndi:BPMNEdge id="SequenceFlow_016sgof_di" bpmnElement="SequenceFlow_016sgof">
-        <di:waypoint x="218" y="117" />
-        <di:waypoint x="300" y="117" />
+      <bpmndi:BPMNEdge id="Flow_1luy180_di" bpmnElement="Flow_1luy180">
+        <di:waypoint x="550" y="117" />
+        <di:waypoint x="620" y="117" />
       </bpmndi:BPMNEdge>
       <bpmndi:BPMNEdge id="Flow_1s7gtbc_di" bpmnElement="Flow_1s7gtbc">
         <di:waypoint x="400" y="117" />
         <di:waypoint x="450" y="117" />
       </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge id="Flow_1luy180_di" bpmnElement="Flow_1luy180">
-        <di:waypoint x="550" y="117" />
-        <di:waypoint x="622" y="117" />
+      <bpmndi:BPMNEdge id="SequenceFlow_016sgof_di" bpmnElement="SequenceFlow_016sgof">
+        <di:waypoint x="218" y="117" />
+        <di:waypoint x="300" y="117" />
       </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_0xq0uda_di" bpmnElement="Flow_0xq0uda">
+        <di:waypoint x="720" y="117" />
+        <di:waypoint x="770" y="117" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNEdge id="Flow_1xcu3yl_di" bpmnElement="Flow_1xcu3yl">
+        <di:waypoint x="870" y="117" />
+        <di:waypoint x="912" y="117" />
+      </bpmndi:BPMNEdge>
+      <bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
+        <dc:Bounds x="182" y="99" width="36" height="36" />
+      </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="ServiceTask_1jf7hlc_di" bpmnElement="ServiceTask_11">
         <dc:Bounds x="300" y="77" width="100" height="80" />
       </bpmndi:BPMNShape>
         <dc:Bounds x="450" y="77" width="100" height="80" />
       </bpmndi:BPMNShape>
       <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
-        <dc:Bounds x="622" y="99" width="36" height="36" />
+        <dc:Bounds x="912" y="99" width="36" height="36" />
       </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
-        <dc:Bounds x="182" y="99" width="36" height="36" />
+      <bpmndi:BPMNShape id="Activity_0oa5fst_di" bpmnElement="Activity_0oa5fst">
+        <dc:Bounds x="620" y="77" width="100" height="80" />
+      </bpmndi:BPMNShape>
+      <bpmndi:BPMNShape id="Activity_00w0lnj_di" bpmnElement="Activity_00w0lnj">
+        <dc:Bounds x="770" y="77" width="100" height="80" />
       </bpmndi:BPMNShape>
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
index 6d7b3e9..927be4d 100644 (file)
@@ -5,15 +5,15 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
@@ -35,6 +35,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
 import org.onap.so.client.exception.ExceptionBuilder;
 import org.onap.so.cnfm.lcm.model.AsInstance;
 import org.onap.so.cnfm.lcm.model.CreateAsRequest;
+import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
 import org.onap.so.serviceinstancebeans.CloudConfiguration;
 import org.onap.so.serviceinstancebeans.ModelInfo;
 import org.onap.so.serviceinstancebeans.RequestDetails;
@@ -46,13 +47,15 @@ import org.springframework.stereotype.Component;
 
 /**
  * This class performs CNF Instantiation
- * 
+ *
  * @author sagar.shetty@est.tech
  * @author Waqas Ikram (waqas.ikram@est.tech)
  */
 @Component
 public class CnfInstantiateTask {
     private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject";
+    private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest";
+    private static final String AS_INSTANCE_ID = "asInstanceid";
     private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
     private final ExceptionBuilder exceptionUtil;
     private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
@@ -120,6 +123,7 @@ public class CnfInstantiateTask {
             }
 
             final AsInstance asInstance = optional.get();
+            execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid());
             LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
 
         } catch (final Exception exception) {
@@ -128,4 +132,34 @@ public class CnfInstantiateTask {
         }
     }
 
+    public void createAsInstanceRequest(final BuildingBlockExecution execution) {
+        try {
+            LOGGER.debug("Executing createAsInstanceRequest task  ...");
+
+            final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest();
+
+            LOGGER.debug("Adding InstantiateAsRequest to execution {}", instantiateAsRequest);
+
+            execution.setVariable(INSTANTIATE_AS_REQUEST_OBJECT, instantiateAsRequest);
+            LOGGER.debug("Finished executing createAsInstanceRequest task ...");
+
+        } catch (final Exception exception) {
+            LOGGER.error("Unable to create CreateAsInstanceRequest", exception);
+            exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
+        }
+    }
+
+    public void invokeCnfmWithInstantiateAsRequest(final BuildingBlockExecution execution) {
+        try {
+            final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT);
+            final String asInstanceId = execution.getVariable(AS_INSTANCE_ID);
+            cnfmHttpServiceProvider.invokeInstantiateAsRequest(createAsRequest, asInstanceId);
+            LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId);
+
+        } catch (final Exception exception) {
+            LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception);
+            exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);
+        }
+    }
+
 }
index 4ff3465..abf3508 100644 (file)
@@ -22,7 +22,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
 import java.util.Optional;
 import org.onap.so.cnfm.lcm.model.AsInstance;
 import org.onap.so.cnfm.lcm.model.CreateAsRequest;
-
+import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
 
 /**
  * @author Sagar Shetty (sagar.shetty@est.tech)
@@ -33,4 +33,6 @@ public interface CnfmHttpServiceProvider {
 
     Optional<AsInstance> invokeCreateAsRequest(final CreateAsRequest createAsRequest);
 
+    void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId);
+
 }
index f861855..bb78960 100644 (file)
@@ -5,15 +5,15 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
@@ -34,6 +34,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
+import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
 
 @Service
 public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
@@ -80,4 +81,28 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
         }
     }
 
+    @Override
+    public void invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId) {
+        try {
+
+            final String url = cnfmUrlProvider.getInstantiateAsRequestUrl(asInstanceId);
+            final ResponseEntity<AsInstance> response =
+                    httpServiceProvider.postHttpRequest(instantiateAsRequest, url, AsInstance.class);
+
+            final HttpStatus httpStatus = response.getStatusCode();
+            if (httpStatus.is2xxSuccessful()) {
+                if (!response.hasBody()) {
+                    LOGGER.error("Received response without body: {}", response);
+                }
+
+            }
+            LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value());
+
+        } catch (final RestProcessingException | InvalidRestRequestException
+                | HttpResouceNotFoundException httpInvocationException) {
+            LOGGER.error("Unexpected error while processing instantiation request", httpInvocationException);
+        }
+
+    }
+
 }
index 3a0e4de..6cd5d1e 100644 (file)
@@ -5,15 +5,15 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
@@ -44,4 +44,9 @@ public class CnfmUrlProvider {
         return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").build().toString();
     }
 
+    public String getInstantiateAsRequestUrl(String asInstanceId) {
+        return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId)
+                .pathSegment("instantiate").build().toString();
+    }
+
 }