use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class PaaSUtils method processNodeTemplateProperties.
/**
* Inject node template and capabilities properties as input parameters for all its interfaces operations <br>
* The injected input names are uppercased and is in form:
* <ul>
* <li>{@code SELF_<PROPERTY_NAME>} for node property
* <li>{@code SELF_CAPABILITIES_<CAPABILITY_NAME>_<PROPERTY_NAME>} for capability property
* </ul>
* In case of name conflict, the overriding order is: (--> = overrides)
*
* <pre>
* declared input --> node property input --> capability property input
* </pre>
*
* @param paaSTemplate The {@link PaaSNodeTemplate} to process
*/
public static void processNodeTemplateProperties(PaaSNodeTemplate paaSTemplate) {
NodeTemplate template = paaSTemplate.getTemplate();
// inject nodetemplate properties
if (MapUtils.isNotEmpty(template.getProperties())) {
injectPropertiesAsInputs(ToscaFunctionConstants.SELF, null, template.getProperties(), paaSTemplate.getInterfaces(), baseName -> StringUtils.joinWith(AlienUtils.DEFAULT_PREFIX_SEPARATOR, ToscaFunctionConstants.SELF, baseName));
}
// inject capabilities properties
injectCapabilitiesProperties(template, paaSTemplate.getInterfaces());
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class WorkflowUtils method isNativeOrSubstitutionNode.
public static boolean isNativeOrSubstitutionNode(String nodeId, TopologyContext topologyContext) {
NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId);
if (nodeTemplate == null) {
return false;
}
NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType());
if (nodeType.isAbstract() || nodeType.getSubstitutionTopologyId() != null) {
return true;
}
// (since these types will be abstract)
return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage");
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class WorkflowUtils method isComputeOrVolume.
public static boolean isComputeOrVolume(String nodeId, TopologyContext topologyContext) {
NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId);
if (nodeTemplate == null) {
return false;
}
NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType());
return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage");
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate 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);
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method removeRelationship.
public void removeRelationship(Topology topology, Csar csar, String sourceNodeId, String relationshipName, RelationshipTemplate relationshipTemplate) {
TopologyContext topologyContext = buildTopologyContext(topology, csar);
topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
NodeTemplate sourceNode = topology.getNodeTemplates().get(sourceNodeId);
String targetNodeId = relationshipTemplate.getTarget();
NodeTemplate targetNode = topologyContext.getTopology().getNodeTemplates().get(targetNodeId);
for (Workflow wf : topology.getWorkflows().values()) {
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
// Remove relationships from source to target
// Remove relationships from target to source
Map<String, RelationshipTemplate> sourceRelationships = sourceNode.getRelationships().entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(targetNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
Map<String, RelationshipTemplate> targetRelationships = AlienUtils.safe(targetNode.getRelationships()).entrySet().stream().filter(relationshipEntry -> relationshipEntry.getValue().getTarget().equals(sourceNodeId)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
builder.removeRelationships(wf, sourceNodeId, sourceRelationships, targetNodeId, targetRelationships);
sourceRelationships.entrySet().stream().filter(entry -> !entry.getKey().equals(relationshipName)).forEach(entry -> builder.addRelationship(wf, sourceNode.getName(), sourceNode, entry.getKey(), entry.getValue(), topologyContext));
targetRelationships.forEach((id, relationship) -> builder.addRelationship(wf, targetNodeId, targetNode, id, relationship, topologyContext));
// Remove unique relationship that we really want to remove
WorkflowUtils.fillHostId(wf, topologyContext);
}
postProcessTopologyWorkflows(topologyContext);
debugWorkflow(topologyContext.getTopology());
}
Aggregations