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.assertTrue;
61 import static org.mockito.ArgumentMatchers.anyObject;
62 import static org.mockito.ArgumentMatchers.anyString;
63 import static org.mockito.ArgumentMatchers.isA;
64 import static org.mockito.Mockito.doNothing;
65 import static org.mockito.Mockito.doReturn;
66 import static org.mockito.Mockito.when;
68 public class WorkflowActionBBTasksTest extends BaseTaskTest {
70 private static final String SAMPLE_MSO_REQUEST_ID = "00f704ca-c5e5-4f95-a72c-6889db7b0688";
71 private static final String SAMPLE_REQUEST_ACTION = "Delete-Network-Collection";
72 private static final int SAMPLE_SEQUENCE = 0;
73 private static final String EMPTY_STRING = "";
75 protected WorkflowAction workflowAction;
78 protected WorkflowActionBBFailure workflowActionBBFailure;
82 protected WorkflowActionBBTasks workflowActionBBTasks;
85 InfraActiveRequests reqMock;
87 private DelegateExecution execution;
90 protected Environment environment;
93 private FlowManipulatorListenerRunner flowManipulatorListenerRunner;
96 public ExpectedException thrown = ExpectedException.none();
99 public void before() throws Exception {
100 execution = new DelegateExecutionFake();
101 ServiceInstance servInstance = new ServiceInstance();
102 servInstance.setServiceInstanceId("TEST");
103 when(bbSetupUtils.getAAIServiceInstanceByName(anyString(), anyObject())).thenReturn(servInstance);
104 workflowAction.setBbInputSetupUtils(bbSetupUtils);
105 workflowAction.setBbInputSetup(bbInputSetup);
109 public void selectBBTest() {
110 String vnfCustomizationUUID = "1234567";
111 String modelUuid = "1234567";
112 prepareDelegateExecution();
113 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
115 BuildingBlock buildingBlock =
116 new BuildingBlock().setBpmnFlowName("ConfigAssignVnfBB").setKey(vnfCustomizationUUID);
117 RequestDetails rd = new RequestDetails();
118 ModelInfo mi = new ModelInfo();
119 mi.setModelUuid(modelUuid);
121 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
122 flowsToExecute.add(ebb);
124 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
125 VnfResourceCustomization vrc = new VnfResourceCustomization();
126 vrc.setSkipPostInstConf(false);
127 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
128 vnfResourceCustomizations.add(vrc);
129 GenericVnf genericVnf = new GenericVnf();
130 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
131 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
132 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
133 vnfResourceCustomizations);
135 execution.setVariable("flowsToExecute", flowsToExecute);
136 workflowActionBBTasks.selectBB(execution);
137 boolean success = (boolean) execution.getVariable("completed");
138 int currentSequence = (int) execution.getVariable("gCurrentSequence");
140 assertEquals(1, currentSequence);
144 public void select2BBTest() {
145 String vnfCustomizationUUID = "1234567";
146 String modelUuid = "1234567";
148 prepareDelegateExecution();
149 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
150 BuildingBlock buildingBlock =
151 new BuildingBlock().setBpmnFlowName("ConfigDeployVnfBB").setKey(vnfCustomizationUUID);
152 RequestDetails rd = new RequestDetails();
153 ModelInfo mi = new ModelInfo();
154 mi.setModelUuid(modelUuid);
156 ExecuteBuildingBlock ebb = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock).setRequestDetails(rd);
157 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock();
159 flowsToExecute.add(ebb);
161 List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList<>();
162 VnfResourceCustomization vrc = new VnfResourceCustomization();
164 vrc.setSkipPostInstConf(false);
165 vrc.setModelCustomizationUUID(vnfCustomizationUUID);
166 vnfResourceCustomizations.add(vrc);
167 GenericVnf genericVnf = new GenericVnf();
168 genericVnf.setModelCustomizationId(vnfCustomizationUUID);
170 doReturn(vnfResourceCustomizations).when(catalogDbClient).getVnfResourceCustomizationByModelUuid(modelUuid);
171 doReturn(vrc).when(catalogDbClient).findVnfResourceCustomizationInList(vnfCustomizationUUID,
172 vnfResourceCustomizations);
174 flowsToExecute.add(ebb2);
175 execution.setVariable("flowsToExecute", flowsToExecute);
176 workflowActionBBTasks.selectBB(execution);
177 boolean success = (boolean) execution.getVariable("completed");
178 int currentSequence = (int) execution.getVariable("gCurrentSequence");
179 assertEquals(false, success);
180 assertEquals(1, currentSequence);
184 public void updateRequestStatusToCompleteTest() {
185 String reqId = "reqId123";
186 execution.setVariable("mso-request-id", reqId);
187 execution.setVariable("requestAction", "createInstance");
188 execution.setVariable("resourceName", "Service");
189 execution.setVariable("aLaCarte", true);
190 InfraActiveRequests req = new InfraActiveRequests();
191 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
192 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
193 workflowActionBBTasks.updateRequestStatusToComplete(execution);
194 assertEquals("ALaCarte-Service-createInstance request was executed correctly.",
195 execution.getVariable("finalStatusMessage"));
199 public void rollbackExecutionPathTest() {
200 execution.setVariable("handlingCode", "Rollback");
201 execution.setVariable("isRollback", false);
202 execution.setVariable("requestAction", EMPTY_STRING);
203 execution.setVariable("resourceName", EMPTY_STRING);
204 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
205 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
206 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
207 flowsToExecute.add(ebb1);
209 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
210 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
211 flowsToExecute.add(ebb2);
213 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
214 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
215 flowsToExecute.add(ebb3);
217 execution.setVariable("flowsToExecute", flowsToExecute);
218 execution.setVariable("gCurrentSequence", 3);
219 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
221 workflowActionBBTasks.rollbackExecutionPath(execution);
222 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
223 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeactivateVfModuleBB");
224 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
225 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
226 assertEquals(0, execution.getVariable("gCurrentSequence"));
230 public void rollbackExecutionPathUnfinishedFlowTest() {
231 execution.setVariable("handlingCode", "Rollback");
232 execution.setVariable("isRollback", false);
233 execution.setVariable("requestAction", EMPTY_STRING);
234 execution.setVariable("resourceName", EMPTY_STRING);
235 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
236 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
237 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
238 flowsToExecute.add(ebb1);
240 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
241 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
242 flowsToExecute.add(ebb2);
244 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
245 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
246 flowsToExecute.add(ebb3);
248 execution.setVariable("flowsToExecute", flowsToExecute);
249 execution.setVariable("gCurrentSequence", 2);
250 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
252 workflowActionBBTasks.rollbackExecutionPath(execution);
253 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
254 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "DeleteVfModuleBB");
255 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "UnassignVfModuleBB");
256 assertEquals(0, execution.getVariable("gCurrentSequence"));
257 assertEquals(0, execution.getVariable("retryCount"));
261 public void rollbackExecutionTest() {
262 execution.setVariable("handlingCode", "Rollback");
263 execution.setVariable("isRollback", false);
264 execution.setVariable("requestAction", EMPTY_STRING);
265 execution.setVariable("resourceName", EMPTY_STRING);
266 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
267 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignServiceInstanceBB");
268 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
269 flowsToExecute.add(ebb1);
271 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateNetworkCollectionBB");
272 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
273 flowsToExecute.add(ebb2);
275 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("AssignNetworkBB");
276 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
277 flowsToExecute.add(ebb3);
279 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("CreateNetworkBB");
280 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
281 flowsToExecute.add(ebb4);
283 execution.setVariable("flowsToExecute", flowsToExecute);
284 execution.setVariable("gCurrentSequence", 3);
285 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
287 workflowActionBBTasks.rollbackExecutionPath(execution);
288 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
289 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "UnassignNetworkBB");
290 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "DeleteNetworkCollectionBB");
291 assertEquals(ebbs.get(2).getBuildingBlock().getBpmnFlowName(), "UnassignServiceInstanceBB");
292 assertEquals(0, execution.getVariable("gCurrentSequence"));
296 public void rollbackExecutionRollbackToAssignedTest() {
297 execution.setVariable("isRollback", false);
298 execution.setVariable("handlingCode", "RollbackToAssigned");
299 execution.setVariable("requestAction", EMPTY_STRING);
300 execution.setVariable("resourceName", EMPTY_STRING);
301 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
303 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
304 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
305 flowsToExecute.add(ebb1);
307 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
308 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
309 flowsToExecute.add(ebb2);
311 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
312 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
313 flowsToExecute.add(ebb3);
315 execution.setVariable("flowsToExecute", flowsToExecute);
316 execution.setVariable("gCurrentSequence", 2);
318 workflowActionBBTasks.rollbackExecutionPath(execution);
319 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
320 assertEquals("DeleteVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
321 assertEquals(0, execution.getVariable("gCurrentSequence"));
322 assertEquals(1, ebbs.size());
326 public void rollbackExecutionPathChangeBBForReplaceVFModuleTest() {
327 execution.setVariable("handlingCode", "Rollback");
328 execution.setVariable("isRollback", false);
329 execution.setVariable("requestAction", "replaceInstance");
330 execution.setVariable("resourceName", "VfModule");
331 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
332 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
333 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
334 flowsToExecute.add(ebb1);
336 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
337 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
338 flowsToExecute.add(ebb2);
340 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
341 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
342 flowsToExecute.add(ebb3);
345 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("ChangeModelVnfBB");
346 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
347 flowsToExecute.add(ebb4);
349 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("ChangeModelServiceInstanceBB");
350 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
351 flowsToExecute.add(ebb5);
353 execution.setVariable("flowsToExecute", flowsToExecute);
354 execution.setVariable("gCurrentSequence", 5);
355 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
357 workflowActionBBTasks.rollbackExecutionPath(execution);
358 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
359 assertEquals(ebbs.get(0).getBuildingBlock().getBpmnFlowName(), "ChangeModelVnfBB");
360 assertEquals(ebbs.get(1).getBuildingBlock().getBpmnFlowName(), "ChangeModelServiceInstanceBB");
361 assertEquals(0, execution.getVariable("gCurrentSequence"));
365 public void rollbackExecutionRollbackToAssignedWithFabricTest() {
366 execution.setVariable("isRollback", false);
367 execution.setVariable("handlingCode", "RollbackToAssigned");
368 execution.setVariable("requestAction", EMPTY_STRING);
369 execution.setVariable("resourceName", EMPTY_STRING);
370 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
372 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
373 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
374 flowsToExecute.add(ebb1);
376 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
377 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
378 flowsToExecute.add(ebb2);
380 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
381 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
382 flowsToExecute.add(ebb3);
384 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("AddFabricConfigurationBB");
385 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
386 flowsToExecute.add(ebb4);
388 execution.setVariable("flowsToExecute", flowsToExecute);
389 execution.setVariable("gCurrentSequence", 4);
391 workflowActionBBTasks.rollbackExecutionPath(execution);
392 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
393 assertEquals(0, execution.getVariable("gCurrentSequence"));
394 assertEquals(3, ebbs.size());
395 assertEquals("DeleteFabricConfigurationBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
396 assertEquals("DeactivateVfModuleBB", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
397 assertEquals("DeleteVfModuleBB", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
402 public void rollbackExecutionRollbackToCreatedTest() {
403 execution.setVariable("isRollback", false);
404 execution.setVariable("handlingCode", "RollbackToCreated");
405 execution.setVariable("requestAction", EMPTY_STRING);
406 execution.setVariable("resourceName", EMPTY_STRING);
407 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
408 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("AssignVfModuleBB");
409 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
410 flowsToExecute.add(ebb1);
412 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("CreateVfModuleBB");
413 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
414 flowsToExecute.add(ebb2);
416 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
417 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
418 flowsToExecute.add(ebb3);
420 execution.setVariable("flowsToExecute", flowsToExecute);
421 execution.setVariable("gCurrentSequence", 3);
423 workflowActionBBTasks.rollbackExecutionPath(execution);
424 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
425 assertEquals("DeactivateVfModuleBB", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
426 assertEquals(0, execution.getVariable("gCurrentSequence"));
427 assertEquals(1, ebbs.size());
431 public void rollbackExecutionRollbackInPlaceSoftwareUpdateTest() {
432 execution.setVariable("isRollback", false);
433 execution.setVariable("handlingCode", "Rollback");
434 execution.setVariable("requestAction", EMPTY_STRING);
435 execution.setVariable("resourceName", EMPTY_STRING);
436 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
437 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
438 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
439 flowsToExecute.add(ebb1);
441 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
442 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
443 flowsToExecute.add(ebb2);
445 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
446 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
447 flowsToExecute.add(ebb3);
449 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
450 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
451 flowsToExecute.add(ebb4);
453 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
454 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
455 flowsToExecute.add(ebb5);
457 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFLockActivity");
458 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
459 flowsToExecute.add(ebb6);
461 BuildingBlock buildingBlock7 = new BuildingBlock().setBpmnFlowName("VNFUpgradePreCheckActivity");
462 ExecuteBuildingBlock ebb7 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock7);
463 flowsToExecute.add(ebb7);
465 BuildingBlock buildingBlock8 = new BuildingBlock().setBpmnFlowName("VNFQuiesceTrafficActivity");
466 ExecuteBuildingBlock ebb8 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock8);
467 flowsToExecute.add(ebb8);
469 BuildingBlock buildingBlock9 = new BuildingBlock().setBpmnFlowName("VNFStopActivity");
470 ExecuteBuildingBlock ebb9 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock9);
471 flowsToExecute.add(ebb9);
473 BuildingBlock buildingBlock10 = new BuildingBlock().setBpmnFlowName("VNFSnapShotActivity");
474 ExecuteBuildingBlock ebb10 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock10);
475 flowsToExecute.add(ebb10);
477 execution.setVariable("flowsToExecute", flowsToExecute);
478 execution.setVariable("gCurrentSequence", 10);
480 workflowActionBBTasks.rollbackExecutionPath(execution);
481 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
482 assertEquals("VNFStartActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
483 assertEquals("VNFResumeTrafficActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
484 assertEquals("VNFUnlockActivity", ebbs.get(2).getBuildingBlock().getBpmnFlowName());
485 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(3).getBuildingBlock().getBpmnFlowName());
486 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(4).getBuildingBlock().getBpmnFlowName());
487 assertEquals(0, execution.getVariable("gCurrentSequence"));
488 assertEquals(5, ebbs.size());
492 public void rollbackExecutionRollbackConfigModifyTest() {
493 execution.setVariable("isRollback", false);
494 execution.setVariable("handlingCode", "Rollback");
495 execution.setVariable("requestAction", EMPTY_STRING);
496 execution.setVariable("resourceName", EMPTY_STRING);
497 List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>();
498 BuildingBlock buildingBlock1 = new BuildingBlock().setBpmnFlowName("VNFCheckPserversLockedFlagActivity");
499 ExecuteBuildingBlock ebb1 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock1);
500 flowsToExecute.add(ebb1);
502 BuildingBlock buildingBlock2 = new BuildingBlock().setBpmnFlowName("VNFCheckInMaintFlagActivity");
503 ExecuteBuildingBlock ebb2 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock2);
504 flowsToExecute.add(ebb2);
506 BuildingBlock buildingBlock3 = new BuildingBlock().setBpmnFlowName("VNFSetInMaintFlagActivity");
507 ExecuteBuildingBlock ebb3 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock3);
508 flowsToExecute.add(ebb3);
510 BuildingBlock buildingBlock4 = new BuildingBlock().setBpmnFlowName("VNFCheckClosedLoopDisabledFlagActivity");
511 ExecuteBuildingBlock ebb4 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock4);
512 flowsToExecute.add(ebb4);
514 BuildingBlock buildingBlock5 = new BuildingBlock().setBpmnFlowName("VNFSetClosedLoopDisabledFlagActivity");
515 ExecuteBuildingBlock ebb5 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock5);
516 flowsToExecute.add(ebb5);
518 BuildingBlock buildingBlock6 = new BuildingBlock().setBpmnFlowName("VNFHealthCheckActivity");
519 ExecuteBuildingBlock ebb6 = new ExecuteBuildingBlock().setBuildingBlock(buildingBlock6);
520 flowsToExecute.add(ebb6);
522 execution.setVariable("flowsToExecute", flowsToExecute);
523 execution.setVariable("gCurrentSequence", 6);
525 workflowActionBBTasks.rollbackExecutionPath(execution);
526 List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
527 assertEquals("VNFUnsetClosedLoopDisabledFlagActivity", ebbs.get(0).getBuildingBlock().getBpmnFlowName());
528 assertEquals("VNFUnsetInMaintFlagActivity", ebbs.get(1).getBuildingBlock().getBpmnFlowName());
529 assertEquals(0, execution.getVariable("gCurrentSequence"));
530 assertEquals(2, ebbs.size());
534 public void postProcessingExecuteBBActivateVfModuleTest() throws CloneNotSupportedException {
535 BuildingBlock bbActivateVfModule = new BuildingBlock().setBpmnFlowName("ActivateVfModuleBB");
536 ExecuteBuildingBlock ebbActivateVfModule = new ExecuteBuildingBlock().setBuildingBlock(bbActivateVfModule);
538 WorkflowResourceIds resourceIdsActivateVfModule = new WorkflowResourceIds();
539 resourceIdsActivateVfModule.setServiceInstanceId("test-service-inbstance-id");
540 resourceIdsActivateVfModule.setVnfId("test-vnf-id");
541 resourceIdsActivateVfModule.setVfModuleId("test-vf-module-id");
542 resourceIdsActivateVfModule.setConfigurationId("");
544 RequestDetails requestDetails = new RequestDetails();
546 ebbActivateVfModule.setApiVersion("7");
547 ebbActivateVfModule.setaLaCarte(true);
548 ebbActivateVfModule.setRequestAction("createInstance");
549 ebbActivateVfModule.setVnfType("test-vnf-type");
550 ebbActivateVfModule.setRequestId("f6c00ae2-a205-4cbd-b055-02e553efde12");
551 ebbActivateVfModule.setRequestDetails(requestDetails);
552 ebbActivateVfModule.setWorkflowResourceIds(resourceIdsActivateVfModule);
554 ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
555 configurationResourceKeys.setCvnfcCustomizationUUID("07d64cd2-4427-4156-b11d-d14b96b3e4cb");
556 configurationResourceKeys.setVfModuleCustomizationUUID("50b61075-6ebb-4aab-a9fc-bedad9a2aa76");
557 configurationResourceKeys.setVnfResourceCustomizationUUID("a1d0e36e-34a9-431b-b5ba-4bbb72f63c7c");
558 configurationResourceKeys.setVnfcName("rdm54bvbgw5001vm018pim001");
560 ExecuteBuildingBlock ebbAddFabricConfig =
561 workflowActionBBTasks.getExecuteBBForConfig("AddFabricConfigurationBB", ebbActivateVfModule,
562 "cc7e12f9-967c-4362-8d14-e5b2bf0608a4", configurationResourceKeys);
564 assertEquals("7", ebbAddFabricConfig.getApiVersion());
565 assertTrue(ebbAddFabricConfig.isaLaCarte());
566 assertEquals("createInstance", ebbAddFabricConfig.getRequestAction());
567 assertEquals("test-vnf-type", ebbAddFabricConfig.getVnfType());
568 assertEquals("f6c00ae2-a205-4cbd-b055-02e553efde12", ebbAddFabricConfig.getRequestId());
569 assertEquals(requestDetails, ebbAddFabricConfig.getRequestDetails());
570 assertEquals("cc7e12f9-967c-4362-8d14-e5b2bf0608a4",
571 ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId());
572 assertEquals("test-service-inbstance-id", ebbAddFabricConfig.getWorkflowResourceIds().getServiceInstanceId());
573 assertEquals("test-vnf-id", ebbAddFabricConfig.getWorkflowResourceIds().getVnfId());
574 assertEquals("test-vf-module-id", ebbAddFabricConfig.getWorkflowResourceIds().getVfModuleId());
576 assertThat(ebbAddFabricConfig.getConfigurationResourceKeys()).isEqualTo(configurationResourceKeys);
577 assertThat(ebbAddFabricConfig.getWorkflowResourceIds())
578 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds());
579 assertThat(ebbAddFabricConfig.getWorkflowResourceIds().getConfigurationId())
580 .isNotEqualTo(ebbActivateVfModule.getWorkflowResourceIds().getConfigurationId());
584 public void checkRetryStatusTest() {
585 String reqId = "reqId123";
586 execution.setVariable("mso-request-id", reqId);
587 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
588 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
589 execution.setVariable("handlingCode", "Retry");
590 execution.setVariable("retryCount", 1);
591 execution.setVariable("gCurrentSequence", 1);
592 InfraActiveRequests req = new InfraActiveRequests();
593 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
594 workflowActionBBTasks.checkRetryStatus(execution);
595 assertEquals(0, execution.getVariable("gCurrentSequence"));
599 public void checkRetryStatusTestExceededMaxRetries() {
600 String reqId = "reqId123";
601 execution.setVariable("mso-request-id", reqId);
602 doNothing().when(workflowActionBBFailure).updateRequestErrorStatusMessage(isA(DelegateExecution.class));
603 doReturn("6").when(environment).getProperty("mso.rainyDay.maxRetries");
604 execution.setVariable("handlingCode", "Retry");
605 execution.setVariable("retryCount", 6);
606 execution.setVariable("gCurrentSequence", 1);
607 InfraActiveRequests req = new InfraActiveRequests();
608 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
610 workflowActionBBTasks.checkRetryStatus(execution);
611 } catch (BpmnError e) {
612 WorkflowException exception = (WorkflowException) execution.getVariable("WorkflowException");
613 assertEquals("Exceeded maximum retries. Ending flow with status Abort", exception.getErrorMessage());
618 public void checkRetryStatusNoRetryTest() {
619 String reqId = "reqId123";
620 execution.setVariable("mso-request-id", reqId);
621 execution.setVariable("retryCount", 3);
622 execution.setVariable("handlingCode", "Success");
623 execution.setVariable("gCurrentSequence", 1);
624 InfraActiveRequests req = new InfraActiveRequests();
625 doReturn(req).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
626 workflowActionBBTasks.checkRetryStatus(execution);
627 assertEquals(0, execution.getVariable("retryCount"));
631 public void updateInstanceId() {
632 String reqId = "req123";
633 String instanceId = "123123123";
634 execution.setVariable("mso-request-id", reqId);
635 execution.setVariable("resourceId", instanceId);
636 execution.setVariable("resourceType", WorkflowType.SERVICE);
637 doReturn(reqMock).when(requestsDbClient).getInfraActiveRequestbyRequestId(reqId);
638 doNothing().when(requestsDbClient).updateInfraActiveRequests(isA(InfraActiveRequests.class));
639 workflowActionBBTasks.updateInstanceId(execution);
640 Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId);
644 public void getConfigurationId() {
645 org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc();
646 vnfc.setModelInvariantId("modelInvariantId");
647 vnfc.setVnfcName("testVnfcName");
648 List<Configuration> configurations = new ArrayList<>();
649 org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration();
650 configuration.setConfigurationId("configurationId");
651 configuration.setModelCustomizationId("modelCustimizationId");
652 configuration.setConfigurationName("testConfigurationName");
653 configurations.add(configuration);
654 doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc);
655 assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId");
659 public void setServiceInstanceNameTest() {
660 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
661 WorkflowType resourceType = WorkflowType.SERVICE;
662 InfraActiveRequests request = new InfraActiveRequests();
663 ServiceInstance service = new ServiceInstance();
664 service.setServiceInstanceName("serviceInstanceName");
665 doReturn(service).when(bbSetupUtils).getAAIServiceInstanceById(resourceId);
667 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
668 assertEquals("serviceInstanceName", request.getServiceInstanceName());
672 public void setVnfNameTest() {
673 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
674 WorkflowType resourceType = WorkflowType.VNF;
675 InfraActiveRequests request = new InfraActiveRequests();
676 GenericVnf vnf = new GenericVnf();
677 vnf.setVnfName("vnfName");
678 doReturn(vnf).when(bbSetupUtils).getAAIGenericVnf(resourceId);
680 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
681 assertEquals("vnfName", request.getVnfName());
685 public void setVfModuleNameTest() {
686 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
687 WorkflowType resourceType = WorkflowType.VFMODULE;
688 InfraActiveRequests request = new InfraActiveRequests();
689 request.setVnfId("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e");
690 VfModule vfModule = new VfModule();
691 vfModule.setVfModuleName("vfModuleName");
692 doReturn(vfModule).when(bbSetupUtils).getAAIVfModule("ae5cc3e8-c13c-4d88-aaf6-694ab4977b0e", resourceId);
694 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
695 assertEquals("vfModuleName", request.getVfModuleName());
699 public void setNetworkNameTest() {
700 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
701 WorkflowType resourceType = WorkflowType.NETWORK;
702 InfraActiveRequests request = new InfraActiveRequests();
703 L3Network network = new L3Network();
704 network.setNetworkName("networkName");
705 doReturn(network).when(bbSetupUtils).getAAIL3Network(resourceId);
707 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
708 assertEquals("networkName", request.getNetworkName());
712 public void setConfigurationNameTest() {
713 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
714 WorkflowType resourceType = WorkflowType.CONFIGURATION;
715 InfraActiveRequests request = new InfraActiveRequests();
716 Configuration configuration = new Configuration();
717 configuration.setConfigurationName("configurationName");
718 doReturn(configuration).when(bbSetupUtils).getAAIConfiguration(resourceId);
720 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
721 assertEquals("configurationName", request.getConfigurationName());
725 public void setInstanceGroupNameTest() {
726 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
727 WorkflowType resourceType = WorkflowType.INSTANCE_GROUP;
728 InfraActiveRequests request = new InfraActiveRequests();
729 InstanceGroup instanceGroup = new InstanceGroup();
730 instanceGroup.setInstanceGroupName("instanceGroupName");
731 doReturn(instanceGroup).when(bbSetupUtils).getAAIInstanceGroup(resourceId);
733 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
734 assertEquals("instanceGroupName", request.getInstanceGroupName());
738 public void setVolumeGroupNameTest() {
739 String resourceId = "40bc4ebd-11df-4610-8055-059f7441ec1c";
740 WorkflowType resourceType = WorkflowType.VOLUMEGROUP;
741 InfraActiveRequests request = new InfraActiveRequests();
742 request.setVnfId("4aa72c90-21eb-4465-8847-997e27af6c3e");
743 VolumeGroup volumeGroup = new VolumeGroup();
744 volumeGroup.setVolumeGroupName("volumeGroupName");
745 Optional<VolumeGroup> returnVolumeGroup = Optional.of(volumeGroup);
747 doReturn(returnVolumeGroup).when(bbSetupUtils).getRelatedVolumeGroupByIdFromVnf(request.getVnfId(), resourceId);
748 workflowActionBBTasks.setInstanceName(resourceId, resourceType, request);
750 assertEquals("volumeGroupName", request.getVolumeGroupName());
753 private void prepareDelegateExecution() {
754 execution.setVariable("mso-request-id", SAMPLE_MSO_REQUEST_ID);
755 execution.setVariable("requestAction", SAMPLE_REQUEST_ACTION);
756 execution.setVariable("gCurrentSequence", SAMPLE_SEQUENCE);
757 execution.setVariable("homing", false);
758 execution.setVariable("calledHoming", false);