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 rollbackExecutionRollbackToCreatedTest() {
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<>();
409 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
410 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
411 flowsToExecute.add(ebb1);
413 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
414 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
415 flowsToExecute.add(ebb2);
417 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
418 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
419 flowsToExecute.add(ebb3);
421 execution.setVariable("flowsToExecute", flowsToExecute);
422 execution.setVariable("gCurrentSequence", 3);
424 workflowActionBBTasks.rollbackExecutionPath(execution);
425 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
426 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
427 assertEquals(0, execution.getVariable("gCurrentSequence"));
428 assertEquals(1, ebbs.size());
432 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
433 execution.setVariable("isRollback", false);
434 execution.setVariable("handlingCode", "Rollback");
435 execution.setVariable("requestAction", EMPTY_STRING);
436 execution.setVariable("resourceName", EMPTY_STRING);
437 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
438 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
439 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
440 flowsToExecute.add(ebb1);
442 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
443 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
444 flowsToExecute.add(ebb2);
446 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
447 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
448 flowsToExecute.add(ebb3);
450 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
451 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
452 flowsToExecute.add(ebb4);
454 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
455 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
456 flowsToExecute.add(ebb5);
458 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
459 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
460 flowsToExecute.add(ebb6);
462 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
463 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
464 flowsToExecute.add(ebb7);
466 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
467 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
468 flowsToExecute.add(ebb8);
470 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
471 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
472 flowsToExecute.add(ebb9);
474 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
475 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
476 flowsToExecute.add(ebb10);
478 execution.setVariable("flowsToExecute", flowsToExecute);
479 execution.setVariable("gCurrentSequence", 10);
481 workflowActionBBTasks.rollbackExecutionPath(execution);
482 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
483 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
484 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
485 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
486 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
487 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
488 assertEquals(0, execution.getVariable("gCurrentSequence"));
489 assertEquals(5, ebbs.size());
493 public void rollbackExecutionRollbackConfigModifyTest() {
494 execution.setVariable("isRollback", false);
495 execution.setVariable("handlingCode", "Rollback");
496 execution.setVariable("requestAction", EMPTY_STRING);
497 execution.setVariable("resourceName", EMPTY_STRING);
498 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
499 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
500 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
501 flowsToExecute.add(ebb1);
503 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
504 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
505 flowsToExecute.add(ebb2);
507 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
508 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
509 flowsToExecute.add(ebb3);
511 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
512 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
513 flowsToExecute.add(ebb4);
515 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
516 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
517 flowsToExecute.add(ebb5);
519 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
520 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
521 flowsToExecute.add(ebb6);
523 execution.setVariable("flowsToExecute", flowsToExecute);
524 execution.setVariable("gCurrentSequence", 6);
526 workflowActionBBTasks.rollbackExecutionPath(execution);
527 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
528 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
529 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
530 assertEquals(0, execution.getVariable("gCurrentSequence"));
531 assertEquals(2, ebbs.size());
535 public void postProcessingExecuteBBActivateVfModuleTest() throws CloneNotSupportedException {
536 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
537 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
539 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
540 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
541 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
542 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
543 resourceIdsActivateVfModule.setConfigurationId("");
545 RequestDetails requestDetails = new RequestDetails();
547 ebbActivateVfModule.setApiVersion("7");
548 ebbActivateVfModule.setaLaCarte(true);
549 ebbActivateVfModule.setRequestAction("createInstance");
550 ebbActivateVfModule.setVnfType("test-vnf-type");
551 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
552 ebbActivateVfModule.setRequestDetails(requestDetails);
553 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
555 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
556 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
557 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
558 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
559 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
561 ExecuteBuildingBlock ebbAddFabricConfig =
562 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
563 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
565 assertEquals("7", ebbAddFabricConfig.getApiVersion());
566 assertTrue(ebbAddFabricConfig.isaLaCarte());
567 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
568 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
569 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
570 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
571 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
572 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
573 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
574 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
575 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
577 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
578 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
579 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
580 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
581 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
585 public void checkRetryStatusTest() {
586 String reqId = "reqId123";
587 execution.setVariable("mso-request-id", reqId);
588 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
589 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
590 execution.setVariable("handlingCode", "Retry");
591 execution.setVariable("retryCount", 1);
592 execution.setVariable("gCurrentSequence", 1);
593 InfraActiveRequests req = new InfraActiveRequests();
594 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
595 workflowActionBBTasks.checkRetryStatus(execution);
596 assertEquals(0, execution.getVariable("gCurrentSequence"));
600 public void checkRetryStatusTestExceededMaxRetries() {
601 String reqId = "reqId123";
602 execution.setVariable("mso-request-id", reqId);
603 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
604 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
605 execution.setVariable("handlingCode", "Retry");
606 execution.setVariable("retryCount", 6);
607 execution.setVariable("gCurrentSequence", 1);
608 InfraActiveRequests req = new InfraActiveRequests();
609 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
611 workflowActionBBTasks.checkRetryStatus(execution);
612 } catch (BpmnError e) {
613 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
614 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
619 public void checkRetryStatusNoRetryTest() {
620 String reqId = "reqId123";
621 execution.setVariable("mso-request-id", reqId);
622 execution.setVariable("retryCount", 3);
623 execution.setVariable("handlingCode", "Success");
624 execution.setVariable("gCurrentSequence", 1);
625 InfraActiveRequests req = new InfraActiveRequests();
626 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
627 workflowActionBBTasks.checkRetryStatus(execution);
628 assertEquals(0, execution.getVariable("retryCount"));
632 public void updateInstanceId() {
633 String reqId = "req123";
634 String instanceId = "123123123";
635 execution.setVariable("mso-request-id", reqId);
636 execution.setVariable("resourceId", instanceId);
637 execution.setVariable("resourceType", WorkflowType.SERVICE);
638 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
639 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
640 workflowActionBBTasks.updateInstanceId(execution);
641 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
645 public void getConfigurationId() {
646 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
647 vnfc.setModelInvariantId("modelInvariantId");
648 vnfc.setVnfcName("testVnfcName");
649 List<Configuration> configurations = new ArrayList<>();
650 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
651 configuration.setConfigurationId("configurationId");
652 configuration.setModelCustomizationId("modelCustimizationId");
653 configuration.setConfigurationName("testConfigurationName");
654 configurations.add(configuration);
655 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
656 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
660 public void setServiceInstanceNameTest() {
661 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
662 WorkflowType resourceType = WorkflowType.SERVICE;
663 InfraActiveRequests request = new InfraActiveRequests();
664 ServiceInstance service = new ServiceInstance();
665 service.setServiceInstanceName("serviceInstanceName");
666 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
668 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
669 assertEquals("serviceInstanceName", request.getServiceInstanceName());
673 public void setVnfNameTest() {
674 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
675 WorkflowType resourceType = WorkflowType.VNF;
676 InfraActiveRequests request = new InfraActiveRequests();
677 GenericVnf vnf = new GenericVnf();
678 vnf.setVnfName("vnfName");
679 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
681 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
682 assertEquals("vnfName", request.getVnfName());
686 public void setVfModuleNameTest() {
687 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
688 WorkflowType resourceType = WorkflowType.VFMODULE;
689 InfraActiveRequests request = new InfraActiveRequests();
690 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
691 VfModule vfModule = new VfModule();
692 vfModule.setVfModuleName("vfModuleName");
693 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
695 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
696 assertEquals("vfModuleName", request.getVfModuleName());
700 public void setNetworkNameTest() {
701 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
702 WorkflowType resourceType = WorkflowType.NETWORK;
703 InfraActiveRequests request = new InfraActiveRequests();
704 L3Network network = new L3Network();
705 network.setNetworkName("networkName");
706 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
708 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
709 assertEquals("networkName", request.getNetworkName());
713 public void setConfigurationNameTest() {
714 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
715 WorkflowType resourceType = WorkflowType.CONFIGURATION;
716 InfraActiveRequests request = new InfraActiveRequests();
717 Configuration configuration = new Configuration();
718 configuration.setConfigurationName("configurationName");
719 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
721 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
722 assertEquals("configurationName", request.getConfigurationName());
726 public void setInstanceGroupNameTest() {
727 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
728 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
729 InfraActiveRequests request = new InfraActiveRequests();
730 InstanceGroup instanceGroup = new InstanceGroup();
731 instanceGroup.setInstanceGroupName("instanceGroupName");
732 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
734 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
735 assertEquals("instanceGroupName", request.getInstanceGroupName());
739 public void setVolumeGroupNameTest() {
740 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
741 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
742 InfraActiveRequests request = new InfraActiveRequests();
743 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
744 VolumeGroup volumeGroup = new VolumeGroup();
745 volumeGroup.setVolumeGroupName("volumeGroupName");
746 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
748 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
749 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
751 assertEquals("volumeGroupName", request.getVolumeGroupName());
754 private void prepareDelegateExecution() {
755 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
756 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
757 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
758 execution.setVariable("homing", false);
759 execution.setVariable("calledHoming", false);