Search in sources :

Example 26 with ParsingError

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

the class SustitutionMappingParser method parse.

@Override
public SubstitutionMapping parse(Node node, ParsingContextExecution context) {
    Topology topology = (Topology) context.getParent();
    if (!(node instanceof MappingNode)) {
        // we expect a MappingNode
        context.getParsingErrors().add(new ParsingError(ErrorCode.YAML_MAPPING_NODE_EXPECTED, null, node.getStartMark(), null, node.getEndMark(), null));
        return null;
    }
    SubstitutionMapping result = new SubstitutionMapping();
    MappingNode mappingNode = ((MappingNode) node);
    List<NodeTuple> nodeTuples = mappingNode.getValue();
    for (NodeTuple nodeTuple : nodeTuples) {
        String key = scalarParser.parse(nodeTuple.getKeyNode(), context);
        Node valueNode = nodeTuple.getValueNode();
        switch(key) {
            case NODE_TYPE:
                String nodeTypeName = scalarParser.parse(valueNode, context);
                result.setSubstitutionType(nodeTypeName);
                break;
            case CAPABILITIES:
                result.setCapabilities(parseSubstitutionTargets(valueNode, context));
                break;
            case REQUIREMENTS:
                result.setRequirements(parseSubstitutionTargets(valueNode, context));
                break;
            default:
                context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNRECOGNIZED_PROPERTY, null, valueNode.getStartMark(), "Key <" + key + "> is not recognized for substitution mapping.", valueNode.getEndMark(), "key"));
        }
    }
    return result;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) SubstitutionMapping(org.alien4cloud.tosca.model.templates.SubstitutionMapping) NodeTuple(org.yaml.snakeyaml.nodes.NodeTuple)

Example 27 with ParsingError

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

the class LaxImportParser method parse.

@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
    String valueAsString = scalarParser.parse(node, context);
    if (StringUtils.isNotBlank(valueAsString)) {
        if (valueAsString.contains(":")) {
            String[] dependencyStrs = valueAsString.split(":");
            if (dependencyStrs.length == 2) {
                String dependencyName = dependencyStrs[0];
                String dependencyVersion = dependencyStrs[1];
                // check that version has the righ format
                try {
                    VersionUtil.parseVersion(dependencyVersion);
                } catch (InvalidVersionException e) {
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Version specified in the dependency is not a valid version.", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
                    return null;
                }
                return new CSARDependency(dependencyName, dependencyVersion);
            }
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Import definition is not valid", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
        } else {
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Relative import is currently not supported in Alien 4 Cloud", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
        }
    }
    return null;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) InvalidVersionException(alien4cloud.utils.version.InvalidVersionException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 28 with ParsingError

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

the class PluginArchiveIndexer method indexArchive.

private void indexArchive(PluginArchive pluginArchive, Orchestrator orchestrator, Location location) {
    ArchiveRoot archive = pluginArchive.getArchive();
    // inject a specific tag to allow components catalog filtering search
    injectWorkSpace(archive.getNodeTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getArtifactTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getCapabilityTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getRelationshipTypes().values(), orchestrator, location);
    List<ParsingError> parsingErrors = Lists.newArrayList();
    // index the archive in alien catalog
    try {
        archiveIndexer.importArchive(archive, CSARSource.ORCHESTRATOR, pluginArchive.getArchiveFilePath(), parsingErrors);
    } catch (AlreadyExistException e) {
        log.debug("Skipping location archive import as the released version already exists in the repository.");
    } catch (CSARUsedInActiveDeployment e) {
        log.debug("Skipping orchestrator archive import as it is used in an active deployment. " + e.getMessage());
    } catch (ToscaTypeAlreadyDefinedInOtherCSAR e) {
        log.debug("Skipping orchestrator archive import, it's archive contain's a tosca type already defined in an other archive." + e.getMessage());
    }
    // Publish event to allow plugins to post-process elements (portability plugin for example).
    publishLocationTypeIndexedEvent(archive.getNodeTypes().values(), orchestrator, location);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) CSARUsedInActiveDeployment(alien4cloud.component.repository.exception.CSARUsedInActiveDeployment) ToscaTypeAlreadyDefinedInOtherCSAR(alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 29 with ParsingError

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

the class SuggestionService method checkProperty.

private AbstractSuggestionEntry checkProperty(String nodePrefix, String propertyName, String propertyTextValue, Class<? extends AbstractInheritableToscaType> type, String elementId, ParsingContext context) {
    AbstractSuggestionEntry suggestionEntry = getSuggestionEntry(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, type.getSimpleName().toLowerCase(), elementId, propertyName);
    if (suggestionEntry != null) {
        PriorityQueue<SuggestionService.MatchedSuggestion> similarValues = getJaroWinklerMatchedSuggestions(suggestionEntry.getSuggestions(), propertyTextValue, 0.8);
        if (!similarValues.isEmpty()) {
            // Has some similar values in the system already
            SuggestionService.MatchedSuggestion mostMatched = similarValues.poll();
            if (!mostMatched.getValue().equals(propertyTextValue)) {
                // If user has entered a property value not the same as the most matched in the system
                ParsingErrorLevel level;
                if (mostMatched.getPriority() == 1.0) {
                    // It's really identical if we take out all white spaces and lower / upper case
                    level = ParsingErrorLevel.WARNING;
                } else {
                    // It's pretty similar
                    level = ParsingErrorLevel.INFO;
                    // Add suggestion anyway
                    addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
                }
                context.getParsingErrors().add(new ParsingError(level, ErrorCode.POTENTIAL_BAD_PROPERTY_VALUE, null, null, null, null, "At path [" + nodePrefix + "." + propertyName + "] existing value [" + mostMatched.getValue() + "] is very similar to [" + propertyTextValue + "]"));
            }
        } else {
            // Not similar add suggestion
            addSuggestionValueToSuggestionEntry(suggestionEntry.getId(), propertyTextValue);
        }
    }
    return suggestionEntry;
}
Also used : ParsingErrorLevel(alien4cloud.tosca.parser.ParsingErrorLevel) ParsingError(alien4cloud.tosca.parser.ParsingError) AbstractSuggestionEntry(alien4cloud.model.common.AbstractSuggestionEntry)

Example 30 with ParsingError

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

the class AbstractPluginArchiveService method parse.

/**
 * Parse an archive given a path relative to the plugin
 *
 * @param archiveRelativePath Relative path where the archive is in the plugin
 * @return The parsed archive as a @{@link PluginArchive}
 * @throws PluginArchiveException
 */
public PluginArchive parse(String archiveRelativePath) throws PluginArchiveException {
    String archiveErrorMsge = "Archive in path: [ " + archiveRelativePath + " ]";
    // Parse the archives
    ParsingResult<ArchiveRoot> result;
    Path archivePath = selfContext.getPluginPath().resolve(archiveRelativePath);
    try {
        result = this.archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    } catch (ParsingException e) {
        throw new PluginArchiveException("Failed to parse " + archiveErrorMsge, e);
    }
    if (result.getContext().getParsingErrors() != null && !result.getContext().getParsingErrors().isEmpty()) {
        log.error("Parsing errors for" + archiveErrorMsge);
        for (ParsingError parsingError : result.getContext().getParsingErrors()) {
            log.error(parsingError.toString());
        }
        throw new PluginArchiveException(archiveErrorMsge + " is invalid");
    }
    return new PluginArchive(result.getResult(), archivePath);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) ParsingException(alien4cloud.tosca.parser.ParsingException) PluginArchiveException(alien4cloud.plugin.exception.PluginArchiveException)

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