Search in sources :

Example 1 with DelegateWorkflowActivity

use of org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity in project yorc-a4c-plugin by ystia.

the class ServiceTopologyModifier method removeServiceDelegateOperation.

private void removeServiceDelegateOperation(Topology topology, String nodeId, NodeTemplate nodeTemplate, String workflowName) {
    Workflow workflow = topology.getWorkflows().get(workflowName);
    if (workflow != null) {
        Set<String> stepsToRemove = new HashSet<String>();
        for (Entry<String, WorkflowStep> stepEntry : workflow.getSteps().entrySet()) {
            String currentStepId = stepEntry.getKey();
            WorkflowStep step = stepEntry.getValue();
            if (WorkflowUtils.isNodeStep(step, nodeId)) {
                AbstractWorkflowActivity activity = step.getActivity();
                if (activity instanceof DelegateWorkflowActivity && workflowName.equals(((DelegateWorkflowActivity) activity).getDelegate())) {
                    // on a Service Node Template
                    for (String precederId : step.getPrecedingSteps()) {
                        WorkflowStep preceder = workflow.getSteps().get(precederId);
                        if (preceder.getOnSuccess() == null) {
                            preceder.setOnSuccess(new HashSet<String>());
                        }
                        preceder.removeFollowing(stepEntry.getKey());
                        preceder.addAllFollowings(step.getOnSuccess());
                    }
                    for (String follower : step.getOnSuccess()) {
                        WorkflowStep followerStep = workflow.getSteps().get(follower);
                        followerStep.getPrecedingSteps().remove(currentStepId);
                    }
                    // Old step will be removed outside the loop to avoid
                    // concurrent modifications
                    stepsToRemove.add(stepEntry.getKey());
                }
            }
        }
        // Removing delegate steps on Service Node Template
        workflow.getSteps().keySet().removeAll(stepsToRemove);
    }
}
Also used : WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) AbstractWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.AbstractWorkflowActivity) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity) HashSet(java.util.HashSet)

Example 2 with DelegateWorkflowActivity

use of org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity 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 3 with DelegateWorkflowActivity

use of org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity in project alien4cloud by alien4cloud.

the class WorkflowGraphUtils method isStepEmpty.

public static boolean isStepEmpty(WorkflowStep step, TopologyContext topologyContext) {
    // No activity
    if (step.getActivity() == null) {
        return true;
    }
    // Inline activity is never empty
    if (step.getActivity() instanceof DelegateWorkflowActivity || step.getActivity() instanceof SetStateWorkflowActivity || step.getActivity() instanceof InlineWorkflowActivity) {
        return false;
    }
    CallOperationWorkflowActivity callOperationWorkflowActivity = (CallOperationWorkflowActivity) step.getActivity();
    NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(step.getTarget());
    String stepInterfaceName = ToscaNormativeUtil.getLongInterfaceName(callOperationWorkflowActivity.getInterfaceName());
    String stepOperationName = callOperationWorkflowActivity.getOperationName();
    if (step instanceof NodeWorkflowStep) {
        return !hasImplementation(nodeTemplate, NodeType.class, topologyContext, stepInterfaceName, stepOperationName);
    } else if (step instanceof RelationshipWorkflowStep) {
        RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
        RelationshipTemplate relationshipTemplate = nodeTemplate.getRelationships().get(relationshipWorkflowStep.getTargetRelationship());
        return !hasImplementation(relationshipTemplate, RelationshipType.class, topologyContext, stepInterfaceName, stepOperationName);
    } else {
        return false;
    }
}
Also used : InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SetStateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity) CallOperationWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)

Example 4 with DelegateWorkflowActivity

use of org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity in project alien4cloud by alien4cloud.

the class WorkflowUtils method createDelegateWorkflowStep.

public static WorkflowStep createDelegateWorkflowStep(Workflow wf, String nodeId) {
    DelegateWorkflowActivity activity = new DelegateWorkflowActivity();
    activity.setDelegate(wf.getName());
    NodeWorkflowStep step = new NodeWorkflowStep();
    step.setTarget(nodeId);
    step.setActivity(activity);
    step.setName(buildStepName(wf, step, 0));
    return step;
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) DelegateWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity)

Aggregations

DelegateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity)4 NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)3 RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)2 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)2 BadWorkflowOperationException (alien4cloud.paas.wf.exception.BadWorkflowOperationException)1 InconsistentWorkflowException (alien4cloud.paas.wf.exception.InconsistentWorkflowException)1 HashSet (java.util.HashSet)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)1 AbstractWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.AbstractWorkflowActivity)1 CallOperationWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)1 InlineWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity)1 SetStateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity)1