Search in sources :

Example 71 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class PropertyValueChecker method checkProperties.

/**
 * Check that the value of a property has the right type and match constraints.
 *
 * @param type The type that defines the properties (NodeType, CapabilityType, RequirementType).
 * @param propertyValues The map of values.
 * @param templateName The name of the node template /capability template / requirement template.
 */
public void checkProperties(final AbstractInheritableToscaType type, final Map<String, AbstractPropertyValue> propertyValues, final String templateName) {
    if (type == null) {
        // if the type is null we cannot check properties against their definition. Error is managed elsewhere.
        return;
    }
    ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
    Topology topology = archiveRoot.getTopology();
    for (Map.Entry<String, AbstractPropertyValue> propertyEntry : safe(propertyValues).entrySet()) {
        String propertyName = propertyEntry.getKey();
        AbstractPropertyValue propertyValue = propertyEntry.getValue();
        Node propertyValueNode = ParsingContextExecution.getObjectToNodeMap().get(propertyValue);
        if (type.getProperties() == null || !type.getProperties().containsKey(propertyName)) {
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.UNRECOGNIZED_PROPERTY, templateName, propertyValueNode.getStartMark(), "Property " + propertyName + " does not exist in type " + type.getElementId(), propertyValueNode.getEndMark(), propertyName));
            continue;
        }
        PropertyDefinition propertyDefinition = type.getProperties().get(propertyName);
        checkProperty(propertyName, propertyValueNode, propertyValue, propertyDefinition, topology.getInputs(), templateName);
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) Map(java.util.Map) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 72 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ToscaDefinitionVersionParser method parse.

@Override
public String parse(Node node, ParsingContextExecution context) {
    ArchiveRoot archiveRoot = (ArchiveRoot) context.getParent();
    String toscaDefinitionVersion = ParserUtils.getScalar(node, context);
    if (toscaDefinitionVersion != null) {
        CSARDependency dependency = ToscaNormativeImports.IMPORTS.get(toscaDefinitionVersion);
        if (dependency != null) {
            // File based parsing implementation of the requirement of normative types will load them from file (meaning basically that we will loop here)
            if (loadingNormative.get() == null) {
                loadingNormative.set(true);
            } else {
                return toscaDefinitionVersion;
            }
            Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
            if (csar == null) {
                return toscaDefinitionVersion;
            }
            // Normative imports are automatically injected and supposed to be accessible, no specific validation is performed here.
            dependency.setHash(csar.getHash());
            ToscaContext.get().addDependency(dependency);
            Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
            if (dependencies == null) {
                dependencies = new HashSet<>();
                archiveRoot.getArchive().setDependencies(dependencies);
            }
            dependencies.add(dependency);
            loadingNormative.remove();
        }
    }
    return toscaDefinitionVersion;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 73 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class GroupPostProcessor method process.

@Override
public void process(NodeGroup instance) {
    final ArchiveRoot archiveRoot = (ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance();
    // ensure that member groups exists and add the group to the nodes.
    Iterator<String> groupMembers = instance.getMembers().iterator();
    while (groupMembers.hasNext()) {
        String nodeTemplateId = groupMembers.next();
        NodeTemplate nodeTemplate = archiveRoot.getTopology().getNodeTemplates().get(nodeTemplateId);
        if (nodeTemplate == null) {
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance);
            // add an error to the context
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKOWN_GROUP_MEMBER, null, node.getStartMark(), null, node.getEndMark(), nodeTemplateId));
            // and remove the member
            groupMembers.remove();
        } else {
            Set<String> groups = nodeTemplate.getGroups();
            if (groups == null) {
                groups = Sets.newHashSet();
                nodeTemplate.setGroups(groups);
            }
            groups.add(instance.getName());
        }
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node)

Example 74 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class MetaDataParser method parse.

@Override
public Csar parse(Node node, ParsingContextExecution context) {
    ArchiveRoot parent = (ArchiveRoot) context.getParent();
    Csar csar = parent.getArchive();
    List<Tag> tagList = Lists.newArrayList();
    if (node instanceof MappingNode) {
        MappingNode mapNode = (MappingNode) node;
        for (NodeTuple entry : mapNode.getValue()) {
            String key = scalarParser.parse(entry.getKeyNode(), context);
            String value = scalarParser.parse(entry.getValueNode(), context);
            if (TEMPLATE_NAME.equals(key)) {
                csar.setName(value);
            } else if (TEMPLATE_AUTHOR.equals(key)) {
                csar.setTemplateAuthor(value);
            } else if (TEMPLATE_VERSION.equals(key)) {
                csar.setVersion(value);
                if (!VersionUtil.isValid(value)) {
                    ParserUtils.addTypeError(entry.getValueNode(), context.getParsingErrors(), "version");
                }
            } else if (value != null) {
                tagList.add(new Tag(key, value));
            }
        }
        csar.setTags(tagList);
    } else {
        ParserUtils.addTypeError(node, context.getParsingErrors(), "meta-data");
    }
    return csar;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Tag(alien4cloud.model.common.Tag) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 75 with ArchiveRoot

use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.

the class ImportParser method parse.

@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
    CSARDependency dependency = laxImportParser.parse(node, context);
    if (dependency == null) {
        return null;
    }
    String valueAsString = dependency.getName() + ":" + dependency.getVersion();
    String currentArchiveVersion = context.<ArchiveRoot>getRootObj().getArchive().getVersion();
    Csar csar = ToscaContext.get().getArchive(dependency.getName(), dependency.getVersion());
    log.debug("Import {} {} {}", dependency.getName(), dependency.getVersion(), csar);
    if (csar == null) {
        // error is not a blocker, as long as no type is missing we just mark it as a warning.
        context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.MISSING_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "Specified dependency is not found in Alien 4 Cloud repository.", node.getEndMark(), valueAsString));
        return null;
    } else {
        if (!VersionUtil.isSnapshot(currentArchiveVersion) && VersionUtil.isSnapshot(dependency.getVersion())) {
            // the current archive is a released version but depends on a snapshot version
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.SNAPSHOT_DEPENDENCY, "Import definition is not valid", node.getStartMark(), "A released archive cannot depends on snapshots archives.", node.getEndMark(), valueAsString));
        }
        dependency.setHash(csar.getHash());
        ToscaContext.get().addDependency(dependency);
        return dependency;
    }
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Aggregations

ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)76 Test (org.junit.Test)43 Set (java.util.Set)26 NodeType (org.alien4cloud.tosca.model.types.NodeType)26 Csar (org.alien4cloud.tosca.model.Csar)25 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)16 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)14 ParsingError (alien4cloud.tosca.parser.ParsingError)13 Path (java.nio.file.Path)11 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Node (org.yaml.snakeyaml.nodes.Node)8 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)6 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)6 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)6 ParsingException (alien4cloud.tosca.parser.ParsingException)5 Map (java.util.Map)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)4 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)4