use of org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow 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