2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2020 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
25 import org.camunda.bpm.engine.delegate.BpmnError;
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
28 import org.junit.Before;
29 import org.junit.Rule;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.Spy;
36 import org.onap.aai.domain.yang.Configuration;
37 import org.onap.aai.domain.yang.GenericVnf;
38 import org.onap.aai.domain.yang.InstanceGroup;
39 import org.onap.aai.domain.yang.L3Network;
40 import org.onap.aai.domain.yang.ServiceInstance;
41 import org.onap.aai.domain.yang.VfModule;
42 import org.onap.aai.domain.yang.VolumeGroup;
43 import org.onap.so.bpmn.BaseTaskTest;
44 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
45 import org.onap.so.bpmn.core.WorkflowException;
46 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
47 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
48 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
49 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
50 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
51 import org.onap.so.db.request.beans.InfraActiveRequests;
52 import org.onap.so.serviceinstancebeans.ModelInfo;
53 import org.onap.so.serviceinstancebeans.RequestDetails;
54 import org.springframework.core.env.Environment;
55 import java.util.ArrayList;
56 import java.util.List;
57 import java.util.Optional;
58 import static org.assertj.core.api.Assertions.assertThat;
59 import static org.junit.Assert.assertEquals;
60 import static org.junit.Assert.assertFalse;
61 import static org.junit.Assert.assertTrue;
62 import static org.mockito.ArgumentMatchers.anyObject;
63 import static org.mockito.ArgumentMatchers.anyString;
64 import static org.mockito.ArgumentMatchers.isA;
65 import static org.mockito.Mockito.doNothing;
66 import static org.mockito.Mockito.doReturn;
67 import static org.mockito.Mockito.when;
69 public class WorkflowActionBBTasksTest extends BaseTaskTest {
71 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
72 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
73 private static final int SAMPLE_SEQUENCE = 0;
74 private static final String EMPTY_STRING = "";
76 protected WorkflowAction workflowAction;
79 protected WorkflowActionBBFailure workflowActionBBFailure;
83 protected WorkflowActionBBTasks workflowActionBBTasks;
86 InfraActiveRequests reqMock;
88 private DelegateExecution execution;
91 protected Environment environment;
94 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
97 public ExpectedException thrown = ExpectedException.none();
100 public void before() throws Exception {
101 execution = new DelegateExecutionFake();
102 ServiceInstance servInstance = new ServiceInstance();
103 servInstance.setServiceInstanceId("TEST");
104 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
105 workflowAction.setBbInputSetupUtils(bbSetupUtils);
106 workflowAction.setBbInputSetup(bbInputSetup);
110 public void selectBBTest() {
111 String vnfCustomizationUUID = "1234567";
112 String modelUuid = "1234567";
113 prepareDelegateExecution();
114 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
116 BuildingBlock buildingBlock =
117 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
118 RequestDetails rd = new RequestDetails();
119 ModelInfo mi = new ModelInfo();
120 mi.setModelUuid(modelUuid);
122 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
123 flowsToExecute.add(ebb);
125 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
126 VnfResourceCustomization vrc = new VnfResourceCustomization();
127 vrc.setSkipPostInstConf(false);
128 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
129 vnfResourceCustomizations.add(vrc);
130 GenericVnf genericVnf = new GenericVnf();
131 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
132 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
133 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
134 vnfResourceCustomizations);
136 execution.setVariable("flowsToExecute", flowsToExecute);
137 workflowActionBBTasks.selectBB(execution);
138 boolean success = (boolean) execution.getVariable("completed");
139 int currentSequence = (int) execution.getVariable("gCurrentSequence");
141 assertEquals(1, currentSequence);
145 public void select2BBTest() {
146 String vnfCustomizationUUID = "1234567";
147 String modelUuid = "1234567";
149 prepareDelegateExecution();
150 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
151 BuildingBlock buildingBlock =
152 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
153 RequestDetails rd = new RequestDetails();
154 ModelInfo mi = new ModelInfo();
155 mi.setModelUuid(modelUuid);
157 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
158 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
160 flowsToExecute.add(ebb);
162 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
163 VnfResourceCustomization vrc = new VnfResourceCustomization();
165 vrc.setSkipPostInstConf(false);
166 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
167 vnfResourceCustomizations.add(vrc);
168 GenericVnf genericVnf = new GenericVnf();
169 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
171 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
172 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
173 vnfResourceCustomizations);
175 flowsToExecute.add(ebb2);
176 execution.setVariable("flowsToExecute", flowsToExecute);
177 workflowActionBBTasks.selectBB(execution);
178 boolean success = (boolean) execution.getVariable("completed");
179 int currentSequence = (int) execution.getVariable("gCurrentSequence");
180 assertFalse(success);
181 assertEquals(1, currentSequence);
185 public void updateRequestStatusToCompleteTest() {
186 String reqId = "reqId123";
187 execution.setVariable("mso-request-id", reqId);
188 execution.setVariable("requestAction", "createInstance");
189 execution.setVariable("resourceName", "Service");
190 execution.setVariable("aLaCarte", true);
191 InfraActiveRequests req = new InfraActiveRequests();
192 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
193 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
194 workflowActionBBTasks.updateRequestStatusToComplete(execution);
195 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
196 execution.getVariable("finalStatusMessage"));
200 public void rollbackExecutionPathTest() {
201 execution.setVariable("handlingCode", "Rollback");
202 execution.setVariable("isRollback", false);
203 execution.setVariable("requestAction", EMPTY_STRING);
204 execution.setVariable("resourceName", EMPTY_STRING);
205 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
206 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
207 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
208 flowsToExecute.add(ebb1);
210 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
211 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
212 flowsToExecute.add(ebb2);
214 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
215 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
216 flowsToExecute.add(ebb3);
218 execution.setVariable("flowsToExecute", flowsToExecute);
219 execution.setVariable("gCurrentSequence", 3);
220 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
222 workflowActionBBTasks.rollbackExecutionPath(execution);
223 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
224 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
225 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
226 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
227 assertEquals(0, execution.getVariable("gCurrentSequence"));
231 public void rollbackExecutionPathUnfinishedFlowTest() {
232 execution.setVariable("handlingCode", "Rollback");
233 execution.setVariable("isRollback", false);
234 execution.setVariable("requestAction", EMPTY_STRING);
235 execution.setVariable("resourceName", EMPTY_STRING);
236 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
237 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
238 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
239 flowsToExecute.add(ebb1);
241 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
242 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
243 flowsToExecute.add(ebb2);
245 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
246 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
247 flowsToExecute.add(ebb3);
249 execution.setVariable("flowsToExecute", flowsToExecute);
250 execution.setVariable("gCurrentSequence", 2);
251 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
253 workflowActionBBTasks.rollbackExecutionPath(execution);
254 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
255 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
256 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
257 assertEquals(0, execution.getVariable("gCurrentSequence"));
258 assertEquals(0, execution.getVariable("retryCount"));
262 public void rollbackExecutionTest() {
263 execution.setVariable("handlingCode", "Rollback");
264 execution.setVariable("isRollback", false);
265 execution.setVariable("requestAction", EMPTY_STRING);
266 execution.setVariable("resourceName", EMPTY_STRING);
267 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
268 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
269 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
270 flowsToExecute.add(ebb1);
272 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
273 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
274 flowsToExecute.add(ebb2);
276 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
277 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
278 flowsToExecute.add(ebb3);
280 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
281 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
282 flowsToExecute.add(ebb4);
284 execution.setVariable("flowsToExecute", flowsToExecute);
285 execution.setVariable("gCurrentSequence", 3);
286 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
288 workflowActionBBTasks.rollbackExecutionPath(execution);
289 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
290 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
291 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
292 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
293 assertEquals(0, execution.getVariable("gCurrentSequence"));
297 public void rollbackExecutionRollbackToAssignedTest() {
298 execution.setVariable("isRollback", false);
299 execution.setVariable("handlingCode", "RollbackToAssigned");
300 execution.setVariable("requestAction", EMPTY_STRING);
301 execution.setVariable("resourceName", EMPTY_STRING);
302 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
304 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
305 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
306 flowsToExecute.add(ebb1);
308 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
309 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
310 flowsToExecute.add(ebb2);
312 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
313 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
314 flowsToExecute.add(ebb3);
316 execution.setVariable("flowsToExecute", flowsToExecute);
317 execution.setVariable("gCurrentSequence", 2);
319 workflowActionBBTasks.rollbackExecutionPath(execution);
320 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
321 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
322 assertEquals(0, execution.getVariable("gCurrentSequence"));
323 assertEquals(1, ebbs.size());
327 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
328 execution.setVariable("handlingCode", "Rollback");
329 execution.setVariable("isRollback", false);
330 execution.setVariable("requestAction", "replaceInstance");
331 execution.setVariable("resourceName", "VfModule");
332 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
333 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
334 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
335 flowsToExecute.add(ebb1);
337 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
338 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
339 flowsToExecute.add(ebb2);
341 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
342 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
343 flowsToExecute.add(ebb3);
346 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
347 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
348 flowsToExecute.add(ebb4);
350 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
351 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
352 flowsToExecute.add(ebb5);
354 execution.setVariable("flowsToExecute", flowsToExecute);
355 execution.setVariable("gCurrentSequence", 5);
356 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
358 workflowActionBBTasks.rollbackExecutionPath(execution);
359 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
360 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
361 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
362 assertEquals(0, execution.getVariable("gCurrentSequence"));
366 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
367 execution.setVariable("isRollback", false);
368 execution.setVariable("handlingCode", "RollbackToAssigned");
369 execution.setVariable("requestAction", EMPTY_STRING);
370 execution.setVariable("resourceName", EMPTY_STRING);
371 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
373 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
374 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
375 flowsToExecute.add(ebb1);
377 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
378 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
379 flowsToExecute.add(ebb2);
381 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
382 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
383 flowsToExecute.add(ebb3);
385 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
386 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
387 flowsToExecute.add(ebb4);
389 execution.setVariable("flowsToExecute", flowsToExecute);
390 execution.setVariable("gCurrentSequence", 4);
392 workflowActionBBTasks.rollbackExecutionPath(execution);
393 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
394 assertEquals(0, execution.getVariable("gCurrentSequence"));
395 assertEquals(3, ebbs.size());
396 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
397 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
398 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
403 public void rollbackExecutionRollbackToCreatedWithFabricTest() {
404 execution.setVariable("isRollback", false);
405 execution.setVariable("handlingCode", "RollbackToCreated");
406 execution.setVariable("requestAction", EMPTY_STRING);
407 execution.setVariable("resourceName", EMPTY_STRING);
408 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
410 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
411 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
412 flowsToExecute.add(ebb1);
414 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
415 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
416 flowsToExecute.add(ebb2);
418 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
419 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
420 flowsToExecute.add(ebb3);
422 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
423 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
424 flowsToExecute.add(ebb4);
426 execution.setVariable("flowsToExecute", flowsToExecute);
427 execution.setVariable("gCurrentSequence", 4);
429 workflowActionBBTasks.rollbackExecutionPath(execution);
430 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
431 assertEquals(0, execution.getVariable("gCurrentSequence"));
432 assertEquals(2, ebbs.size());
433 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
434 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
439 public void rollbackExecutionRollbackToCreatedTest() {
440 execution.setVariable("isRollback", false);
441 execution.setVariable("handlingCode", "RollbackToCreated");
442 execution.setVariable("requestAction", EMPTY_STRING);
443 execution.setVariable("resourceName", EMPTY_STRING);
444 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
445 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
446 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
447 flowsToExecute.add(ebb1);
449 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
450 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
451 flowsToExecute.add(ebb2);
453 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
454 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
455 flowsToExecute.add(ebb3);
457 execution.setVariable("flowsToExecute", flowsToExecute);
458 execution.setVariable("gCurrentSequence", 3);
460 workflowActionBBTasks.rollbackExecutionPath(execution);
461 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
462 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
463 assertEquals(0, execution.getVariable("gCurrentSequence"));
464 assertEquals(1, ebbs.size());
468 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
469 execution.setVariable("isRollback", false);
470 execution.setVariable("handlingCode", "Rollback");
471 execution.setVariable("requestAction", EMPTY_STRING);
472 execution.setVariable("resourceName", EMPTY_STRING);
473 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
474 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
475 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
476 flowsToExecute.add(ebb1);
478 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
479 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
480 flowsToExecute.add(ebb2);
482 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
483 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
484 flowsToExecute.add(ebb3);
486 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
487 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
488 flowsToExecute.add(ebb4);
490 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
491 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
492 flowsToExecute.add(ebb5);
494 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
495 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
496 flowsToExecute.add(ebb6);
498 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
499 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
500 flowsToExecute.add(ebb7);
502 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
503 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
504 flowsToExecute.add(ebb8);
506 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
507 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
508 flowsToExecute.add(ebb9);
510 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
511 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
512 flowsToExecute.add(ebb10);
514 execution.setVariable("flowsToExecute", flowsToExecute);
515 execution.setVariable("gCurrentSequence", 10);
517 workflowActionBBTasks.rollbackExecutionPath(execution);
518 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
519 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
520 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
521 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
522 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
523 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
524 assertEquals(0, execution.getVariable("gCurrentSequence"));
525 assertEquals(5, ebbs.size());
529 public void rollbackExecutionRollbackConfigModifyTest() {
530 execution.setVariable("isRollback", false);
531 execution.setVariable("handlingCode", "Rollback");
532 execution.setVariable("requestAction", EMPTY_STRING);
533 execution.setVariable("resourceName", EMPTY_STRING);
534 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
535 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
536 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
537 flowsToExecute.add(ebb1);
539 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
540 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
541 flowsToExecute.add(ebb2);
543 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
544 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
545 flowsToExecute.add(ebb3);
547 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
548 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
549 flowsToExecute.add(ebb4);
551 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
552 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
553 flowsToExecute.add(ebb5);
555 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
556 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
557 flowsToExecute.add(ebb6);
559 execution.setVariable("flowsToExecute", flowsToExecute);
560 execution.setVariable("gCurrentSequence", 6);
562 workflowActionBBTasks.rollbackExecutionPath(execution);
563 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
564 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
565 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
566 assertEquals(0, execution.getVariable("gCurrentSequence"));
567 assertEquals(2, ebbs.size());
571 public void postProcessingExecuteBBActivateVfModuleTest() throws CloneNotSupportedException {
572 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
573 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
575 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
576 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
577 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
578 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
579 resourceIdsActivateVfModule.setConfigurationId("");
581 RequestDetails requestDetails = new RequestDetails();
583 ebbActivateVfModule.setApiVersion("7");
584 ebbActivateVfModule.setaLaCarte(true);
585 ebbActivateVfModule.setRequestAction("createInstance");
586 ebbActivateVfModule.setVnfType("test-vnf-type");
587 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
588 ebbActivateVfModule.setRequestDetails(requestDetails);
589 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
591 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
592 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
593 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
594 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
595 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
597 ExecuteBuildingBlock ebbAddFabricConfig =
598 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
599 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
601 assertEquals("7", ebbAddFabricConfig.getApiVersion());
602 assertTrue(ebbAddFabricConfig.isaLaCarte());
603 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
604 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
605 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
606 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
607 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
608 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
609 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
610 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
611 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
613 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
614 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
615 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
616 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
617 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
621 public void checkRetryStatusTest() {
622 String reqId = "reqId123";
623 execution.setVariable("mso-request-id", reqId);
624 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
625 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
626 execution.setVariable("handlingCode", "Retry");
627 execution.setVariable("retryCount", 1);
628 execution.setVariable("gCurrentSequence", 1);
629 InfraActiveRequests req = new InfraActiveRequests();
630 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
631 workflowActionBBTasks.checkRetryStatus(execution);
632 assertEquals(0, execution.getVariable("gCurrentSequence"));
636 public void checkRetryStatusTestExceededMaxRetries() {
637 String reqId = "reqId123";
638 execution.setVariable("mso-request-id", reqId);
639 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
640 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
641 execution.setVariable("handlingCode", "Retry");
642 execution.setVariable("retryCount", 6);
643 execution.setVariable("gCurrentSequence", 1);
644 InfraActiveRequests req = new InfraActiveRequests();
645 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
647 workflowActionBBTasks.checkRetryStatus(execution);
648 } catch (BpmnError e) {
649 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
650 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
655 public void checkRetryStatusNoRetryTest() {
656 String reqId = "reqId123";
657 execution.setVariable("mso-request-id", reqId);
658 execution.setVariable("retryCount", 3);
659 execution.setVariable("handlingCode", "Success");
660 execution.setVariable("gCurrentSequence", 1);
661 InfraActiveRequests req = new InfraActiveRequests();
662 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
663 workflowActionBBTasks.checkRetryStatus(execution);
664 assertEquals(0, execution.getVariable("retryCount"));
668 public void updateInstanceId() {
669 String reqId = "req123";
670 String instanceId = "123123123";
671 execution.setVariable("mso-request-id", reqId);
672 execution.setVariable("resourceId", instanceId);
673 execution.setVariable("resourceType", WorkflowType.SERVICE);
674 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
675 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
676 workflowActionBBTasks.updateInstanceId(execution);
677 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
681 public void getConfigurationId() {
682 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
683 vnfc.setModelInvariantId("modelInvariantId");
684 vnfc.setVnfcName("testVnfcName");
685 List<Configuration> configurations = new ArrayList<>();
686 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
687 configuration.setConfigurationId("configurationId");
688 configuration.setModelCustomizationId("modelCustimizationId");
689 configuration.setConfigurationName("testConfigurationName");
690 configurations.add(configuration);
691 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
692 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
696 public void setServiceInstanceNameTest() {
697 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
698 WorkflowType resourceType = WorkflowType.SERVICE;
699 InfraActiveRequests request = new InfraActiveRequests();
700 ServiceInstance service = new ServiceInstance();
701 service.setServiceInstanceName("serviceInstanceName");
702 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
704 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
705 assertEquals("serviceInstanceName", request.getServiceInstanceName());
709 public void setVnfNameTest() {
710 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
711 WorkflowType resourceType = WorkflowType.VNF;
712 InfraActiveRequests request = new InfraActiveRequests();
713 GenericVnf vnf = new GenericVnf();
714 vnf.setVnfName("vnfName");
715 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
717 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
718 assertEquals("vnfName", request.getVnfName());
722 public void setVfModuleNameTest() {
723 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
724 WorkflowType resourceType = WorkflowType.VFMODULE;
725 InfraActiveRequests request = new InfraActiveRequests();
726 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
727 VfModule vfModule = new VfModule();
728 vfModule.setVfModuleName("vfModuleName");
729 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
731 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
732 assertEquals("vfModuleName", request.getVfModuleName());
736 public void setNetworkNameTest() {
737 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
738 WorkflowType resourceType = WorkflowType.NETWORK;
739 InfraActiveRequests request = new InfraActiveRequests();
740 L3Network network = new L3Network();
741 network.setNetworkName("networkName");
742 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
744 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
745 assertEquals("networkName", request.getNetworkName());
749 public void setConfigurationNameTest() {
750 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
751 WorkflowType resourceType = WorkflowType.CONFIGURATION;
752 InfraActiveRequests request = new InfraActiveRequests();
753 Configuration configuration = new Configuration();
754 configuration.setConfigurationName("configurationName");
755 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
757 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
758 assertEquals("configurationName", request.getConfigurationName());
762 public void setInstanceGroupNameTest() {
763 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
764 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
765 InfraActiveRequests request = new InfraActiveRequests();
766 InstanceGroup instanceGroup = new InstanceGroup();
767 instanceGroup.setInstanceGroupName("instanceGroupName");
768 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
770 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
771 assertEquals("instanceGroupName", request.getInstanceGroupName());
775 public void setVolumeGroupNameTest() {
776 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
777 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
778 InfraActiveRequests request = new InfraActiveRequests();
779 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
780 VolumeGroup volumeGroup = new VolumeGroup();
781 volumeGroup.setVolumeGroupName("volumeGroupName");
782 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
784 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
785 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
787 assertEquals("volumeGroupName", request.getVolumeGroupName());
790 private void prepareDelegateExecution() {
791 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
792 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
793 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
794 execution.setVariable("homing", false);
795 execution.setVariable("calledHoming", false);