diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
7 files changed, 466 insertions, 4 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java new file mode 100644 index 0000000000..2fba3b3b25 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasks.java @@ -0,0 +1,202 @@ +package org.onap.so.bpmn.infrastructure.manualhandling.tasks; + +import java.util.Map; +import java.util.HashMap; + +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateTask; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.ticket.ExternalTicket; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.logger.MessageEnum; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class ManualHandlingTasks { + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, ManualHandlingTasks.class); + + private static final String TASK_TYPE_PAUSE = "pause"; + private static final String TASK_TYPE_FALLOUT = "fallout"; + + @Autowired + private ExceptionBuilder exceptionUtil; + + @Autowired + private RequestsDbClient requestDbclient; + + public void setFalloutTaskVariables (DelegateTask task) { + + DelegateExecution execution = task.getExecution(); + try { + String taskId = task.getId(); + msoLogger.debug("taskId is: " + taskId); + String type = TASK_TYPE_FALLOUT; + String nfRole = (String) execution.getVariable("vnfType"); + String subscriptionServiceType = (String) execution.getVariable("serviceType"); + String originalRequestId = (String) execution.getVariable("msoRequestId"); + String originalRequestorId = (String) execution.getVariable("requestorId"); + String description = ""; + String timeout = ""; + String errorSource = (String) execution.getVariable("failedActivity"); + String errorCode = (String) execution.getVariable("errorCode"); + String errorMessage = (String) execution.getVariable("errorText"); + String buildingBlockName = (String) execution.getVariable("currentActivity"); + String buildingBlockStep = (String) execution.getVariable("workStep"); + String validResponses = (String) execution.getVariable("validResponses"); + + Map<String, String> taskVariables = new HashMap<String, String>(); + taskVariables.put("type", type); + taskVariables.put("nfRole", nfRole); + taskVariables.put("subscriptionServiceType", subscriptionServiceType); + taskVariables.put("originalRequestId", originalRequestId); + taskVariables.put("originalRequestorId", originalRequestorId); + taskVariables.put("errorSource", errorSource); + taskVariables.put("errorCode", errorCode); + taskVariables.put("errorMessage", errorMessage); + taskVariables.put("buildingBlockName", buildingBlockName); + taskVariables.put("buildingBlockStep", buildingBlockStep); + taskVariables.put("validResponses", validResponses); + taskVariables.put("tmeout", timeout); + taskVariables.put("description", description); + TaskService taskService = execution.getProcessEngineServices().getTaskService(); + + taskService.setVariables(taskId, taskVariables); + msoLogger.debug("successfully created fallout task: "+ taskId); + } catch (BpmnError e) { + msoLogger.debug("BPMN exception: " + e.getMessage()); + throw e; + } catch (Exception ex){ + String msg = "Exception in setFalloutTaskVariables " + ex.getMessage(); + msoLogger.debug(msg); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } + } + + public void setPauseTaskVariables (DelegateTask task) { + + DelegateExecution execution = task.getExecution(); + + try { + String taskId = task.getId(); + msoLogger.debug("taskId is: " + taskId); + String type = TASK_TYPE_PAUSE; + String nfRole = (String) execution.getVariable("vnfType"); + String subscriptionServiceType = (String) execution.getVariable("serviceType"); + String originalRequestId = (String) execution.getVariable("msoRequestId"); + String originalRequestorId = (String) execution.getVariable("requestorId"); + String description = (String) execution.getVariable("description"); + String timeout = (String) execution.getVariable("taskTimeout"); + String errorSource = ""; + String errorCode = ""; + String errorMessage = ""; + String buildingBlockName = ""; + String buildingBlockStep = ""; + String validResponses = (String) execution.getVariable("validResponses"); + + Map<String, String> taskVariables = new HashMap<String, String>(); + taskVariables.put("type", type); + taskVariables.put("nfRole", nfRole); + taskVariables.put("description", description); + taskVariables.put("timeout", timeout); + taskVariables.put("subscriptionServiceType", subscriptionServiceType); + taskVariables.put("originalRequestId", originalRequestId); + taskVariables.put("originalRequestorId", originalRequestorId); + taskVariables.put("errorSource", errorSource); + taskVariables.put("errorCode", errorCode); + taskVariables.put("errorMessage", errorMessage); + taskVariables.put("buildingBlockName", buildingBlockName); + taskVariables.put("buildingBlockStep", buildingBlockStep); + taskVariables.put("validResponses", validResponses); + TaskService taskService = execution.getProcessEngineServices().getTaskService(); + + taskService.setVariables(taskId, taskVariables); + msoLogger.debug("successfully created pause task: "+ taskId); + } catch (BpmnError e) { + msoLogger.debug("BPMN exception: " + e.getMessage()); + throw e; + } catch (Exception ex){ + String msg = "Exception in setPauseTaskVariables " + ex.getMessage(); + msoLogger.debug(msg); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } + + } + + public void completeTask (DelegateTask task) { + + DelegateExecution execution = task.getExecution(); + + try { + + String taskId = task.getId(); + msoLogger.debug("taskId is: " + taskId); + TaskService taskService = execution.getProcessEngineServices().getTaskService(); + + Map<String, Object> taskVariables = taskService.getVariables(taskId); + String responseValue = (String) taskVariables.get("responseValue"); + + msoLogger.debug("Received responseValue on completion: "+ responseValue); + // Have to set the first letter of the response to upper case + String responseValueUppercaseStart = responseValue.substring(0, 1).toUpperCase() + responseValue.substring(1); + msoLogger.debug("ResponseValue to taskListener: "+ responseValueUppercaseStart); + execution.setVariable("responseValueTask", responseValueUppercaseStart); + + } catch (BpmnError e) { + msoLogger.debug("BPMN exception: " + e.getMessage()); + throw e; + } catch (Exception ex){ + String msg = "Exception in completeManualTask " + ex.getMessage(); + msoLogger.debug(msg); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg); + } + + } + + public void createExternalTicket (DelegateExecution execution) { + + try { + ExternalTicket ticket = new ExternalTicket(); + + ticket.setRequestId((String) execution.getVariable("msoRequestId")); + ticket.setCurrentActivity((String) execution.getVariable("currentActivity")); + ticket.setNfRole((String) execution.getVariable("vnfType")); + ticket.setDescription((String) execution.getVariable("description")); + ticket.setSubscriptionServiceType((String) execution.getVariable("serviceType")); + ticket.setRequestorId((String) execution.getVariable("requestorId")); + ticket.setTimeout((String) execution.getVariable("taskTimeout")); + ticket.setErrorSource((String) execution.getVariable("failedActivity")); + ticket.setErrorCode((String) execution.getVariable("errorCode")); + ticket.setErrorMessage((String) execution.getVariable("errorText")); + ticket.setWorkStep((String) execution.getVariable("workStep")); + + ticket.createTicket(); + } catch (BpmnError e) { + String msg = "BPMN error in createAOTSTicket " + e.getMessage(); + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, ""); + } catch (Exception ex){ + String msg = "Exception in createExternalTicket " + ex.getMessage(); + msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", MsoLogger.ErrorCode.UnknownError, ""); + } + + } + + public void updateRequestDbStatus(DelegateExecution execution, String status) { + try { + String requestId = (String) execution.getVariable("msoRequestId"); + InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + + request.setRequestStatus(status); + request.setLastModifiedBy("ManualHandling"); + + requestDbclient.updateInfraActiveRequests(request); + } catch (Exception e) { + msoLogger.error("Unable to save the updated request status to the DB",e); + } + } + +} 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 877a0dded7..482957e006 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 @@ -368,7 +368,8 @@ public class WorkflowActionBBTasks { ExecuteBuildingBlock ebb, List<ExecuteBuildingBlock> flowsToExecute) { try { String vnfId = ebb.getWorkflowResourceIds().getVnfId(); - String vfModuleId = ebb.getWorkflowResourceIds().getVfModuleId(); + String vfModuleId = ebb.getResourceId(); + ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId); String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId(); String vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId(); List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, AAIObjectType.VNFC); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java index c8eeaa7a2b..518da1fa5f 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java @@ -254,6 +254,9 @@ public class AAIObjectMapper { map().setModelCustomizationId(source.getModelInfoConfiguration().getModelCustomizationId()); map().setModelVersionId(source.getModelInfoConfiguration().getModelVersionId()); map().setModelInvariantId(source.getModelInfoConfiguration().getModelInvariantId()); + map().setConfigurationType(source.getModelInfoConfiguration().getConfigurationType()); + map().setConfigurationSubType(source.getModelInfoConfiguration().getConfigurationRole()); + map().setConfigPolicyName(source.getModelInfoConfiguration().getPolicyName()); } }); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java index 3bb1d81e27..138a20b609 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIConfigurationResources.java @@ -165,7 +165,7 @@ public class AAIConfigurationResources { injectionHelper.getAaiClient().connect(configurationURI, vpnBindingURI); } - public void connectConfigurationToVfModule(String configurationId, String vfModuleId, String vnfId){ + public void connectConfigurationToVfModule(String configurationId, String vnfId, String vfModuleId){ AAIResourceUri configurationURI = AAIUriFactory.createResourceUri(AAIObjectType.CONFIGURATION, configurationId); AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId); injectionHelper.getAaiClient().connect(configurationURI, vfModuleURI); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java new file mode 100644 index 0000000000..519afe6f2d --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/ticket/ExternalTicket.java @@ -0,0 +1,155 @@ +package org.onap.so.client.ticket; + +public class ExternalTicket { + private String requestId; + private String nfRole; + private String currentActivity; + private String description; + private String subscriptionServiceType; + private String requestorId; + private String timeout; + private String errorSource; + private String errorCode; + private String errorMessage; + private String workStep; + + public String getRequestId() { + return requestId; + } + + + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + + + public String getNfRole() { + return nfRole; + } + + + + public void setNfRole(String nfRole) { + this.nfRole = nfRole; + } + + + + public String getCurrentActivity() { + return currentActivity; + } + + + + public void setCurrentActivity(String currentActivity) { + this.currentActivity = currentActivity; + } + + + + public String getDescription() { + return description; + } + + + + public void setDescription(String description) { + this.description = description; + } + + + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + + + public String getRequestorId() { + return requestorId; + } + + + + public void setRequestorId(String requestorId) { + this.requestorId = requestorId; + } + + + + public String getTimeout() { + return timeout; + } + + + + public void setTimeout(String timeout) { + this.timeout = timeout; + } + + + + public String getErrorSource() { + return errorSource; + } + + + + public void setErrorSource(String errorSource) { + this.errorSource = errorSource; + } + + + + public String getErrorCode() { + return errorCode; + } + + + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + + + public String getErrorMessage() { + return errorMessage; + } + + + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + + + public String getWorkStep() { + return workStep; + } + + + + public void setWorkStep(String workStep) { + this.workStep = workStep; + } + + + + public void createTicket() throws Exception { + //Replace with your ticket creation mechanism if any + } + + + + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java new file mode 100644 index 0000000000..5e9565446f --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ManualHandlingTasksTest.java @@ -0,0 +1,98 @@ +package org.onap.so.bpmn.infrastructure.manualhandling.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import org.camunda.bpm.engine.ProcessEngineServices; +import org.camunda.bpm.engine.TaskService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.DelegateTask; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.db.request.beans.InfraActiveRequests; + +public class ManualHandlingTasksTest extends BaseTaskTest { + @InjectMocks + protected ManualHandlingTasks manualHandlingTasks = new ManualHandlingTasks(); + + @Mock + TaskService taskService; + + @Mock + private DelegateExecution mockExecution; + + @Mock + ProcessEngineServices processEngineServices; + + @Mock + private DelegateTask task; + + private DelegateExecution delegateExecution; + + @Before + public void before() throws Exception { + delegateExecution = new DelegateExecutionFake(); + } + + @Test + public void setFalloutTaskVariables_Test () { + when(task.getId()).thenReturn("taskId"); + when(task.getExecution()).thenReturn(mockExecution); + when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices); + when(processEngineServices.getTaskService()).thenReturn(taskService); + manualHandlingTasks.setFalloutTaskVariables(task); + verify(taskService, times(1)).setVariables(any(String.class), any(Map.class)); + } + + @Test + public void setPauseTaskVariables_Test () { + when(task.getId()).thenReturn("taskId"); + when(task.getExecution()).thenReturn(mockExecution); + when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices); + when(processEngineServices.getTaskService()).thenReturn(taskService); + manualHandlingTasks.setPauseTaskVariables(task); + verify(taskService, times(1)).setVariables(any(String.class), any(Map.class)); + } + + @Test + public void completeTask_Test() throws Exception{ + when(task.getId()).thenReturn("taskId"); + when(task.getExecution()).thenReturn(mockExecution); + Map<String, Object> taskVariables = new HashMap<String, Object>(); + taskVariables.put("responseValue", "resume"); + when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices); + when(processEngineServices.getTaskService()).thenReturn(taskService); + when(taskService.getVariables(any(String.class))).thenReturn(taskVariables); + manualHandlingTasks.completeTask(task); + verify(mockExecution, times(1)).setVariable("responseValueTask", "Resume"); + } + + @Test + public void updateRequestDbStatus_Test() throws Exception{ + InfraActiveRequests mockedRequest = new InfraActiveRequests(); + delegateExecution.setVariable("msoRequestId", "testMsoRequestId"); + when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest); + doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class)); + manualHandlingTasks.updateRequestDbStatus(delegateExecution, "IN_PROGRESS"); + verify(requestsDbClient, times(1)).updateInfraActiveRequests(any(InfraActiveRequests.class)); + assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS"); + } + + @Test + public void createExternalTicket_Test() throws Exception{ + delegateExecution.setVariable("msoRequestId", ("testMsoRequestId")); + delegateExecution.setVariable("vnfType", "testVnfType"); + manualHandlingTasks.createExternalTicket(delegateExecution); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java index a8e9a7e57e..d5b529288f 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java @@ -74,24 +74,27 @@ public class AAIObjectMapperTest { Configuration configuration = new Configuration(); configuration.setConfigurationId("configId"); configuration.setConfigurationName("VNR"); - configuration.setConfigurationType("VNR-TYPE"); configuration.setOrchestrationStatus(OrchestrationStatus.ASSIGNED); configuration.setManagementOption("managementOption"); ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration(); modelInfoConfiguration.setModelCustomizationId("modelCustId"); modelInfoConfiguration.setModelInvariantId("modelInvariantId"); modelInfoConfiguration.setModelVersionId("modelVersionId"); + modelInfoConfiguration.setConfigurationType("5G"); + modelInfoConfiguration.setConfigurationRole("ConfigurationRole"); configuration.setModelInfoConfiguration(modelInfoConfiguration); org.onap.aai.domain.yang.Configuration expectedConfiguration = new org.onap.aai.domain.yang.Configuration(); expectedConfiguration.setConfigurationId(configuration.getConfigurationId()); expectedConfiguration.setConfigurationName(configuration.getConfigurationName()); - expectedConfiguration.setConfigurationType(configuration.getConfigurationType()); + expectedConfiguration.setConfigurationType(configuration.getModelInfoConfiguration().getConfigurationType()); expectedConfiguration.setOrchestrationStatus(configuration.getOrchestrationStatus().toString()); expectedConfiguration.setManagementOption(configuration.getManagementOption()); expectedConfiguration.setModelInvariantId(configuration.getModelInfoConfiguration().getModelInvariantId()); expectedConfiguration.setModelVersionId(configuration.getModelInfoConfiguration().getModelVersionId()); expectedConfiguration.setModelCustomizationId(configuration.getModelInfoConfiguration().getModelCustomizationId()); + expectedConfiguration.setConfigurationSubType(configuration.getModelInfoConfiguration().getConfigurationRole()); + expectedConfiguration.setConfigPolicyName(configuration.getModelInfoConfiguration().getPolicyName()); org.onap.aai.domain.yang.Configuration actualConfiguration = aaiObjectMapper.mapConfiguration(configuration); |