Search in sources :

Example 6 with ParsingException

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

the class ArchiveUploadService method preParsing.

@ToscaContextual
public Map<CSARDependency, CsarDependenciesBean> preParsing(Set<Path> paths, List<ParsingResult<Csar>> parsingResults) {
    Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = Maps.newHashMap();
    for (Path path : paths) {
        try {
            // FIXME cleanup git import archives
            ParsingResult<CsarDependenciesBean> parsingResult = parser.parseImports(path);
            parsingResult.getResult().setPath(path);
            csarDependenciesBeans.put(parsingResult.getResult().getSelf(), parsingResult.getResult());
        } catch (ParsingException e) {
            ParsingResult<Csar> failedResult = new ParsingResult<>();
            failedResult.setContext(new ParsingContext(path.getFileName().toString()));
            failedResult.getContext().setParsingErrors(e.getParsingErrors());
            parsingResults.add(failedResult);
            log.debug("Not able to parse archive, ignoring it", e);
        }
    }
    return csarDependenciesBeans;
}
Also used : Path(java.nio.file.Path) ParsingResult(alien4cloud.tosca.parser.ParsingResult) ParsingContext(alien4cloud.tosca.parser.ParsingContext) ParsingException(alien4cloud.tosca.parser.ParsingException) CsarDependenciesBean(org.alien4cloud.tosca.model.CsarDependenciesBean) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 7 with ParsingException

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

Example 8 with ParsingException

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

the class ArchiveUploadService method upload.

/**
 * Upload a TOSCA archive and index its components.
 *
 * @param path The archive path.
 * @param csarSource The source of the upload.
 * @return The Csar object from the parsing.
 * @throws ParsingException
 * @throws CSARUsedInActiveDeployment
 */
@ToscaContextual
public ParsingResult<Csar> upload(Path path, CSARSource csarSource, String workspace) throws ParsingException, CSARUsedInActiveDeployment, ToscaTypeAlreadyDefinedInOtherCSAR {
    // parse the archive.
    ParsingResult<ArchiveRoot> parsingResult = parser.parseWithExistingContext(path, workspace);
    final ArchiveRoot archiveRoot = parsingResult.getResult();
    // check if any blocker error has been found during parsing process.
    if (parsingResult.hasError(ParsingErrorLevel.ERROR)) {
        // do not save anything if any blocker error has been found during import.
        return ArchiveParserUtil.toSimpleResult(parsingResult);
    }
    archiveIndexer.importArchive(archiveRoot, csarSource, path, parsingResult.getContext().getParsingErrors());
    try {
        suggestionService.postProcessSuggestionFromArchive(parsingResult);
        suggestionService.setAllSuggestionIdOnPropertyDefinition();
    } catch (Exception e) {
        log.error("Could not post process suggestion for the archive <" + archiveRoot.getArchive().getName() + "/" + archiveRoot.getArchive().getVersion() + ">", e);
    }
    return ArchiveParserUtil.toSimpleResult(parsingResult);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingException(alien4cloud.tosca.parser.ParsingException) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 9 with ParsingException

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

the class EditorTopologyUploadService method processTopology.

/**
 * Process the import of a topology archive or yaml in the context of the editor.
 *
 * @param archivePath The path of the yaml or archive.
 */
public void processTopology(Path archivePath, String workspace) {
    // parse the archive.
    try {
        ParsingResult<ArchiveRoot> parsingResult = toscaArchiveParser.parse(archivePath, true);
        processTopologyParseResult(archivePath, parsingResult, workspace);
    } catch (ParsingException e) {
        // Manage parsing error and dispatch them in the right editor exception
        throw new EditorToscaYamlParsingException("The uploaded file to override the topology yaml is not a valid Tosca Yaml.", toParsingResult(e));
    }
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) EditorToscaYamlParsingException(org.alien4cloud.tosca.editor.exception.EditorToscaYamlParsingException) ParsingException(alien4cloud.tosca.parser.ParsingException) EditorToscaYamlParsingException(org.alien4cloud.tosca.editor.exception.EditorToscaYamlParsingException)

Example 10 with ParsingException

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

the class MockOpenStackLocationConfigurer method getMatchingConfigurations.

@Override
public Map<String, MatchingConfiguration> getMatchingConfigurations() {
    Path matchingConfigPath = selfContext.getPluginPath().resolve("openstack/mock-resources-matching-config.yml");
    MatchingConfigurations matchingConfigurations = null;
    try {
        matchingConfigurations = matchingConfigurationsParser.parseFile(matchingConfigPath).getResult();
    } catch (ParsingException e) {
        return Maps.newHashMap();
    }
    return matchingConfigurations.getMatchingConfigurations();
}
Also used : Path(java.nio.file.Path) MatchingConfigurations(alien4cloud.deployment.matching.services.nodes.MatchingConfigurations) ParsingException(alien4cloud.tosca.parser.ParsingException)

Aggregations

ParsingException (alien4cloud.tosca.parser.ParsingException)12 Path (java.nio.file.Path)9 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)5 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)3 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)3 MatchingConfigurations (alien4cloud.deployment.matching.services.nodes.MatchingConfigurations)3 AlreadyExistException (alien4cloud.exception.AlreadyExistException)3 PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)2 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)2 ParsingContext (alien4cloud.tosca.parser.ParsingContext)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ParsingResult (alien4cloud.tosca.parser.ParsingResult)2 IOException (java.io.IOException)2 EditorToscaYamlParsingException (org.alien4cloud.tosca.editor.exception.EditorToscaYamlParsingException)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 Csar (org.alien4cloud.tosca.model.Csar)2 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)2 Audit (alien4cloud.audit.annotation.Audit)1 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)1 PluginArchiveException (alien4cloud.plugin.exception.PluginArchiveException)1