use of org.alien4cloud.tosca.model.templates.RelationshipTemplate 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;
}
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class WorkflowUtils method getRelationshipTarget.
private static String getRelationshipTarget(String source, String relationshipId, TopologyContext topologyContext) {
NodeTemplate sourceNode = safe(topologyContext.getTopology().getNodeTemplates()).get(source);
if (sourceNode == null) {
throw new NotFoundException("Source " + source + " cannot be found in the topology " + topologyContext.getTopology().getId());
}
RelationshipTemplate relationshipTemplate = safe(sourceNode.getRelationships()).get(relationshipId);
if (relationshipTemplate == null) {
throw new NotFoundException("Source " + source + " does not have the relationship " + relationshipId + " in the topology " + topologyContext.getTopology().getId());
}
return relationshipTemplate.getTarget();
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method addRelationship.
public void addRelationship(TopologyContext topologyContext, String nodeTemplateName, String relationshipName) {
topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeTemplateName);
RelationshipTemplate relationshipTemplate = nodeTemplate.getRelationships().get(relationshipName);
for (Workflow wf : topologyContext.getTopology().getWorkflows().values()) {
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.addRelationship(wf, nodeTemplateName, nodeTemplate, relationshipName, relationshipTemplate, topologyContext);
WorkflowUtils.fillHostId(wf, topologyContext);
}
postProcessTopologyWorkflows(topologyContext);
debugWorkflow(topologyContext.getTopology());
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class TopologyUtils method refreshNodeTemplateNameInRelationships.
private static void refreshNodeTemplateNameInRelationships(String oldNodeTemplateName, String newNodeTemplateName, Map<String, RelationshipTemplate> relationshipTemplates) {
Map<String, String> updatedKeys = Maps.newHashMap();
for (Map.Entry<String, RelationshipTemplate> relationshipTemplateEntry : relationshipTemplates.entrySet()) {
String relationshipTemplateId = relationshipTemplateEntry.getKey();
RelationshipTemplate relationshipTemplate = relationshipTemplateEntry.getValue();
if (relationshipTemplate.getTarget().equals(oldNodeTemplateName)) {
relationshipTemplate.setTarget(newNodeTemplateName);
String formatedOldNodeName = getRelationShipName(relationshipTemplate.getType(), oldNodeTemplateName);
// if the id/name of the relationship is auto-generated we should update it also as auto-generation is <typeName+targetId>
if (relationshipTemplateId.equals(formatedOldNodeName)) {
// check that the new name is not already used (so we won't override another relationship)...
String validNewRelationshipTemplateId = getNexAvailableName(getRelationShipName(relationshipTemplate.getType(), newNodeTemplateName), "", relationshipTemplates.keySet());
updatedKeys.put(relationshipTemplateId, validNewRelationshipTemplateId);
}
}
}
// update the relationship keys if any has been impacted
for (Map.Entry<String, String> updateKeyEntry : updatedKeys.entrySet()) {
RelationshipTemplate relationshipTemplate = relationshipTemplates.remove(updateKeyEntry.getKey());
relationshipTemplates.put(updateKeyEntry.getValue(), relationshipTemplate);
}
}
use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.
the class DanglingRequirementService method addDanglingNode.
private NodeTemplate addDanglingNode(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, NodeType danglingNodeType, RelationshipType danglingRelationshipType, CapabilityDefinition targetCapabilityDefinition) {
NodeTemplate danglingTemplate = TemplateBuilder.buildNodeTemplate(danglingNodeType);
// Add the filter as defined in the node type.
danglingTemplate.setNodeFilter(requirementDefinition.getNodeFilter());
// generate the dangling template name
String danglingTemplateName = TopologyUtils.getNexAvailableName(nodeTemplate.getName() + "_" + requirementDefinition.getId(), "_", topology.getNodeTemplates().keySet());
danglingTemplate.setName(danglingTemplateName);
topology.getNodeTemplates().put(danglingTemplateName, danglingTemplate);
workflowsBuilderService.addNode(topologyContext, danglingTemplateName);
// Add the dangling requirement relationship
if (nodeTemplate.getRelationships() == null) {
nodeTemplate.setRelationships(Maps.newHashMap());
}
String danglingRelationshipTemplateName = TopologyUtils.getNexAvailableName(nodeTemplate.getName() + "_" + requirementDefinition.getId(), "_", nodeTemplate.getRelationships().keySet());
RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
relationshipTemplate.setName(danglingRelationshipTemplateName);
relationshipTemplate.setTarget(danglingTemplateName);
String targetCapabilityName = targetCapabilityDefinition == null ? null : targetCapabilityDefinition.getId();
relationshipTemplate.setTargetedCapabilityName(targetCapabilityName);
relationshipTemplate.setRequirementName(requirementDefinition.getId());
relationshipTemplate.setRequirementType(requirementDefinition.getType());
relationshipTemplate.setType(danglingRelationshipType.getElementId());
relationshipTemplate.setArtifacts(newLinkedHashMap(safe(danglingRelationshipType.getArtifacts())));
relationshipTemplate.setAttributes(newLinkedHashMap(safe(danglingRelationshipType.getAttributes())));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
TemplateBuilder.fillProperties(properties, danglingRelationshipType.getProperties(), null);
relationshipTemplate.setProperties(properties);
nodeTemplate.getRelationships().put(danglingRelationshipTemplateName, relationshipTemplate);
workflowsBuilderService.addRelationship(topologyContext, nodeTemplate.getName(), danglingRelationshipTemplateName);
// TODO remove this workaround as soon as matchin leverages
setPropertiesFromFilter(danglingTemplate, danglingNodeType);
return danglingTemplate;
}
Aggregations