Search in sources :

Example 11 with NodeTemplate

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);
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) SubstitutionTarget(org.alien4cloud.tosca.model.templates.SubstitutionTarget) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 12 with NodeTemplate

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);
                }
            }
        }
    }
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 13 with NodeTemplate

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);
            }
        }
    }
}
Also used : Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 14 with NodeTemplate

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);
                }
            }
        }
    }
}
Also used : IValue(org.alien4cloud.tosca.model.definitions.IValue) Set(java.util.Set) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 15 with NodeTemplate

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);
}
Also used : Requirement(org.alien4cloud.tosca.model.templates.Requirement) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10