use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method renameStep.
public void renameStep(Workflow wf, String stepId, String newStepName) {
if (wf.getSteps().containsKey(newStepName)) {
throw new AlreadyExistException(String.format("A step named ''%s'' already exists in workflow '%s'", newStepName, wf.getName()));
}
WorkflowStep step = wf.getSteps().remove(stepId);
step.setName(newStepName);
wf.addStep(step);
// now explore the links
if (step.getPrecedingSteps() != null) {
for (String precedingId : step.getPrecedingSteps()) {
WorkflowStep precedingStep = wf.getSteps().get(precedingId);
precedingStep.removeFollowing(stepId);
precedingStep.addFollowing(newStepName);
}
}
if (step.getOnSuccess() != null) {
for (String followingId : step.getOnSuccess()) {
WorkflowStep followingStep = wf.getSteps().get(followingId);
followingStep.removePreceding(stepId);
followingStep.addPreceding(newStepName);
}
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method removeNode.
public void removeNode(Workflow wf, String nodeName) {
WorkflowStep[] steps = new WorkflowStep[wf.getSteps().size()];
steps = wf.getSteps().values().toArray(steps);
for (WorkflowStep step : steps) {
if (nodeName.equals(step.getTarget())) {
removeStep(wf, step.getName(), true);
}
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method appendActivityStep.
private void appendActivityStep(Workflow wf, String stepId, String target, String targetRelationship, AbstractWorkflowActivity activity) {
WorkflowStep lastStep = wf.getSteps().get(stepId);
String stepAfterId = null;
if (lastStep.getOnSuccess() != null && lastStep.getOnSuccess().size() == 1) {
stepAfterId = lastStep.getOnSuccess().iterator().next();
}
WorkflowStep insertedStep = addActivityStep(wf, target, targetRelationship, activity);
WorkflowUtils.linkSteps(lastStep, insertedStep);
if (stepAfterId != null) {
WorkflowStep stepAfter = wf.getSteps().get(stepAfterId);
unlinkSteps(lastStep, stepAfter);
WorkflowUtils.linkSteps(insertedStep, stepAfter);
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep 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);
}
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class DefaultWorkflowBuilder method addRelationship.
@Override
public void addRelationship(Workflow workflow, String nodeId, NodeTemplate nodeTemplate, String relationshipName, RelationshipTemplate relationshipTemplate, TopologyContext topologyContext) {
boolean sourceIsNative = WorkflowUtils.isNativeOrSubstitutionNode(nodeId, topologyContext);
boolean targetIsNative = WorkflowUtils.isNativeOrSubstitutionNode(relationshipTemplate.getTarget(), topologyContext);
if (!sourceIsNative || !targetIsNative) {
// source or target is native or abstract
// for native types we don't care about relation ships in workflows
RelationshipDeclarativeWorkflow relationshipDeclarativeWorkflow = defaultDeclarativeWorkflows.getRelationshipWorkflows().get(workflow.getName());
// only trigger this method if it's a default workflow
if (relationshipDeclarativeWorkflow != null) {
Map<String, WorkflowStep> relationshipOperationSteps = safe(relationshipDeclarativeWorkflow.getOperations()).entrySet().stream().filter(operationEntry -> !targetIsNative || operationEntry.getValue().getOperationHost() == RelationshipOperationHost.SOURCE).filter(operationEntry -> !sourceIsNative || operationEntry.getValue().getOperationHost() == RelationshipOperationHost.TARGET).collect(Collectors.toMap(Map.Entry::getKey, operationEntry -> WorkflowUtils.addRelationshipOperationStep(workflow, nodeId, relationshipTemplate.getName(), ToscaRelationshipLifecycleConstants.CONFIGURE_SHORT, operationEntry.getKey(), operationEntry.getValue().getOperationHost().toString())));
Steps sourceSteps = new Steps(workflow, nodeId);
Steps targetSteps = new Steps(workflow, relationshipTemplate.getTarget());
safe(relationshipDeclarativeWorkflow.getOperations()).forEach((relationshipOperationName, relationshipOperationDependencies) -> {
WorkflowStep currentStep = relationshipOperationSteps.get(relationshipOperationName);
if (currentStep != null) {
// It might be filtered if source or target is native
declareStepDependencies(relationshipOperationDependencies.getSource(), currentStep, sourceSteps);
declareStepDependencies(relationshipOperationDependencies.getTarget(), currentStep, targetSteps);
declareStepDependencies(relationshipOperationDependencies, currentStep, new Steps(relationshipOperationSteps, Collections.emptyMap(), null));
}
});
RelationshipWeavingDeclarativeWorkflow relationshipWeavingDeclarativeWorkflow = getRelationshipWeavingDeclarativeWorkflow(relationshipTemplate.getType(), topologyContext, workflow.getName());
declareWeaving(relationshipWeavingDeclarativeWorkflow.getSource(), sourceSteps, targetSteps);
declareWeaving(relationshipWeavingDeclarativeWorkflow.getTarget(), targetSteps, sourceSteps);
}
} else {
// both source and target are native then the relationship does not have any operation implemented
// we will just try to declare weaving between source node operations and target node operations
Steps sourceSteps = new Steps(workflow, nodeId);
Steps targetSteps = new Steps(workflow, relationshipTemplate.getTarget());
RelationshipWeavingDeclarativeWorkflow relationshipWeavingDeclarativeWorkflow = getRelationshipWeavingDeclarativeWorkflow(relationshipTemplate.getType(), topologyContext, workflow.getName());
declareWeaving(relationshipWeavingDeclarativeWorkflow.getSource(), sourceSteps, targetSteps);
declareWeaving(relationshipWeavingDeclarativeWorkflow.getTarget(), targetSteps, sourceSteps);
}
}
Aggregations