Search in sources :

Example 6 with ParsingResult

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

the class ArchiveParserUtil method cleanup.

public static <T> ParsingResult<T> cleanup(ParsingResult<?> result) {
    ParsingContext context = new ParsingContext(result.getContext().getFileName());
    context.getParsingErrors().addAll(result.getContext().getParsingErrors());
    return new ParsingResult<T>(null, context);
}
Also used : ParsingContext(alien4cloud.tosca.parser.ParsingContext) ParsingResult(alien4cloud.tosca.parser.ParsingResult)

Example 7 with ParsingResult

use of alien4cloud.tosca.parser.ParsingResult 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 8 with ParsingResult

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

the class CsarGitService method importFromGitRepository.

/**
 * Import Cloud Service ARchives from a git repository.
 *
 * @param id The id to access the git repository.
 * @return The result of the import (that may contains errors etc.)
 */
public List<ParsingResult<Csar>> importFromGitRepository(String id) {
    CsarGitRepository csarGitRepository = csarGitRepositoryService.getOrFail(id);
    List<ParsingResult<Csar>> results = Lists.newArrayList();
    try {
        // Iterate over locations (branches, folders etc.) and process the import
        for (CsarGitCheckoutLocation csarGitCheckoutLocation : csarGitRepository.getImportLocations()) {
            List<ParsingResult<Csar>> result = doImport(csarGitRepository, csarGitCheckoutLocation);
            if (result != null) {
                results.addAll(result);
            }
        }
    } finally {
        // cleanup
        Path archiveZipRoot = tempZipDirPath.resolve(csarGitRepository.getId());
        Path archiveGitRoot = tempDirPath.resolve(csarGitRepository.getId());
        try {
            FileUtil.delete(archiveZipRoot);
            if (!csarGitRepository.isStoredLocally()) {
                FileUtil.delete(archiveGitRoot);
            }
        } catch (IOException e) {
            log.error("Failed to cleanup files after git import.", e);
        }
    }
    return results;
}
Also used : Path(java.nio.file.Path) ParsingResult(alien4cloud.tosca.parser.ParsingResult) CsarGitCheckoutLocation(alien4cloud.model.git.CsarGitCheckoutLocation) CsarGitRepository(alien4cloud.model.git.CsarGitRepository) IOException(java.io.IOException)

Example 9 with ParsingResult

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

the class CsarGitServiceTest method importArchiveInProperOrder.

@Test
public void importArchiveInProperOrder() {
    CsarGitCheckoutLocation normativeTypesMasterLocation = new CsarGitCheckoutLocation();
    normativeTypesMasterLocation.setBranchId("1.2.0");
    List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
    importLocations.add(normativeTypesMasterLocation);
    String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
    List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
    Assert.assertFalse(result.get(0).hasError(ParsingErrorLevel.ERROR));
    CsarGitCheckoutLocation testArchiveLocation = new CsarGitCheckoutLocation();
    testArchiveLocation.setBranchId("test-order-import");
    importLocations.clear();
    importLocations.add(testArchiveLocation);
    repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/samples.git", "", "", importLocations, false);
    List<ParsingResult<Csar>> sampleResult = csarGitService.importFromGitRepository(repoId);
    Assert.assertEquals(3, sampleResult.size());
    for (ParsingResult<Csar> csarParsingResult : sampleResult) {
        boolean hasError = csarParsingResult.hasError(ParsingErrorLevel.ERROR);
        if (hasError) {
            ParserTestUtil.displayErrors(csarParsingResult);
        }
        Assert.assertFalse(hasError);
    }
    Assert.assertEquals("test-archive-1", sampleResult.get(0).getResult().getName());
    Assert.assertEquals("test-archive-3", sampleResult.get(1).getResult().getName());
    Assert.assertEquals("test-archive-2", sampleResult.get(2).getResult().getName());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ParsingResult(alien4cloud.tosca.parser.ParsingResult) CsarGitCheckoutLocation(alien4cloud.model.git.CsarGitCheckoutLocation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 10 with ParsingResult

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

the class CsarGitServiceTest method importOneBranchFromGit.

@Test
public void importOneBranchFromGit() {
    CsarGitCheckoutLocation alien12Location = new CsarGitCheckoutLocation();
    alien12Location.setBranchId("1.2.0");
    List<CsarGitCheckoutLocation> importLocations = new LinkedList<>();
    importLocations.add(alien12Location);
    String repoId = csarGitRepositoryService.create("https://github.com/alien4cloud/tosca-normative-types.git", "", "", importLocations, false);
    List<ParsingResult<Csar>> result = csarGitService.importFromGitRepository(repoId);
    Assert.assertEquals(1, result.size());
    Assert.assertEquals("tosca-normative-types", result.get(0).getResult().getName());
}
Also used : ParsingResult(alien4cloud.tosca.parser.ParsingResult) CsarGitCheckoutLocation(alien4cloud.model.git.CsarGitCheckoutLocation) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

ParsingResult (alien4cloud.tosca.parser.ParsingResult)10 CsarGitCheckoutLocation (alien4cloud.model.git.CsarGitCheckoutLocation)5 ParsingContext (alien4cloud.tosca.parser.ParsingContext)4 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4 Path (java.nio.file.Path)3 Csar (org.alien4cloud.tosca.model.Csar)3 ParsingException (alien4cloud.tosca.parser.ParsingException)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)2 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)1 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 CsarGitRepository (alien4cloud.model.git.CsarGitRepository)1 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 ParsingError (alien4cloud.tosca.parser.ParsingError)1 IOException (java.io.IOException)1 Git (org.eclipse.jgit.api.Git)1