diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks')
13 files changed, 538 insertions, 106 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index 86645391b4..f1fbe545ce 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -32,6 +32,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; @@ -44,6 +45,7 @@ import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAICollectionResources; import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.client.orchestration.AAINetworkResources; +import org.onap.so.client.orchestration.AAIPnfResources; import org.onap.so.client.orchestration.AAIServiceInstanceResources; import org.onap.so.client.orchestration.AAIVfModuleResources; import org.onap.so.client.orchestration.AAIVnfResources; @@ -78,6 +80,8 @@ public class AAIUpdateTasks { private AAICollectionResources aaiCollectionResources; @Autowired private AAIConfigurationResources aaiConfigurationResources; + @Autowired + private AAIPnfResources aaiPnfResources; /** * BPMN access method to update the status of Service to Assigned in AAI @@ -114,6 +118,22 @@ public class AAIUpdateTasks { } } + + /** + * BPMN access method to update status of Pnf to Active in AAI + * + * @param execution + */ + public void updateOrchestrationStatusActivePnf(BuildingBlockExecution execution) { + try { + Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + } catch (Exception ex) { + logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusActivePnf", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + /** * BPMN access method to update status of Vnf to Assigned in AAI * diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java index 4b967c7bc4..9697246b03 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/appc/tasks/AppcOrchestratorPreProcessor.java @@ -24,6 +24,7 @@ import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAIVnfResources; import org.onap.so.db.catalog.beans.ControllerSelectionReference; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.exceptions.ValidationException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -77,11 +78,11 @@ public class AppcOrchestratorPreProcessor { if (payload == null) { payload = ""; } - String existingSoftwareVersion = JsonUtils.getJsonValue(payload, "existing-software-version"); + String existingSoftwareVersion = JsonUtils.getJsonValue(payload, "existing_software_version"); appcTaskRequest.setExistingSoftwareVersion(existingSoftwareVersion); - String newSoftwareVersion = JsonUtils.getJsonValue(payload, "new-software-version"); + String newSoftwareVersion = JsonUtils.getJsonValue(payload, "new_software_version"); appcTaskRequest.setNewSoftwareVersion(newSoftwareVersion); - String operationsTimeout = JsonUtils.getJsonValue(payload, "operations-timeout"); + String operationsTimeout = JsonUtils.getJsonValue(payload, "operations_timeout"); appcTaskRequest.setOperationsTimeout(operationsTimeout); } @@ -123,9 +124,12 @@ public class AppcOrchestratorPreProcessor { applicationControllerVnf.setVnfName(vnfName); appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf); + verifyApplicationControllerTaskRequest(execution, appcTaskRequest); + execution.setVariable("appcOrchestratorRequest", appcTaskRequest); + logger.debug("SET APPC ORCHESTRATOR REQUEST"); } catch (Exception e) { - logger.error("Error building ApplicationControllerTaskRequest Object", e); + logger.error("Error building ApplicationControllerTaskRequest Object", e.getMessage()); exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); } } @@ -186,4 +190,54 @@ public class AppcOrchestratorPreProcessor { } } } + + protected void verifyApplicationControllerTaskRequest(BuildingBlockExecution execution, + ApplicationControllerTaskRequest appcTaskRequest) throws ValidationException { + String errorMessage = null; + switch (appcTaskRequest.getAction()) { + case QuiesceTraffic: + if (appcTaskRequest.getOperationsTimeout() == null + || appcTaskRequest.getOperationsTimeout().isEmpty()) { + errorMessage = "APPC action QuiesceTraffic is missing operations_timeout parameter. "; + } + break; + case UpgradePreCheck: + case UpgradePostCheck: + case UpgradeBackup: + case UpgradeSoftware: + if (appcTaskRequest.getExistingSoftwareVersion() == null + || appcTaskRequest.getExistingSoftwareVersion().isEmpty()) { + errorMessage = + "APPC action " + appcTaskRequest.getAction() + " is missing existing_software parameter. "; + } + if (appcTaskRequest.getNewSoftwareVersion() == null + || appcTaskRequest.getNewSoftwareVersion().isEmpty()) { + errorMessage = + "APPC action " + appcTaskRequest.getAction() + " is missing new_software parameter. "; + } + break; + case Snapshot: + if (appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm() != null) { + if (appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVmId() == null + || appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVmId() + .isEmpty()) { + errorMessage = "APPC action Snapshot is missing vmId parameter. "; + } + if (appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm() + .getVserverId() == null + || appcTaskRequest.getApplicationControllerVnf().getApplicationControllerVm().getVserverId() + .isEmpty()) { + errorMessage = "APPC action Snapshot is missing vserverId parameter. "; + } + break; + } + default: + break; + } + if (errorMessage != null) { + logger.debug("verifyApplicationControllerTaskRequest() failed with " + errorMessage); + throw new ValidationException(errorMessage, false); + } + return; + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketCreation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketCreation.java new file mode 100644 index 0000000000..70d56db26b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketCreation.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.manualhandling.tasks; + +import org.onap.so.bpmn.common.BuildingBlockExecution; + +public interface ExternalTicketCreation { + public void createExternalTicket(BuildingBlockExecution execution); +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasks.java new file mode 100644 index 0000000000..6bfe618460 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasks.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.manualhandling.tasks; + +import org.onap.so.logger.LoggingAnchor; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.ticket.ExternalTicket; +import org.onap.so.logger.ErrorCode; +import org.onap.so.logger.MessageEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class ExternalTicketTasks implements ExternalTicketCreation { + private static final Logger logger = LoggerFactory.getLogger(ExternalTicketTasks.class); + + protected static final String VNF_TYPE = "vnfType"; + protected static final String DESCRIPTION = "description"; + protected static final String SERVICE_TYPE = "serviceType"; + protected static final String MSO_REQUEST_ID = "mso-request-id"; + protected static final String REQUESTOR_ID = "requestorId"; + protected static final String ERROR_CODE = "errorCode"; + protected static final String VALID_RESPONSES = "validResponses"; + protected static final String TASK_TIMEOUT = "taskTimeout"; + protected static final String RESPONSE_VALUE_TASK = "responseValueTask"; + protected static final String RESPONSE_VALUE = "responseValue"; + protected static final String WORKSTEP = "workStep"; + + protected static final String TASK_VARIABLE_TYPE = "type"; + protected static final String TASK_VARIABLE_NFROLE = "nfRole"; + protected static final String TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE = "subscriptionServiceType"; + protected static final String TASK_VARIABLE_ORIGINAL_REQUEST_ID = "originalRequestId"; + protected static final String TASK_VARIABLE_ORIGINAL_REQUESTOR_ID = "originalRequestorId"; + protected static final String TASK_VARIABLE_ERROR_SOURCE = "errorSource"; + protected static final String TASK_VARIABLE_ERROR_CODE = "errorCode"; + protected static final String TASK_VARIABLE_ERROR_MESSAGE = "errorMessage"; + protected static final String TASK_VARIABLE_BUILDING_BLOCK_NAME = "buildingBlockName"; + protected static final String TASK_VARIABLE_BUILDING_BLOCK_STEP = "buildingBlockStep"; + protected static final String TASK_VARIABLE_DESCRIPTION = "description"; + protected static final String TASK_VARIABLE_TIMEOUT = "timeout"; + protected static final String TASK_VARIABLE_VALID_RESPONSES = "validResponses"; + + protected static final String BPMN_EXCEPTION = "BPMN exception: "; + protected static final String RAINY_DAY_SERVICE_TYPE = "rainyDayServiceType"; + protected static final String RAINY_DAY_VNF_TYPE = "rainyDayVnfType"; + protected static final String RAINY_DAY_VNF_NAME = "rainyDayVnfName"; + protected static final String G_BUILDING_BLOCK_EXECUTION = "gBuildingBlockExecution"; + protected static final String WORKFLOW_EXCEPTION = "WorkflowException"; + + public void createExternalTicket(BuildingBlockExecution execution) { + + logger.debug("Creating ExternalTicket()"); + try { + ExternalTicket ticket = getExternalTicket(); + + ticket.setRequestId((String) execution.getVariable(MSO_REQUEST_ID)); + ticket.setCurrentActivity((String) execution.getVariable("currentActivity")); + ticket.setNfRole((String) execution.getVariable(VNF_TYPE)); + ticket.setDescription((String) execution.getVariable(DESCRIPTION)); + ticket.setSubscriptionServiceType((String) execution.getVariable(SERVICE_TYPE)); + ticket.setRequestorId((String) execution.getVariable(REQUESTOR_ID)); + ticket.setTimeout((String) execution.getVariable(TASK_TIMEOUT)); + ticket.setErrorSource((String) execution.getVariable("failedActivity")); + ticket.setErrorCode((String) execution.getVariable(ERROR_CODE)); + ticket.setErrorMessage((String) execution.getVariable("errorText")); + ticket.setWorkStep((String) execution.getVariable(WORKSTEP)); + + ticket.createTicket(); + } catch (BpmnError e) { + String msg = "BPMN error in createExternalTicket " + e.getMessage(); + logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", + ErrorCode.UnknownError.getValue()); + } catch (Exception ex) { + String msg = "Exception in createExternalTicket " + ex.getMessage(); + logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", + ErrorCode.UnknownError.getValue()); + } + + } + + protected ExternalTicket getExternalTicket() { + return new ExternalTicket(); + } + + +} 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 index 7e45c3b640..d9f5e65ba3 100644 --- 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 @@ -21,22 +21,23 @@ package org.onap.so.bpmn.infrastructure.manualhandling.tasks; import java.util.Map; +import java.time.Duration; +import java.util.Date; import java.util.HashMap; -import org.onap.so.logger.LoggingAnchor; 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.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.core.WorkflowException; import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.client.ticket.ExternalTicket; +import org.onap.so.constants.Status; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; -import org.onap.so.logger.ErrorCode; -import org.onap.so.logger.MessageEnum; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; @Component @@ -46,13 +47,38 @@ public class ManualHandlingTasks { private static final String TASK_TYPE_PAUSE = "pause"; private static final String TASK_TYPE_FALLOUT = "fallout"; public static final String VNF_TYPE = "vnfType"; + public static final String DESCRIPTION = "description"; public static final String SERVICE_TYPE = "serviceType"; public static final String MSO_REQUEST_ID = "mso-request-id"; public static final String REQUESTOR_ID = "requestorId"; public static final String ERROR_CODE = "errorCode"; public static final String VALID_RESPONSES = "validResponses"; - public static final String DESCRIPTION = "description"; + public static final String TASK_TIMEOUT = "taskTimeout"; + public static final String RESPONSE_VALUE_TASK = "responseValueTask"; + public static final String RESPONSE_VALUE = "responseValue"; + private static final String ASTERISK = "*"; + private static final String WORKSTEP = "workStep"; + + public static final String TASK_VARIABLE_TYPE = "type"; + public static final String TASK_VARIABLE_NFROLE = "nfRole"; + public static final String TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE = "subscriptionServiceType"; + public static final String TASK_VARIABLE_ORIGINAL_REQUEST_ID = "originalRequestId"; + public static final String TASK_VARIABLE_ORIGINAL_REQUESTOR_ID = "originalRequestorId"; + public static final String TASK_VARIABLE_ERROR_SOURCE = "errorSource"; + public static final String TASK_VARIABLE_ERROR_CODE = "errorCode"; + public static final String TASK_VARIABLE_ERROR_MESSAGE = "errorMessage"; + public static final String TASK_VARIABLE_BUILDING_BLOCK_NAME = "buildingBlockName"; + public static final String TASK_VARIABLE_BUILDING_BLOCK_STEP = "buildingBlockStep"; + public static final String TASK_VARIABLE_DESCRIPTION = "description"; + public static final String TASK_VARIABLE_TIMEOUT = "timeout"; + public static final String TASK_VARIABLE_VALID_RESPONSES = "validResponses"; + public static final String BPMN_EXCEPTION = "BPMN exception: "; + public static final String RAINY_DAY_SERVICE_TYPE = "rainyDayServiceType"; + public static final String RAINY_DAY_VNF_TYPE = "rainyDayVnfType"; + public static final String RAINY_DAY_VNF_NAME = "rainyDayVnfName"; + public static final String G_BUILDING_BLOCK_EXECUTION = "gBuildingBlockExecution"; + public static final String WORKFLOW_EXCEPTION = "WorkflowException"; @Autowired private ExceptionBuilder exceptionUtil; @@ -60,40 +86,91 @@ public class ManualHandlingTasks { @Autowired private RequestsDbClient requestDbclient; + @Autowired + private Environment environment; + + @Autowired + private ExternalTicketCreation externalTicketCreation; + + protected String manualTaskTimeoutPath = "mso.rainyDay.manualTask.taskTimeout"; + protected String validResponsesPath = "mso.rainyDay.manualTask.validResponses"; + + + public void initRainyDayManualHandling(BuildingBlockExecution execution) { + try { + String manualTaskTimeout = this.environment.getProperty(manualTaskTimeoutPath); + execution.setVariable(TASK_TIMEOUT, manualTaskTimeout); + } catch (Exception e) { + logger.error("Exception occurred", e); + throw new BpmnError("Unknown error reading configuration for manual task handling"); + } + } + public void setFalloutTaskVariables(DelegateTask task) { DelegateExecution execution = task.getExecution(); try { + logger.debug("Setting fallout task variables:"); String taskId = task.getId(); logger.debug("taskId is: " + taskId); String type = TASK_TYPE_FALLOUT; - String nfRole = (String) execution.getVariable(VNF_TYPE); - String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE); + BuildingBlockExecution gBuildingBlockExecution = + (BuildingBlockExecution) execution.getVariable(G_BUILDING_BLOCK_EXECUTION); + WorkflowException workflowException = (WorkflowException) execution.getVariable(WORKFLOW_EXCEPTION); + String nfRole = (String) execution.getVariable(RAINY_DAY_VNF_TYPE); + logger.debug(TASK_VARIABLE_NFROLE + ": " + nfRole); + String subscriptionServiceType = (String) execution.getVariable(RAINY_DAY_SERVICE_TYPE); + logger.debug(TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE + ": " + subscriptionServiceType); String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID); - String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID); - String description = ""; - String timeout = ""; - String errorSource = (String) execution.getVariable("failedActivity"); - String errorCode = (String) execution.getVariable(ERROR_CODE); - String errorMessage = (String) execution.getVariable("errorText"); - String buildingBlockName = (String) execution.getVariable("currentActivity"); - String buildingBlockStep = (String) execution.getVariable("workStep"); - String validResponses = (String) execution.getVariable(VALID_RESPONSES); + logger.debug(TASK_VARIABLE_ORIGINAL_REQUEST_ID + ": " + originalRequestId); + String originalRequestorId = + gBuildingBlockExecution.getGeneralBuildingBlock().getRequestContext().getRequestorId(); + logger.debug(TASK_VARIABLE_ORIGINAL_REQUESTOR_ID + ": " + originalRequestorId); + String description = "Manual user task to handle a failure of a BB execution"; + logger.debug(TASK_VARIABLE_DESCRIPTION + ": " + description); + String taskTimeout = (String) gBuildingBlockExecution.getVariable(TASK_TIMEOUT); + String timeout = Date.from((new Date()).toInstant().plus(Duration.parse(taskTimeout))).toGMTString(); + logger.debug(TASK_VARIABLE_TIMEOUT + ": " + timeout); + String errorSource = ASTERISK; + if (workflowException != null && workflowException.getExtSystemErrorSource() != null) { + errorSource = workflowException.getExtSystemErrorSource().toString(); + } + logger.debug(TASK_VARIABLE_ERROR_SOURCE + ": " + errorSource); + String errorCode = ASTERISK; + if (workflowException != null) { + errorCode = workflowException.getErrorCode() + ""; + } + logger.debug(TASK_VARIABLE_ERROR_CODE + ": " + errorCode); + String errorMessage = ASTERISK; + if (workflowException != null) { + errorMessage = workflowException.getErrorMessage(); + } + logger.debug(TASK_VARIABLE_ERROR_MESSAGE + ": " + errorMessage); + String buildingBlockName = gBuildingBlockExecution.getFlowToBeCalled(); + logger.debug(TASK_VARIABLE_BUILDING_BLOCK_NAME + ": " + buildingBlockName); + String buildingBlockStep = ASTERISK; + if (workflowException != null) { + buildingBlockStep = workflowException.getWorkStep(); + } + execution.setVariable(WORKSTEP, buildingBlockStep); + logger.debug(TASK_VARIABLE_BUILDING_BLOCK_STEP + ": " + buildingBlockStep); + String validResponses = this.environment.getProperty(validResponsesPath); + logger.debug(TASK_VARIABLE_VALID_RESPONSES + ": " + validResponses); Map<String, String> taskVariables = new HashMap<>(); - 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(ERROR_CODE, errorCode); - taskVariables.put("errorMessage", errorMessage); - taskVariables.put("buildingBlockName", buildingBlockName); - taskVariables.put("buildingBlockStep", buildingBlockStep); - taskVariables.put(VALID_RESPONSES, validResponses); - taskVariables.put("tmeout", timeout); - taskVariables.put(DESCRIPTION, description); + taskVariables.put(TASK_VARIABLE_TYPE, type); + taskVariables.put(TASK_VARIABLE_NFROLE, nfRole); + taskVariables.put(TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE, subscriptionServiceType); + taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUEST_ID, originalRequestId); + taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUESTOR_ID, originalRequestorId); + taskVariables.put(TASK_VARIABLE_ERROR_SOURCE, errorSource); + taskVariables.put(TASK_VARIABLE_ERROR_CODE, errorCode); + taskVariables.put(TASK_VARIABLE_ERROR_MESSAGE, errorMessage); + taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_NAME, buildingBlockName); + taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_STEP, buildingBlockStep); + taskVariables.put(TASK_VARIABLE_VALID_RESPONSES, validResponses); + taskVariables.put(TASK_VARIABLE_TIMEOUT, timeout); + taskVariables.put(TASK_VARIABLE_DESCRIPTION, description); TaskService taskService = execution.getProcessEngineServices().getTaskService(); taskService.setVariables(taskId, taskVariables); @@ -116,33 +193,34 @@ public class ManualHandlingTasks { String taskId = task.getId(); logger.debug("taskId is: " + taskId); String type = TASK_TYPE_PAUSE; + String nfRole = (String) execution.getVariable(VNF_TYPE); String subscriptionServiceType = (String) execution.getVariable(SERVICE_TYPE); String originalRequestId = (String) execution.getVariable(MSO_REQUEST_ID); String originalRequestorId = (String) execution.getVariable(REQUESTOR_ID); String description = (String) execution.getVariable(DESCRIPTION); String timeout = ""; - String errorSource = ""; - String errorCode = ""; - String errorMessage = ""; - String buildingBlockName = ""; - String buildingBlockStep = ""; + String errorSource = ASTERISK; + String errorCode = ASTERISK; + String errorMessage = ASTERISK; + String buildingBlockName = ASTERISK; + String buildingBlockStep = ASTERISK; String validResponses = (String) execution.getVariable(VALID_RESPONSES); Map<String, String> taskVariables = new HashMap<>(); - 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(ERROR_CODE, errorCode); - taskVariables.put("errorMessage", errorMessage); - taskVariables.put("buildingBlockName", buildingBlockName); - taskVariables.put("buildingBlockStep", buildingBlockStep); - taskVariables.put(VALID_RESPONSES, validResponses); + taskVariables.put(TASK_VARIABLE_TYPE, type); + taskVariables.put(TASK_VARIABLE_NFROLE, nfRole); + taskVariables.put(TASK_VARIABLE_DESCRIPTION, description); + taskVariables.put(TASK_VARIABLE_TIMEOUT, timeout); + taskVariables.put(TASK_VARIABLE_SUBSCRIPTION_SERVICE_TYPE, subscriptionServiceType); + taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUEST_ID, originalRequestId); + taskVariables.put(TASK_VARIABLE_ORIGINAL_REQUESTOR_ID, originalRequestorId); + taskVariables.put(TASK_VARIABLE_ERROR_SOURCE, errorSource); + taskVariables.put(TASK_VARIABLE_ERROR_CODE, errorCode); + taskVariables.put(TASK_VARIABLE_ERROR_MESSAGE, errorMessage); + taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_NAME, buildingBlockName); + taskVariables.put(TASK_VARIABLE_BUILDING_BLOCK_STEP, buildingBlockStep); + taskVariables.put(TASK_VARIABLE_VALID_RESPONSES, validResponses); TaskService taskService = execution.getProcessEngineServices().getTaskService(); taskService.setVariables(taskId, taskVariables); @@ -169,14 +247,14 @@ public class ManualHandlingTasks { TaskService taskService = execution.getProcessEngineServices().getTaskService(); Map<String, Object> taskVariables = taskService.getVariables(taskId); - String responseValue = (String) taskVariables.get("responseValue"); + String responseValue = (String) taskVariables.get(RESPONSE_VALUE); logger.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); logger.debug("ResponseValue to taskListener: " + responseValueUppercaseStart); - execution.setVariable("responseValueTask", responseValueUppercaseStart); + execution.setVariable(RESPONSE_VALUE_TASK, responseValueUppercaseStart); } catch (BpmnError e) { logger.debug(BPMN_EXCEPTION + e.getMessage()); @@ -190,33 +268,7 @@ public class ManualHandlingTasks { } public void createExternalTicket(BuildingBlockExecution execution) { - - try { - ExternalTicket ticket = new ExternalTicket(); - - ticket.setRequestId((String) execution.getVariable(MSO_REQUEST_ID)); - ticket.setCurrentActivity((String) execution.getVariable("currentActivity")); - ticket.setNfRole((String) execution.getVariable(VNF_TYPE)); - ticket.setDescription((String) execution.getVariable(DESCRIPTION)); - ticket.setSubscriptionServiceType((String) execution.getVariable(SERVICE_TYPE)); - ticket.setRequestorId((String) execution.getVariable(REQUESTOR_ID)); - ticket.setTimeout((String) execution.getVariable("taskTimeout")); - ticket.setErrorSource((String) execution.getVariable("failedActivity")); - ticket.setErrorCode((String) execution.getVariable(ERROR_CODE)); - 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(); - logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", - ErrorCode.UnknownError.getValue()); - } catch (Exception ex) { - String msg = "Exception in createExternalTicket " + ex.getMessage(); - logger.error(LoggingAnchor.FOUR, MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, msg, "BPMN", - ErrorCode.UnknownError.getValue()); - } - + externalTicketCreation.createExternalTicket(execution); } public void updateRequestDbStatus(BuildingBlockExecution execution, String status) { @@ -224,6 +276,9 @@ public class ManualHandlingTasks { String requestId = (String) execution.getVariable(MSO_REQUEST_ID); InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); + if (status.equalsIgnoreCase(Status.TIMEOUT.name())) { + execution.setVariable(RESPONSE_VALUE_TASK, "Timeout"); + } request.setRequestStatus(status); request.setLastModifiedBy("ManualHandling"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 8911ebf15d..80c6f0b969 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -198,7 +198,7 @@ public class WorkflowAction { try { suppressRollback = requestDetails.getRequestInfo().getSuppressRollback(); } catch (Exception ex) { - logger.error("Exception in getSuppressRollback", ex); + logger.warn("Exception in getSuppressRollback", ex); suppressRollback = false; } execution.setVariable("suppressRollback", suppressRollback); @@ -431,7 +431,7 @@ public class WorkflowAction { execution.setVariable("isRollbackComplete", false); } catch (Exception ex) { - buildAndThrowException(execution, "Exception in execution list. ", ex); + buildAndThrowException(execution, "Exception while setting execution list. ", ex); } } @@ -1562,8 +1562,8 @@ public class WorkflowAction { protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { logger.error(msg, ex); - execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg); - exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg); + execution.setVariable(WORKFLOW_ACTION_ERROR_MESSAGE, msg + ex.getMessage()); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, msg + ex.getMessage()); } protected void buildAndThrowException(DelegateExecution execution, String msg) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index 9dd44c43e9..1dde814584 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -49,4 +49,14 @@ public class AAIPnfResources { injectionHelper.getAaiClient().createIfNotExists(pnfURI, Optional.of(aaiObjectMapper.mapPnf(pnf))) .connect(pnfURI, serviceInstanceURI); } + + public void updateOrchestrationStatusPnf(Pnf pnf, OrchestrationStatus orchestrationStatus) { + AAIResourceUri pnfURI = AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName()); + + Pnf pnfCopy = pnf.shallowCopyId(); + + pnf.setOrchestrationStatus(orchestrationStatus); + pnfCopy.setOrchestrationStatus(orchestrationStatus); + injectionHelper.getAaiClient().update(pnfURI, aaiObjectMapper.mapPnf(pnfCopy)); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java index c337f7f1b5..ae6dde6521 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasksTest.java @@ -20,21 +20,7 @@ package org.onap.so.bpmn.infrastructure.aai.tasks; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.util.HashMap; import org.camunda.bpm.engine.delegate.BpmnError; -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatchers; @@ -48,6 +34,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; @@ -56,6 +43,18 @@ import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import java.util.HashMap; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class AAIUpdateTasksTest extends BaseTaskTest { @@ -140,6 +139,27 @@ public class AAIUpdateTasksTest extends BaseTaskTest { aaiUpdateTasks.updateOrchestrationStatusActiveService(execution); } + + @Test + public void updateOrchestrationStatusActivePnfTest() throws Exception { + Pnf pnf = preparePnfAndExtractForPnf(); + doNothing().when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + + aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution); + + verify(aaiPnfResources, times(1)).updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + } + + @Test + public void updateOrchestrationStatusActivePnfExceptionTest() throws Exception { + Pnf pnf = preparePnfAndExtractForPnf(); + doThrow(RuntimeException.class).when(aaiPnfResources).updateOrchestrationStatusPnf(pnf, + OrchestrationStatus.ACTIVE); + + expectedException.expect(BpmnError.class); + aaiUpdateTasks.updateOrchestrationStatusActivePnf(execution); + } + @Test public void updateOrchestrationStatusAssignedVnfTest() throws Exception { doNothing().when(aaiVnfResources).updateOrchestrationStatusVnf(genericVnf, OrchestrationStatus.ASSIGNED); @@ -743,4 +763,10 @@ public class AAIUpdateTasksTest extends BaseTaskTest { aaiUpdateTasks.updateOrchestrationStatusConfigDeployConfiguredVnf(execution); } + + private Pnf preparePnfAndExtractForPnf() throws BBObjectNotFoundException { + Pnf pnf = buildPnf(); + when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.PNF))).thenReturn(pnf); + return pnf; + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasksTest.java new file mode 100644 index 0000000000..f8ecf01579 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/manualhandling/tasks/ExternalTicketTasksTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.manualhandling.tasks; + +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.ticket.ExternalTicket; + +public class ExternalTicketTasksTest extends BaseTaskTest { + + @Mock + private BuildingBlockExecution buildingBlockExecution; + + @Mock + private GeneralBuildingBlock generalBuildingBlock; + + @Mock + private RequestContext requestContext; + + @Mock + private ExternalTicket MOCK_externalTicket; + + @Before + public void before() throws Exception { + delegateExecution = new DelegateExecutionFake(); + buildingBlockExecution = new DelegateExecutionImpl(delegateExecution); + generalBuildingBlock = new GeneralBuildingBlock(); + requestContext = new RequestContext(); + requestContext.setRequestorId("someRequestorId"); + generalBuildingBlock.setRequestContext(requestContext); + buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId")); + buildingBlockExecution.setVariable("vnfType", "testVnfType"); + buildingBlockExecution.setVariable("gBBInput", generalBuildingBlock); + buildingBlockExecution.setVariable("rainyDayVnfName", "someVnfName"); + buildingBlockExecution.setVariable("workStep", "someWorkstep"); + buildingBlockExecution.setVariable("taskTimeout", "PT5M"); + } + + @Test + public void createExternalTicket_Test() throws Exception { + ExternalTicketTasks externalTicketTasksSpy = spy(new ExternalTicketTasks()); + when(externalTicketTasksSpy.getExternalTicket()).thenReturn(MOCK_externalTicket); + externalTicketTasksSpy.createExternalTicket(buildingBlockExecution); + verify(MOCK_externalTicket, times(1)).createTicket(); + } +} 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 index b40195c07b..b6dcd96534 100644 --- 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 @@ -37,9 +37,13 @@ import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.client.ticket.ExternalTicket; import org.onap.so.db.request.beans.InfraActiveRequests; public class ManualHandlingTasksTest extends BaseTaskTest { @@ -61,14 +65,36 @@ public class ManualHandlingTasksTest extends BaseTaskTest { @Mock private BuildingBlockExecution buildingBlockExecution; + @Mock + private GeneralBuildingBlock generalBuildingBlock; + + @Mock + private RequestContext requestContext; + + @Mock + private ExternalTicket MOCK_externalTicket; + @Before public void before() throws Exception { + MockitoAnnotations.initMocks(this); delegateExecution = new DelegateExecutionFake(); buildingBlockExecution = new DelegateExecutionImpl(delegateExecution); + generalBuildingBlock = new GeneralBuildingBlock(); + requestContext = new RequestContext(); + requestContext.setRequestorId("someRequestorId"); + generalBuildingBlock.setRequestContext(requestContext); + buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId")); + buildingBlockExecution.setVariable("vnfType", "testVnfType"); + buildingBlockExecution.setVariable("gBBInput", generalBuildingBlock); + buildingBlockExecution.setVariable("rainyDayVnfName", "someVnfName"); + buildingBlockExecution.setVariable("workStep", "someWorkstep"); + buildingBlockExecution.setVariable("taskTimeout", "PT5M"); } @Test public void setFalloutTaskVariables_Test() { + when(mockExecution.getVariable("gBuildingBlockExecution")).thenReturn(buildingBlockExecution); + buildingBlockExecution.setVariable("gBBInput", generalBuildingBlock); when(task.getId()).thenReturn("taskId"); when(task.getExecution()).thenReturn(mockExecution); when(mockExecution.getProcessEngineServices()).thenReturn(processEngineServices); @@ -103,7 +129,6 @@ public class ManualHandlingTasksTest extends BaseTaskTest { @Test public void updateRequestDbStatus_Test() throws Exception { InfraActiveRequests mockedRequest = new InfraActiveRequests(); - buildingBlockExecution.setVariable("mso-request-id", "msoRequestId"); when(requestsDbClient.getInfraActiveRequestbyRequestId(any(String.class))).thenReturn(mockedRequest); doNothing().when(requestsDbClient).updateInfraActiveRequests(any(InfraActiveRequests.class)); manualHandlingTasks.updateRequestDbStatus(buildingBlockExecution, "IN_PROGRESS"); @@ -111,10 +136,4 @@ public class ManualHandlingTasksTest extends BaseTaskTest { assertEquals(mockedRequest.getRequestStatus(), "IN_PROGRESS"); } - @Test - public void createExternalTicket_Test() throws Exception { - buildingBlockExecution.setVariable("mso-request-id", ("testMsoRequestId")); - buildingBlockExecution.setVariable("vnfType", "testVnfType"); - manualHandlingTasks.createExternalTicket(buildingBlockExecution); - } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index cc4a5ce04e..8e47c34cb0 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -36,8 +36,11 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; @@ -224,6 +227,28 @@ public class WorkflowActionTest extends BaseTaskTest { assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB", "ActivateServiceInstanceBB"); } + @Test + public void selectExecutionListDuplicateNameExceptionTest() throws Exception { + String gAction = "createInstance"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", true); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances"); + execution.setVariable("requestAction", gAction); + + doThrow(new DuplicateNameException( + "serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.")) + .when(SPY_workflowAction).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE), + eq("test"), any(RequestDetails.class), any(WorkflowResourceIds.class)); + + SPY_workflowAction.selectExecutionList(execution); + assertEquals(execution.getVariable("WorkflowActionErrorMessage"), + "Exception while setting execution list. serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique."); + } + /** * SERVICE MACRO TESTS */ diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java index a929f256ac..6d5e6db083 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIPnfResourcesTest.java @@ -22,6 +22,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; @@ -83,4 +84,17 @@ public class AAIPnfResourcesTest extends TestDataSetup { verify(aaiResourcesClientMock, times(1)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); } + @Test + public void updateOrchestrationStatusPnfShouldSetStatusAndUpdatePnfInAAI() { + org.onap.aai.domain.yang.Pnf pnfYang = new org.onap.aai.domain.yang.Pnf(); + doReturn(pnfYang).when(aaiObjectMapperMock).mapPnf(pnf); + + aaiPnfResources.updateOrchestrationStatusPnf(pnf, OrchestrationStatus.ACTIVE); + + assertEquals(OrchestrationStatus.ACTIVE, pnf.getOrchestrationStatus()); + verify(aaiObjectMapperMock, times(1)) + .mapPnf(argThat(arg -> OrchestrationStatus.ACTIVE.equals(arg.getOrchestrationStatus()))); + verify(aaiResourcesClientMock, times(1)).update(any(AAIResourceUri.class), eq(pnfYang)); + } + } diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json index 39e87f19f1..1dd475cad4 100644 --- a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroAssign.json @@ -24,7 +24,8 @@ "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "source": "VID", "suppressRollback": true, - "requestorId": "xxxxxx" + "requestorId": "xxxxxx", + "instanceName": "test" }, "requestParameters": { "subscriptionServiceType": "VMX", |