use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importManyBranchFromGit.
@Test
public void importManyBranchFromGit() {
CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
alien12Location.setBranchId("1.2.0");
CsarGitCheckoutLocation alien14Location = new CsarGitCheckoutLocation();
alien14Location.setBranchId("1.4.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(alien12Location);
importLocations.add(alien14Location);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN12", result.get(0).getResult().getVersion());
Assert.assertEquals("tosca-normative-types", result.get(1).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN14", result.get(1).getResult().getVersion());
}
use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class CsarGitServiceTest method importManyBranchFromGitAndStoreLocally.
@Test
public void importManyBranchFromGitAndStoreLocally() {
CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
alien12Location.setBranchId("1.2.0");
CsarGitCheckoutLocation alien14Location = new CsarGitCheckoutLocation();
alien14Location.setBranchId("1.4.0");
List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
importLocations.add(alien12Location);
importLocations.add(alien14Location);
String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, true);
List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN12", result.get(0).getResult().getVersion());
Assert.assertEquals("tosca-normative-types", result.get(1).getResult().getName());
Assert.assertEquals("1.0.0-ALIEN14", result.get(1).getResult().getVersion());
// now we re-import
result = csarGitService.importFromGitRepository(repoId);
Assert.assertEquals(2, result.size());
Assert.assertEquals(ErrorCode.CSAR_ALREADY_INDEXED, result.get(0).getContext().getParsingErrors().get(0).getErrorCode());
Assert.assertEquals(ErrorCode.CSAR_ALREADY_INDEXED, result.get(1).getContext().getParsingErrors().get(0).getErrorCode());
}
use of alien4cloud.tosca.parser.ParsingResult in project alien4cloud by alien4cloud.
the class CsarGitService method doImport.
private List<ParsingResult<Csar>> doImport(CsarGitRepository csarGitRepository, CsarGitCheckoutLocation csarGitCheckoutLocation) {
Git git = null;
try {
// checkout the repository branch
log.debug("Checkout repository: url: [ {} ] branch [ {} ] to [ {} ]", csarGitRepository.getRepositoryUrl(), csarGitCheckoutLocation.getBranchId(), tempDirPath);
git = RepositoryManager.cloneOrCheckout(tempDirPath, csarGitRepository.getRepositoryUrl(), csarGitRepository.getUsername(), csarGitRepository.getPassword(), csarGitCheckoutLocation.getBranchId(), csarGitRepository.getId());
// if the repository is persistent we also have to pull to get the latest version
if (csarGitRepository.isStoredLocally() && !RepositoryManager.isATag(git, csarGitCheckoutLocation.getBranchId())) {
// try to pull
log.debug("Pull local repository");
RepositoryManager.pull(git, csarGitRepository.getUsername(), csarGitRepository.getPassword());
}
String hash = RepositoryManager.getLastHash(git);
log.debug("Importing archives from git repository, pulled hash is {}", hash);
// now that the repository is checked out and up to date process with the import
List<ParsingResult<Csar>> results = processImport(csarGitRepository, csarGitCheckoutLocation, hash);
if (!Objects.equals(csarGitCheckoutLocation.getLastImportedHash(), hash)) {
csarGitCheckoutLocation.setLastImportedHash(hash);
// update the hash for this location.
alienDAO.save(csarGitRepository);
}
// TODO best would be to provide with a better result to show that we didn't retried import
return results;
} finally {
RepositoryManager.close(git);
}
}
use of alien4cloud.tosca.parser.ParsingResult 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;
}
use of alien4cloud.tosca.parser.ParsingResult 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);
}
Aggregations