diff options
Diffstat (limited to 'bpmn')
9 files changed, 221 insertions, 10 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java index 5f70ab5924..3a1e126fef 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java @@ -82,7 +82,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple String correlationValue = messageId; callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "queryVnfNotification") @@ -117,7 +117,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setOutputs(outputs); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "createVnfNotification") @@ -150,7 +150,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setRollback(rollback); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "updateVnfNotification") @@ -181,7 +181,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setRollback(rollback); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "deleteVnfNotification") @@ -208,6 +208,6 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setErrorMessage(errorMessage); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } } diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java new file mode 100644 index 0000000000..d15d71a9e9 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java @@ -0,0 +1,118 @@ +package org.onap.so.bpmn.common.workflow.service; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.adapter.vnf.CreateVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.DeleteVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.MsoExceptionCategory; +import org.onap.so.bpmn.common.adapter.vnf.QueryVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.RollbackVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.UpdateVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.VnfRollback; +import org.onap.so.bpmn.common.adapter.vnf.VnfStatus; +import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAdapterNotifyServiceImplTest { + + + @InjectMocks + @Spy + private VnfAdapterNotifyServiceImpl vnfAdapterNotifyServiceImpl; + + @Mock + private CallbackHandlerService callbackHandlerService; + + @Mock + private CallbackResult callbackResult; + + protected CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs(); + protected QueryVnfNotification.Outputs queryOutputs = new QueryVnfNotification.Outputs(); + protected UpdateVnfNotification.Outputs updateOutputs = new UpdateVnfNotification.Outputs(); + + protected VnfRollback vnfRollback = new VnfRollback(); + + @Test + public void rollbackVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("rollbackVnfNotification"), + any(RollbackVnfNotification.class), eq("rollbackVnfNotificationCallback"), + eq("rollbackVnfNotificationCallback"), eq("VNFRB_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.rollbackVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, + "Error creating stack"); + + verify(callbackHandlerService, times(1)).handleCallback(eq("rollbackVnfNotification"), + any(RollbackVnfNotification.class), eq("rollbackVnfNotificationCallback"), + eq("rollbackVnfNotificationCallback"), eq("VNFRB_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void queryVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("queryVnfNotification"), + any(QueryVnfNotification.class), eq("queryVnfNotificationCallback"), eq("queryVnfNotificationCallback"), + eq("VNFQ_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + + vnfAdapterNotifyServiceImpl.queryVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + Boolean.TRUE, "vnfid", VnfStatus.ACTIVE, queryOutputs); + + verify(callbackHandlerService, times(1)).handleCallback(eq("queryVnfNotification"), + any(QueryVnfNotification.class), eq("queryVnfNotificationCallback"), eq("queryVnfNotificationCallback"), + eq("VNFQ_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + } + + @Test + public void createVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("createVnfNotification"), + any(CreateVnfNotification.class), eq("createVnfNotificationCallback"), + eq("createVnfNotificationCallback"), eq("VNFC_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.createVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + "vnfId", outputs, vnfRollback); + + verify(callbackHandlerService, times(1)).handleCallback(eq("createVnfNotification"), + any(CreateVnfNotification.class), eq("createVnfNotificationCallback"), + eq("createVnfNotificationCallback"), eq("VNFC_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void updateVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("updateVnfNotification"), + any(UpdateVnfNotification.class), eq("updateVnfNotificationCallback"), + eq("updateVnfNotificationCallback"), eq("VNFU_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.updateVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + updateOutputs, vnfRollback); + + verify(callbackHandlerService, times(1)).handleCallback(eq("updateVnfNotification"), + any(UpdateVnfNotification.class), eq("updateVnfNotificationCallback"), + eq("updateVnfNotificationCallback"), eq("VNFU_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void deleteVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("deleteVnfNotification"), + any(DeleteVnfNotification.class), eq("deleteVnfACallback"), eq("deleteVnfACallback"), eq("VNFDEL_uuid"), + eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + + vnfAdapterNotifyServiceImpl.deleteVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, ""); + + verify(callbackHandlerService, times(1)).handleCallback(eq("deleteVnfNotification"), + any(DeleteVnfNotification.class), eq("deleteVnfACallback"), eq("deleteVnfACallback"), eq("VNFDEL_uuid"), + eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + } +} 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 9c72d229b2..79ccd9216f 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 @@ -24,6 +24,7 @@ package org.onap.so.bpmn.infrastructure.appc.tasks; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import org.onap.so.logger.LoggingAnchor; import org.json.JSONArray; @@ -31,6 +32,7 @@ import org.json.JSONObject; import org.onap.aai.domain.yang.Vserver; import org.onap.appc.client.lcm.model.Action; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.core.json.JsonUtils; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; @@ -166,6 +168,10 @@ public class AppcRunTasks { String pay = requestParameters.getPayload(); if (pay != null) { payload = Optional.of(pay); + } else { + String payloadFromUserParams = + buildPayloadFromUserParams(gBBInput.getRequestContext().getUserParams()); + payload = Optional.of(payloadFromUserParams); } } logger.debug("Running APP-C action: {}", action.toString()); @@ -221,6 +227,21 @@ public class AppcRunTasks { return payloadInfo; } + protected String buildPayloadFromUserParams(Map<String, Object> userParams) { + if (userParams == null || userParams.size() == 0) { + return null; + } + + String payload = "{}"; + for (Map.Entry<String, Object> entry : userParams.entrySet()) { + payload = JsonUtils.addJsonValue(payload, entry.getKey(), (String) entry.getValue()); + } + + payload = payload.replaceAll("\"", "\\\\\""); + payload = payload.replaceAll("\n", ""); + return payload; + } + protected void getVserversForAppc(BuildingBlockExecution execution, GenericVnf vnf) throws Exception { AAIResultWrapper aaiRW = aaiVnfResources.queryVnfWrapperById(vnf); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/UnassignNetworkException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/UnassignNetworkException.java new file mode 100644 index 0000000000..566cdccd50 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/exceptions/UnassignNetworkException.java @@ -0,0 +1,14 @@ +package org.onap.so.bpmn.infrastructure.flowspecific.exceptions; + +public class UnassignNetworkException extends Exception { + + private static final long serialVersionUID = 2864418350216433736L; + + public UnassignNetworkException() { + super(); + } + + public UnassignNetworkException(String message) { + super(message); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java index c9a937b824..f95e7afed9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBB.java @@ -24,19 +24,22 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import java.util.Optional; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.flowspecific.exceptions.UnassignNetworkException; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAINetworkResources; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class UnassignNetworkBB { - + private static final Logger logger = LoggerFactory.getLogger(UnassignNetworkBB.class); private static String messageCannotPerformUnassign = "Cannot perform Unassign Network. Network is still related to "; private static String messageErrorRollback = " Rollback is not possible. Please restore data manually."; @@ -71,7 +74,8 @@ public class UnassignNetworkBB { if (networkBBUtils.isRelationshipRelatedToExists(network, relatedToValue)) { String msg = messageCannotPerformUnassign + relatedToValue; execution.setVariable("ErrorUnassignNetworkBB", msg); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + logger.error("ErrorUnassignNetworkBB: {}", msg); + throw new UnassignNetworkException(msg); } } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java index d5798150d1..f5bbcf5bc0 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasks.java @@ -38,6 +38,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.Configuration; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; @@ -398,7 +399,7 @@ public class WorkflowActionBBTasks { if (fabricConfig != null && fabricConfig.getConfigurationResource() != null && fabricConfig.getConfigurationResource().getToscaNodeType() != null && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) { - String configurationId = UUID.randomUUID().toString(); + String configurationId = getConfigurationId(vnfc); ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys(); configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId); configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID); @@ -429,6 +430,17 @@ public class WorkflowActionBBTasks { } } + protected String getConfigurationId(Vnfc vnfc) { + List<Configuration> configurations = + workflowAction.getRelatedResourcesInVnfc(vnfc, Configuration.class, AAIObjectType.CONFIGURATION); + if (!configurations.isEmpty()) { + Configuration configuration = configurations.get(0); + return configuration.getConfigurationId(); + } else { + return UUID.randomUUID().toString(); + } + } + protected ExecuteBuildingBlock getExecuteBBForConfig(String bbName, ExecuteBuildingBlock ebb, String configurationId, ConfigurationResourceKeys configurationResourceKeys) { ExecuteBuildingBlock configBB = new ExecuteBuildingBlock(); 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 cc25689358..f0c333007e 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 @@ -33,6 +33,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; import org.junit.Test; import org.mockito.InjectMocks; @@ -168,6 +170,21 @@ public class AppcRunTasksTest extends BaseTaskTest { assertEquals(vmIdList, expectedVmIdList); } + @Test + public void testUserParams() throws Exception { + Map<String, Object> userParams = new HashMap<String, Object>(); + userParams.put("existing_software_version", "3.1"); + userParams.put("new_software_version", "3.2"); + userParams.put("operations_timeout", "150000"); + + String actualPayload = appcRunTasks.buildPayloadFromUserParams(userParams); + System.out.println(actualPayload); + String expectedPayload = + "{\\\"operations_timeout\\\":\\\"150000\\\",\\\"existing_software_version\\\":\\\"3.1\\\",\\\"new_software_version\\\":\\\"3.2\\\"}"; + assertEquals(expectedPayload, actualPayload.replaceAll(" ", "")); + + } + private void mockReferenceResponse() { ControllerSelectionReference reference = new ControllerSelectionReference(); reference.setControllerName("TEST-CONTROLLER-NAME"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java index bacc57758b..ed55c56231 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/UnassignNetworkBBTest.java @@ -40,9 +40,7 @@ import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; -import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.aai.entities.AAIResultWrapper; -import org.springframework.beans.factory.annotation.Autowired; public class UnassignNetworkBBTest extends BaseTaskTest { @@ -84,6 +82,15 @@ public class UnassignNetworkBBTest extends BaseTaskTest { } @Test + public void checkRelationshipRelatedToUnassignNetworkExceptionTest() throws Exception { + String msg = "Cannot perform Unassign Network. Network is still related to vf-module"; + expectedException.expect(BpmnError.class); + doReturn(true).when(networkBBUtils).isRelationshipRelatedToExists(any(Optional.class), eq("vf-module")); + unassignNetworkBB.checkRelationshipRelatedTo(execution, "vf-module"); + assertEquals(execution.getVariable("ErrorUnassignNetworkBB"), msg); + } + + @Test public void getCloudSdncRegion25Test() throws Exception { CloudRegion cloudRegion = setCloudRegion(); cloudRegion.setCloudRegionVersion("2.5"); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java index aac09b4475..1df4ad797f 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBTasksTest.java @@ -417,4 +417,22 @@ public class WorkflowActionBBTasksTest extends BaseTaskTest { workflowActionBBTasks.updateInstanceId(execution); Mockito.verify(reqMock, Mockito.times(1)).setServiceInstanceId(instanceId); } + + @Test + public void getConfigurationId() { + org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc(); + vnfc.setModelInvariantId("modelInvariantId"); + vnfc.setVnfcName("testVnfcName"); + List<org.onap.aai.domain.yang.Configuration> configurations = + new ArrayList<org.onap.aai.domain.yang.Configuration>(); + org.onap.aai.domain.yang.Configuration configuration = new org.onap.aai.domain.yang.Configuration(); + configuration.setConfigurationId("configurationId"); + configuration.setModelCustomizationId("modelCustimizationId"); + configuration.setConfigurationName("testConfigurationName"); + configurations.add(configuration); + doReturn(configurations.get(0).getConfigurationId()).when(workflowActionBBTasks).getConfigurationId(vnfc); + assertEquals(workflowActionBBTasks.getConfigurationId(vnfc), "configurationId"); + } + + } |