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;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPDATE_INSTANCE;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.HEALTH_CHECK;
import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE;
+import static org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_CNF;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
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 {
List<Resource> resourceList = new ArrayList<>();
List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
- if (resourceType == WorkflowType.SERVICE || isVNFCreateOrDelete(resourceType, requestAction)) {
+ if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction)) {
resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution,
serviceInstanceId, resourceId, aaiResourceIds);
- } else if (resourceType == WorkflowType.VNF && (REPLACEINSTANCE.equalsIgnoreCase(requestAction)
- || (RECREATE_INSTANCE.equalsIgnoreCase(requestAction)))) {
+ } else if (resourceType == WorkflowType.VNF
+ && (DELETE_INSTANCE.equalsIgnoreCase(requestAction) || REPLACEINSTANCE.equalsIgnoreCase(requestAction)
+ || (RECREATE_INSTANCE.equalsIgnoreCase(requestAction)))) {
vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
workflowResourceIds.getVnfId(), aaiResourceIds);
} else if (resourceType == WorkflowType.VNF && UPDATE_INSTANCE.equalsIgnoreCase(requestAction)) {
} else if (resourceType == WorkflowType.VNF && HEALTH_CHECK.equalsIgnoreCase(requestAction)) {
vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
workflowResourceIds.getVnfId(), aaiResourceIds);
+ } else if (resourceType == WorkflowType.VNF && UPGRADE_CNF.equalsIgnoreCase(requestAction)) {
+ vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(),
+ workflowResourceIds.getVnfId(), aaiResourceIds);
} else {
buildAndThrowException(execution, "Current Macro Request is not supported");
}
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))
return flowsToExecute;
}
- private boolean isVNFCreateOrDelete(WorkflowType resourceType, String requestAction) {
- return resourceType == WorkflowType.VNF
- && (CREATE_INSTANCE.equalsIgnoreCase(requestAction) || DELETE_INSTANCE.equalsIgnoreCase(requestAction));
+ private boolean isVNFCreate(WorkflowType resourceType, String requestAction) {
+ return resourceType == WorkflowType.VNF && CREATE_INSTANCE.equalsIgnoreCase(requestAction);
}
private void setExecutionVariables(DelegateExecution execution, List<ExecuteBuildingBlock> flowsToExecute,
logger.debug("{}, {}", pair.getValue0(), pair.getValue1());
}
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()))
- .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
- retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId,
- resourceInstanceIds)));
+ Arrays.stream(WorkflowType.values()).forEach(type -> resourceList.stream()
+ .filter(resource -> type.equals(resource.getResourceType())
+ && !(WorkflowType.SERVICE.equals(type) && !resource.hasParent()))
+ .forEach(resource -> updateWorkflowResourceIds(flowsToExecute, type, resource,
+ retrieveAAIResourceId(aaiResourceIds, type), null, serviceInstanceId, resourceInstanceIds)));
}
private String retrieveAAIResourceId(List<Pair<WorkflowType, String>> aaiResourceIds, WorkflowType resource) {
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)));
}
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())) {
+ String childServiceInstanceId = resource.isGenerated() ? resourceId : resource.getResourceId();
+ workflowResourceIds.setChildServiceInstanceId(childServiceInstanceId);
+ workflowResourceIds.setChildServiceInstanceName(resource.getInstanceName());
+ } else {
+ WorkflowResourceIdsUtils.setInstanceNameByWorkflowType(workflowResourceIds, resourceType,
+ resource.getInstanceName());
+ WorkflowResourceIdsUtils.setResourceIdByWorkflowType(workflowResourceIds, resourceType, resourceId);
+ }
ebb.setWorkflowResourceIds(workflowResourceIds);
assignedFlows.add(flowName + action);
}
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();
}