Search in sources :

Example 11 with ParsingError

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

the class PolicyTemplatePostProcessor method process.

@Override
public void process(final PolicyTemplate instance) {
    // ensure type exists
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
    final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
    if (policyType == null) {
        // error managed by the reference post processor.
        return;
    }
    final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
    // check that the targets are exiting node templates
    // TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
    safe(instance.getTargets()).forEach(target -> {
        if (!safe((topology.getNodeTemplates())).containsKey(target)) {
            // Dispatch an error.
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
        }
    });
    // Merge the policy template with data coming from the type (default values etc.).
    PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
    instance.setProperties(tempObject.getProperties());
    propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 12 with ParsingError

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

the class PropertyDefinitionPostProcessor method validate.

private void validate(PropertyDefinition propertyDefinition, PropertyConstraint constraint) {
    IPropertyType<?> toscaType = ToscaTypes.fromYamlTypeName(propertyDefinition.getType());
    if (toscaType == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition.getType());
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.INVALID_CONSTRAINT, "Constraint parsing issue", node.getStartMark(), "Limitation - Constraint cannot be used for type " + propertyDefinition.getType(), node.getEndMark(), "constraint"));
    } else {
        try {
            constraint.initialize(toscaType);
        } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
            Node node = ParsingContextExecution.getObjectToNodeMap().get(constraint);
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.VALIDATION_ERROR, "ToscaPropertyConstraint", node.getStartMark(), e.getMessage(), node.getEndMark(), "constraint"));
        }
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) ConstraintValueDoNotMatchPropertyTypeException(org.alien4cloud.tosca.exceptions.ConstraintValueDoNotMatchPropertyTypeException) Node(org.yaml.snakeyaml.nodes.Node)

Example 13 with ParsingError

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

the class PropertyDefinitionPostProcessor method validateType.

private void validateType(PropertyDefinition propertyDefinition) {
    String propertyType = propertyDefinition.getType();
    if (propertyType == null) {
        Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
        if (node == null) {
            node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
        }
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Property type must be defined", node.getEndMark(), "type"));
    } else if (!ToscaTypes.isSimple(propertyType)) {
        if (ToscaTypes.LIST.equals(propertyType) || ToscaTypes.MAP.equals(propertyType)) {
            PropertyDefinition entrySchema = propertyDefinition.getEntrySchema();
            if (entrySchema == null) {
                Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyDefinition);
                ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.VALIDATION_ERROR, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " must define entry schema", node.getEndMark(), "type"));
            } else {
                validateType(entrySchema);
            }
        } else {
            // It's data type
            ArchiveRoot archiveRoot = ParsingContextExecution.getRootObj();
            if (!archiveRoot.getDataTypes().containsKey(propertyType)) {
                DataType dataType = ToscaContext.get(DataType.class, propertyType);
                if (dataType == null) {
                    Node node = ParsingContextExecution.getObjectToNodeMap().get(propertyType);
                    ParsingContextExecution.getParsingErrors().add(new ParsingError(ErrorCode.TYPE_NOT_FOUND, "ToscaPropertyType", node.getStartMark(), "Type " + propertyType + " is not found.", node.getEndMark(), "type"));
                }
            }
        }
    }
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Node(org.yaml.snakeyaml.nodes.Node) DataType(org.alien4cloud.tosca.model.types.DataType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition)

Example 14 with ParsingError

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

the class CsarGitService method addAlreadyImportParsingResult.

/**
 * Just add a parsing info to the list stating that the archive is already imported and
 *
 * @param archivePath The path of the archive in the repo.
 * @param parsingResults The list of parsing results.
 */
private void addAlreadyImportParsingResult(String archivePath, List<ParsingResult<Csar>> parsingResults) {
    ParsingResult<Csar> result = new ParsingResult<>();
    result.setContext(new ParsingContext(archivePath));
    result.getContext().setParsingErrors(Lists.newArrayList(new ParsingError(ParsingErrorLevel.INFO, ErrorCode.CSAR_ALREADY_INDEXED, "No new commit since last import and archive already indexed.", null, null, null, null)));
    parsingResults.add(result);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ParsingResult(alien4cloud.tosca.parser.ParsingResult) ParsingContext(alien4cloud.tosca.parser.ParsingContext) ParsingError(alien4cloud.tosca.parser.ParsingError)

Example 15 with ParsingError

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

the class UploadCSARSStepDefinition method iThereShouldBeAParsingErrorLevelAndCode.

@And("^I there should be a parsing error level \"([^\"]*)\" and code \"([^\"]*)\"$")
public void iThereShouldBeAParsingErrorLevelAndCode(ParsingErrorLevel errorLevel, ErrorCode expectedCode) throws Throwable {
    RestResponse<CsarUploadResult> result = JsonUtil.read(Context.getInstance().getRestResponse(), CsarUploadResult.class);
    Assert.assertFalse("There must have messages after parsing the csar", result.getData().getErrors().isEmpty());
    int errorCount = 0;
    boolean found = false;
    for (List<ParsingError> errors : result.getData().getErrors().values()) {
        for (ParsingError error : errors) {
            if (Objects.equals(error.getErrorCode(), expectedCode) && Objects.equals(error.getErrorLevel(), errorLevel)) {
                found = true;
                break;
            }
        }
        if (found) {
            break;
        }
    }
    Assert.assertTrue(found);
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) CsarUploadResult(alien4cloud.rest.csar.CsarUploadResult) And(cucumber.api.java.en.And)

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