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;
}
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);
}
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);
}
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));
}
}
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();
}
Aggregations