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 static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertTrue;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.ArgumentMatchers.anyObject;
31 import static org.mockito.ArgumentMatchers.anyString;
32 import static org.mockito.ArgumentMatchers.isA;
33 import static org.mockito.Mockito.doNothing;
34 import static org.mockito.Mockito.doReturn;
35 import static org.mockito.Mockito.times;
36 import static org.mockito.Mockito.verify;
37 import static org.mockito.Mockito.when;
38 import java.util.Arrays;
39 import java.util.Collections;
40 import java.util.ArrayList;
41 import java.util.List;
42 import java.util.Optional;
43 import org.camunda.bpm.engine.delegate.BpmnError;
44 import org.camunda.bpm.engine.delegate.DelegateExecution;
45 import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake;
46 import org.junit.Before;
47 import org.junit.Rule;
48 import org.junit.Test;
49 import org.junit.rules.ExpectedException;
50 import org.mockito.ArgumentCaptor;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.Spy;
55 import org.onap.aai.domain.yang.Configuration;
56 import org.onap.aai.domain.yang.GenericVnf;
57 import org.onap.aai.domain.yang.InstanceGroup;
58 import org.onap.aai.domain.yang.L3Network;
59 import org.onap.aai.domain.yang.ServiceInstance;
60 import org.onap.aai.domain.yang.VfModule;
61 import org.onap.aai.domain.yang.VolumeGroup;
62 import org.onap.so.bpmn.BaseTaskTest;
63 import org.onap.so.bpmn.common.listener.flowmanipulator.FlowManipulatorListenerRunner;
64 import org.onap.so.bpmn.core.WorkflowException;
65 import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock;
66 import org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys;
67 import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
68 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
69 import org.onap.so.db.catalog.beans.BuildingBlockRollback;
70 import org.onap.so.db.catalog.beans.ConfigurationResource;
71 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
72 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
73 import org.onap.so.db.request.beans.InfraActiveRequests;
74 import org.onap.so.serviceinstancebeans.ModelInfo;
75 import org.onap.so.serviceinstancebeans.ModelType;
76 import org.onap.so.serviceinstancebeans.RelatedInstance;
77 import org.onap.so.serviceinstancebeans.RelatedInstanceList;
78 import org.onap.so.serviceinstancebeans.RequestDetails;
79 import org.springframework.core.env.Environment;
81 public class WorkflowActionBBTasksTest extends BaseTaskTest {
83 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
84 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
85 private static final int SAMPLE_SEQUENCE = 0;
86 private static final String EMPTY_STRING = "";
88 protected WorkflowAction workflowAction;
91 protected WorkflowActionBBFailure workflowActionBBFailure;
95 protected WorkflowActionBBTasks workflowActionBBTasks;
98 InfraActiveRequests reqMock;
100 private DelegateExecution execution;
103 protected Environment environment;
106 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
109 public ExpectedException thrown = ExpectedException.none();
112 private DelegateExecution mockExecution;
115 public void initCatalogDBRollbackTable() {
116 when(catalogDbClient.getBuildingBlockRollbackEntries()).thenReturn(getRollbackBuildingBlockList());
120 public void before() throws Exception {
121 execution = new DelegateExecutionFake();
122 ServiceInstance servInstance = new ServiceInstance();
123 servInstance.setServiceInstanceId("TEST");
124 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
125 workflowAction.setBbInputSetupUtils(bbSetupUtils);
126 workflowAction.setBbInputSetup(bbInputSetup);
130 public void selectBBTest() {
131 String vnfCustomizationUUID = "1234567";
132 String modelUuid = "1234567";
133 prepareDelegateExecution();
134 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
136 BuildingBlock buildingBlock =
137 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
138 RequestDetails rd = new RequestDetails();
139 ModelInfo mi = new ModelInfo();
140 mi.setModelUuid(modelUuid);
142 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
143 flowsToExecute.add(ebb);
145 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
146 VnfResourceCustomization vrc = new VnfResourceCustomization();
147 vrc.setSkipPostInstConf(false);
148 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
149 vnfResourceCustomizations.add(vrc);
150 GenericVnf genericVnf = new GenericVnf();
151 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
152 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
153 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
154 vnfResourceCustomizations);
156 execution.setVariable("flowsToExecute", flowsToExecute);
157 workflowActionBBTasks.selectBB(execution);
158 boolean success = (boolean) execution.getVariable("completed");
159 int currentSequence = (int) execution.getVariable("gCurrentSequence");
160 assertFalse(success);
161 assertEquals(1, currentSequence);
165 public void select2BBTest() {
166 String vnfCustomizationUUID = "1234567";
167 String modelUuid = "1234567";
169 prepareDelegateExecution();
170 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
171 BuildingBlock buildingBlock =
172 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
173 RequestDetails rd = new RequestDetails();
174 ModelInfo mi = new ModelInfo();
175 mi.setModelUuid(modelUuid);
177 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
178 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
180 flowsToExecute.add(ebb);
182 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
183 VnfResourceCustomization vrc = new VnfResourceCustomization();
185 vrc.setSkipPostInstConf(false);
186 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
187 vnfResourceCustomizations.add(vrc);
188 GenericVnf genericVnf = new GenericVnf();
189 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
191 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
192 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
193 vnfResourceCustomizations);
195 flowsToExecute.add(ebb2);
196 execution.setVariable("flowsToExecute", flowsToExecute);
197 workflowActionBBTasks.selectBB(execution);
198 boolean success = (boolean) execution.getVariable("completed");
199 int currentSequence = (int) execution.getVariable("gCurrentSequence");
200 assertFalse(success);
201 assertEquals(1, currentSequence);
205 public void updateRequestStatusToCompleteTest() {
206 String reqId = "reqId123";
207 execution.setVariable("mso-request-id", reqId);
208 execution.setVariable("requestAction", "createInstance");
209 execution.setVariable("resourceName", "Service");
210 execution.setVariable("aLaCarte", true);
211 InfraActiveRequests req = new InfraActiveRequests();
212 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
213 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
214 workflowActionBBTasks.updateRequestStatusToComplete(execution);
215 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
216 execution.getVariable("finalStatusMessage"));
220 public void rollbackExecutionPathTest() {
221 execution.setVariable("handlingCode", "Rollback");
222 execution.setVariable("isRollback", false);
223 execution.setVariable("requestAction", EMPTY_STRING);
224 execution.setVariable("resourceName", EMPTY_STRING);
225 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
226 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
227 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
228 flowsToExecute.add(ebb1);
230 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
231 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
232 flowsToExecute.add(ebb2);
234 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
235 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
236 flowsToExecute.add(ebb3);
238 execution.setVariable("flowsToExecute", flowsToExecute);
239 execution.setVariable("gCurrentSequence", 3);
240 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
242 workflowActionBBTasks.rollbackExecutionPath(execution);
243 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
244 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
245 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
246 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
247 assertEquals(0, execution.getVariable("gCurrentSequence"));
251 public void rollbackExecutionPathUnfinishedFlowTest() {
252 execution.setVariable("handlingCode", "Rollback");
253 execution.setVariable("isRollback", false);
254 execution.setVariable("requestAction", EMPTY_STRING);
255 execution.setVariable("resourceName", EMPTY_STRING);
256 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
257 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
258 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
259 flowsToExecute.add(ebb1);
261 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
262 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
263 flowsToExecute.add(ebb2);
265 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
266 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
267 flowsToExecute.add(ebb3);
269 execution.setVariable("flowsToExecute", flowsToExecute);
270 execution.setVariable("gCurrentSequence", 2);
271 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
273 workflowActionBBTasks.rollbackExecutionPath(execution);
274 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
275 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
276 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
277 assertEquals(0, execution.getVariable("gCurrentSequence"));
278 assertEquals(0, execution.getVariable("retryCount"));
282 public void rollbackExecutionTest() {
283 execution.setVariable("handlingCode", "Rollback");
284 execution.setVariable("isRollback", false);
285 execution.setVariable("requestAction", EMPTY_STRING);
286 execution.setVariable("resourceName", EMPTY_STRING);
287 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
288 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
289 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
290 flowsToExecute.add(ebb1);
292 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
293 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
294 flowsToExecute.add(ebb2);
296 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
297 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
298 flowsToExecute.add(ebb3);
300 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
301 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
302 flowsToExecute.add(ebb4);
304 execution.setVariable("flowsToExecute", flowsToExecute);
305 execution.setVariable("gCurrentSequence", 3);
306 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
308 workflowActionBBTasks.rollbackExecutionPath(execution);
309 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
310 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
311 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
312 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
313 assertEquals(0, execution.getVariable("gCurrentSequence"));
317 public void rollbackExecutionRollbackToAssignedTest() {
318 execution.setVariable("isRollback", false);
319 execution.setVariable("handlingCode", "RollbackToAssigned");
320 execution.setVariable("requestAction", EMPTY_STRING);
321 execution.setVariable("resourceName", EMPTY_STRING);
322 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
324 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
325 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
326 flowsToExecute.add(ebb1);
328 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
329 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
330 flowsToExecute.add(ebb2);
332 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
333 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
334 flowsToExecute.add(ebb3);
336 execution.setVariable("flowsToExecute", flowsToExecute);
337 execution.setVariable("gCurrentSequence", 2);
339 workflowActionBBTasks.rollbackExecutionPath(execution);
340 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
341 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
342 assertEquals(0, execution.getVariable("gCurrentSequence"));
343 assertEquals(1, ebbs.size());
347 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
348 execution.setVariable("handlingCode", "Rollback");
349 execution.setVariable("isRollback", false);
350 execution.setVariable("requestAction", "replaceInstance");
351 execution.setVariable("resourceName", "VfModule");
352 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
353 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
354 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
355 flowsToExecute.add(ebb1);
357 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
358 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
359 flowsToExecute.add(ebb2);
361 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
362 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
363 flowsToExecute.add(ebb3);
366 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
367 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
368 flowsToExecute.add(ebb4);
370 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
371 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
372 flowsToExecute.add(ebb5);
374 execution.setVariable("flowsToExecute", flowsToExecute);
375 execution.setVariable("gCurrentSequence", 5);
376 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
378 workflowActionBBTasks.rollbackExecutionPath(execution);
379 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
380 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
381 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
382 assertEquals(0, execution.getVariable("gCurrentSequence"));
386 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
387 execution.setVariable("isRollback", false);
388 execution.setVariable("handlingCode", "RollbackToAssigned");
389 execution.setVariable("requestAction", EMPTY_STRING);
390 execution.setVariable("resourceName", EMPTY_STRING);
391 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
393 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
394 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
395 flowsToExecute.add(ebb1);
397 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
398 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
399 flowsToExecute.add(ebb2);
401 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
402 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
403 flowsToExecute.add(ebb3);
405 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
406 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
407 flowsToExecute.add(ebb4);
409 execution.setVariable("flowsToExecute", flowsToExecute);
410 execution.setVariable("gCurrentSequence", 4);
412 workflowActionBBTasks.rollbackExecutionPath(execution);
413 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
414 assertEquals(0, execution.getVariable("gCurrentSequence"));
415 assertEquals(3, ebbs.size());
416 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
417 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
418 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
423 public void rollbackExecutionRollbackToCreatedWithFabricTest() {
424 execution.setVariable("isRollback", false);
425 execution.setVariable("handlingCode", "RollbackToCreated");
426 execution.setVariable("requestAction", EMPTY_STRING);
427 execution.setVariable("resourceName", EMPTY_STRING);
428 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
430 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
431 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
432 flowsToExecute.add(ebb1);
434 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
435 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
436 flowsToExecute.add(ebb2);
438 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
439 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
440 flowsToExecute.add(ebb3);
442 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
443 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
444 flowsToExecute.add(ebb4);
446 execution.setVariable("flowsToExecute", flowsToExecute);
447 execution.setVariable("gCurrentSequence", 4);
449 workflowActionBBTasks.rollbackExecutionPath(execution);
450 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
451 assertEquals(0, execution.getVariable("gCurrentSequence"));
452 assertEquals(2, ebbs.size());
453 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
454 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
459 public void rollbackExecutionRollbackToCreatedNoConfigurationWithFabricTest() {
460 execution.setVariable("isRollback", false);
461 execution.setVariable("handlingCode", "RollbackToCreatedNoConfiguration");
462 execution.setVariable("requestAction", EMPTY_STRING);
463 execution.setVariable("resourceName", EMPTY_STRING);
464 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
466 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
467 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
468 flowsToExecute.add(ebb1);
470 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
471 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
472 flowsToExecute.add(ebb2);
474 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
475 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
476 flowsToExecute.add(ebb3);
478 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
479 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
480 flowsToExecute.add(ebb4);
482 execution.setVariable("flowsToExecute", flowsToExecute);
483 execution.setVariable("gCurrentSequence", 4);
485 workflowActionBBTasks.rollbackExecutionPath(execution);
486 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
487 assertEquals(0, execution.getVariable("gCurrentSequence"));
488 assertEquals(1, ebbs.size());
489 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
493 public void rollbackExecutionRollbackToCreatedTest() {
494 execution.setVariable("isRollback", false);
495 execution.setVariable("handlingCode", "RollbackToCreated");
496 execution.setVariable("requestAction", EMPTY_STRING);
497 execution.setVariable("resourceName", EMPTY_STRING);
498 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
499 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
500 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
501 flowsToExecute.add(ebb1);
503 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
504 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
505 flowsToExecute.add(ebb2);
507 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
508 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
509 flowsToExecute.add(ebb3);
511 execution.setVariable("flowsToExecute", flowsToExecute);
512 execution.setVariable("gCurrentSequence", 3);
514 workflowActionBBTasks.rollbackExecutionPath(execution);
515 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
516 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
517 assertEquals(0, execution.getVariable("gCurrentSequence"));
518 assertEquals(1, ebbs.size());
522 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
523 execution.setVariable("isRollback", false);
524 execution.setVariable("handlingCode", "Rollback");
525 execution.setVariable("requestAction", EMPTY_STRING);
526 execution.setVariable("resourceName", EMPTY_STRING);
527 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
528 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
529 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
530 flowsToExecute.add(ebb1);
532 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
533 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
534 flowsToExecute.add(ebb2);
536 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
537 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
538 flowsToExecute.add(ebb3);
540 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
541 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
542 flowsToExecute.add(ebb4);
544 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
545 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
546 flowsToExecute.add(ebb5);
548 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
549 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
550 flowsToExecute.add(ebb6);
552 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
553 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
554 flowsToExecute.add(ebb7);
556 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
557 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
558 flowsToExecute.add(ebb8);
560 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
561 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
562 flowsToExecute.add(ebb9);
564 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
565 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
566 flowsToExecute.add(ebb10);
568 execution.setVariable("flowsToExecute", flowsToExecute);
569 execution.setVariable("gCurrentSequence", 10);
571 workflowActionBBTasks.rollbackExecutionPath(execution);
572 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
573 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
574 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
575 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
576 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
577 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
578 assertEquals(0, execution.getVariable("gCurrentSequence"));
579 assertEquals(5, ebbs.size());
583 public void rollbackExecutionRollbackConfigModifyTest() {
584 execution.setVariable("isRollback", false);
585 execution.setVariable("handlingCode", "Rollback");
586 execution.setVariable("requestAction", EMPTY_STRING);
587 execution.setVariable("resourceName", EMPTY_STRING);
588 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
589 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
590 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
591 flowsToExecute.add(ebb1);
593 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
594 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
595 flowsToExecute.add(ebb2);
597 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
598 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
599 flowsToExecute.add(ebb3);
601 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
602 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
603 flowsToExecute.add(ebb4);
605 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
606 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
607 flowsToExecute.add(ebb5);
609 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
610 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
611 flowsToExecute.add(ebb6);
613 execution.setVariable("flowsToExecute", flowsToExecute);
614 execution.setVariable("gCurrentSequence", 6);
616 workflowActionBBTasks.rollbackExecutionPath(execution);
617 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
618 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
619 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
620 assertEquals(0, execution.getVariable("gCurrentSequence"));
621 assertEquals(2, ebbs.size());
625 public void rollbackExecutionRollbackControllerExecutionBBTest() {
626 execution.setVariable("isRollback", false);
627 execution.setVariable("handlingCode", "Rollback");
628 execution.setVariable("requestAction", EMPTY_STRING);
629 execution.setVariable("resourceName", EMPTY_STRING);
630 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
631 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
632 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
633 flowsToExecute.add(ebb1);
635 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
636 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
637 flowsToExecute.add(ebb2);
639 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignVnfBB");
640 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
641 flowsToExecute.add(ebb3);
643 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
644 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
645 flowsToExecute.add(ebb4);
647 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ControllerExecutionBB");
648 buildingBlock5.setBpmnScope("vnf");
649 buildingBlock5.setBpmnAction("config-assign");
650 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
651 flowsToExecute.add(ebb5);
653 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
654 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
655 flowsToExecute.add(ebb6);
657 execution.setVariable("flowsToExecute", flowsToExecute);
658 execution.setVariable("gCurrentSequence", 5);
660 workflowActionBBTasks.rollbackExecutionPath(execution);
661 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
662 BuildingBlock bb = ebbs.get(0).getBuildingBlock();
663 assertEquals("ControllerExecutionBB", bb.getBpmnFlowName());
664 assertEquals("vnf", bb.getBpmnScope());
665 assertEquals("config-unassign", bb.getBpmnAction());
666 assertEquals(0, execution.getVariable("gCurrentSequence"));
667 assertEquals(5, ebbs.size());
671 public void postProcessingExecuteBBActivateVfModuleNotReplaceInstanceTest() throws CloneNotSupportedException {
672 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
673 workflowResourceIds.setServiceInstanceId("1");
674 workflowResourceIds.setVnfId("1");
676 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
677 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
678 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
679 ebbActivateVfModule.setResourceId("1");
681 ServiceInstance service = new ServiceInstance();
682 service.setServiceInstanceName("name");
683 service.setModelVersionId("1");
684 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
686 GenericVnf vnf = new GenericVnf();
687 vnf.setVnfName("name");
688 vnf.setModelCustomizationId("1");
689 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
691 VfModule vfModule = new VfModule();
692 vfModule.setVfModuleName("name");
693 vfModule.setModelCustomizationId("1");
694 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
696 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
697 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
698 vnfc.setModelInvariantId("1");
699 vnfc.setVnfcName("name");
700 vnfc.setModelCustomizationId("2");
702 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
704 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
705 ConfigurationResource configuration = new ConfigurationResource();
706 configuration.setToscaNodeType("FabricConfiguration");
707 configuration.setModelUUID("1");
708 vfModuleCustomization.setConfigurationResource(configuration);
710 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
712 prepareDelegateExecution();
713 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
714 flowsToExecute.add(ebbActivateVfModule);
716 execution.setVariable("requestAction", "createInstance");
717 execution.setVariable("completed", true);
719 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
720 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
721 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
722 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
723 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
724 bbCaptor.capture(), listCaptor.capture());
725 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
726 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
728 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
729 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
730 .getCvnfcCustomizationUUID());
731 assertEquals("AddFabricConfigurationBB", ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues()
732 .get(0).getVariable("flowsToExecute")).get(1)).getBuildingBlock().getBpmnFlowName());
736 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasConfigurationTest()
737 throws CloneNotSupportedException {
738 RequestDetails reqDetails = new RequestDetails();
739 RelatedInstanceList[] list = new RelatedInstanceList[2];
740 RelatedInstanceList vnfList = new RelatedInstanceList();
741 RelatedInstanceList serviceList = new RelatedInstanceList();
743 list[1] = serviceList;
744 RelatedInstance vnfInstance = new RelatedInstance();
745 RelatedInstance serviceInstance = new RelatedInstance();
746 ModelInfo vnfModelInfo = new ModelInfo();
747 vnfModelInfo.setModelType(ModelType.vnf);
748 vnfModelInfo.setModelCustomizationId("1");
749 ModelInfo serviceModelInfo = new ModelInfo();
750 serviceModelInfo.setModelType(ModelType.service);
751 serviceModelInfo.setModelVersionId("1");
752 vnfInstance.setModelInfo(vnfModelInfo);
753 serviceInstance.setModelInfo(serviceModelInfo);
754 reqDetails.setRelatedInstanceList(list);
755 vnfList.setRelatedInstance(vnfInstance);
756 serviceList.setRelatedInstance(serviceInstance);
757 ModelInfo vfModuleInfo = new ModelInfo();
758 vfModuleInfo.setModelCustomizationId("1");
759 reqDetails.setModelInfo(vfModuleInfo);
760 BuildingBlock bbAddFabric = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
761 ExecuteBuildingBlock ebbAddFabric = new ExecuteBuildingBlock().setBuildingBlock(bbAddFabric);
762 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
763 workflowResourceIds.setServiceInstanceId("1");
764 workflowResourceIds.setVnfId("1");
765 ebbAddFabric.setWorkflowResourceIds(workflowResourceIds);
766 ebbAddFabric.setResourceId("1");
768 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
769 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
770 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
771 ebbActivateVfModule.setResourceId("1");
772 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
773 ebbAddFabric.setConfigurationResourceKeys(configurationResourceKeys);
774 ebbActivateVfModule.setRequestDetails(reqDetails);
776 ServiceInstance service = new ServiceInstance();
777 service.setServiceInstanceName("name");
778 service.setModelVersionId("1");
779 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
781 GenericVnf vnf = new GenericVnf();
782 vnf.setVnfName("name");
783 vnf.setModelCustomizationId("1");
784 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
786 VfModule vfModule = new VfModule();
787 vfModule.setVfModuleName("name");
788 vfModule.setModelCustomizationId("1");
789 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
791 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
792 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
793 vnfc.setModelInvariantId("1");
794 vnfc.setVnfcName("name");
795 vnfc.setModelCustomizationId("2");
797 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
799 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
800 ConfigurationResource configuration = new ConfigurationResource();
801 configuration.setToscaNodeType("FabricConfiguration");
802 configuration.setModelUUID("1");
803 vfModuleCustomization.setConfigurationResource(configuration);
805 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
807 prepareDelegateExecution();
808 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
809 flowsToExecute.add(ebbActivateVfModule);
811 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
812 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
813 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
815 execution.setVariable("requestAction", "replaceInstance");
816 execution.setVariable("completed", true);
817 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
818 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
819 bbCaptor.capture(), listCaptor.capture());
820 assertEquals(false, executionCaptor.getAllValues().get(0).getVariable("completed"));
821 assertEquals(2, ((ArrayList) executionCaptor.getAllValues().get(0).getVariable("flowsToExecute")).size());
823 ((ExecuteBuildingBlock) ((ArrayList) executionCaptor.getAllValues().get(0)
824 .getVariable("flowsToExecute")).get(1)).getConfigurationResourceKeys()
825 .getCvnfcCustomizationUUID());
829 public void postProcessingExecuteBBActivateVfModuleReplaceInstanceHasNoConfigurationTest()
830 throws CloneNotSupportedException {
832 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
833 workflowResourceIds.setServiceInstanceId("1");
834 workflowResourceIds.setVnfId("1");
836 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
837 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
838 ebbActivateVfModule.setWorkflowResourceIds(workflowResourceIds);
839 ebbActivateVfModule.setResourceId("1");
841 ServiceInstance service = new ServiceInstance();
842 service.setServiceInstanceName("name");
843 service.setModelVersionId("1");
844 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById("1");
846 GenericVnf vnf = new GenericVnf();
847 vnf.setVnfName("name");
848 vnf.setModelCustomizationId("1");
849 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf("1");
851 VfModule vfModule = new VfModule();
852 vfModule.setVfModuleName("name");
853 vfModule.setModelCustomizationId("1");
854 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("1", "1");
856 List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
857 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
858 vnfc.setModelInvariantId("1");
859 vnfc.setVnfcName("name");
860 vnfc.setModelCustomizationId("2");
862 doReturn(vnfcs).when(workflowAction).getRelatedResourcesInVfModule(any(), any(), any(), any());
864 CvnfcConfigurationCustomization vfModuleCustomization = new CvnfcConfigurationCustomization();
865 ConfigurationResource configuration = new ConfigurationResource();
866 configuration.setToscaNodeType("FabricConfiguration");
867 configuration.setModelUUID("1");
868 vfModuleCustomization.setConfigurationResource(configuration);
870 doReturn(vfModuleCustomization).when(catalogDbClient).getCvnfcCustomization("1", "1", "1", "2");
872 prepareDelegateExecution();
873 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
874 flowsToExecute.add(ebbActivateVfModule);
876 ArgumentCaptor<DelegateExecution> executionCaptor = ArgumentCaptor.forClass(DelegateExecution.class);
877 ArgumentCaptor<ExecuteBuildingBlock> bbCaptor = ArgumentCaptor.forClass(ExecuteBuildingBlock.class);
878 ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
880 execution.setVariable("requestAction", "replaceInstance");
881 execution.setVariable("completed", true);
883 workflowActionBBTasks.postProcessingExecuteBBActivateVfModule(execution, ebbActivateVfModule, flowsToExecute);
884 verify(workflowActionBBTasks, times(1)).postProcessingExecuteBBActivateVfModule(executionCaptor.capture(),
885 bbCaptor.capture(), listCaptor.capture());
886 assertEquals(true, executionCaptor.getAllValues().get(0).getVariable("completed"));
892 public void getExecuteBBForConfigTest() throws CloneNotSupportedException {
893 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
894 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
896 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
897 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
898 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
899 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
900 resourceIdsActivateVfModule.setConfigurationId("");
902 RequestDetails requestDetails = new RequestDetails();
904 ebbActivateVfModule.setApiVersion("7");
905 ebbActivateVfModule.setaLaCarte(true);
906 ebbActivateVfModule.setRequestAction("createInstance");
907 ebbActivateVfModule.setVnfType("test-vnf-type");
908 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
909 ebbActivateVfModule.setRequestDetails(requestDetails);
910 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
912 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
913 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
914 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
915 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
916 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
918 ExecuteBuildingBlock ebbAddFabricConfig =
919 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
920 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
922 assertEquals("7", ebbAddFabricConfig.getApiVersion());
923 assertTrue(ebbAddFabricConfig.isaLaCarte());
924 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
925 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
926 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
927 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
928 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
929 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
930 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
931 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
932 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
934 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
935 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
936 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
937 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
938 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
942 public void checkRetryStatusTest() {
943 String reqId = "reqId123";
944 execution.setVariable("mso-request-id", reqId);
945 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
946 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
947 execution.setVariable("handlingCode", "Retry");
948 execution.setVariable("retryCount", 1);
949 execution.setVariable("gCurrentSequence", 1);
950 InfraActiveRequests req = new InfraActiveRequests();
951 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
952 workflowActionBBTasks.checkRetryStatus(execution);
953 assertEquals(0, execution.getVariable("gCurrentSequence"));
957 public void checkRetryStatusTestExceededMaxRetries() {
958 String reqId = "reqId123";
959 execution.setVariable("mso-request-id", reqId);
960 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
961 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
962 execution.setVariable("handlingCode", "Retry");
963 execution.setVariable("retryCount", 6);
964 execution.setVariable("gCurrentSequence", 1);
965 InfraActiveRequests req = new InfraActiveRequests();
966 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
968 workflowActionBBTasks.checkRetryStatus(execution);
969 } catch (BpmnError e) {
970 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
971 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
976 public void checkRetryStatusNoRetryTest() {
977 String reqId = "reqId123";
978 execution.setVariable("mso-request-id", reqId);
979 execution.setVariable("retryCount", 3);
980 execution.setVariable("handlingCode", "Success");
981 execution.setVariable("gCurrentSequence", 1);
982 InfraActiveRequests req = new InfraActiveRequests();
983 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
984 workflowActionBBTasks.checkRetryStatus(execution);
985 assertEquals(0, execution.getVariable("retryCount"));
989 public void updateInstanceId() {
990 String reqId = "req123";
991 String instanceId = "123123123";
992 execution.setVariable("mso-request-id", reqId);
993 execution.setVariable("resourceId", instanceId);
994 execution.setVariable("resourceType", WorkflowType.SERVICE);
995 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
996 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
997 workflowActionBBTasks.updateInstanceId(execution);
998 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
1002 public void getConfigurationId() throws Exception {
1003 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
1004 vnfc.setModelInvariantId("modelInvariantId");
1005 vnfc.setVnfcName("testVnfcName");
1006 List<Configuration> configurations = new ArrayList<>();
1007 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
1008 configuration.setConfigurationId("configurationId");
1009 configuration.setModelCustomizationId("modelCustimizationId");
1010 configuration.setConfigurationName("testConfigurationName");
1011 configurations.add(configuration);
1012 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
1013 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
1017 public void setServiceInstanceNameTest() {
1018 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1019 WorkflowType resourceType = WorkflowType.SERVICE;
1020 InfraActiveRequests request = new InfraActiveRequests();
1021 ServiceInstance service = new ServiceInstance();
1022 service.setServiceInstanceName("serviceInstanceName");
1023 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
1025 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1026 assertEquals("serviceInstanceName", request.getServiceInstanceName());
1030 public void setVnfNameTest() {
1031 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1032 WorkflowType resourceType = WorkflowType.VNF;
1033 InfraActiveRequests request = new InfraActiveRequests();
1034 GenericVnf vnf = new GenericVnf();
1035 vnf.setVnfName("vnfName");
1036 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
1038 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1039 assertEquals("vnfName", request.getVnfName());
1043 public void setVfModuleNameTest() {
1044 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1045 WorkflowType resourceType = WorkflowType.VFMODULE;
1046 InfraActiveRequests request = new InfraActiveRequests();
1047 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
1048 VfModule vfModule = new VfModule();
1049 vfModule.setVfModuleName("vfModuleName");
1050 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
1052 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1053 assertEquals("vfModuleName", request.getVfModuleName());
1057 public void setNetworkNameTest() {
1058 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1059 WorkflowType resourceType = WorkflowType.NETWORK;
1060 InfraActiveRequests request = new InfraActiveRequests();
1061 L3Network network = new L3Network();
1062 network.setNetworkName("networkName");
1063 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
1065 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1066 assertEquals("networkName", request.getNetworkName());
1070 public void setConfigurationNameTest() {
1071 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1072 WorkflowType resourceType = WorkflowType.CONFIGURATION;
1073 InfraActiveRequests request = new InfraActiveRequests();
1074 Configuration configuration = new Configuration();
1075 configuration.setConfigurationName("configurationName");
1076 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
1078 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1079 assertEquals("configurationName", request.getConfigurationName());
1083 public void setInstanceGroupNameTest() {
1084 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1085 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
1086 InfraActiveRequests request = new InfraActiveRequests();
1087 InstanceGroup instanceGroup = new InstanceGroup();
1088 instanceGroup.setInstanceGroupName("instanceGroupName");
1089 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
1091 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1092 assertEquals("instanceGroupName", request.getInstanceGroupName());
1096 public void setVolumeGroupNameTest() {
1097 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
1098 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
1099 InfraActiveRequests request = new InfraActiveRequests();
1100 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
1101 VolumeGroup volumeGroup = new VolumeGroup();
1102 volumeGroup.setVolumeGroupName("volumeGroupName");
1103 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
1105 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
1106 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
1108 assertEquals("volumeGroupName", request.getVolumeGroupName());
1111 private void prepareDelegateExecution() {
1112 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
1113 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
1114 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
1115 execution.setVariable("homing", false);
1116 execution.setVariable("calledHoming", false);
1119 private List<BuildingBlockRollback> getRollbackBuildingBlockList() {
1120 List<BuildingBlockRollback> rollbackBBList = Collections.unmodifiableList(Arrays.asList(
1121 new BuildingBlockRollback(1, "ActivateNetworkBB", null, "DeactivateNetworkBB", null),
1122 new BuildingBlockRollback(2, "ActivatePnfBB", null, "DeactivatePnfBB", null),
1123 new BuildingBlockRollback(3, "ActivateServiceInstanceBB", null, "DeactivateServiceInstanceBB", null),
1124 new BuildingBlockRollback(4, "ActivateVfModuleBB", null, "DeactivateVfModuleBB", null),
1125 new BuildingBlockRollback(5, "ActivateVnfBB", null, "DeactivateVnfBB", null),
1126 new BuildingBlockRollback(6, "ActivateVolumeGroupBB", null, "DeactivateVolumeGroupBB", null),
1127 new BuildingBlockRollback(7, "AssignNetworkBB", null, "UnassignNetworkBB", null),
1128 new BuildingBlockRollback(8, "AssignServiceInstanceBB", null, "UnassignServiceInstanceBB", null),
1129 new BuildingBlockRollback(9, "AssignVfModuleBB", null, "UnassignVfModuleBB", null),
1130 new BuildingBlockRollback(10, "AssignVnfBB", null, "UnassignVnfBB", null),
1131 new BuildingBlockRollback(11, "AssignVolumeGroupBB", null, "UnassignVolumeGroupBB", null),
1132 new BuildingBlockRollback(12, "ControllerExecutionBB", "config-assign", "ControllerExecutionBB",
1134 new BuildingBlockRollback(13, "ControllerExecutionBB", "config-deploy", "ControllerExecutionBB",
1136 new BuildingBlockRollback(14, "ControllerExecutionBB", "service-config-deploy", "ControllerExecutionBB",
1137 "service-config-undeploy"),
1138 new BuildingBlockRollback(15, "CreateNetworkBB", null, "DeleteNetworkBB", null),
1139 new BuildingBlockRollback(16, "CreateNetworkCollectionBB", null, "DeleteNetworkCollectionBB", null),
1140 new BuildingBlockRollback(17, "CreateVfModuleBB", null, "DeleteVfModuleBB", null),
1141 new BuildingBlockRollback(18, "CreateVolumeGroupBB", null, "DeleteVolumeGroupBB", null),
1142 new BuildingBlockRollback(19, "VNFSetInMaintFlagActivity", null, "VNFUnsetInMaintFlagActivity", null),
1143 new BuildingBlockRollback(20, "VNFSetClosedLoopDisabledFlagActivity", null,
1144 "VNFUnsetClosedLoopDisabledFlagActivity", null),
1145 new BuildingBlockRollback(21, "VNFLockActivity", null, "VNFUnlockActivity", null),
1146 new BuildingBlockRollback(22, "VNFStopActivity", null, "VNFStartActivity", null),
1147 new BuildingBlockRollback(23, "VNFQuiesceTrafficActivity", null, "VNFResumeTrafficActivity", null),
1148 new BuildingBlockRollback(24, "EtsiVnfInstantiateBB", null, "EtsiVnfDeleteBB", null),
1149 // AddFabricConfigurationBB this does not seem to be present as a bpmn in Guilin
1150 new BuildingBlockRollback(25, "AddFabricConfigurationBB", null, "DeleteFabricConfigurationBB", null)));
1151 return rollbackBBList;