Search in sources :

Example 1 with Steps

use of alien4cloud.paas.wf.util.Steps in project alien4cloud by alien4cloud.

the class DefaultWorkflowBuilder method addRelationship.

@Override
public void addRelationship(Workflow workflow, String nodeId, NodeTemplate nodeTemplate, String relationshipName, RelationshipTemplate relationshipTemplate, TopologyContext topologyContext) {
    boolean sourceIsNative = WorkflowUtils.isNativeOrSubstitutionNode(nodeId, topologyContext);
    boolean targetIsNative = WorkflowUtils.isNativeOrSubstitutionNode(relationshipTemplate.getTarget(), topologyContext);
    if (!sourceIsNative || !targetIsNative) {
        // source or target is native or abstract
        // for native types we don't care about relation ships in workflows
        RelationshipDeclarativeWorkflow relationshipDeclarativeWorkflow = defaultDeclarativeWorkflows.getRelationshipWorkflows().get(workflow.getName());
        // only trigger this method if it's a default workflow
        if (relationshipDeclarativeWorkflow != null) {
            Map<String, WorkflowStep> relationshipOperationSteps = safe(relationshipDeclarativeWorkflow.getOperations()).entrySet().stream().filter(operationEntry -> !targetIsNative || operationEntry.getValue().getOperationHost() == RelationshipOperationHost.SOURCE).filter(operationEntry -> !sourceIsNative || operationEntry.getValue().getOperationHost() == RelationshipOperationHost.TARGET).collect(Collectors.toMap(Map.Entry::getKey, operationEntry -> WorkflowUtils.addRelationshipOperationStep(workflow, nodeId, relationshipTemplate.getName(), ToscaRelationshipLifecycleConstants.CONFIGURE_SHORT, operationEntry.getKey(), operationEntry.getValue().getOperationHost().toString())));
            Steps sourceSteps = new Steps(workflow, nodeId);
            Steps targetSteps = new Steps(workflow, relationshipTemplate.getTarget());
            safe(relationshipDeclarativeWorkflow.getOperations()).forEach((relationshipOperationName, relationshipOperationDependencies) -> {
                WorkflowStep currentStep = relationshipOperationSteps.get(relationshipOperationName);
                if (currentStep != null) {
                    // It might be filtered if source or target is native
                    declareStepDependencies(relationshipOperationDependencies.getSource(), currentStep, sourceSteps);
                    declareStepDependencies(relationshipOperationDependencies.getTarget(), currentStep, targetSteps);
                    declareStepDependencies(relationshipOperationDependencies, currentStep, new Steps(relationshipOperationSteps, Collections.emptyMap(), null));
                }
            });
            RelationshipWeavingDeclarativeWorkflow relationshipWeavingDeclarativeWorkflow = getRelationshipWeavingDeclarativeWorkflow(relationshipTemplate.getType(), topologyContext, workflow.getName());
            declareWeaving(relationshipWeavingDeclarativeWorkflow.getSource(), sourceSteps, targetSteps);
            declareWeaving(relationshipWeavingDeclarativeWorkflow.getTarget(), targetSteps, sourceSteps);
        }
    } else {
        // both source and target are native then the relationship does not have any operation implemented
        // we will just try to declare weaving between source node operations and target node operations
        Steps sourceSteps = new Steps(workflow, nodeId);
        Steps targetSteps = new Steps(workflow, relationshipTemplate.getTarget());
        RelationshipWeavingDeclarativeWorkflow relationshipWeavingDeclarativeWorkflow = getRelationshipWeavingDeclarativeWorkflow(relationshipTemplate.getType(), topologyContext, workflow.getName());
        declareWeaving(relationshipWeavingDeclarativeWorkflow.getSource(), sourceSteps, targetSteps);
        declareWeaving(relationshipWeavingDeclarativeWorkflow.getTarget(), targetSteps, sourceSteps);
    }
}
Also used : ToscaNodeLifecycleConstants(alien4cloud.paas.plan.ToscaNodeLifecycleConstants) RelationshipWeavingDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeavingDeclarativeWorkflow) OperationDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.OperationDeclarativeWorkflow) ToscaRelationshipLifecycleConstants(alien4cloud.paas.plan.ToscaRelationshipLifecycleConstants) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) ArrayList(java.util.ArrayList) DefaultDeclarativeWorkflows(org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows) List(java.util.List) RelationshipDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow) NodeDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipWeaving(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeaving) RelationshipOperationHost(org.alien4cloud.tosca.model.workflow.declarative.RelationshipOperationHost) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Steps(alien4cloud.paas.wf.util.Steps) Collections(java.util.Collections) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) WorkflowUtils(alien4cloud.paas.wf.util.WorkflowUtils) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Steps(alien4cloud.paas.wf.util.Steps) RelationshipWeavingDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeavingDeclarativeWorkflow) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) RelationshipDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow) Map(java.util.Map)

Example 2 with Steps

use of alien4cloud.paas.wf.util.Steps in project alien4cloud by alien4cloud.

the class DefaultWorkflowBuilder method addNode.

@Override
public void addNode(Workflow workflow, String nodeId, TopologyContext topologyContext, boolean isCompute) {
    if (WorkflowUtils.isNativeOrSubstitutionNode(nodeId, topologyContext)) {
        // for a native node, we just add a sub-workflow step
        WorkflowUtils.addDelegateWorkflowStep(workflow, nodeId);
    } else {
        NodeDeclarativeWorkflow nodeDeclarativeWorkflow = defaultDeclarativeWorkflows.getNodeWorkflows().get(workflow.getName());
        // only trigger this method if it's a default workflow
        if (nodeDeclarativeWorkflow != null) {
            // Create all the states of the workflow at first
            Map<String, WorkflowStep> statesSteps = safe(nodeDeclarativeWorkflow.getStates()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, stateEntry -> WorkflowUtils.addStateStep(workflow, nodeId, stateEntry.getKey())));
            // Create all the operations of the workflow at first
            Map<String, WorkflowStep> operationSteps = safe(nodeDeclarativeWorkflow.getOperations()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, operationEntry -> WorkflowUtils.addOperationStep(workflow, nodeId, ToscaNodeLifecycleConstants.STANDARD_SHORT, operationEntry.getKey())));
            Steps steps = new Steps(operationSteps, statesSteps, null);
            // Declare dependencies on the states steps
            safe(nodeDeclarativeWorkflow.getStates()).forEach((stateName, stateDependencies) -> declareStepDependencies(stateDependencies, steps.getStateStep(stateName), steps));
            // Declare dependencies on the operation steps
            safe(nodeDeclarativeWorkflow.getOperations()).forEach((operationName, operationDependencies) -> declareStepDependencies(operationDependencies, steps.getOperationStep(operationName), steps));
        }
    }
}
Also used : ToscaNodeLifecycleConstants(alien4cloud.paas.plan.ToscaNodeLifecycleConstants) RelationshipWeavingDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeavingDeclarativeWorkflow) OperationDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.OperationDeclarativeWorkflow) ToscaRelationshipLifecycleConstants(alien4cloud.paas.plan.ToscaRelationshipLifecycleConstants) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) ArrayList(java.util.ArrayList) DefaultDeclarativeWorkflows(org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows) List(java.util.List) RelationshipDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow) NodeDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipWeaving(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeaving) RelationshipOperationHost(org.alien4cloud.tosca.model.workflow.declarative.RelationshipOperationHost) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Steps(alien4cloud.paas.wf.util.Steps) Collections(java.util.Collections) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) WorkflowUtils(alien4cloud.paas.wf.util.WorkflowUtils) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Steps(alien4cloud.paas.wf.util.Steps) NodeDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Map(java.util.Map)

Aggregations

ToscaNodeLifecycleConstants (alien4cloud.paas.plan.ToscaNodeLifecycleConstants)2 ToscaRelationshipLifecycleConstants (alien4cloud.paas.plan.ToscaRelationshipLifecycleConstants)2 Steps (alien4cloud.paas.wf.util.Steps)2 WorkflowUtils (alien4cloud.paas.wf.util.WorkflowUtils)2 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)2 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)2 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)2 DefaultDeclarativeWorkflows (org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows)2 NodeDeclarativeWorkflow (org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow)2 OperationDeclarativeWorkflow (org.alien4cloud.tosca.model.workflow.declarative.OperationDeclarativeWorkflow)2 RelationshipDeclarativeWorkflow (org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow)2 RelationshipOperationHost (org.alien4cloud.tosca.model.workflow.declarative.RelationshipOperationHost)2