Search in sources :

Example 6 with RelationshipWorkflowStep

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

the class SemanticValidation method validate.

@Override
public List<AbstractWorkflowError> validate(TopologyContext topologyContext, Workflow workflow) throws WorkflowException {
    if (workflow.getSteps() == null || workflow.getSteps().isEmpty()) {
        return null;
    }
    List<AbstractWorkflowError> errors = Lists.newArrayList();
    for (WorkflowStep step : workflow.getSteps().values()) {
        if (step.getActivity() instanceof InlineWorkflowActivity) {
            // TODO when the tosca model is clear we should create InlineWorkflowStep
            String inlinedWorkflow = ((InlineWorkflowActivity) step.getActivity()).getInline();
            if (topologyContext.getTopology().getWorkflows() == null || !topologyContext.getTopology().getWorkflows().containsKey(inlinedWorkflow)) {
                errors.add(new InlinedWorkflowNotFoundError(step.getName(), inlinedWorkflow));
            }
        } else if (StringUtils.isEmpty(step.getTarget())) {
            errors.add(new UnknownNodeError(step.getName(), "undefined target in non inline workflow activity"));
        } else {
            String nodeId = step.getTarget();
            NodeTemplate nodeTemplate = null;
            if (topologyContext.getTopology().getNodeTemplates() != null) {
                nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId);
            }
            if (nodeTemplate == null) {
                errors.add(new UnknownNodeError(step.getName(), nodeId));
            } else if (step instanceof RelationshipWorkflowStep) {
                RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
                String relationshipId = relationshipWorkflowStep.getTargetRelationship();
                if (nodeTemplate.getRelationships() == null || !nodeTemplate.getRelationships().containsKey(relationshipId)) {
                    errors.add(new UnknownRelationshipError(step.getName(), nodeId, relationshipId));
                }
            }
        // TODO: here we should check interface & operation
        }
    }
    return errors;
}
Also used : InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 7 with RelationshipWorkflowStep

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

the class AbstractWorkflowBuilder method addActivityStep.

private WorkflowStep addActivityStep(Workflow wf, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    WorkflowStep step;
    if (StringUtils.isEmpty(targetRelationship)) {
        step = new NodeWorkflowStep();
    } else {
        RelationshipWorkflowStep relationshipWorkflowStep = new RelationshipWorkflowStep();
        relationshipWorkflowStep.setTargetRelationship(targetRelationship);
        step = relationshipWorkflowStep;
    }
    step.setTarget(target);
    step.setActivity(activity);
    step.setName(WorkflowUtils.buildStepName(wf, step, 0));
    wf.addStep(step);
    return step;
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 8 with RelationshipWorkflowStep

use of org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep 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 9 with RelationshipWorkflowStep

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

the class WorkflowStepWeightComparator method compareWorkflowSteps.

public static int compareWorkflowSteps(Topology topology, WorkflowStep l, WorkflowStep r) {
    if (l instanceof RelationshipWorkflowStep) {
        if (r instanceof RelationshipWorkflowStep) {
            RelationshipWorkflowStep lr = (RelationshipWorkflowStep) l;
            RelationshipWorkflowStep rr = (RelationshipWorkflowStep) r;
            if (lr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                if (rr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                    return 0;
                } else {
                    // l is target operation, r is source operation, execute for source before target so put l after r
                    return 1;
                }
            } else {
                if (rr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                    // l is source operation, r is target operation, execute for source before target so put l before r
                    return -1;
                } else {
                    // l and r are source operations
                    if (lr.getTarget().equals(rr.getTarget())) {
                        // l and r are operation concerning the same target
                        NodeTemplate nodeTemplate = topology.getNodeTemplates().get(lr.getTarget());
                        Integer lri = 0;
                        Integer rri = 0;
                        int counter = 0;
                        for (Map.Entry<String, RelationshipTemplate> relationshipTemplateEntry : nodeTemplate.getRelationships().entrySet()) {
                            // Hope that's linked hash map here so order is preserved
                            if (relationshipTemplateEntry.getKey().equals(lr.getTargetRelationship())) {
                                lri = counter;
                            }
                            if (relationshipTemplateEntry.getKey().equals(rr.getTargetRelationship())) {
                                rri = counter;
                            }
                            counter++;
                        }
                        // Execute operation coming from relationship in the same order at the source side
                        return lri.compareTo(rri);
                    } else {
                        // not the same target so don't care about order
                        return 0;
                    }
                }
            }
        } else {
            // execute node step before relationship step
            return -1;
        }
    } else {
        // l is node step
        if (r instanceof RelationshipWorkflowStep) {
            // execute node step before relationship step
            return 1;
        } else {
            // both are node steps then don't care about order
            return 0;
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) Map(java.util.Map)

Aggregations

RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)9 NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)6 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)6 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)3 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)2 CallOperationWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)2 InlineWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity)2 Test (org.junit.Test)2 Map (java.util.Map)1 Set (java.util.Set)1 Csar (org.alien4cloud.tosca.model.Csar)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1 DelegateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity)1 SetStateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity)1