Search in sources :

Example 16 with Workflow

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

the class WorkflowsBuilderService method swapSteps.

public void swapSteps(Topology topology, Csar csar, String workflowName, String stepId, String targetId) {
    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.swapSteps(wf, stepId, targetId);
    WorkflowUtils.fillHostId(wf, topologyContext);
    if (log.isDebugEnabled()) {
        log.debug(WorkflowUtils.debugWorkflow(wf));
    }
    workflowValidator.validate(topologyContext, wf);
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NotFoundException(alien4cloud.exception.NotFoundException)

Example 17 with Workflow

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

the class WorkflowsBuilderService method validateWorkflows.

public List<WorkflowTask> validateWorkflows(Topology topology) {
    List<WorkflowTask> tasks = Lists.newArrayList();
    if (topology.getWorkflows() != null) {
        TopologyContext topologyContext = buildTopologyContext(topology);
        for (Workflow workflow : topology.getWorkflows().values()) {
            int errorCount = validateWorkflow(topologyContext, workflow);
            if (errorCount > 0) {
                WorkflowTask workflowTask = new WorkflowTask();
                workflowTask.setCode(TaskCode.WORKFLOW_INVALID);
                workflowTask.setWorkflowName(workflow.getName());
                workflowTask.setErrorCount(errorCount);
                tasks.add(workflowTask);
            }
        }
    }
    return tasks;
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) WorkflowTask(alien4cloud.topology.task.WorkflowTask)

Example 18 with Workflow

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

the class WorkflowsBuilderService method addActivity.

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

Example 19 with Workflow

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

the class WorkflowsBuilderService method removeRelationship.

public void removeRelationship(Topology topology, Csar csar, String sourceNodeId, String relationshipName, RelationshipTemplate relationshipTemplate) {
    TopologyContext topologyContext = buildTopologyContext(topology, csar);
    topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
    NodeTemplate sourceNode = topology.getNodeTemplates().get(sourceNodeId);
    String targetNodeId = relationshipTemplate.getTarget();
    NodeTemplate targetNode = topologyContext.getTopology().getNodeTemplates().get(targetNodeId);
    for (Workflow wf : topology.getWorkflows().values()) {
        AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
        // Remove relationships from source to target
        // Remove relationships from target to source
        Map<String, RelationshipTemplate> sourceRelationships = sourceNode.getRelationships().entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(targetNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        Map<String, RelationshipTemplate> targetRelationships = AlienUtils.safe(targetNode.getRelationships()).entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(sourceNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        builder.removeRelationships(wf, sourceNodeId, sourceRelationships, targetNodeId, targetRelationships);
        sourceRelationships.entrySet().stream().filter(entry -> !entry.getKey().equals(relationshipName)).forEach(entry -> builder.addRelationship(wf, sourceNode.getName(), sourceNode, entry.getKey(), entry.getValue(), topologyContext));
        targetRelationships.forEach((id, relationship) -> builder.addRelationship(wf, targetNodeId, targetNode, id, relationship, topologyContext));
        // Remove unique relationship that we really want to remove
        WorkflowUtils.fillHostId(wf, topologyContext);
    }
    postProcessTopologyWorkflows(topologyContext);
    debugWorkflow(topologyContext.getTopology());
}
Also used : ToscaParser(alien4cloud.tosca.parser.ToscaParser) Lists(org.elasticsearch.common.collect.Lists) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) HashMap(java.util.HashMap) STOP(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.STOP) Maps(org.elasticsearch.common.collect.Maps) DefaultDeclarativeWorkflows(org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows) START(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.START) INSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.INSTALL) Map(java.util.Map) YamlParserUtil(alien4cloud.utils.YamlParserUtil) Csar(org.alien4cloud.tosca.model.Csar) WorkflowValidator(alien4cloud.paas.wf.validation.WorkflowValidator) AlienUtils(alien4cloud.utils.AlienUtils) Resource(javax.annotation.Resource) TaskCode(alien4cloud.topology.task.TaskCode) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ICSARRepositorySearchService(alien4cloud.component.ICSARRepositorySearchService) NotFoundException(alien4cloud.exception.NotFoundException) List(java.util.List) Component(org.springframework.stereotype.Component) Slf4j(lombok.extern.slf4j.Slf4j) AbstractWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.AbstractWorkflowActivity) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PostConstruct(javax.annotation.PostConstruct) BadWorkflowOperationException(alien4cloud.paas.wf.exception.BadWorkflowOperationException) Topology(org.alien4cloud.tosca.model.templates.Topology) UNINSTALL(org.alien4cloud.tosca.normative.constants.NormativeWorkflowNameConstants.UNINSTALL) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) WorkflowUtils(alien4cloud.paas.wf.util.WorkflowUtils) WorkflowTask(alien4cloud.topology.task.WorkflowTask) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) HashMap(java.util.HashMap) Map(java.util.Map)

Example 20 with Workflow

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

the class WorkflowsBuilderService method createWorkflow.

public Workflow createWorkflow(Topology topology, String name) {
    String workflowName = getWorkflowName(topology, name, 0);
    Workflow wf = new Workflow();
    wf.setName(workflowName);
    wf.setStandard(false);
    wf.setHasCustomModifications(true);
    Map<String, Workflow> wfs = topology.getWorkflows();
    if (wfs == null) {
        wfs = Maps.newLinkedHashMap();
        topology.setWorkflows(wfs);
    }
    wfs.put(workflowName, wf);
    return wf;
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

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