use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillCapabilities.
private void fillCapabilities(Topology topology, NodeType substituteNodeType) {
if (topology.getSubstitutionMapping().getCapabilities() != null) {
for (Map.Entry<String, SubstitutionTarget> e : topology.getSubstitutionMapping().getCapabilities().entrySet()) {
String key = e.getKey();
String nodeName = e.getValue().getNodeTemplateName();
String capabilityName = e.getValue().getTargetId();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = IndexedModelUtils.getCapabilityDefinitionById(nodeTemplateType.getCapabilities(), capabilityName);
// We cannot change the capability definition here or we will change the original one so we need a clone
capabilityDefinition = CloneUtil.clone(capabilityDefinition);
capabilityDefinition.setId(key);
substituteNodeType.getCapabilities().add(capabilityDefinition);
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillAttributesFromOutputCapabilitiesProperties.
private void fillAttributesFromOutputCapabilitiesProperties(Topology topology, NodeType substituteNodeType) {
Map<String, Map<String, Set<String>>> outputCapabilityProperties = topology.getOutputCapabilityProperties();
if (outputCapabilityProperties != null) {
for (Map.Entry<String, Map<String, Set<String>>> ocpe : outputCapabilityProperties.entrySet()) {
String nodeName = ocpe.getKey();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
for (Map.Entry<String, Set<String>> cpe : ocpe.getValue().entrySet()) {
String capabilityName = cpe.getKey();
String capabilityTypeName = nodeTemplate.getCapabilities().get(capabilityName).getType();
CapabilityType capabilityType = ToscaContext.getOrFail(CapabilityType.class, capabilityTypeName);
for (String propertyName : cpe.getValue()) {
PropertyDefinition pd = capabilityType.getProperties().get(propertyName);
// there is a conflict
addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillSubstituteAttributesFromOutputProperties.
private void fillSubstituteAttributesFromOutputProperties(Topology topology, NodeType substituteNodeType) {
Map<String, Set<String>> outputProperties = topology.getOutputProperties();
if (outputProperties != null) {
for (Map.Entry<String, Set<String>> ope : outputProperties.entrySet()) {
String nodeName = ope.getKey();
NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
for (String propertyName : ope.getValue()) {
PropertyDefinition pd = nodeTemplateType.getProperties().get(propertyName);
// is a conflict
addAttributeFromPropertyDefinition(pd, propertyName, substituteNodeType);
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class TopologySubstitutionService method fillSubstituteAttributesFromTypeAtttributes.
private void fillSubstituteAttributesFromTypeAtttributes(Topology topology, NodeType substituteNodeType) {
Map<String, IValue> attributes = substituteNodeType.getAttributes();
Map<String, Set<String>> outputAttributes = topology.getOutputAttributes();
if (outputAttributes != null) {
for (Map.Entry<String, Set<String>> oae : outputAttributes.entrySet()) {
String nodeName = oae.getKey();
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeName);
NodeType nodeTemplateType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
for (String attributeName : oae.getValue()) {
IValue ivalue = nodeTemplateType.getAttributes().get(attributeName);
// is a conflict
if (ivalue != null && !attributes.containsKey(attributeName)) {
attributes.put(attributeName, ivalue);
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluator method doGetProperty.
private static AbstractPropertyValue doGetProperty(FunctionEvaluatorContext evaluatorContext, AbstractInstantiableTemplate targetTemplate, FunctionPropertyValue function) {
if (targetTemplate == null) {
return null;
}
// If a requirement or capability name is defined then it is applied to the node template.
if (function.getCapabilityOrRequirementName() != null) {
if (targetTemplate instanceof RelationshipTemplate) {
throw new IllegalArgumentException("Get property that specifies a capability or relationship target must be placed on a node template and not a relationship template.");
}
AbstractPropertyValue propertyValue = null;
Capability targetCapability = safe(((NodeTemplate) targetTemplate).getCapabilities()).get(function.getCapabilityOrRequirementName());
if (targetCapability != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, targetCapability.getProperties(), function.getElementNameToFetch());
}
if (propertyValue == null) {
Requirement requirement = safe(((NodeTemplate) targetTemplate).getRequirements()).get(function.getCapabilityOrRequirementName());
if (requirement != null) {
propertyValue = getFromPath(evaluatorContext, targetTemplate, requirement.getProperties(), function.getElementNameToFetch());
}
}
if (propertyValue == null) {
// try to find the value from the host node.
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
// Try to fetch from the node.
AbstractPropertyValue propertyValue = getFromPath(evaluatorContext, targetTemplate, targetTemplate.getProperties(), function.getElementNameToFetch());
if (propertyValue == null && targetTemplate instanceof NodeTemplate) {
propertyValue = doGetProperty(evaluatorContext, TopologyNavigationUtil.getImmediateHostTemplate(evaluatorContext.getTopology(), (NodeTemplate) targetTemplate), function);
}
// if the property refers to a function (get_input/get_property then try to resolve it).
return tryResolveValue(evaluatorContext, targetTemplate, targetTemplate.getProperties(), propertyValue);
}
Aggregations