Search in sources :

Example 21 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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 22 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologyDTOBuilder method getCapabilityTypes.

private <T extends Topology> Map<String, CapabilityType> getCapabilityTypes(AbstractTopologyDTO<T> topologyDTO) {
    Map<String, CapabilityType> types = Maps.newHashMap();
    Map<String, NodeType> delayedNodeTypeAddMap = Maps.newHashMap();
    for (NodeType nodeType : topologyDTO.getNodeTypes().values()) {
        if (nodeType != null) {
            for (CapabilityDefinition capabilityDefinition : safe(nodeType.getCapabilities())) {
                types.put(capabilityDefinition.getType(), ToscaContext.get(CapabilityType.class, capabilityDefinition.getType()));
            }
            for (RequirementDefinition requirementDefinition : safe(nodeType.getRequirements())) {
                CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, requirementDefinition.getType());
                if (capabilityType != null) {
                    types.put(requirementDefinition.getType(), capabilityType);
                } else {
                    // requirements are authorized to be a node type rather than a capability type TODO is it still possible in TOSCA ?
                    NodeType indexedNodeType = ToscaContext.get(NodeType.class, requirementDefinition.getType());
                    // add it to the actual node types map
                    delayedNodeTypeAddMap.put(requirementDefinition.getType(), indexedNodeType);
                }
            }
        }
    }
    for (Map.Entry<String, NodeType> delayedNodeType : delayedNodeTypeAddMap.entrySet()) {
        topologyDTO.getNodeTypes().put(delayedNodeType.getKey(), delayedNodeType.getValue());
    }
    return types;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class AddSubstitutionTypeProcessor method process.

@Override
public void process(Csar csar, Topology topology, AddSubstitutionTypeOperation operation) {
    if (topology.getSubstitutionMapping() == null) {
        topology.setSubstitutionMapping(new SubstitutionMapping());
    }
    NodeType nodeType = toscaTypeSearchService.getElementInDependencies(NodeType.class, operation.getElementId(), topology.getDependencies());
    // if not null the node type exists in the dependencies, there is no choices for this type version
    if (nodeType == null) {
        // the node type does'nt exist in this topology dependencies
        // we need to find the latest version of this component and use it as default
        nodeType = toscaTypeSearchService.findMostRecent(NodeType.class, operation.getElementId());
        if (nodeType == null) {
            throw new NotFoundException("Node type with name <" + operation.getElementId() + "> cannot be found in the catalog.");
        }
        topologyService.loadType(topology, nodeType);
    }
    topology.getSubstitutionMapping().setSubstitutionType(operation.getElementId());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) SubstitutionMapping(org.alien4cloud.tosca.model.templates.SubstitutionMapping)

Example 24 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class EditorTopologyRecoveryHelperService method checkCapability.

/**
 * validate that a node still has a capability, by checkibg directly from the related node type
 *
 * @param capabilityName The name of the capability to check
 * @param nodeTemplate The node template in which to check for the capability
 */
private void checkCapability(String capabilityName, NodeTemplate nodeTemplate) {
    // FIXME check if the relationship is still valid concerning binded capability
    // This call should never throw a NotFoundException
    NodeType indexedNodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
    Map<String, CapabilityDefinition> capabilitiesMap = AlienUtils.fromListToMap(indexedNodeType.getCapabilities(), "id", true);
    if (!AlienUtils.safe(capabilitiesMap).containsKey(capabilityName)) {
        throw new InvalidStateException("A capability with name [" + capabilityName + "] cannot be found in the node [" + nodeTemplate.getName() + "].");
    }
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition)

Example 25 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class EditorTopologyRecoveryHelperService method validateRelationShip.

/**
 * checks if a relationship is still valid
 *
 * @param nodeTemplate The source node of the relationship
 * @param relationshipTemplate The relationship to validate
 * @param topology The related topology
 */
private void validateRelationShip(NodeTemplate nodeTemplate, RelationshipTemplate relationshipTemplate, Topology topology) {
    // This call should never throw a NotFoundException
    NodeType nodeType = ToscaContext.getOrFail(NodeType.class, nodeTemplate.getType());
    // validate the requirement
    checkRequirement(relationshipTemplate, nodeTemplate, nodeType);
    // validate the targeted capability
    checkCapability(relationshipTemplate.getTargetedCapabilityName(), topology.getNodeTemplates().get(relationshipTemplate.getTarget()));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7