use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TemplateBuilder method buildNodeTemplate.
/**
* Build a node template. Note that a Tosca Context is required.
*
* @param nodeType the type of the node
* @param templateToMerge the template that can be used to merge into the new node template
* @param adaptToType This flag allow to know if we should adapt the templateToMerge node to the type.
* @return new constructed node template.
*/
public static NodeTemplate buildNodeTemplate(NodeType nodeType, NodeTemplate templateToMerge, boolean adaptToType) {
// clone the type of the node to avoid impacts, this should be improved in the future
nodeType = CloneUtil.clone(nodeType);
NodeTemplate nodeTemplate = new NodeTemplate();
fillAbstractInstantiableTemplate(nodeTemplate, nodeType, templateToMerge, !adaptToType);
nodeTemplate.setCapabilities(Maps.newLinkedHashMap());
nodeTemplate.setRequirements(Maps.newLinkedHashMap());
fillCapabilitiesMap(nodeTemplate.getCapabilities(), nodeType.getCapabilities(), templateToMerge != null ? templateToMerge.getCapabilities() : null, adaptToType);
fillRequirementsMap(nodeTemplate.getRequirements(), nodeType.getRequirements(), templateToMerge != null ? templateToMerge.getRequirements() : null, adaptToType);
if (templateToMerge != null && templateToMerge.getRelationships() != null) {
nodeTemplate.setRelationships(templateToMerge.getRelationships());
}
return nodeTemplate;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyUtils method renameNodeTemplate.
/**
* Rename formattedOldNodeName node template of a topology.
*
* @param topology
* @param nodeTemplateName
* @param newNodeTemplateName
*/
public static void renameNodeTemplate(Topology topology, String nodeTemplateName, String newNodeTemplateName) {
Map<String, NodeTemplate> nodeTemplates = getNodeTemplates(topology);
NodeTemplate nodeTemplate = getNodeTemplate(topology.getId(), nodeTemplateName, nodeTemplates);
nodeTemplate.setName(newNodeTemplateName);
nodeTemplates.put(newNodeTemplateName, nodeTemplate);
nodeTemplates.remove(nodeTemplateName);
refreshNodeTempNameInRelationships(nodeTemplateName, newNodeTemplateName, nodeTemplates);
updateOnNodeTemplateNameChange(nodeTemplateName, newNodeTemplateName, topology);
updateGroupMembers(topology, nodeTemplate, nodeTemplateName, newNodeTemplateName);
updatePolicyMembers(topology, nodeTemplateName, newNodeTemplateName);
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologyNavigationUtil method getHostOfTypeInHostingHierarchy.
/**
* Deeply explore the hosted_on hierarchy of the given node to find a node of the given type.
*/
public static NodeTemplate getHostOfTypeInHostingHierarchy(Topology topology, NodeTemplate nodeTemplate, String hostType) {
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
if (isOfType(relationshipType, NormativeRelationshipConstants.HOSTED_ON)) {
NodeTemplate hostNode = topology.getNodeTemplates().get(relationshipTemplate.getTarget());
NodeType hostNodeType = ToscaContext.get(NodeType.class, hostNode.getType());
if (isOfType(hostNodeType, hostType)) {
return hostNode;
} else {
return getHostOfTypeInHostingHierarchy(topology, hostNode, hostType);
}
}
}
}
return null;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DanglingRequirementService method addDanglingNodes.
private void addDanglingNodes(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, int count) {
// TODO If the TOSCA context does not has the TOSCA normative types then add it automatically
String danglingTemplateType = requirementDefinition.getNodeType() == null ? NormativeTypesConstant.ROOT_NODE_TYPE : requirementDefinition.getNodeType();
NodeType danglingNodeType = ToscaContext.get(NodeType.class, danglingTemplateType);
List<CapabilityDefinition> compatibleCapabilityByType = capabilityMatcherService.getCompatibleCapabilityByType(danglingNodeType, requirementDefinition.getType());
CapabilityDefinition targetCapabilityDefinition = compatibleCapabilityByType.size() == 0 ? null : compatibleCapabilityByType.get(0);
RelationshipType danglingRelationshipType = fetchValidRelationshipType(requirementDefinition, targetCapabilityDefinition);
// check if the type is scalable (then count is used as a scalability parameter) or if we should add multiple instances
CapabilityDefinition scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, NormativeCapabilityTypes.SCALABLE);
if (scalable == null) {
scalable = NodeTypeUtils.getCapabilityByType(danglingNodeType, AlienCapabilityTypes.CLUSTER_CONTROLLER);
}
List<NodeTemplate> addedNodes = Lists.newArrayList();
if (scalable == null) {
for (int i = 0; i < count; i++) {
NodeTemplate addedNode = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
addedNodes.add(addedNode);
}
} else {
NodeTemplate danglingTemplate = addDanglingNode(topology, topologyContext, nodeTemplate, requirementDefinition, danglingNodeType, danglingRelationshipType, targetCapabilityDefinition);
Capability scalableCapability = danglingTemplate.getCapabilities().get(scalable.getId());
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, count, scalableCapability);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_MAX_INSTANCES, requirementDefinition.getUpperBound(), scalableCapability);
addedNodes.add(danglingTemplate);
}
// Recursively add dangling nodes.
for (NodeTemplate addedNode : addedNodes) {
addDanglingRequirements(topology, topologyContext, addedNode, null);
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class DeleteInputProcessor method processInputOperation.
@Override
protected void processInputOperation(Csar csar, Topology topology, DeleteInputOperation operation, Map<String, PropertyDefinition> inputs) {
if (!inputs.containsKey(operation.getInputName())) {
throw new NotFoundException("Input " + operation.getInputName() + "not found in topology");
}
for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
NodeType nodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
removeInputIdInProperties(nodeTemplate.getProperties(), nodeType.getProperties(), operation.getInputName());
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
removeInputIdInProperties(relationshipTemplate.getProperties(), relationshipType.getProperties(), operation.getInputName());
}
}
if (nodeTemplate.getCapabilities() != null) {
for (Capability capability : nodeTemplate.getCapabilities().values()) {
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
removeInputIdInProperties(capability.getProperties(), capabilityType.getProperties(), operation.getInputName());
}
}
}
deletePreConfiguredInput(csar, topology, operation);
inputs.remove(operation.getInputName());
log.debug("Remove the input " + operation.getInputName() + " from the topology " + topology.getId());
}
Aggregations