Search in sources :

Example 46 with CapabilityType

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

the class CapabilityMatcherService method getCompatibleCapabilityByType.

@Override
public Map<String, Capability> getCompatibleCapabilityByType(NodeTemplate nodeTemplate, String type) {
    Map<String, Capability> capabilities = nodeTemplate.getCapabilities();
    if (capabilities == null) {
        return Collections.emptyMap();
    }
    Map<String, Capability> targetCapabilitiesMatch = Maps.newHashMap();
    for (Map.Entry<String, Capability> capabilityEntry : capabilities.entrySet()) {
        String capabilityTypeName = capabilityEntry.getValue().getType();
        CapabilityType capabilityType = toscaContextFinder.find(CapabilityType.class, capabilityTypeName);
        if (ToscaTypeUtils.isOfType(capabilityType, type)) {
            targetCapabilitiesMatch.put(capabilityEntry.getKey(), capabilityEntry.getValue());
        }
    }
    return targetCapabilitiesMatch;
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) Map(java.util.Map)

Example 47 with CapabilityType

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

the class CapabilityPostProcessor method process.

@Override
public void process(Map.Entry<String, Capability> instance) {
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance.getValue(), instance.getValue().getType(), CapabilityType.class));
    CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, instance.getValue().getType());
    if (capabilityType == null) {
        return;
    }
    propertyValueChecker.checkProperties(capabilityType, instance.getValue().getProperties(), instance.getKey());
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType)

Example 48 with CapabilityType

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

the class DerivedFromPostProcessor method process.

private void process(Map<AbstractInheritableToscaType, String> processed, Map<AbstractInheritableToscaType, String> processing, AbstractInheritableToscaType instance, Map<String, ? extends AbstractInheritableToscaType> instances) {
    if (processed.containsKey(instance)) {
        // Already processed
        return;
    }
    if (processing.containsKey(instance)) {
        // Cyclic dependency as parent is currently being processed...
        Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.CYCLIC_DERIVED_FROM, "Cyclic derived from has been detected", node.getStartMark(), "The type specified as parent or one of it's parent type refers the current type as parent, invalid cycle detected.", node.getEndMark(), instance.getElementId()));
        processing.remove(instance);
        return;
    }
    List<String> derivedFrom = instance.getDerivedFrom();
    if (derivedFrom != null && derivedFrom.size() > 1) {
        // The type has been already processed.
        return;
    }
    if (derivedFrom == null || derivedFrom.isEmpty()) {
        // If the user forgot to derive from Root, automatically do it but make an alert
        String defaultDerivedFrom = null;
        if (instance instanceof NodeType && !NormativeTypesConstant.ROOT_NODE_TYPE.equals(instance.getElementId())) {
            defaultDerivedFrom = NormativeTypesConstant.ROOT_NODE_TYPE;
        } else if (instance instanceof RelationshipType && !NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE.equals(instance.getElementId())) {
            defaultDerivedFrom = NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE;
        } else if (instance instanceof DataType && !NormativeTypesConstant.ROOT_DATA_TYPE.equals(instance.getElementId())) {
            defaultDerivedFrom = NormativeTypesConstant.ROOT_DATA_TYPE;
        } else if (instance instanceof CapabilityType && !NormativeCapabilityTypes.ROOT.equals(instance.getElementId())) {
            defaultDerivedFrom = NormativeCapabilityTypes.ROOT;
        } else if (instance instanceof ArtifactType && !NormativeTypesConstant.ROOT_ARTIFACT_TYPE.equals(instance.getElementId())) {
            defaultDerivedFrom = NormativeTypesConstant.ROOT_ARTIFACT_TYPE;
        }
        if (defaultDerivedFrom != null) {
            derivedFrom = new ArrayList<>();
            derivedFrom.add(defaultDerivedFrom);
            instance.setDerivedFrom(derivedFrom);
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.DERIVED_FROM_NOTHING, defaultDerivedFrom, node.getStartMark(), "The " + instance.getClass().getSimpleName() + " " + instance.getElementId() + " derives from nothing, default " + defaultDerivedFrom + " will be set as parent type.", node.getEndMark(), instance.getElementId()));
        } else {
            // Non managed default parent type then returns
            return;
        }
    }
    String parentElementType = derivedFrom.get(0);
    // Merge the type with it's parent except for primitive data types.
    if (instance instanceof DataType && ToscaTypes.isSimple(parentElementType)) {
        if (instance instanceof PrimitiveDataType) {
            log.debug("Do not merge data type instance with parent as it extends from a primitive type.");
        } else {
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
            // type has not been parsed as primitive because it has some properties
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.SYNTAX_ERROR, "Primitive types cannot define properties.", node.getStartMark(), "The defined type inherit from a primitive type but defines some properties.", node.getEndMark(), parentElementType));
        }
        return;
    }
    AbstractInheritableToscaType parent = instances.get(parentElementType);
    if (parent == null) {
        parent = ToscaContext.get(instance.getClass(), parentElementType);
    } else {
        // first process the parent type
        processing.put(instance, null);
        process(processed, processing, parent, instances);
        processing.remove(instance);
    }
    if (parent == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "Derived_from type not found", node.getStartMark(), "The type specified as parent is not found neither in the archive or its dependencies.", node.getEndMark(), parentElementType));
        return;
    }
    // Merge with parent type
    IndexedModelUtils.mergeInheritableIndex(parent, instance);
    processed.put(instance, null);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) ParsingError(alien4cloud.tosca.parser.ParsingError) PrimitiveDataType(org.alien4cloud.tosca.model.types.PrimitiveDataType) ArtifactType(org.alien4cloud.tosca.model.types.ArtifactType) Node(org.yaml.snakeyaml.nodes.Node) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) DataType(org.alien4cloud.tosca.model.types.DataType) PrimitiveDataType(org.alien4cloud.tosca.model.types.PrimitiveDataType) AbstractInheritableToscaType(org.alien4cloud.tosca.model.types.AbstractInheritableToscaType)

Aggregations

CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)48 Capability (org.alien4cloud.tosca.model.templates.Capability)25 NodeType (org.alien4cloud.tosca.model.types.NodeType)21 Set (java.util.Set)20 Test (org.junit.Test)18 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)14 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)13 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)10 Map (java.util.Map)9 Csar (org.alien4cloud.tosca.model.Csar)8 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)8 NotFoundException (alien4cloud.exception.NotFoundException)7 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)5 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)5 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)5 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4 List (java.util.List)3 FunctionPropertyValue (org.alien4cloud.tosca.model.definitions.FunctionPropertyValue)3 MatchingFilterDefinition (alien4cloud.model.deployment.matching.MatchingFilterDefinition)2