diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
4 files changed, 280 insertions, 17 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java index 798837fa7d..e0cbb82484 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasks.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,23 +23,20 @@ package org.onap.so.bpmn.infrastructure.appc.tasks; import java.util.HashMap; -import java.util.List; import java.util.Optional; - -import org.camunda.bpm.engine.delegate.BpmnError; +import org.onap.appc.client.lcm.model.Action; +import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.client.appc.ApplicationControllerAction; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.appc.client.lcm.model.Action; -import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.client.appc.ApplicationControllerAction; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.springframework.beans.factory.annotation.Autowired; @@ -84,13 +83,20 @@ public class AppcRunTasks { } catch (BBObjectNotFoundException e) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists"); } - String vnfId = vnf.getVnfId(); + String vnfId = null; + String vnfName = null; + String vnfType = null; + String vnfHostIpAddress = null; + + if (vnf != null) { + vnfId = vnf.getVnfId(); + vnfName = vnf.getVnfName(); + vnfType = vnf.getVnfType(); + vnfHostIpAddress = vnf.getIpv4OamAddress(); + } String msoRequestId = gBBInput.getRequestContext().getMsoRequestId(); - String vnfName = vnf.getVnfName(); - String vnfType = vnf.getVnfType(); - + String aicIdentity = execution.getVariable("aicIdentity"); - String vnfHostIpAddress = vnf.getIpv4OamAddress(); String vmIdList = execution.getVariable("vmIdList"); String vserverIdList = execution.getVariable("vserverIdList"); String identityUrl = execution.getVariable("identityUrl"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java new file mode 100644 index 0000000000..7a433c06a6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java @@ -0,0 +1,48 @@ +package org.onap.so.bpmn.infrastructure.validations; + +import java.util.Optional; +import java.util.regex.Pattern; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.validation.PreBuildingBlockValidator; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CloudRegionOrchestrationValidator implements PreBuildingBlockValidator { + + private static Logger logger = LoggerFactory.getLogger(CloudRegionOrchestrationValidator.class); + private final Pattern pattern = Pattern.compile("(?:Activate|Assign|Create|Deactivate|Delete|Unassign|Update)(?:Network|Vnf|VfModule|VolumeGroup|FabricConfiguration)BB"); + + @Autowired + private ExceptionBuilder exceptionBuilder; + + @Override + public boolean shouldRunFor(String bbName) { + return pattern.matcher(bbName).find(); + } + + @Override + public Optional<String> validate(BuildingBlockExecution execution) { + String msg = null; + try { + CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion(); + if (Boolean.TRUE.equals(cloudRegion.getOrchestrationDisabled())) { + msg = String.format("Error: The request has failed due to orchestration currently disabled for the target cloud region %s for cloud owner %s", + cloudRegion.getLcpCloudRegionId(), cloudRegion.getCloudOwner()); + logger.error(msg); + return Optional.ofNullable(msg); + } + } + catch(Exception e) { + logger.error("failed to validate", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e); + } + return Optional.empty(); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java index 114066aae3..7495cc1e8d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcRunTasksTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -20,19 +22,32 @@ package org.onap.so.bpmn.infrastructure.appc.tasks; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import org.junit.Test; +import org.mockito.InjectMocks; import org.onap.appc.client.lcm.model.Action; +import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.db.catalog.beans.ControllerSelectionReference; -public class AppcRunTasksTest { +public class AppcRunTasksTest extends BaseTaskTest { - + @InjectMocks private AppcRunTasks appcRunTasks = new AppcRunTasks(); + @Test public void mapRollbackVariablesTest() { @@ -53,4 +68,101 @@ public class AppcRunTasksTest { appcRunTasks.mapRollbackVariables(mock, Action.ResumeTraffic, "0"); verify(mock, times(1)).setVariable("rollbackQuiesceTraffic", false); } + + @Test + public void runAppcCommandVnfNull() throws BBObjectNotFoundException { + execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "NULL-TEST"); + fillRequiredAppcExecutionFields(); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("NULL-TEST"))) + .thenReturn(null); + when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory( + isNull(), eq(Action.Lock.toString()))). + thenThrow(new IllegalArgumentException("name or values is null")); + + appcRunTasks.runAppcCommand(execution, Action.Lock); + + // if vnf = null -> vnfType = null -> + // IllegalArgumentException will be thrown in catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory + verify(exceptionUtil, times(1)). + buildAndThrowWorkflowException( + any(BuildingBlockExecution.class), eq(1002), eq("name or values is null")); + } + + @Test + public void runAppcCommandBBObjectNotFoundException() throws BBObjectNotFoundException { + execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "EXCEPTION-TEST"); + fillRequiredAppcExecutionFields(); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("EXCEPTION-TEST"))) + .thenThrow(new BBObjectNotFoundException()); + + appcRunTasks.runAppcCommand(execution, Action.Lock); + + verify(exceptionUtil, times(1)). + buildAndThrowWorkflowException( + any(BuildingBlockExecution.class), eq(7000), eq("No valid VNF exists")); + } + + @Test + public void runAppcCommandVfModuleNull() throws BBObjectNotFoundException { + execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "SUCCESS-TEST"); + fillRequiredAppcExecutionFields(); + GenericVnf genericVnf = getTestGenericVnf(); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("SUCCESS-TEST"))) + .thenReturn(genericVnf); + mockReferenceResponse(); + execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST"); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID), eq("VF-MODULE-ID-TEST"))) + .thenReturn(null); + when(appCClient.getErrorCode()).thenReturn("0"); + + appcRunTasks.runAppcCommand(execution, Action.Lock); + + assertEquals(true, execution.getVariable("rollbackVnfLock")); + } + + @Test + public void runAppcCommand() throws BBObjectNotFoundException { + execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "SUCCESS-TEST"); + fillRequiredAppcExecutionFields(); + GenericVnf genericVnf = getTestGenericVnf(); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID), eq("SUCCESS-TEST"))) + .thenReturn(genericVnf); + mockReferenceResponse(); + execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST"); + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("VF-MODULE-ID"); + when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID), eq("VF-MODULE-ID-TEST"))) + .thenReturn(vfModule); + when(appCClient.getErrorCode()).thenReturn("0"); + + appcRunTasks.runAppcCommand(execution, Action.Lock); + + assertEquals(true, execution.getVariable("rollbackVnfLock")); + } + + private void mockReferenceResponse() { + ControllerSelectionReference reference = new ControllerSelectionReference(); + reference.setControllerName("TEST-CONTROLLER-NAME"); + when(catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory( + eq("TEST-VNF-TYPE"), eq(Action.Lock.toString()))).thenReturn(reference); + } + + private void fillRequiredAppcExecutionFields() { + RequestContext context = new RequestContext(); + context.setMsoRequestId("TEST-MSO-ID"); + execution.setVariable("aicIdentity", "AIC-TEST"); + execution.setVariable("vmIdList", "VM-ID-LIST-TEST"); + execution.setVariable("vserverIdList", "VSERVER-ID-LIST"); + execution.setVariable("identityUrl", "IDENTITY-URL-TEST"); + execution.getGeneralBuildingBlock().setRequestContext(context); + } + + private GenericVnf getTestGenericVnf() { + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId("TEST-VNF-ID"); + genericVnf.setVnfType("TEST-VNF-TYPE"); + genericVnf.setVnfName("TEST-VNF-NAME"); + genericVnf.setIpv4OamAddress("129.0.0.1"); + return genericVnf; + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java new file mode 100644 index 0000000000..f6988fdcd4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java @@ -0,0 +1,97 @@ +package org.onap.so.bpmn.infrastructure.validations; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import java.util.Optional; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; + +public class CloudRegionOrchestrationValidatorTest { + + private BuildingBlockExecution mockExecution; + private CloudRegion cloudRegion; + + @Before + public void setUp() { + cloudRegion = new CloudRegion(); + cloudRegion.setCloudOwner("CloudOwner"); + cloudRegion.setLcpCloudRegionId("my-region-id"); + GeneralBuildingBlock gbb = new GeneralBuildingBlock(); + gbb.setCloudRegion(cloudRegion); + mockExecution = mock(BuildingBlockExecution.class); + doReturn(gbb).when(mockExecution).getGeneralBuildingBlock(); + } + + @Test + public void validateDisabledTest() { + cloudRegion.setOrchestrationDisabled(true); + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertEquals("Error: The request has failed due to orchestration currently disabled for the target cloud region my-region-id for cloud owner CloudOwner", + result.get()); + } + + @Test + public void validateNotDisabledTest() { + cloudRegion.setOrchestrationDisabled(false); + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertFalse(result.isPresent()); + } + + @Test + public void validateDisabledIsNullTest() { + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertFalse(result.isPresent()); + } + + @Test + public void shouldRunForTest() { + CloudRegionOrchestrationValidator validator = new CloudRegionOrchestrationValidator(); + assertTrue(validator.shouldRunFor("ActivateNetworkBB")); + assertTrue(validator.shouldRunFor("AssignNetworkBB")); + assertTrue(validator.shouldRunFor("CreateNetworkBB")); + assertTrue(validator.shouldRunFor("DeactivateNetworkBB")); + assertTrue(validator.shouldRunFor("DeleteNetworkBB")); + assertTrue(validator.shouldRunFor("UnassignNetworkBB")); + assertTrue(validator.shouldRunFor("UpdateNetworkBB")); + + assertTrue(validator.shouldRunFor("ActivateVnfBB")); + assertTrue(validator.shouldRunFor("AssignVnfBB")); + assertTrue(validator.shouldRunFor("UnassignVnfBB")); + assertTrue(validator.shouldRunFor("DeactivateVnfBB")); + + assertTrue(validator.shouldRunFor("ActivateVfModuleBB")); + assertTrue(validator.shouldRunFor("AssignVfModuleBB")); + assertTrue(validator.shouldRunFor("CreateVfModuleBB")); + assertTrue(validator.shouldRunFor("DeactivateVfModuleBB")); + assertTrue(validator.shouldRunFor("DeleteVfModuleBB")); + assertTrue(validator.shouldRunFor("UnassignVfModuleBB")); + + assertTrue(validator.shouldRunFor("ActivateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("AssignVolumeGroupBB")); + assertTrue(validator.shouldRunFor("CreateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("DeactivateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("DeleteVolumeGroupBB")); + assertTrue(validator.shouldRunFor("UnassignVolumeGroupBB")); + + assertTrue(validator.shouldRunFor("ActivateFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("AssignFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("UnassignFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("DeactivateFabricConfigurationBB")); + + assertFalse(validator.shouldRunFor("AssignServiceInstanceBB")); + assertFalse(validator.shouldRunFor("AAICheckVnfInMaintBB")); + assertFalse(validator.shouldRunFor("ChangeModelVfModuleBB")); + assertFalse(validator.shouldRunFor("CreateNetworkCollectionBB")); + } +} |