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;
}
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;
}
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;
}
}
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;
}
}
}
Aggregations