Search in sources :

Example 6 with RepositoryManagerException

use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.

the class IndyRepositorySession method extractBuildArtifacts.

/**
 * Retrieve tracking report from repository manager. Add each tracked download to the dependencies of the build
 * result. Add each tracked upload to the built artifacts of the build result. Promote uploaded artifacts to the
 * product-level storage. Finally delete the group associated with the completed build.
 *
 * @param liveBuild {@inheritDoc} - if true, the promotion of the collected artifacts and dependencies is done,
 *        tracking report is sealed and the build group is removed, if false it only reads the data without any
 *        actions
 */
@Override
public RepositoryManagerResult extractBuildArtifacts(final boolean liveBuild) throws RepositoryManagerException {
    TrackedContentDTO report = sealAndGetTrackingReport(liveBuild);
    Comparator<Artifact> comp = (one, two) -> one.getIdentifier().compareTo(two.getIdentifier());
    Uploads uploads = collectUploads(report);
    List<Artifact> uploadedArtifacts = uploads.getData();
    Collections.sort(uploadedArtifacts, comp);
    List<Artifact> downloadedArtifacts = null;
    String log = "";
    CompletionStatus status = CompletionStatus.SUCCESS;
    try {
        downloadedArtifacts = processDownloads(report, liveBuild);
        Collections.sort(downloadedArtifacts, comp);
    } catch (PromotionValidationException ex) {
        status = CompletionStatus.FAILED;
        log = ex.getMessage();
        logger.warn("Dependencies promotion failed. Error(s): {}", log);
        userLog.error("Dependencies promotion failed. Error(s): {}", log);
    }
    if (liveBuild) {
        deleteBuildGroup();
    }
    // if the promotion of dependencies succeeded...
    if (status == CompletionStatus.SUCCESS) {
        logger.info("Returning built artifacts / dependencies:\nUploads:\n  {}\n\nDownloads:\n  {}\n\n", StringUtils.join(uploads.getData(), "\n  "), StringUtils.join(downloadedArtifacts, "\n  "));
        if (liveBuild) {
            logger.info("BEGIN: promotion to build content set");
            StopWatch stopWatch = StopWatch.createStarted();
            try {
                promoteToBuildContentSet(uploads.getPromotion());
            } catch (PromotionValidationException ex) {
                status = CompletionStatus.FAILED;
                log = ex.getMessage();
                logger.warn("Built artifact promotion failed. Error(s): {}", log);
                userLog.error("Built artifact promotion failed. Error(s): {}", log);
            }
            logger.info("END: promotion to build content set, took: {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
            stopWatch.reset();
        }
    }
    if (status == CompletionStatus.FAILED) {
        // prevent saving artifacts and dependencies to a failed build
        downloadedArtifacts = Collections.emptyList();
        uploadedArtifacts = Collections.emptyList();
    }
    return new IndyRepositoryManagerResult(uploadedArtifacts, downloadedArtifacts, buildContentId, log, status);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Date(java.util.Date) ValidationResult(org.commonjava.indy.promote.model.ValidationResult) LoggerFactory(org.slf4j.LoggerFactory) AbstractPromoteResult(org.commonjava.indy.promote.model.AbstractPromoteResult) Map(java.util.Map) ConstraintViolation(javax.validation.ConstraintViolation) StoreKey(org.commonjava.indy.model.core.StoreKey) TargetRepository(org.jboss.pnc.model.TargetRepository) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) NpmPackageRef(org.commonjava.atlas.npm.ident.ref.NpmPackageRef) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) StringUtils.isEmpty(org.apache.commons.lang.StringUtils.isEmpty) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) Artifact(org.jboss.pnc.model.Artifact) StoreType(org.commonjava.indy.model.core.StoreType) Validator(javax.validation.Validator) Set(java.util.Set) StopWatch(org.apache.commons.lang3.time.StopWatch) Instant(java.time.Instant) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) IndyPromoteClientModule(org.commonjava.indy.promote.client.IndyPromoteClientModule) IOUtils(org.apache.commons.io.IOUtils) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) List(java.util.List) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) IndyClientException(org.commonjava.indy.client.core.IndyClientException) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) NPM_PKG_KEY(org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_PKG_KEY) PackageURL(com.github.packageurl.PackageURL) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) SHARED_IMPORTS_ID(org.jboss.pnc.indyrepositorymanager.IndyRepositoryConstants.SHARED_IMPORTS_ID) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ReposiotryIdentifier(org.jboss.pnc.constants.ReposiotryIdentifier) MalformedPackageURLException(com.github.packageurl.MalformedPackageURLException) CollectionUtils(org.apache.commons.collections.CollectionUtils) RepositoryType(org.jboss.pnc.enums.RepositoryType) Validation(javax.validation.Validation) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) Logger(org.slf4j.Logger) Indy(org.commonjava.indy.client.core.Indy) PathsPromoteResult(org.commonjava.indy.promote.model.PathsPromoteResult) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) HostedRepository(org.commonjava.indy.model.core.HostedRepository) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) PackageURLBuilder(com.github.packageurl.PackageURLBuilder) BuildCategory(org.jboss.pnc.enums.BuildCategory) Comparator(java.util.Comparator) NpmPackagePathInfo(org.commonjava.atlas.npm.ident.util.NpmPackagePathInfo) Collections(java.util.Collections) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) Artifact(org.jboss.pnc.model.Artifact) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 7 with RepositoryManagerException

use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.

the class IndyRunningPromotion method monitor.

/**
 * Trigger the repository promotion configured for this instance, and send the result to the appropriate consumer.
 *
 * @param onComplete The consumer which will handle non-error results
 * @param onError Handles errors
 */
@Override
public void monitor(Consumer<CompletedRepositoryPromotion> onComplete, Consumer<Exception> onError) {
    try {
        StoreKey fromKey = new StoreKey(pakageType, fromType, fromId);
        if (!indy.stores().exists(fromKey)) {
            throw new RepositoryManagerException("No such %s repository: %s", fromType.singularEndpointName(), fromId);
        }
        StoreKey toKey = new StoreKey(pakageType, StoreType.group, toId);
        Group recordSetGroup = indy.stores().load(toKey, Group.class);
        if (recordSetGroup == null) {
            throw new RepositoryManagerException("No such group: %s", toId);
        }
        recordSetGroup.addConstituent(fromKey);
        boolean result = indy.stores().update(recordSetGroup, "Promoting " + fromType.singularEndpointName() + " repository : " + fromId + " to group: " + toId);
        onComplete.accept(new IndyCompletedPromotion(result));
    } catch (IndyClientException | RepositoryManagerException e) {
        onError.accept(e);
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 8 with RepositoryManagerException

use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.

the class DefaultBuildExecutor method cancel.

@Override
public void cancel(String executionConfigurationId) throws ExecutorException {
    DefaultBuildExecutionSession buildExecutionSession = runningExecutions.get(executionConfigurationId);
    if (buildExecutionSession != null) {
        log.info("Cancelling build {}.", buildExecutionSession.getId());
        if (buildExecutionSession.cancel()) {
            String buildContentId = buildExecutionSession.getBuildExecutionConfiguration().getBuildContentId();
            RunningEnvironment runningEnvironment = buildExecutionSession.getRunningEnvironment();
            if (runningEnvironment == null) {
                log.warn("Could not retrieve running environment for build {}", buildContentId);
            } else {
                RepositorySession repositorySession = runningEnvironment.getRepositorySession();
                if (repositorySession == null) {
                    log.warn("Could not retrieve repository session for build {}", buildContentId);
                } else {
                    try {
                        repositorySession.deleteBuildGroup();
                    } catch (RepositoryManagerException e) {
                        log.error("Error deleting build group for build " + buildContentId + " when canceling it.", e);
                    }
                }
            }
        }
    } else {
        log.warn("Trying to cancel non existing session.");
    }
}
Also used : RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) RunningEnvironment(org.jboss.pnc.spi.environment.RunningEnvironment)

Example 9 with RepositoryManagerException

use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.

the class BuildMaintenanceEndpointImpl method collectRepoManagerResult.

@Override
public Response collectRepoManagerResult(String id) {
    logger.info("Getting repository manager result for build record id {}.", id);
    RepositoryManagerResult result;
    try {
        result = repositoryManager.collectRepoManagerResult(id);
    } catch (RepositoryManagerException ex) {
        logger.error("Error when collecting repository manager result for build record " + id, ex);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.toString()).build();
    }
    if (result == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    return Response.ok(result).build();
}
Also used : RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException)

Example 10 with RepositoryManagerException

use of org.jboss.pnc.spi.repositorymanager.RepositoryManagerException in project pnc by project-ncl.

the class ExtraDependencyRepositoriesTest method shouldAddExtraRepositoryToBuildGroup.

@Test
public void shouldAddExtraRepositoryToBuildGroup() throws RepositoryManagerException, IndyClientException {
    final String REPO_NAME = "i-test-com";
    Map<String, String> genericParams = createGenericParamsMap("http://test.com/maven/");
    BuildExecution execution = new TestBuildExecution();
    RepositorySession repositorySession = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, genericParams, false);
    assertNotNull(repositorySession);
    StoreKey buildGroupKey = new StoreKey(MavenPackageTypeDescriptor.MAVEN_PKG_KEY, StoreType.group, repositorySession.getBuildRepositoryId());
    Group buildGroup = indy.stores().load(buildGroupKey, Group.class);
    long hits = buildGroup.getConstituents().stream().filter((key) -> REPO_NAME.equals(key.getName())).count();
    assertEquals(1, hits);
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildConfigurationParameterKeys(org.jboss.pnc.api.constants.BuildConfigurationParameterKeys) ArtifactRepository(org.jboss.pnc.spi.repositorymanager.ArtifactRepository) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) Assert.assertNotNull(org.junit.Assert.assertNotNull) StoreType(org.commonjava.indy.model.core.StoreType) Test(org.junit.Test) HashMap(java.util.HashMap) Category(org.junit.experimental.categories.Category) Group(org.commonjava.indy.model.core.Group) ContainerTest(org.jboss.pnc.test.category.ContainerTest) List(java.util.List) MavenPackageTypeDescriptor(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryType(org.jboss.pnc.enums.RepositoryType) Map(java.util.Map) IndyClientException(org.commonjava.indy.client.core.IndyClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) Assert.assertEquals(org.junit.Assert.assertEquals) Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Aggregations

RepositoryManagerException (org.jboss.pnc.spi.repositorymanager.RepositoryManagerException)14 IndyClientException (org.commonjava.indy.client.core.IndyClientException)9 StoreKey (org.commonjava.indy.model.core.StoreKey)9 StopWatch (org.apache.commons.lang3.time.StopWatch)4 RepositoryType (org.jboss.pnc.enums.RepositoryType)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 IndyContentClientModule (org.commonjava.indy.client.core.module.IndyContentClientModule)3 IndyFoloAdminClientModule (org.commonjava.indy.folo.client.IndyFoloAdminClientModule)3 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)3 Artifact (org.jboss.pnc.model.Artifact)3 TargetRepository (org.jboss.pnc.model.TargetRepository)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)2 HostedRepository (org.commonjava.indy.model.core.HostedRepository)2 ArtifactQuality (org.jboss.pnc.enums.ArtifactQuality)2