Search in sources :

Example 21 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method renameStep.

public void renameStep(Workflow wf, String stepId, String newStepName) {
    if (wf.getSteps().containsKey(newStepName)) {
        throw new AlreadyExistException(String.format("A step named ''%s'' already exists in workflow '%s'", newStepName, wf.getName()));
    }
    WorkflowStep step = wf.getSteps().remove(stepId);
    step.setName(newStepName);
    wf.addStep(step);
    // now explore the links
    if (step.getPrecedingSteps() != null) {
        for (String precedingId : step.getPrecedingSteps()) {
            WorkflowStep precedingStep = wf.getSteps().get(precedingId);
            precedingStep.removeFollowing(stepId);
            precedingStep.addFollowing(newStepName);
        }
    }
    if (step.getOnSuccess() != null) {
        for (String followingId : step.getOnSuccess()) {
            WorkflowStep followingStep = wf.getSteps().get(followingId);
            followingStep.removePreceding(stepId);
            followingStep.addPreceding(newStepName);
        }
    }
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 22 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method removeNode.

public void removeNode(Workflow wf, String nodeName) {
    WorkflowStep[] steps = new WorkflowStep[wf.getSteps().size()];
    steps = wf.getSteps().values().toArray(steps);
    for (WorkflowStep step : steps) {
        if (nodeName.equals(step.getTarget())) {
            removeStep(wf, step.getName(), true);
        }
    }
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 23 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method appendActivityStep.

private void appendActivityStep(Workflow wf, String stepId, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    WorkflowStep lastStep = wf.getSteps().get(stepId);
    String stepAfterId = null;
    if (lastStep.getOnSuccess() != null && lastStep.getOnSuccess().size() == 1) {
        stepAfterId = lastStep.getOnSuccess().iterator().next();
    }
    WorkflowStep insertedStep = addActivityStep(wf, target, targetRelationship, activity);
    WorkflowUtils.linkSteps(lastStep, insertedStep);
    if (stepAfterId != null) {
        WorkflowStep stepAfter = wf.getSteps().get(stepAfterId);
        unlinkSteps(lastStep, stepAfter);
        WorkflowUtils.linkSteps(insertedStep, stepAfter);
    }
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 24 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method removeStep.

void removeStep(Workflow wf, String stepId, boolean force) {
    WorkflowStep step = wf.getSteps().remove(stepId);
    if (step == null) {
        throw new InconsistentWorkflowException(String.format("Inconsistent workflow: a step nammed '%s' can not be found while it's referenced else where ...", stepId));
    }
    if (!force && step.getActivity() instanceof DelegateWorkflowActivity) {
        throw new BadWorkflowOperationException("Native steps can not be removed from workflow");
    }
    if (step.getPrecedingSteps() != null) {
        if (step.getOnSuccess() != null) {
            // connect all preceding to all following
            for (String precedingId : step.getPrecedingSteps()) {
                WorkflowStep preceding = wf.getSteps().get(precedingId);
                for (String followingId : step.getOnSuccess()) {
                    WorkflowStep following = wf.getSteps().get(followingId);
                    WorkflowUtils.linkSteps(preceding, following);
                }
            }
        }
        for (Object precedingId : step.getPrecedingSteps().toArray()) {
            WorkflowStep preceding = wf.getSteps().get(precedingId);
            unlinkSteps(preceding, step);
        }
    }
    if (step.getOnSuccess() != null) {
        for (Object followingId : step.getOnSuccess().toArray()) {
            WorkflowStep following = wf.getSteps().get(followingId);
            unlinkSteps(step, following);
        }
    }
}
Also used : InconsistentWorkflowException(alien4cloud.paas.wf.exception.InconsistentWorkflowException) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity)

Example 25 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep 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)

Aggregations

WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)51 RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)24 NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)23 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)20 Test (org.junit.Test)17 Path (alien4cloud.paas.wf.model.Path)7 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 InconsistentWorkflowException (alien4cloud.paas.wf.exception.InconsistentWorkflowException)4 TopologyDTO (alien4cloud.topology.TopologyDTO)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 StringUtils (org.apache.commons.lang3.StringUtils)3