use of alien4cloud.tosca.parser.ParsingException in project yorc-a4c-plugin by ystia.
the class AbstractLocationConfigurer method getMatchingConfigurations.
public Map<String, MatchingConfiguration> getMatchingConfigurations(String matchingConfigRelativePath) {
Path matchingConfigPath = selfContext.getPluginPath().resolve(matchingConfigRelativePath);
MatchingConfigurations matchingConfigurations = null;
try {
matchingConfigurations = matchingConfigurationsParser.parseFile(matchingConfigPath).getResult();
} catch (ParsingException e) {
return Maps.newHashMap();
}
Map<String, MatchingConfiguration> ret = matchingConfigurations.getMatchingConfigurations();
printMatchingConfigurations(ret);
return ret;
}
use of alien4cloud.tosca.parser.ParsingException in project alien4cloud by alien4cloud.
the class EditorTopologyUploadService method processTopologyDir.
public void processTopologyDir(Path archivePath, String workspace) {
// parse the archive.
try {
ParsingResult<ArchiveRoot> parsingResult = toscaArchiveParser.parseDir(archivePath);
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 CloudServiceArchiveController method uploadCSAR.
@ApiOperation(value = "Upload a csar zip file.")
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
@Audit
public RestResponse<CsarUploadResult> uploadCSAR(@RequestParam(required = false) String workspace, @RequestParam("file") MultipartFile csar) throws IOException {
Path csarPath = null;
try {
if (workspace == null) {
workspace = AlienConstants.GLOBAL_WORKSPACE_ID;
}
// Perform check that the user has one of ARCHITECT, COMPONENT_MANAGER or ADMIN role
archiveIndexerAuthorizationFilter.preCheckAuthorization(workspace);
log.info("Serving file upload with name [" + csar.getOriginalFilename() + "]");
csarPath = Files.createTempFile(tempDirPath, null, '.' + CsarFileRepository.CSAR_EXTENSION);
// save the archive in the temp directory
FileUploadUtil.safeTransferTo(csarPath, csar);
// load, parse the archive definitions and save on disk
ParsingResult<Csar> result = csarUploadService.upload(csarPath, CSARSource.UPLOAD, workspace);
RestError error = null;
if (result.hasError(ParsingErrorLevel.ERROR)) {
error = RestErrorBuilder.builder(RestErrorCode.CSAR_PARSING_ERROR).build();
}
return RestResponseBuilder.<CsarUploadResult>builder().error(error).data(CsarUploadUtil.toUploadResult(result)).build();
} catch (ParsingException e) {
log.error("Error happened while parsing csar file <" + e.getFileName() + ">", e);
String fileName = e.getFileName() == null ? csar.getOriginalFilename() : e.getFileName();
CsarUploadResult uploadResult = new CsarUploadResult();
uploadResult.getErrors().put(fileName, e.getParsingErrors());
return RestResponseBuilder.<CsarUploadResult>builder().error(RestErrorBuilder.builder(RestErrorCode.CSAR_INVALID_ERROR).build()).data(uploadResult).build();
} catch (AlreadyExistException | CSARUsedInActiveDeployment | ToscaTypeAlreadyDefinedInOtherCSAR e) {
CsarUploadResult uploadResult = new CsarUploadResult();
uploadResult.getErrors().put(csar.getOriginalFilename(), Lists.newArrayList(UploadExceptionUtil.parsingErrorFromException(e)));
return RestResponseBuilder.<CsarUploadResult>builder().error(RestErrorBuilder.builder(RestErrorCode.ALREADY_EXIST_ERROR).build()).data(uploadResult).build();
} finally {
if (csarPath != null) {
// Clean up
try {
FileUtil.delete(csarPath);
} catch (IOException e) {
// The repository might just move the file instead of copying to save IO disk access
}
}
}
}
use of alien4cloud.tosca.parser.ParsingException in project alien4cloud by alien4cloud.
the class InitialLoader method loadArchives.
private void loadArchives(Path rootDirectory) {
if (!Files.exists(rootDirectory) || !Files.isDirectory(rootDirectory)) {
log.warn("Skipping archives' initial loading: directory cannot be found {}.", rootDirectory.toString());
return;
}
// this operation is performed using admin role
SecurityContextImpl adminContext = new SecurityContextImpl();
Set<SimpleGrantedAuthority> authorities = Sets.newHashSet();
authorities.add(new SimpleGrantedAuthority(Role.ADMIN.name()));
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken("alien4cloud_init_loader", "alien4cloud_init_loader", authorities);
adminContext.setAuthentication(auth);
SecurityContextHolder.setContext(adminContext);
// archives must be in zip format and placed in the actual folder
try {
List<Path> archives = FileUtil.listFiles(rootDirectory, ".+\\.(zip|csar)");
Collections.sort(archives);
for (Path archive : archives) {
try {
log.debug("Initial load of archives from [ {} ].", archive.toString());
csarUploadService.upload(archive, CSARSource.ALIEN, AlienConstants.GLOBAL_WORKSPACE_ID);
} catch (AlreadyExistException e) {
log.debug("Skipping initial upload of archive [ {} ]. Archive has already been loaded.", archive.toString(), e);
} catch (CSARUsedInActiveDeployment e) {
log.debug("Skipping initial upload of archive [ {} ]. Archive is used in an active depoyment, and then cannot be overrided.", archive.toString(), e);
} catch (ParsingException e) {
log.error("Initial upload of archive [ {} ] has failed.", archive.toString(), e);
} catch (ToscaTypeAlreadyDefinedInOtherCSAR e) {
log.debug("Skipping initial upload of archive [ {} ], it's archive contain's a tosca type already defined in an other archive." + e.getMessage(), archive.toString(), e);
}
}
} catch (IOException e) {
log.error("Failed to load initial archives", e);
} finally {
// clear the security context
SecurityContextHolder.clearContext();
}
}
use of alien4cloud.tosca.parser.ParsingException in project alien4cloud by alien4cloud.
the class CsarGitService method processImport.
private List<ParsingResult<Csar>> processImport(CsarGitRepository csarGitRepository, CsarGitCheckoutLocation csarGitCheckoutLocation, String gitHash) {
// find all the archives under the given hierarchy and zip them to create archives
Path archiveZipRoot = tempZipDirPath.resolve(csarGitRepository.getId());
Path archiveGitRoot = tempDirPath.resolve(csarGitRepository.getId());
if (csarGitCheckoutLocation.getSubPath() != null && !csarGitCheckoutLocation.getSubPath().isEmpty()) {
archiveGitRoot = archiveGitRoot.resolve(csarGitCheckoutLocation.getSubPath());
}
Set<Path> archivePaths = csarFinderService.prepare(archiveGitRoot, archiveZipRoot);
List<ParsingResult<Csar>> parsingResults = Lists.newArrayList();
Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = uploadService.preParsing(archivePaths, parsingResults);
List<CsarDependenciesBean> sorted = sort(csarDependenciesBeans);
for (CsarDependenciesBean csarBean : sorted) {
String archiveRepoPath = archiveZipRoot.relativize(csarBean.getPath().getParent()).toString();
if (csarGitCheckoutLocation.getLastImportedHash() != null && csarGitCheckoutLocation.getLastImportedHash().equals(gitHash) && csarService.get(csarBean.getSelf().getName(), csarBean.getSelf().getVersion()) != null) {
// no commit since last import and the archive still exist in the repo, so do not import
addAlreadyImportParsingResult(archiveRepoPath, parsingResults);
continue;
}
try {
// FIXME Add possibility to choose an workspace
ParsingResult<Csar> result = uploadService.upload(csarBean.getPath(), CSARSource.GIT, AlienConstants.GLOBAL_WORKSPACE_ID);
result.getContext().setFileName(archiveRepoPath + "/" + result.getContext().getFileName());
parsingResults.add(result);
} catch (ParsingException e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(archiveRepoPath));
failedResult.getContext().setParsingErrors(e.getParsingErrors());
parsingResults.add(failedResult);
log.debug("Failed to import archive from git as it cannot be parsed", e);
} catch (AlreadyExistException | ToscaTypeAlreadyDefinedInOtherCSAR | CSARUsedInActiveDeployment e) {
ParsingResult<Csar> failedResult = new ParsingResult<>();
failedResult.setContext(new ParsingContext(archiveRepoPath));
failedResult.getContext().setParsingErrors(Lists.newArrayList(UploadExceptionUtil.parsingErrorFromException(e)));
parsingResults.add(failedResult);
}
}
return parsingResults;
}
Aggregations