diff options
author | Jozsef Csongvai <jozsef.csongvai@bell.ca> | 2021-11-26 17:24:42 -0500 |
---|---|---|
committer | Jozsef Csongvai <jozsef.csongvai@bell.ca> | 2021-11-26 17:24:42 -0500 |
commit | 1e3c281b0ae601b3c1bed4ba52fc5cb9ae0b0f7a (patch) | |
tree | 64af3d2665f4d30ef9234c21f7e419ca568634c9 /bpmn/so-bpmn-tasks/src/main/java/org | |
parent | 18cc4f0fb16e1f03072222268eb2c5661d29bc23 (diff) |
Enable CreateChildServiceBB for Service-Macro-Create
Issue-ID: SO-3811
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Change-Id: I7979082a9f145a84f6f03cf2c44e9ccbca198c5a
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org')
7 files changed, 101 insertions, 11 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java index 920369784e..b0182c1b00 100755 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ExecuteBuildingBlockBuilder.java @@ -109,13 +109,22 @@ public class ExecuteBuildingBlockBuilder { String requestId, String apiVersion, String resourceId, String requestAction, String vnfType, WorkflowResourceIds workflowResourceIds, RequestDetails requestDetails, boolean replaceVnf) { List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); - if (orchFlow.getFlowName().contains(SERVICE) || (orchFlow.getFlowName().contains(CONTROLLER) + if (orchFlow.getFlowName().contains(CHILD_SERVICE)) { + if (WorkflowType.SERVICE.equals(resource.getResourceType()) && resource.hasParent()) { + addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.SERVICE, orchFlow, requestId, + apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, + false); + } + } else if (orchFlow.getFlowName().contains(SERVICE) || (orchFlow.getFlowName().contains(CONTROLLER) && (SERVICE).equalsIgnoreCase(orchFlow.getBpmnScope()))) { if (!replaceVnf) { workflowResourceIds.setServiceInstanceId(resourceId); } - addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.SERVICE, orchFlow, requestId, - apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, false); + if (!resource.hasParent()) { + addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.SERVICE, orchFlow, requestId, + apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, false, + false); + } } else if (orchFlow.getFlowName().contains(VNF) || (orchFlow.getFlowName().contains(CONTROLLER) && (VNF).equalsIgnoreCase(orchFlow.getBpmnScope()))) { addBuildingBlockToExecuteBBList(flowsToExecute, resource, WorkflowType.VNF, orchFlow, requestId, apiVersion, 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 10cea171ce..ef0fbc850e 100755 --- 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 @@ -28,6 +28,8 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.IS_CHILD_PROCESS; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.PARENT_CORRELATION_ID; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGN_INSTANCE; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER; import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE; @@ -96,6 +98,7 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.serviceinstancebeans.InstanceDirection; @Component public class WorkflowAction { @@ -347,6 +350,19 @@ public class WorkflowAction { log += ", Action: " + block.getBuildingBlock().getBpmnAction(); logger.info(log); } + + RelatedInstanceList[] instanceList = sIRequest.getRequestDetails().getRelatedInstanceList(); + execution.setVariable(IS_CHILD_PROCESS, Boolean.FALSE); + if (instanceList != null) { + for (RelatedInstanceList relatedInstanceList : instanceList) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if (InstanceDirection.source.equals(relatedInstance.getInstanceDirection())) { + execution.setVariable(IS_CHILD_PROCESS, Boolean.TRUE); + execution.setVariable(PARENT_CORRELATION_ID, requestDetails.getRequestInfo().getCorrelator()); + } + } + } + // By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE if (resourceType == WorkflowType.SERVICE && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGN_INSTANCE)) @@ -698,8 +714,9 @@ public class WorkflowAction { private void generateResourceIds(List<ExecuteBuildingBlock> flowsToExecute, List<Resource> resourceList, String serviceInstanceId) { Map<Resource, String> resourceInstanceIds = new HashMap<>(); - Arrays.stream(WorkflowType.values()).filter(type -> !type.equals(WorkflowType.SERVICE)) - .forEach(type -> resourceList.stream().filter(resource -> type.equals(resource.getResourceType())) + Arrays.stream(WorkflowType.values()) + .forEach(type -> resourceList.stream() + .filter(resource -> resource.hasParent() && type.equals(resource.getResourceType())) .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource, null, resource.getVirtualLinkKey(), serviceInstanceId, resourceInstanceIds))); } @@ -727,13 +744,19 @@ public class WorkflowAction { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId(serviceInstanceId); Resource parent = resource.getParent(); - if (parent != null && resourceInstanceIds.containsKey(parent)) { + if (resource.hasParent() && resourceInstanceIds.containsKey(parent)) { WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, parent.getResourceType(), resourceInstanceIds.get(parent)); } - WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType, - resource.getInstanceName()); - WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId); + if (resource.hasParent() && WorkflowType.SERVICE.equals(resourceType) + && WorkflowType.SERVICE.equals(parent.getResourceType())) { + workflowResourceIds.setChildServiceInstanceId(resourceId); + workflowResourceIds.setChildServiceInstanceName(resource.getInstanceName()); + } else { + WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType, + resource.getInstanceName()); + WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId); + } ebb.setWorkflowResourceIds(workflowResourceIds); assignedFlows.add(flowName + action); } @@ -749,7 +772,9 @@ public class WorkflowAction { private boolean isFlowAssignable(Set<String> assignedFlows, ExecuteBuildingBlock ebb, WorkflowType resourceType, String assignedFlowName) { - String id = WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType); + String id = WorkflowType.SERVICE.equals(resourceType) + ? StringUtils.defaultString(ebb.getWorkflowResourceIds().getChildServiceInstanceId()) + : WorkflowResourceIdsUtils.getResourceIdByWorkflowType(ebb.getWorkflowResourceIds(), resourceType); return !assignedFlows.contains(assignedFlowName) && id.isEmpty(); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java index 8d9e020f67..38fe6a3157 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionBBFailure.java @@ -35,6 +35,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_ERROR; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_MESSAGE_NAME; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_STATUS; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.IS_CHILD_PROCESS; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.PARENT_CORRELATION_ID; @Component public class WorkflowActionBBFailure { @@ -44,6 +50,7 @@ public class WorkflowActionBBFailure { private static final String DELETE_FABRIC_CONFIGURATION_FLOW = "DeleteFabricConfigurationBB"; private static final Logger logger = LoggerFactory.getLogger(WorkflowActionBBFailure.class); public static final String ROLLBACK_TARGET_STATE = "rollbackTargetState"; + @Autowired private RequestsDbClient requestDbclient; @Autowired @@ -83,6 +90,7 @@ public class WorkflowActionBBFailure { InfraActiveRequests request = requestDbclient.getInfraActiveRequestbyRequestId(requestId); String rollbackErrorMsg = ""; String errorMsg = ""; + String childErrorMessage = ""; Boolean rollbackCompletedSuccessfully = (Boolean) execution.getVariable("isRollbackComplete"); Boolean isRollbackFailure = (Boolean) execution.getVariable("isRollback"); ExecuteBuildingBlock ebb = (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); @@ -94,6 +102,7 @@ public class WorkflowActionBBFailure { if (rollbackCompletedSuccessfully) { rollbackErrorMsg = "Rollback has been completed successfully."; + childErrorMessage = rollbackErrorMsg; request.setRollbackStatusMessage(rollbackErrorMsg); execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); String rollbackTargetState = (String) execution.getVariable(ROLLBACK_TARGET_STATE); @@ -116,6 +125,7 @@ public class WorkflowActionBBFailure { } else { rollbackErrorMsg = "Failed to determine rollback error message."; } + childErrorMessage = rollbackErrorMsg; request.setRollbackStatusMessage(rollbackErrorMsg); execution.setVariable("RollbackErrorMessage", rollbackErrorMsg); request.setRequestStatus(Status.FAILED.toString()); @@ -126,6 +136,7 @@ public class WorkflowActionBBFailure { } else { errorMsg = "Failed to determine error message"; } + childErrorMessage = errorMsg; request.setStatusMessage(errorMsg); execution.setVariable("ErrorMessage", errorMsg); String handlingCode = (String) execution.getVariable("handlingCode"); @@ -146,6 +157,16 @@ public class WorkflowActionBBFailure { execution.setVariable("flowStatus", flowStatus); } + if (Boolean.TRUE.equals(execution.getVariable(IS_CHILD_PROCESS))) { + String parentCorrelationId = (String) execution.getVariable(PARENT_CORRELATION_ID); + logger.info("Child service creation failed. Sending message to parent with correlationId: " + + parentCorrelationId); + execution.getProcessEngineServices().getRuntimeService() + .createMessageCorrelation(CHILD_SVC_REQ_MESSAGE_NAME) + .setVariable(CHILD_SVC_REQ_STATUS, "FAILED").setVariable(CHILD_SVC_REQ_ERROR, childErrorMessage) + .processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID, parentCorrelationId).correlate(); + } + request.setProgress(Long.valueOf(100)); request.setLastModifiedBy("CamundaBPMN"); request.setEndTime(new Timestamp(System.currentTimeMillis())); 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 b76cf1eb5f..dda217fc79 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 @@ -65,6 +65,12 @@ import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_ERROR; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_MESSAGE_NAME; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_STATUS; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.IS_CHILD_PROCESS; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.CHILD_SVC_REQ_CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.service.composition.ServiceCompositionConstants.PARENT_CORRELATION_ID; @Component public class WorkflowActionBBTasks { @@ -231,6 +237,17 @@ public class WorkflowActionBBTasks { final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE); final String resourceName = (String) execution.getVariable("resourceName"); String statusMessage = (String) execution.getVariable("StatusMessage"); + + if (Boolean.TRUE.equals(execution.getVariable(IS_CHILD_PROCESS))) { + String parentCorrelationId = (String) execution.getVariable(PARENT_CORRELATION_ID); + logger.info("Child service request completed. Sending message to parent process with correlationId: " + + parentCorrelationId); + execution.getProcessEngineServices().getRuntimeService() + .createMessageCorrelation(CHILD_SVC_REQ_MESSAGE_NAME) + .setVariable(CHILD_SVC_REQ_STATUS, "COMPLETED").setVariable(CHILD_SVC_REQ_ERROR, "") + .processInstanceVariableEquals(CHILD_SVC_REQ_CORRELATION_ID, parentCorrelationId).correlate(); + } + String macroAction; if (statusMessage == null) { if (aLaCarte) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java index a41613982d..7bbc9f3739 100755 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionConstants.java @@ -34,6 +34,7 @@ public final class WorkflowActionConstants { public static final String ACTIVATE_INSTANCE = "activateInstance"; public static final String ASSIGN_INSTANCE = "assignInstance"; + public static final String CHILD_SERVICE = "ChildService"; public static final String CONFIGURATION = "Configuration"; public static final String CONTROLLER = "Controller"; public static final String CREATE_INSTANCE = "createInstance"; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java index b5ad8d8c03..79e801b740 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java @@ -133,7 +133,7 @@ public class ServiceEBBLoader { resourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, userParams, serviceInstanceId, requestAction); } - if (!foundRelated(resourceList)) { + if (!isComposedService(resourceList) && !foundRelated(resourceList)) { traverseCatalogDbService(execution, sIRequest, resourceList, aaiResourceIds); } } else if ((ACTIVATE_INSTANCE.equalsIgnoreCase(requestAction) @@ -190,6 +190,10 @@ public class ServiceEBBLoader { || containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); } + public boolean isComposedService(List<Resource> resourceList) { + return resourceList.stream().anyMatch(s -> s.getResourceType() == WorkflowType.SERVICE && s.hasParent()); + } + public void traverseAAIService(DelegateExecution execution, List<Resource> resourceList, String resourceId, List<Pair<WorkflowType, String>> aaiResourceIds) { try { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java index c383b4a73a..074aa9e5a1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversal.java @@ -94,6 +94,9 @@ public class UserParamsServiceTraversal { Resource serviceResource = new Resource(WorkflowType.SERVICE, validate.getModelInfo().getModelVersionId(), false, null); resourceList.add(serviceResource); + if (validate.getResources().getServices() != null) { + setResourceListForChildServices(execution, resourceList, serviceResource, validate); + } if (validate.getResources().getVnfs() != null) { setResourceListForVnfs(execution, resourceList, serviceResource, validate); } @@ -107,6 +110,16 @@ public class UserParamsServiceTraversal { return resourceList; } + private void setResourceListForChildServices(DelegateExecution execution, List<Resource> resourceList, + Resource serviceResource, Service validate) { + for (Service childService : validate.getResources().getServices()) { + Resource childServiceResource = new Resource(WorkflowType.SERVICE, + childService.getModelInfo().getModelVersionId(), false, serviceResource); + childServiceResource.setInstanceName(childService.getInstanceName()); + resourceList.add(childServiceResource); + } + } + private void setResourceListForVnfs(DelegateExecution execution, List<Resource> resourceList, Resource serviceResource, Service validate) { for (Vnfs vnf : validate.getResources().getVnfs()) { |