aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorraviteja.karumuri <raviteja.karumuri@est.tech>2022-07-13 13:17:49 +0100
committerraviteja.karumuri <raviteja.karumuri@est.tech>2023-02-17 16:59:11 +0000
commitfb516859f920197eba4cbc1f5b82279f3e3753c6 (patch)
treeae72025fc67b49cfae46d892936ceb6449b5dcc8
parentd0493f954a48021662b5b6d3ba45b262750690c9 (diff)
[SO] SO changes to support Delete AS
Issue-ID: SO-4084 Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech> Change-Id: Ib75076bdd98291b48149a9ad859fd383a551cd45
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql17
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn83
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn21
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn8
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java123
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java18
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java7
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java55
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java (renamed from bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java)98
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java2
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java126
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java14
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java140
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java (renamed from bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java)39
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java19
16 files changed, 664 insertions, 115 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
index 7087b6c3e3..67f66222dc 100644
--- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/R__MacroData.sql
@@ -43,7 +43,8 @@ INSERT INTO northbound_request_ref_lookup(MACRO_ACTION, ACTION, REQUEST_SCOPE, I
('CNF-Macro-Upgrade', 'upgradeCnf', 'Vnf', false,true, '7', '7','DEFAULT', '*'),
('PNF-Macro-Delete', 'deleteInstance', 'Pnf', false,true, '7', '7','DEFAULT', '*'),
('PNF-Macro-Create', 'createInstance', 'Pnf', false,true, '7', '7','DEFAULT', '*'),
-('Cnf-Create', 'createInstance', 'Cnf', true, true, '7','7','DEFAULT', '*');
+('Cnf-Create', 'createInstance', 'Cnf', true, true, '7','7','DEFAULT', '*'),
+('Cnf-Delete', 'deleteInstance', 'Cnf', true, true, '7','7','DEFAULT', '*');
INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, SCOPE, ACTION, FLOW_VERSION, NB_REQ_REF_LOOKUP_ID) VALUES
@@ -283,7 +284,8 @@ INSERT INTO orchestration_flow_reference(COMPOSITE_ACTION, SEQ_NO, FLOW_NAME, SC
('PNF-Macro-Create', '5', 'ActivatePnfBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'PNF-Macro-Create' and CLOUD_OWNER = 'DEFAULT')),
('PNF-Macro-Delete', '1', 'DeactivatePnfBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'PNF-Macro-Delete' and CLOUD_OWNER = 'DEFAULT')),
('PNF-Macro-Delete', '2', 'UnassignPnfBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'PNF-Macro-Delete' and CLOUD_OWNER = 'DEFAULT')),
-('CNF-Create', '1', 'CnfInstantiateBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Create' and CLOUD_OWNER = 'DEFAULT'));
+('CNF-Create', '1', 'CnfInstantiateBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Create' and CLOUD_OWNER = 'DEFAULT')),
+('CNF-Delete', '2', 'CnfDeleteBB', NULL, NULL, 1.0,(SELECT id from northbound_request_ref_lookup WHERE MACRO_ACTION = 'Cnf-Delete' and CLOUD_OWNER = 'DEFAULT'));
INSERT INTO rainy_day_handler_macro (FLOW_NAME, SERVICE_TYPE, VNF_TYPE, ERROR_CODE, WORK_STEP, POLICY, SECONDARY_POLICY, REG_EX_ERROR_MESSAGE, SERVICE_ROLE)
@@ -352,7 +354,8 @@ VALUES
('VNFUnsetClosedLoopDisabledActivity','*','*','*','*','Manual','Abort','*', '*'),
('DeleteChildServiceBB', '*', '*', '*', '*', 'Rollback', 'Abort', '*', '*'),
('CreateChildServiceBB', '*', '*', '*', '*', 'Rollback', 'Abort', '*', '*'),
-('UpgradeVfModuleBB', '*', '*', '*', '*', 'Rollback', 'Abort', '*', '*');
+('UpgradeVfModuleBB', '*', '*', '*', '*', 'Rollback', 'Abort', '*', '*'),
+('CnfDeleteBB', '*', '*', '*', '*' , 'Abort', 'Abort', '*', '*');
INSERT INTO building_block_detail (building_block_name, resource_type, target_action)
VALUES
@@ -450,7 +453,8 @@ VALUES
('HealthCheckBB', 'NO_VALIDATE', 'CUSTOM'),
('UpgradeVfModuleBB', 'NO_VALIDATE', 'CUSTOM'),
('VfModuleUpgradeStatusBB', 'NO_VALIDATE', 'CUSTOM'),
-('CnfInstantiateBB', 'CNF', 'ACTIVATE');
+('CnfInstantiateBB', 'CNF', 'ACTIVATE'),
+('CnfDeleteBB', 'CNF', 'DEACTIVATE');
INSERT INTO orchestration_status_state_transition_directive (resource_type, orchestration_status, target_action, flow_directive)
@@ -883,7 +887,10 @@ VALUES
('CONFIGURATION', 'PENDING ACTIVATION', 'DEACTIVATE', 'FAIL'),
('CONFIGURATION', 'PENDING', 'DEACTIVATE', 'FAIL'),
('VNF','CONFIGDEPLOYED','ACTIVATE','CONTINUE'),
-('CNF','PRECREATED','ACTIVATE','CONTINUE');
+('CNF','PRECREATED','ACTIVATE','CONTINUE'),
+('CNF','PRECREATED','DEACTIVATE','CONTINUE'),
+('CNF','CREATED','DEACTIVATE','CONTINUE');
+
INSERT INTO vnf_components_recipe (VNF_TYPE, VNF_COMPONENT_TYPE, ACTION, VERSION, ORCHESTRATION_URI, RECIPE_TIMEOUT)
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn
new file mode 100644
index 0000000000..09c9b69ccf
--- /dev/null
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfDeleteBB.bpmn
@@ -0,0 +1,83 @@
+<?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:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0lxlukw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0">
+ <bpmn:process id="CnfDeleteBB" name="Invoke CNFM to Delete ASInstance" isExecutable="true">
+ <bpmn:startEvent id="StartEvent_0ru3x55">
+ <bpmn:outgoing>SequenceFlow_016sgof</bpmn:outgoing>
+ </bpmn:startEvent>
+ <bpmn:endEvent id="EndEvent_001k15i">
+ <bpmn:incoming>Flow_1s7gtbc</bpmn:incoming>
+ </bpmn:endEvent>
+ <bpmn:serviceTask id="invokeCnfmToDeleteAsInstnace" name="Invoke CNFM to DeleteASInstance" camunda:expression="${CnfDeleteTask.invokeCnfmToDeleteAsInstance(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>Flow_00hczi1</bpmn:incoming>
+ <bpmn:outgoing>Flow_1s7gtbc</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="SequenceFlow_016sgof" sourceRef="StartEvent_0ru3x55" targetRef="Activity_1uqgwny" />
+ <bpmn:sequenceFlow id="Flow_1s7gtbc" sourceRef="invokeCnfmToDeleteAsInstnace" targetRef="EndEvent_001k15i" />
+ <bpmn:serviceTask id="invokeCnfmToTerminateAsInstnace" name="Invoke CNFM to TerminateAsInstnace" camunda:expression="${CnfDeleteTask.invokeCnfmToTerminateAsInstance(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>Flow_19rm5pn</bpmn:incoming>
+ <bpmn:outgoing>Flow_0td4p22</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="Flow_19rm5pn" sourceRef="Activity_1uqgwny" targetRef="invokeCnfmToTerminateAsInstnace" />
+ <bpmn:serviceTask id="Activity_1uqgwny" name="Invoke Create TerminateAsRequest" camunda:expression="${CnfDeleteTask.createTerminateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>SequenceFlow_016sgof</bpmn:incoming>
+ <bpmn:outgoing>Flow_19rm5pn</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="Flow_0td4p22" sourceRef="invokeCnfmToTerminateAsInstnace" targetRef="Monitor_Termination_Job" />
+ <bpmn:callActivity id="Monitor_Termination_Job" name="Monitor Termination Job" calledElement="MonitorCnfmJob">
+ <bpmn:extensionElements>
+ <camunda:out source="WorkflowException" target="WorkflowException" />
+ <camunda:in source="mso-request-id" target="mso-request-id" />
+ <camunda:in source="gBuildingBlockExecution" target="gBuildingBlockExecution" />
+ <camunda:out source="gBuildingBlockExecution" target="gBuildingBlockExecution" />
+ <camunda:in source="CnfmStatusCheckUrl" target="CnfmStatusCheckUrl" />
+ <camunda:out source="WorkflowExceptionErrorMessage" target="WorkflowExceptionErrorMessage" />
+ <camunda:in source="MonitorJobName" target="MonitorJobName" />
+ </bpmn:extensionElements>
+ <bpmn:incoming>Flow_0td4p22</bpmn:incoming>
+ <bpmn:outgoing>Flow_00hczi1</bpmn:outgoing>
+ </bpmn:callActivity>
+ <bpmn:sequenceFlow id="Flow_00hczi1" sourceRef="Monitor_Termination_Job" targetRef="invokeCnfmToDeleteAsInstnace" />
+ </bpmn:process>
+ <bpmndi:BPMNDiagram id="BPMNDiagram_1">
+ <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CnfDeleteBB">
+ <bpmndi:BPMNEdge id="Flow_00hczi1_di" bpmnElement="Flow_00hczi1">
+ <di:waypoint x="640" y="140" />
+ <di:waypoint x="710" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_0td4p22_di" bpmnElement="Flow_0td4p22">
+ <di:waypoint x="480" y="140" />
+ <di:waypoint x="540" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_19rm5pn_di" bpmnElement="Flow_19rm5pn">
+ <di:waypoint x="320" y="140" />
+ <di:waypoint x="380" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_1s7gtbc_di" bpmnElement="Flow_1s7gtbc">
+ <di:waypoint x="810" y="140" />
+ <di:waypoint x="1022" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="SequenceFlow_016sgof_di" bpmnElement="SequenceFlow_016sgof">
+ <di:waypoint x="178" y="140" />
+ <di:waypoint x="220" y="140" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
+ <dc:Bounds x="142" y="122" width="36" height="36" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
+ <dc:Bounds x="1022" y="122" width="36" height="36" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="ServiceTask_11_di" bpmnElement="invokeCnfmToDeleteAsInstnace">
+ <dc:Bounds x="710" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_06oby7l_di" bpmnElement="invokeCnfmToTerminateAsInstnace">
+ <dc:Bounds x="380" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_0ziu33x_di" bpmnElement="Activity_1uqgwny">
+ <dc:Bounds x="220" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="CallActivity_0fuqfru_di" bpmnElement="Monitor_Termination_Job">
+ <dc:Bounds x="540" y="100" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ </bpmndi:BPMNPlane>
+ </bpmndi:BPMNDiagram>
+</bpmn:definitions>
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
index 6e1996acd8..d2d986e87b 100644
--- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
@@ -36,6 +36,7 @@
<camunda:out source="gBuildingBlockExecution" target="gBuildingBlockExecution" />
<camunda:in source="CnfmStatusCheckUrl" target="CnfmStatusCheckUrl" />
<camunda:out source="WorkflowExceptionErrorMessage" target="WorkflowExceptionErrorMessage" />
+ <camunda:in source="MonitorJobName" target="MonitorJobName" />
</bpmn:extensionElements>
<bpmn:incoming>Flow_1xcu3yl</bpmn:incoming>
<bpmn:outgoing>Flow_149m8py</bpmn:outgoing>
@@ -44,6 +45,10 @@
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CnfInstantiateBB">
+ <bpmndi:BPMNEdge id="Flow_149m8py_di" bpmnElement="Flow_149m8py">
+ <di:waypoint x="1000" y="117" />
+ <di:waypoint x="1062" y="117" />
+ </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1xcu3yl_di" bpmnElement="Flow_1xcu3yl">
<di:waypoint x="840" y="117" />
<di:waypoint x="900" y="117" />
@@ -64,31 +69,27 @@
<di:waypoint x="178" y="117" />
<di:waypoint x="240" y="117" />
</bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge id="Flow_149m8py_di" bpmnElement="Flow_149m8py">
- <di:waypoint x="1000" y="117" />
- <di:waypoint x="1062" y="117" />
- </bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
<dc:Bounds x="142" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
+ <dc:Bounds x="1062" y="99" width="36" height="36" />
+ </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_1jf7hlc_di" bpmnElement="ServiceTask_11">
<dc:Bounds x="240" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1y5x7jl_di" bpmnElement="Activity_1y5x7jl">
<dc:Bounds x="410" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="Activity_0oa5fst_di" bpmnElement="Activity_0oa5fst">
- <dc:Bounds x="570" y="77" width="100" height="80" />
- </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_00w0lnj_di" bpmnElement="Activity_00w0lnj">
<dc:Bounds x="740" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_0oa5fst_di" bpmnElement="Activity_0oa5fst">
+ <dc:Bounds x="570" y="77" width="100" height="80" />
+ </bpmndi:BPMNShape>
<bpmndi:BPMNShape id="CallActivity_0fuqfru_di" bpmnElement="CallActivity_0fuqfru">
<dc:Bounds x="900" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
- <dc:Bounds x="1062" y="99" width="36" height="36" />
- </bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn
index be683b9ca6..73fd9b4a1b 100644
--- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/MonitorCnfmJob.bpmn
@@ -30,14 +30,14 @@
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_0s1plu9" sourceRef="StartEvent_01r97z2" targetRef="ServiceTask_17jlnng" />
<bpmn:sequenceFlow id="SequenceFlow_0etw572" sourceRef="IntermediateCatchEvent_1besn3n" targetRef="ServiceTask_17jlnng" />
- <bpmn:serviceTask id="ServiceTask_17jlnng" name="&#10;Get Current Operation Status&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmCreateJobTask.getCurrentOperationStatus(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:serviceTask id="ServiceTask_17jlnng" name="&#10;Get Current Operation Status&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmJobTask.getCurrentOperationStatus(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
<bpmn:incoming>SequenceFlow_0etw572</bpmn:incoming>
<bpmn:incoming>SequenceFlow_0s1plu9</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_153a3kp</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="SequenceFlow_1vmxw9g" sourceRef="ExclusiveGateway_1hkl6yy" targetRef="IntermediateCatchEvent_1besn3n" />
<bpmn:sequenceFlow id="SequenceFlow_0is7myf" sourceRef="ExclusiveGateway_1hkl6yy" targetRef="EndEvent_1ohsce9">
- <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${MonitorCnfmCreateJobTask.hasOperationFinished(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}</bpmn:conditionExpression>
+ <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${MonitorCnfmJobTask.hasOperationFinished(InjectExecution.execute(execution, execution.getVariable("gBuildingBlockExecution")))}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<bpmn:sequenceFlow id="SequenceFlow_153a3kp" sourceRef="ServiceTask_17jlnng" targetRef="ExclusiveGateway_1hkl6yy" />
</bpmn:subProcess>
@@ -54,12 +54,12 @@
<bpmn:sequenceFlow id="SequenceFlow_1v4yr3f" sourceRef="SubProcess_19j0v63" targetRef="ServiceTask_1gms128" />
<bpmn:sequenceFlow id="SequenceFlow_1i1o9sh" sourceRef="BoundaryEvent_0xiabzp" targetRef="ServiceTask_1s87b92" />
<bpmn:sequenceFlow id="SequenceFlow_1x3tbl0" sourceRef="StartEvent_1" targetRef="SubProcess_19j0v63" />
- <bpmn:serviceTask id="ServiceTask_1s87b92" name="&#10;Time Out Log Failure&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmCreateJobTask.timeOutLogFailue(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:serviceTask id="ServiceTask_1s87b92" name="&#10;Time Out Log Failure&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmJobTask.timeOutLogFailure(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
<bpmn:incoming>SequenceFlow_1i1o9sh</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0bcgtzj</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="SequenceFlow_0bcgtzj" sourceRef="ServiceTask_1s87b92" targetRef="EndEvent_1w3t3t0" />
- <bpmn:serviceTask id="ServiceTask_1gms128" name="&#10;Check if operation was successful&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmCreateJobTask.checkIfOperationWasSuccessful(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:serviceTask id="ServiceTask_1gms128" name="&#10;Check if operation was successful&#10;" camunda:asyncAfter="true" camunda:expression="${MonitorCnfmJobTask.checkIfOperationWasSuccessful(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
<bpmn:incoming>SequenceFlow_1v4yr3f</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1543qy7</bpmn:outgoing>
</bpmn:serviceTask>
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
new file mode 100644
index 0000000000..ce0b3000e0
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTask.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
+
+import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import org.camunda.bpm.engine.delegate.BpmnError;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * This class performs CNF Delete
+ *
+ * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
+ */
+@Component
+public class CnfDeleteTask {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
+ private final ExceptionBuilder exceptionUtil;
+ private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
+ private final ExtractPojosForBB extractPojosForBB;
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
+ private static final String AS_INSTANCE_ID = "asInstanceid";
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
+
+ @Autowired
+ public CnfDeleteTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider, final ExceptionBuilder exceptionUtil,
+ ExtractPojosForBB extractPojosForBB) {
+ this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
+ this.exceptionUtil = exceptionUtil;
+ this.extractPojosForBB = extractPojosForBB;
+ }
+
+ public void createTerminateAsRequest(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing createTerminateAsRequest task ...");
+
+ final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
+ terminateAsRequest.setTerminationType(TerminateAsRequest.TerminationTypeEnum.GRACEFUL);
+ terminateAsRequest.setGracefulTerminationTimeout(0);
+ terminateAsRequest.setAdditionalParams(new HashMap<>());
+
+ LOGGER.debug("Adding TerminateAsRequest to execution {}", terminateAsRequest);
+
+ execution.setVariable(TERMINATE_AS_REQUEST_OBJECT, terminateAsRequest);
+ LOGGER.debug("Finished executing terminateAsRequest task ...");
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to create TerminateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
+ }
+ }
+
+ public void invokeCnfmToTerminateAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing TerminateAsInstance task ...");
+
+ final TerminateAsRequest terminateAsRequest = execution.getVariable(TERMINATE_AS_REQUEST_OBJECT);
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<URI> terminateStatusCheck =
+ cnfmHttpServiceProvider.invokeTerminateAsRequest(asInstanceId, terminateAsRequest);
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL,
+ terminateStatusCheck.orElseThrow(() -> new NoSuchElementException("Status check url Not found")));
+ execution.setVariable(MONITOR_JOB_NAME, "Terminate");
+ LOGGER.debug("Successfully invoked CNFM terminate AS request: {}", asInstanceId);
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM TerminateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2002, exception);
+ }
+ }
+
+ public void invokeCnfmToDeleteAsInstance(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing DeleteAsInstance task ...");
+
+ final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
+ final String asInstanceId = vnf.getVnfId();
+
+ Optional<Boolean> response = cnfmHttpServiceProvider.invokeDeleteAsRequest(asInstanceId);
+ if (Boolean.TRUE.equals(response
+ .orElseThrow(() -> new BpmnError("Unable to complete DeleteAsRequest of ID: " + asInstanceId)))) {
+ LOGGER.debug("Successfully invoked CNFM delete AS request with ID: {}", asInstanceId);
+ }
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM DeleteAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2003, exception);
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
index 105cca28c8..c7f3310391 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
@@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
import static java.util.Objects.isNull;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.RESOURCE_ID_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY;
@@ -30,6 +31,7 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.groovy.util.Maps;
import org.onap.logging.filter.base.ONAPComponents;
@@ -63,6 +65,7 @@ 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 CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
private static final String AS_INSTANCE_ID = "asInstanceid";
private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
private final ExceptionBuilder exceptionUtil;
@@ -98,6 +101,7 @@ public class CnfInstantiateTask {
final ModelInfo modelInfo = requestDetails.getModelInfo();
final CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
final ServiceInstance serviceInstance = generalBuildingBlock.getServiceInstance();
+ final String resourceId = executeBuildingBlock.getResourceId();
final CreateAsRequest createAsRequest = new CreateAsRequest().asdId(modelInfo.getModelVersionId())
.asInstanceName(requestDetails.getRequestInfo().getInstanceName())
@@ -105,7 +109,7 @@ public class CnfInstantiateTask {
CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId(), TENANT_ID_PARAM_KEY,
cloudConfiguration.getTenantId(), SERVICE_INSTANCE_ID_PARAM_KEY,
serviceInstance.getServiceInstanceId(), SERVICE_INSTANCE_NAME_PARAM_KEY,
- serviceInstance.getServiceInstanceName()));
+ serviceInstance.getServiceInstanceName(), RESOURCE_ID_KEY, resourceId));
LOGGER.debug("Adding CreateAsRequest to execution {}", createAsRequest);
@@ -130,7 +134,8 @@ public class CnfInstantiateTask {
"Unable to invoke CNFM for CreateAsRequest", ONAPComponents.SO);
}
- final AsInstance asInstance = optional.orElseThrow();
+ final AsInstance asInstance =
+ optional.orElseThrow(() -> new NoSuchElementException("AsInstance object is empty"));
execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid());
LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
@@ -150,8 +155,8 @@ public class CnfInstantiateTask {
if (requestDetails != null && requestDetails.getRequestParameters() != null) {
List<Map<String, Object>> userParams = requestDetails.getRequestParameters().getUserParams();
if (userParams != null && !userParams.isEmpty()) {
- List deploymentItems = new ArrayList<Object>();
- List deploymentItemsReq = new ArrayList<AsInfoModificationRequestDeploymentItems>();
+ List<Object> deploymentItems = new ArrayList<>();
+ List<AsInfoModificationRequestDeploymentItems> deploymentItemsReq = new ArrayList<>();
for (Map<String, Object> userParam : userParams) {
if (userParam.containsKey("deploymentItems")) {
deploymentItems = (ArrayList<Object>) userParam.get("deploymentItems");
@@ -183,9 +188,10 @@ public class CnfInstantiateTask {
try {
final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT);
final String asInstanceId = execution.getVariable(AS_INSTANCE_ID);
- Optional<URI> cnf_status_check_url =
+ Optional<URI> cnfStatusCheckURL =
cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId);
- execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnf_status_check_url.get());
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnfStatusCheckURL.orElseThrow());
+ execution.setVariable(MONITOR_JOB_NAME, "Instantiate");
LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId);
} catch (final Exception exception) {
LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception);
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
index cb6a96c152..5b8ab355a0 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
@@ -25,6 +25,7 @@ import org.onap.so.cnfm.lcm.model.AsInstance;
import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
/**
* @author Sagar Shetty (sagar.shetty@est.tech)
@@ -38,5 +39,9 @@ public interface CnfmHttpServiceProvider {
Optional<URI> invokeInstantiateAsRequest(InstantiateAsRequest instantiateAsRequest, String asInstanceId);
- Optional<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url);
+ Optional<AsLcmOpOcc> getOperationJobStatus(final String url);
+
+ Optional<Boolean> invokeDeleteAsRequest(final String asInstanceId);
+
+ Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest);
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
index 1035f4314e..0edeb4089c 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
@@ -26,6 +26,7 @@ import org.onap.so.cnfm.lcm.model.AsInstance;
import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
@@ -111,14 +112,14 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
@Override
- public Optional<AsLcmOpOcc> getInstantiateOperationJobStatus(final String url) {
+ public Optional<AsLcmOpOcc> getOperationJobStatus(final String url) {
try {
final ResponseEntity<AsLcmOpOcc> response = httpServiceProvider.getHttpResponse(url, AsLcmOpOcc.class);
final HttpStatus httpStatus = response.getStatusCode();
if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) {
- LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: ", url, httpStatus.value());
+ LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: {}", url, httpStatus.value());
return Optional.empty();
}
@@ -134,4 +135,54 @@ public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
}
}
+ @Override
+ public Optional<Boolean> invokeDeleteAsRequest(String asInstanceId) {
+ try {
+
+ final String url = cnfmUrlProvider.getDeleteAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.deleteHttpRequest(url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (!(httpStatus.is2xxSuccessful())) {
+ LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value());
+ return Optional.empty();
+ }
+ return Optional.of(Boolean.TRUE);
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing delete request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ public Optional<URI> invokeTerminateAsRequest(String asInstanceId, TerminateAsRequest terminateAsRequest) {
+ try {
+
+ final String url = cnfmUrlProvider.getTerminateAsRequestUrl(asInstanceId);
+ LOGGER.debug("Will send request to CNFM to terminate by uisng the url: {}", url);
+
+ ResponseEntity<Void> response = httpServiceProvider.postHttpRequest(terminateAsRequest, url, Void.class);
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (httpStatus.is2xxSuccessful()) {
+ URI statusUri = response.getHeaders().getLocation();
+ if (statusUri == null) {
+ LOGGER.error("Received response without status URL while terminating of instance with ID: {}",
+ asInstanceId);
+ return Optional.empty();
+ }
+ return Optional.of(statusUri);
+ }
+ LOGGER.error("Unable to invoke HTTP DELETE while terminating by using URL: {}, Response Code: {}", url,
+ httpStatus.value());
+ return Optional.empty();
+
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing terminate request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
index cef2f3f818..d7247b40d0 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
@@ -51,4 +51,13 @@ public class CnfmUrlProvider {
.pathSegment("instantiate").build().toString();
}
+ public String getDeleteAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId).build()
+ .toString();
+ }
+
+ public String getTerminateAsRequestUrl(String asInstanceId) {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").pathSegment(asInstanceId)
+ .pathSegment("terminate").build().toString();
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java
index eb1cd1c1b6..f84120e558 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTask.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTask.java
@@ -18,73 +18,75 @@
package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
-import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_CNF_STATUS_RESPONSE_PARAM_NAME;
+import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CNF_STATUS_RESPONSE_PARAM_NAME;
import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
import java.net.URI;
import java.util.Optional;
-import org.onap.logging.filter.base.ONAPComponents;
+import java.util.Set;
+import org.camunda.bpm.engine.delegate.BpmnError;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.google.common.collect.ImmutableSet;
-import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
-import org.onap.so.cnfm.lcm.model.AsLcmOpOcc.OperationStateEnum;
-
/**
* @author sagar.shetty@est.tech
+ * @author Raviteja Karumuri (raviteja.karumuri@est.tech)
*/
@Component
-public class MonitorCnfmCreateJobTask {
+public class MonitorCnfmJobTask {
- public static final ImmutableSet<OperationStateEnum> OPERATION_FINISHED_STATES =
- ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK);
private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
- private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmCreateJobTask.class);
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
+ public static final Set<OperationStateEnum> OPERATION_FINISHED_STATES =
+ Set.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK);
+ private static final Logger LOGGER = LoggerFactory.getLogger(MonitorCnfmJobTask.class);
protected final ExceptionBuilder exceptionUtil;
private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
@Autowired
- public MonitorCnfmCreateJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider,
+ public MonitorCnfmJobTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider,
final ExceptionBuilder exceptionUtil) {
this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
this.exceptionUtil = exceptionUtil;
}
/**
- * Get the current operation status of instantiation job
- *
+ * Get the current operation status of cnfm job
+ *
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
try {
LOGGER.debug("Executing getCurrentOperationStatus ...");
- final URI operationStatusURL = execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL);
+ final Optional<URI> operationStatusURL = Optional.of(execution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL));
LOGGER.debug("Executing getCurrentOperationStatus for CNF... :{}", operationStatusURL);
- final Optional<AsLcmOpOcc> instantiateOperationJobStatus =
- cnfmHttpServiceProvider.getInstantiateOperationJobStatus(operationStatusURL.toString());
- if (instantiateOperationJobStatus.isPresent()) {
- final AsLcmOpOcc asLcmOpOccResponse = instantiateOperationJobStatus.get();
- if (asLcmOpOccResponse.getOperationState() != null) {
- final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState();
- LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(),
- operationStatus, asLcmOpOccResponse.getOperationState());
- execution.setVariable(OPERATION_STATUS_PARAM_NAME, asLcmOpOccResponse.getOperationState());
- }
+ final Optional<AsLcmOpOcc> operationalJobStatus =
+ cnfmHttpServiceProvider.getOperationJobStatus(String.valueOf(operationStatusURL
+ .orElseThrow(() -> new BpmnError("Operational Status check url Not found"))));
- LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}",
- asLcmOpOccResponse.getId(), asLcmOpOccResponse.getOperationState());
+ final AsLcmOpOcc asLcmOpOccResponse = operationalJobStatus
+ .orElseThrow(() -> new BpmnError("Unable to get operational Job status from the CNFM"));
+
+ if (asLcmOpOccResponse.getOperationState() != null) {
+ final OperationStateEnum operationStatus = asLcmOpOccResponse.getOperationState();
+ LOGGER.debug("Operation {} with {} and operation retrieval status : {}", asLcmOpOccResponse.getId(),
+ operationStatus, operationStatus);
+ execution.setVariable(OPERATION_STATUS_PARAM_NAME, operationStatus);
+ } else {
+ LOGGER.debug("Operation {} without operationStatus", asLcmOpOccResponse.getId());
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1206,
+ new Exception("Operation Status is empty"));
}
- execution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, instantiateOperationJobStatus.orElseThrow());
+ execution.setVariable(CNF_STATUS_RESPONSE_PARAM_NAME, asLcmOpOccResponse);
LOGGER.debug("Finished executing getCurrentOperationStatus for CNF...");
} catch (final Exception exception) {
- final String message = "Unable to invoke get current Operation status";
- LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1209, message, ONAPComponents.SO);
-
+ LOGGER.error("Unable to invoke get current Operation status");
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1209, exception);
}
}
@@ -93,36 +95,30 @@ public class MonitorCnfmCreateJobTask {
*
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
- public void timeOutLogFailue(final BuildingBlockExecution execution) {
- final String message = "CNF Instantiation operation time out";
+ public void timeOutLogFailure(final BuildingBlockExecution execution) {
+ String message = "CNF" + execution.getVariable(MONITOR_JOB_NAME) + "operation time out";
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message, ONAPComponents.SO);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1205, new Exception(message));
}
/**
- * Check the final status of instantiation throw exception if not completed successfully
- *
+ * Check the final status of cnfm job throw exception if not completed successfully
+ *
* @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
*/
public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
LOGGER.debug("Executing CNF checkIfOperationWasSuccessful ...");
final OperationStateEnum operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
- final AsLcmOpOcc cnfInstantiateStautusResponse = execution.getVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME);
- if (operationStatusOption == null) {
- final String message = "Unable to instantiate CNF jobId: "
- + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null")
- + "Unable to retrieve OperationStatus";
+ final AsLcmOpOcc cnfStautusResponse = execution.getVariable(CNF_STATUS_RESPONSE_PARAM_NAME);
+ if ((operationStatusOption == OperationStateEnum.FAILED)
+ || (operationStatusOption == OperationStateEnum.FAILED_TEMP)) {
+ final String message = "Unable to" + execution.getVariable(MONITOR_JOB_NAME) + "CNF jobId: "
+ + (cnfStautusResponse != null ? cnfStautusResponse.getId() : "null");
LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message, ONAPComponents.SO);
- } else {
- if (operationStatusOption != OperationStateEnum.COMPLETED) {
- final String message = "Unable to instantiate jobId: "
- + (cnfInstantiateStautusResponse != null ? cnfInstantiateStautusResponse.getId() : "null")
- + " OperationStatus: " + operationStatusOption;
- LOGGER.error(message);
- exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message, ONAPComponents.SO);
- }
- LOGGER.debug("Successfully completed CNF instatiation of job status {}", cnfInstantiateStautusResponse);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 1206, new Exception());
+ } else if ((operationStatusOption == OperationStateEnum.COMPLETED)) {
+ String monitorJobName = execution.getVariable(MONITOR_JOB_NAME);
+ LOGGER.debug("Successfully completed CNF {} job", monitorJobName);
}
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java
index 37d6221b77..267bdcbe86 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java
@@ -33,7 +33,7 @@ public class Constants {
public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest";
public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse";
- public static final String CREATE_CNF_STATUS_RESPONSE_PARAM_NAME = "createCnfStatusResponse";
+ public static final String CNF_STATUS_RESPONSE_PARAM_NAME = "cnfStatusResponse";
public static final String INPUT_PARAMETER = "inputParameter";
public static final String DELETE_VNF_RESPONSE_PARAM_NAME = "deleteVnfResponse";
public static final String DELETE_VNF_NODE_STATUS = "deleteVnfNodeStatus";
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java
new file mode 100644
index 0000000000..4764aa00f1
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfDeleteTaskTest.java
@@ -0,0 +1,126 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import java.net.URI;
+import java.util.Optional;
+import javax.swing.text.html.Option;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
+import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
+import org.onap.so.client.exception.BBObjectNotFoundException;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
+import org.reactivestreams.Publisher;
+
+/**
+ * @author raviteja.kaumuri@est.tech
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class CnfDeleteTaskTest {
+
+ @Mock
+ private CnfmHttpServiceProvider cnfmHttpServiceProvider;
+ @Mock
+ private ExceptionBuilder exceptionUtil;
+ @Mock
+ private ExtractPojosForBB extractPojosForBB;
+ private CnfDeleteTask cnfDeleteTask;
+ private static final String TERMINATE_AS_REQUEST_OBJECT = "TerminateAsRequest";
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution();
+
+ @Before
+ public void setup() {
+ cnfDeleteTask = new CnfDeleteTask(cnfmHttpServiceProvider, exceptionUtil, extractPojosForBB);
+ }
+
+ @Test
+ public void test_createTerminateAsRequest_success() {
+ cnfDeleteTask.createTerminateAsRequest(stubbedExecution);
+ assertNotNull(stubbedExecution.getVariable(TERMINATE_AS_REQUEST_OBJECT));
+ }
+
+ @Test
+ public void test_invokeCnfmToTerminateAsInstance_success() throws BBObjectNotFoundException {
+ stubbedExecution.setVariable(TERMINATE_AS_REQUEST_OBJECT, getTerminateAsRequest());
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenReturn(getGenericVnf());
+ when(cnfmHttpServiceProvider.invokeTerminateAsRequest(Mockito.anyString(),
+ Mockito.any(TerminateAsRequest.class))).thenReturn(getURI());
+ cnfDeleteTask.invokeCnfmToTerminateAsInstance(stubbedExecution);
+ URI returnedContent = stubbedExecution.getVariable(CNFM_REQUEST_STATUS_CHECK_URL);
+ assertEquals(getURI().orElseThrow().getPath(), returnedContent.getPath());
+ }
+
+ @Test
+ public void test_invokeCnfmToTerminateAsInstance_Exception() throws BBObjectNotFoundException {
+ stubbedExecution.setVariable(TERMINATE_AS_REQUEST_OBJECT, getTerminateAsRequest());
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
+ cnfDeleteTask.invokeCnfmToTerminateAsInstance(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2002),
+ any(Exception.class));
+ }
+
+ @Test
+ public void test_invokeCnfmToDeleteAsInstance_success() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenReturn(getGenericVnf());
+ when(cnfmHttpServiceProvider.invokeDeleteAsRequest(Mockito.anyString())).thenReturn(Optional.of(Boolean.TRUE));
+ CnfDeleteTask mockCnfDeleteTask = Mockito.spy(cnfDeleteTask);
+ mockCnfDeleteTask.invokeCnfmToDeleteAsInstance(stubbedExecution);
+ verify(mockCnfDeleteTask, times(1)).invokeCnfmToDeleteAsInstance(stubbedExecution);
+ }
+
+ @Test
+ public void test_invokeCnfmToDeleteAsInstance_Exception() throws BBObjectNotFoundException {
+ when(extractPojosForBB.extractByKey(Mockito.any(), Mockito.any())).thenThrow(new RuntimeException());
+ cnfDeleteTask.invokeCnfmToDeleteAsInstance(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(2003),
+ any(Exception.class));
+ }
+
+ private GenericVnf getGenericVnf() {
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("12345");
+ return genericVnf;
+ }
+
+ private TerminateAsRequest getTerminateAsRequest() {
+ return new TerminateAsRequest();
+ }
+
+ private Optional<URI> getURI() {
+ return Optional.of(URI.create("test_sample"));
+ }
+}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java
index f4d8bb8439..79b47776f2 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java
@@ -33,19 +33,20 @@ import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY;
-import java.net.URI;
-import java.util.Optional;
import java.util.Collections;
+import java.util.Optional;
import java.util.UUID;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.onap.so.bpmn.BaseTaskTest;
+import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.bpmn.common.BuildingBlockExecution;
import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
+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;
@@ -54,12 +55,13 @@ import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
/**
* @author raviteja.kaumuri@est.tech
*/
-public class CnfInstantiateTaskTest extends BaseTaskTest {
+@RunWith(MockitoJUnitRunner.class)
+public class CnfInstantiateTaskTest {
+ @Mock
+ protected ExceptionBuilder exceptionUtil;
private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject";
private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest";
- private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
- private static final String MONITOR_JOB_NAME = "MonitorJobName";
private static final String MODEL_INSTANCE_NAME = "instanceTest";
private static final String AS_INSTANCE_ID = "asInstanceid";
private static final String CLOUD_OWNER = "CloudOwner";
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
index aac685fe37..aab44cee3d 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImplTest.java
@@ -22,6 +22,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import java.net.URI;
@@ -33,9 +34,12 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.so.cnfm.lcm.model.AsInstance;
+import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.TerminateAsRequest;
import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -49,10 +53,13 @@ public class CnfmHttpServiceProviderImplTest {
@Mock
private CnfmUrlProvider cnfmUrlProvider;
@Mock
- private HttpRestServiceProvider httpRestServiceProvider;
+ private HttpRestServiceProviderImpl httpRestServiceProvider;
@Mock
private ResponseEntity<AsInstance> responseEntity;
+ @Mock
+ private ResponseEntity<Void> responseEntityVoid;
+ private ResponseEntity<AsLcmOpOcc> responseEntityAsLCM;
private final String createURL = "http://so-cnfm-lcm.onap:9888/so/so-cnfm/v1/api/aslcm/v1/as_instances";
private final String instantiateURL = "http://so-cnfm-lcm.onap:9888/so/so-cnfm/v1/api/aslcm/v1/as_instances"
+ getAsInstance().getAsInstanceid() + "/instantiate";
@@ -60,6 +67,7 @@ public class CnfmHttpServiceProviderImplTest {
private final URI uri = URI.create("sample");
private final CreateAsRequest createAsRequest = new CreateAsRequest();
private final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest();
+ private final TerminateAsRequest terminateAsRequest = new TerminateAsRequest();
@Before
public void setup() {
@@ -69,7 +77,7 @@ public class CnfmHttpServiceProviderImplTest {
}
@Test
- public void invokeCreateAsRequest_withStatuscodeSuccess_hasBody() {
+ public void invokeCreateAsRequest_withStatuscode_Success_hasBody() {
when(cnfmUrlProvider.getCreateAsRequestUrl()).thenReturn(createURL);
when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
@@ -90,7 +98,7 @@ public class CnfmHttpServiceProviderImplTest {
@Test
- public void invokeCreateAsRequest_withStatuscodeSuccess_hasBody_emptyInstanceID() {
+ public void invokeCreateAsRequest_withStatuscode_Success_hasBody_emptyInstanceID() {
AsInstance emptyInstanceID = getAsInstance();
emptyInstanceID.setAsInstanceid(null);
@@ -103,7 +111,7 @@ public class CnfmHttpServiceProviderImplTest {
}
@Test
- public void invokeCreateAsRequest_withStatuscodeNotSuccess_hasBody_emptyInstanceID() {
+ public void invokeCreateAsRequest_withStatuscode_NotSuccess_hasBody_emptyInstanceID() {
AsInstance emptyInstanceID = getAsInstance();
emptyInstanceID.setAsInstanceid(null);
@@ -115,7 +123,8 @@ public class CnfmHttpServiceProviderImplTest {
@Test
- public void InstantiateAsRequest_withStatuscodeSuccess() {
+ public void invokeInstantiateAsRequest_withStatuscode_Success() {
+
final String asinstanceId = getAsInstance().getAsInstanceid();
when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
@@ -125,6 +134,115 @@ public class CnfmHttpServiceProviderImplTest {
assertEquals(uri.toString(), returnedContent.orElseThrow().toString());
}
+ @Test
+ public void invokeInstantiateAsRequest_withStatuscode_Success_NoStatusURI() {
+
+ final String asinstanceId = getAsInstance().getAsInstanceid();
+ final HttpHeaders httpHeaders = getHttpHeaders();
+ httpHeaders.setLocation(null);
+ when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
+ when(responseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntity.getHeaders()).thenReturn(httpHeaders);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeInstantiateAsRequest(instantiateAsRequest, asinstanceId);
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void invokeInstantiateAsRequest_withStatuscode_NotSuccess_NoStatusURI() {
+
+ final String asinstanceId = getAsInstance().getAsInstanceid();
+ when(cnfmUrlProvider.getInstantiateAsRequestUrl(asinstanceId)).thenReturn(instantiateURL);
+ when(responseEntity.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeInstantiateAsRequest(instantiateAsRequest, asinstanceId);
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void test_getOperationJobStatus_statuscode_Accepted() {
+
+ responseEntityAsLCM = getResponseEntityAsLCM(HttpStatus.ACCEPTED);
+ when(httpRestServiceProvider.getHttpResponse(Mockito.anyString(), eq(AsLcmOpOcc.class)))
+ .thenReturn(responseEntityAsLCM);
+ final Optional<AsLcmOpOcc> returnedContent = cnfmHttpServiceProviderImpl.getOperationJobStatus("sample URL");
+ assertEquals(returnedContent.orElseThrow().getAsInstanceId(), getAsLcmOpOcc().getAsInstanceId());
+ }
+
+ @Test
+ public void test_getOperationJobStatus_statuscode_NotFound() {
+
+ responseEntityAsLCM = getResponseEntityAsLCM(HttpStatus.NOT_FOUND);
+ when(httpRestServiceProvider.getHttpResponse(Mockito.anyString(), eq(AsLcmOpOcc.class)))
+ .thenReturn(responseEntityAsLCM);
+ final Optional<AsLcmOpOcc> returnedContent = cnfmHttpServiceProviderImpl.getOperationJobStatus("sample URL");
+ assertFalse(returnedContent.isPresent());
+ }
+
+ @Test
+ public void invokeDeleteAsRequest_withStatuscode_Success() {
+
+ when(cnfmUrlProvider.getDeleteAsRequestUrl(Mockito.anyString())).thenReturn("deleteURL");
+ when(httpRestServiceProvider.deleteHttpRequest(Mockito.anyString(), eq(Void.class)))
+ .thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ final Optional<Boolean> returnedContent = cnfmHttpServiceProviderImpl.invokeDeleteAsRequest("2345");
+ assertTrue(returnedContent.orElseThrow());
+ }
+
+ @Test
+ public void invokeDeleteAsRequest_withStatuscode_BadRequest() {
+
+ when(cnfmUrlProvider.getDeleteAsRequestUrl(Mockito.anyString())).thenReturn("deleteURL");
+ when(httpRestServiceProvider.deleteHttpRequest(Mockito.anyString(), eq(Void.class)))
+ .thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ final Optional<Boolean> returnedContent = cnfmHttpServiceProviderImpl.invokeDeleteAsRequest("2345");
+ assertTrue(returnedContent.isEmpty());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_Success() {
+
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntityVoid.getHeaders()).thenReturn(getHttpHeaders());
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isPresent());
+ assertEquals(uri.getPath(), returnedContent.orElseThrow().getPath());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_Success_NullStatusURI() {
+
+ final HttpHeaders httpHeaders = getHttpHeaders();
+ httpHeaders.setLocation(null);
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.ACCEPTED);
+ when(responseEntityVoid.getHeaders()).thenReturn(httpHeaders);
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isEmpty());
+ }
+
+ @Test
+ public void invokeTerminateAsRequest_withStatuscode_BadRequest() {
+
+ when(cnfmUrlProvider.getTerminateAsRequestUrl(Mockito.anyString())).thenReturn("terminateURL");
+ when(httpRestServiceProvider.postHttpRequest(Mockito.any(TerminateAsRequest.class), Mockito.anyString(),
+ eq(Void.class))).thenReturn(responseEntityVoid);
+ when(responseEntityVoid.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST);
+ // when(responseEntityVoid.getHeaders()).thenReturn(getHttpHeaders());
+ final Optional<URI> returnedContent =
+ cnfmHttpServiceProviderImpl.invokeTerminateAsRequest("12356", terminateAsRequest);
+ assertTrue(returnedContent.isEmpty());
+ }
+
private AsInstance getAsInstance() {
AsInstance asInstance = new AsInstance();
asInstance.setAsInstanceid("12345");
@@ -136,4 +254,16 @@ public class CnfmHttpServiceProviderImplTest {
httpHeaders.setLocation(uri);
return httpHeaders;
}
+
+ private ResponseEntity<AsLcmOpOcc> getResponseEntityAsLCM(HttpStatus httpStatus) {
+ ResponseEntity<AsLcmOpOcc> asLcmOpOccResponseEntity =
+ new ResponseEntity<AsLcmOpOcc>(getAsLcmOpOcc(), httpStatus);
+ return asLcmOpOccResponseEntity;
+ }
+
+ private AsLcmOpOcc getAsLcmOpOcc() {
+ AsLcmOpOcc asLcmOpOcc = new AsLcmOpOcc();
+ asLcmOpOcc.setAsInstanceId("12345");
+ return asLcmOpOcc;
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java
index c32f6dd905..1ef3bc8753 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmCreateJobTaskTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/MonitorCnfmJobTaskTest.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -45,13 +44,13 @@ import org.onap.so.cnfm.lcm.model.AsLcmOpOcc;
* @author Raviteja Karumuri (raviteja.karumuri@est.tech)
*/
@RunWith(MockitoJUnitRunner.class)
-public class MonitorCnfmCreateJobTaskTest {
+public class MonitorCnfmJobTaskTest {
private final BuildingBlockExecution stubbedExecution = new StubbedBuildingBlockExecution();
public static final String CREATE_CNF_STATUS_RESPONSE_PARAM_NAME = "createCnfStatusResponse";
private final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
public static final String OPERATION_STATUS_PARAM_NAME = "operationStatus";
- private MonitorCnfmCreateJobTask monitorCnfmCreateJobTask;
+ private MonitorCnfmJobTask monitorCnfmCreateJobTask;
@Mock
private CnfmHttpServiceProvider mockedCnfmHttpServiceProvider;
@Mock
@@ -59,14 +58,13 @@ public class MonitorCnfmCreateJobTaskTest {
@Before
public void setup() {
- monitorCnfmCreateJobTask = new MonitorCnfmCreateJobTask(mockedCnfmHttpServiceProvider, exceptionUtil);
+ monitorCnfmCreateJobTask = new MonitorCnfmJobTask(mockedCnfmHttpServiceProvider, exceptionUtil);
}
@Test
- public void getCurrentOperationStatus_completed() {
+ public void test_getCurrentOperationStatus_completed() {
stubbedExecution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, URI.create("sampleURL"));
- when(mockedCnfmHttpServiceProvider.getInstantiateOperationJobStatus(Mockito.anyString()))
- .thenReturn(getAsLcmOpOcc());
+ when(mockedCnfmHttpServiceProvider.getOperationJobStatus(Mockito.anyString())).thenReturn(getAsLcmOpOcc());
monitorCnfmCreateJobTask.getCurrentOperationStatus(stubbedExecution);
assertEquals(AsLcmOpOcc.OperationStateEnum.COMPLETED,
stubbedExecution.getVariable(OPERATION_STATUS_PARAM_NAME));
@@ -75,16 +73,17 @@ public class MonitorCnfmCreateJobTaskTest {
@Test
public void test_getCurrentOperationStatus_Exception() {
stubbedExecution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, URI.create("sampleURL"));
- when(mockedCnfmHttpServiceProvider.getInstantiateOperationJobStatus(Mockito.anyString()))
+ when(mockedCnfmHttpServiceProvider.getOperationJobStatus(Mockito.anyString()))
.thenThrow(new RuntimeException());
monitorCnfmCreateJobTask.getCurrentOperationStatus(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1209), anyString(),
- any());
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1209),
+ any(Exception.class));
}
@Test
public void test_checkIfOperationWasSuccessful_status_completed() {
- final MonitorCnfmCreateJobTask mockedMonitorCnfmCreateJobTask = Mockito.spy(monitorCnfmCreateJobTask);
+ stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, AsLcmOpOcc.OperationStateEnum.COMPLETED);
+ final MonitorCnfmJobTask mockedMonitorCnfmCreateJobTask = Mockito.spy(monitorCnfmCreateJobTask);
mockedMonitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
verify(mockedMonitorCnfmCreateJobTask, times(1)).checkIfOperationWasSuccessful(stubbedExecution);
}
@@ -96,16 +95,8 @@ public class MonitorCnfmCreateJobTaskTest {
stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, AsLcmOpOcc.OperationStateEnum.FAILED);
stubbedExecution.setVariable(CREATE_CNF_STATUS_RESPONSE_PARAM_NAME, mockedAsLcmOpOcc.orElseThrow());
monitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1207), anyString(),
- any());
- }
-
- @Test
- public void test_checkIfOperationWasSuccessful_status_Null() {
- stubbedExecution.setVariable(OPERATION_STATUS_PARAM_NAME, null);
- monitorCnfmCreateJobTask.checkIfOperationWasSuccessful(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1206), anyString(),
- any());
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1206),
+ any(Exception.class));
}
@Test
@@ -138,9 +129,9 @@ public class MonitorCnfmCreateJobTaskTest {
@Test
public void test_timeOutLogFailure() {
- monitorCnfmCreateJobTask.timeOutLogFailue(stubbedExecution);
- verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1205), anyString(),
- any());
+ monitorCnfmCreateJobTask.timeOutLogFailure(stubbedExecution);
+ verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1205),
+ any(Exception.class));
}
private Optional<AsLcmOpOcc> getAsLcmOpOcc() {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index 021807703e..d4331dcfe8 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -402,6 +402,25 @@ public class ServiceInstances extends AbstractRestHandler {
}
}
+ @DELETE
+ @Path("/{version:[vV][7]}/serviceInstances/{serviceInstanceId}/cnfs/{cnfInstanceId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Delete provided for CNF instance", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Transactional
+ public Response deleteCnfInstance(String request, @PathParam("version") String version,
+ @PathParam("serviceInstanceId") String serviceInstanceId, @PathParam("cnfInstanceId") String cnfInstanceId,
+ @Context ContainerRequestContext requestContext) throws ApiException {
+ logger.debug("Inside API Handler to perform delete CNF Instance");
+ String requestId = requestHandlerUtils.getRequestId(requestContext);
+ HashMap<String, String> instanceIdMap = new HashMap<>();
+ instanceIdMap.put("serviceInstanceId", serviceInstanceId);
+ instanceIdMap.put("vnfInstanceId", cnfInstanceId);
+ return serviceInstances(request, Action.deleteInstance, instanceIdMap, version, requestId,
+ requestHandlerUtils.getRequestUri(requestContext, uriPrefix));
+ }
+
@POST
@Path("/{version:[vV][5-7]}/serviceInstances/{serviceInstanceId}/upgrade")
@Consumes(MediaType.APPLICATION_JSON)