Search in sources :

Example 41 with ParsingError

use of alien4cloud.tosca.parser.ParsingError 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 42 with ParsingError

use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.

the class PropertyDefinitionPostProcessor method process.

@Override
public void process(Map.Entry<String, PropertyDefinition> instance) {
    PropertyDefinition propertyDefinition = instance.getValue();
    validateType(propertyDefinition);
    if (propertyDefinition.getConstraints() != null) {
        Set<String> definedConstraints = Sets.newHashSet();
        for (PropertyConstraint constraint : propertyDefinition.getConstraints()) {
            validate(propertyDefinition, constraint);
            if (!definedConstraints.add(constraint.getClass().getName())) {
                Node node = ParsingContextExecution.getObjectToNodeMap().get(constraint);
                ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.VALIDATION_ERROR, "ToscaPropertyConstraintDuplicate", node.getStartMark(), "Constraint duplicated", node.getEndMark(), "constraint"));
            }
        }
    }
    if (propertyDefinition.getDefault() != null) {
        checkDefaultValue(instance.getKey(), propertyDefinition);
    }
}
Also used : PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 43 with ParsingError

use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.

the class NodeTemplatePostProcessor method process.

@Override
public void process(final NodeTemplate instance) {
    // ensure type exists
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), NodeType.class));
    final NodeType nodeType = ToscaContext.get(NodeType.class, instance.getType());
    if (nodeType == null) {
        // error managed by the reference post processor.
        return;
    }
    // FIXME we should check that the artifact is defined at the type level.
    safe(instance.getArtifacts()).values().forEach(templateDeploymentArtifactPostProcessor);
    // TODO Manage interfaces inputs to copy them to all operations.
    safe(instance.getInterfaces()).values().stream().flatMap(anInterface -> safe(anInterface.getOperations()).values().stream()).map(Operation::getImplementationArtifact).filter(Objects::nonNull).forEach(implementationArtifactPostProcessor);
    // Merge the node template with data coming from the type (default values etc.).
    NodeTemplate tempObject = TemplateBuilder.buildNodeTemplate(nodeType, instance, false);
    safe(instance.getCapabilities()).keySet().forEach(s -> {
        if (!safe(tempObject.getCapabilities()).containsKey(s)) {
            Node node = ParsingContextExecution.getObjectToNodeMap().get(s);
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CAPABILITY, null, node.getStartMark(), null, node.getEndMark(), s));
        }
    });
    instance.setAttributes(tempObject.getAttributes());
    instance.setCapabilities(tempObject.getCapabilities());
    instance.setProperties(tempObject.getProperties());
    instance.setRequirements(tempObject.getRequirements());
    instance.setArtifacts(tempObject.getArtifacts());
    instance.setInterfaces(tempObject.getInterfaces());
    // apply post processor to capabilities defined locally on the element (no need to post-processed the one merged)
    safe(instance.getCapabilities()).entrySet().forEach(capabilityPostProcessor);
    safe(instance.getRequirements()).entrySet().forEach(requirementPostProcessor);
    propertyValueChecker.checkProperties(nodeType, instance.getProperties(), instance.getName());
}
Also used : Operation(org.alien4cloud.tosca.model.definitions.Operation) ParsingErrorLevel(alien4cloud.tosca.parser.ParsingErrorLevel) Resource(javax.annotation.Resource) TemplateBuilder(alien4cloud.tosca.topology.TemplateBuilder) ErrorCode(alien4cloud.tosca.parser.impl.ErrorCode) NodeType(org.alien4cloud.tosca.model.types.NodeType) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Objects(java.util.Objects) Node(org.yaml.snakeyaml.nodes.Node) Component(org.springframework.stereotype.Component) ParsingContextExecution(alien4cloud.tosca.parser.ParsingContextExecution) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) ToscaContext(alien4cloud.tosca.context.ToscaContext) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ParsingError(alien4cloud.tosca.parser.ParsingError) NodeType(org.alien4cloud.tosca.model.types.NodeType) Node(org.yaml.snakeyaml.nodes.Node) Operation(org.alien4cloud.tosca.model.definitions.Operation)

Example 44 with ParsingError

use of alien4cloud.tosca.parser.ParsingError in project alien4cloud by alien4cloud.

the class FailGetArtifactParser method parse.

@Override
public Object parse(Node node, ParsingContextExecution context) {
    if (node instanceof MappingNode) {
        NodeTuple nodeTuple = ((MappingNode) node).getValue().get(0);
        if (nodeTuple.getKeyNode() instanceof ScalarNode) {
            String key = ((ScalarNode) nodeTuple.getKeyNode()).getValue();
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, "Ignored field during import", nodeTuple.getKeyNode().getStartMark(), "tosca key is not recognized", nodeTuple.getValueNode().getEndMark(), key));
        }
    }
    return null;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) ScalarNode(org.yaml.snakeyaml.nodes.ScalarNode) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 45 with ParsingError

use of alien4cloud.tosca.parser.ParsingError 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

ParsingError (alien4cloud.tosca.parser.ParsingError)46 Node (org.yaml.snakeyaml.nodes.Node)21 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)13 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)7 NodeTuple (org.yaml.snakeyaml.nodes.NodeTuple)7 Map (java.util.Map)6 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)4 Csar (org.alien4cloud.tosca.model.Csar)4 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)4 ScalarNode (org.yaml.snakeyaml.nodes.ScalarNode)4 ToscaContext (alien4cloud.tosca.context.ToscaContext)3 INodeParser (alien4cloud.tosca.parser.INodeParser)3 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)2 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)2 AlreadyExistException (alien4cloud.exception.AlreadyExistException)2