Search in sources :

Example 31 with Workflow

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

Example 32 with Workflow

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

the class WorkflowUtils method cloneWorkflow.

public static Workflow cloneWorkflow(Workflow workflow) {
    Workflow cloned = new Workflow();
    cloned.setName(workflow.getName());
    cloned.setDescription(workflow.getDescription());
    cloned.setMetadata(workflow.getMetadata());
    cloned.setInputs(workflow.getInputs());
    cloned.setPreconditions(workflow.getPreconditions());
    cloned.setSteps(safe(workflow.getSteps()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> cloneStep(entry.getValue()))));
    cloned.setHasCustomModifications(workflow.isHasCustomModifications());
    cloned.setStandard(workflow.isStandard());
    cloned.setHosts(workflow.getHosts());
    cloned.setErrors(workflow.getErrors());
    return cloned;
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 33 with Workflow

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

the class WorkflowsBuilderService method connectStepTo.

public Workflow connectStepTo(Topology topology, Csar csar, String workflowName, String stepId, String[] stepNames) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.connectStepTo(wf, stepId, stepNames);
    workflowValidator.validate(topologyContext, wf);
    return wf;
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Example 34 with Workflow

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

the class WorkflowsBuilderService method reinitWorkflow.

public void reinitWorkflow(String workflowName, TopologyContext topologyContext, boolean simplify) {
    Workflow wf = topologyContext.getTopology().getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    if (!wf.isStandard()) {
        throw new BadWorkflowOperationException(String.format("Reinit can not be performed on non standard workflow '%s'", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    wf = builder.reinit(wf, topologyContext);
    WorkflowUtils.fillHostId(wf, topologyContext);
    if (simplify) {
        postProcessTopologyWorkflows(topologyContext);
    }
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException)

Example 35 with Workflow

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

the class WorkflowsBuilderService method renameStep.

public void renameStep(Topology topology, Csar csar, String workflowName, String stepId, String newStepName) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    Workflow wf = topology.getWorkflows().get(workflowName);
    if (wf == null) {
        throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
    }
    AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
    builder.renameStep(wf, stepId, newStepName);
    if (log.isDebugEnabled()) {
        log.debug(WorkflowUtils.debugWorkflow(wf));
    }
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Aggregations

Workflow (org.alien4cloud.tosca.model.workflow.Workflow)46 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)20 NotFoundException (alien4cloud.exception.NotFoundException)11 Test (org.junit.Test)10 Map (java.util.Map)7 Path (alien4cloud.paas.wf.model.Path)6 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)6 List (java.util.List)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)5 TopologyDTO (alien4cloud.topology.TopologyDTO)4 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Csar (org.alien4cloud.tosca.model.Csar)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 WorkflowUtils (alien4cloud.paas.wf.util.WorkflowUtils)3