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