Search in sources :

Example 1 with RepositoryManagerException

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

the class IndyRepositorySession method deleteBuildGroup.

@Override
public void deleteBuildGroup() throws RepositoryManagerException {
    logger.info("BEGIN: Removing build aggregation group: {}", buildContentId);
    userLog.info("Removing build aggregation group");
    StopWatch stopWatch = StopWatch.createStarted();
    try {
        StoreKey key = new StoreKey(packageType, StoreType.group, buildContentId);
        serviceAccountIndy.stores().delete(key, "[Post-Build] Removing build aggregation group: " + buildContentId);
    } catch (IndyClientException e) {
        throw new RepositoryManagerException("Failed to retrieve Indy stores module. Reason: %s", e, e.getMessage());
    }
    logger.info("END: Removing build aggregation group: {}, took: {} seconds", buildContentId, stopWatch.getTime(TimeUnit.SECONDS));
    stopWatch.reset();
}
Also used : IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with RepositoryManagerException

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

the class IndyRepositorySession method collectUploads.

/**
 * Return list of output artifacts for promotion.
 *
 * @param report The tracking report that contains info about artifacts uploaded (output) from the build
 * @return List of output artifacts meta data
 * @throws RepositoryManagerException In case of a client API transport error or an error during promotion of
 *         artifacts
 */
private Uploads collectUploads(TrackedContentDTO report) throws RepositoryManagerException {
    List<Artifact> data;
    List<String> promotion;
    logger.info("BEGIN: Process artifacts uploaded from build");
    userLog.info("Processing built artifacts");
    StopWatch stopWatch = StopWatch.createStarted();
    Set<TrackedContentEntryDTO> uploads = report.getUploads();
    if (CollectionUtils.isEmpty(uploads)) {
        data = Collections.emptyList();
        promotion = Collections.emptyList();
    } else {
        data = new ArrayList<>();
        Set<String> promotionSet = new HashSet<>();
        IndyContentClientModule content;
        try {
            content = indy.content();
        } catch (IndyClientException e) {
            throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
        }
        for (TrackedContentEntryDTO upload : uploads) {
            String path = upload.getPath();
            StoreKey storeKey = upload.getStoreKey();
            if (artifactFilter.acceptsForData(upload)) {
                String identifier = computeIdentifier(upload);
                String purl = computePurl(upload);
                logger.info("Recording upload: {}", identifier);
                RepositoryType repoType = toRepoType(storeKey.getPackageType());
                TargetRepository targetRepository = getUploadsTargetRepository(repoType, content);
                ArtifactQuality artifactQuality = getArtifactQuality(isTempBuild);
                Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(upload.getMd5()).sha1(upload.getSha1()).sha256(upload.getSha256()).size(upload.getSize()).deployPath(upload.getPath()).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository).artifactQuality(artifactQuality).buildCategory(buildCategory);
                Artifact artifact = validateArtifact(artifactBuilder.build());
                data.add(artifact);
            }
            if (artifactFilter.acceptsForPromotion(upload, false)) {
                promotionSet.add(path);
                if (MAVEN_PKG_KEY.equals(storeKey.getPackageType()) && !isChecksum(path)) {
                    // add the standard checksums to ensure, they are promoted (Maven usually uses only one, so
                    // the other would be missing) but avoid adding checksums of checksums.
                    promotionSet.add(path + ".md5");
                    promotionSet.add(path + ".sha1");
                }
            }
        }
        promotion = new ArrayList<>(promotionSet);
    }
    logger.info("END: Process artifacts uploaded from build, took {} seconds", stopWatch.getTime(TimeUnit.SECONDS));
    return new Uploads(data, promotion);
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) StopWatch(org.apache.commons.lang3.time.StopWatch) TargetRepository(org.jboss.pnc.model.TargetRepository) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) ArtifactQuality(org.jboss.pnc.enums.ArtifactQuality) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with RepositoryManagerException

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

the class IndyRepositorySession method collectDownloadedArtifacts.

private List<Artifact> collectDownloadedArtifacts(TrackedContentDTO report) throws RepositoryManagerException {
    IndyContentClientModule content;
    try {
        content = indy.content();
    } catch (IndyClientException e) {
        throw new RepositoryManagerException("Failed to retrieve Indy content module. Reason: %s", e, e.getMessage());
    }
    Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    List<Artifact> deps = new ArrayList<>(downloads.size());
    for (TrackedContentEntryDTO download : downloads) {
        String path = download.getPath();
        if (artifactFilter.acceptsForData(download)) {
            String identifier = computeIdentifier(download);
            String purl = computePurl(download);
            logger.info("Recording download: {}", identifier);
            String originUrl = download.getOriginUrl();
            if (originUrl == null) {
                // this is from a hosted repository, either shared-imports or a build, or something like that.
                originUrl = download.getLocalUrl();
            }
            TargetRepository targetRepository = getDownloadsTargetRepository(download, content);
            Artifact.Builder artifactBuilder = Artifact.Builder.newBuilder().md5(download.getMd5()).sha1(download.getSha1()).sha256(download.getSha256()).size(download.getSize()).deployPath(path).originUrl(originUrl).importDate(Date.from(Instant.now())).filename(new File(path).getName()).identifier(identifier).purl(purl).targetRepository(targetRepository);
            Artifact artifact = validateArtifact(artifactBuilder.build());
            deps.add(artifact);
        }
    }
    return deps;
}
Also used : TargetRepository(org.jboss.pnc.model.TargetRepository) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) IndyContentClientModule(org.commonjava.indy.client.core.module.IndyContentClientModule) ArrayList(java.util.ArrayList) IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) File(java.io.File) Artifact(org.jboss.pnc.model.Artifact)

Example 4 with RepositoryManagerException

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

the class IndyRepositorySession method setHostedReadOnly.

/**
 * Sets readonly flag on a hosted repo after promotion. If it fails, it rolls back the promotion and throws
 * RepositoryManagerException.
 *
 * @param key the hosted repo key to be set readonly
 * @param promoter promote client module used for potential rollback
 * @param result the promotion result used for potential rollback
 * @throws IndyClientException in case the repo data cannot be loaded
 * @throws RepositoryManagerException in case the repo update fails
 */
private void setHostedReadOnly(StoreKey key, IndyPromoteClientModule promoter, PathsPromoteResult result) throws IndyClientException, RepositoryManagerException {
    HostedRepository hosted = serviceAccountIndy.stores().load(key, HostedRepository.class);
    hosted.setReadonly(true);
    try {
        serviceAccountIndy.stores().update(hosted, "Setting readonly after successful build and promotion.");
    } catch (IndyClientException ex) {
        try {
            promoter.rollbackPathPromote(result);
        } catch (IndyClientException ex2) {
            logger.error("Failed to set readonly flag on repo: {}. Reason given was: {}.", key, ex.getMessage(), ex);
            throw new RepositoryManagerException("Subsequently also failed to rollback the promotion of paths from %s to %s. Reason " + "given was: %s", ex2, result.getRequest().getSource(), result.getRequest().getTarget(), ex2.getMessage());
        }
        throw new RepositoryManagerException("Failed to set readonly flag on repo: %s. Reason given was: %s", ex, key, ex.getMessage());
    }
}
Also used : IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 5 with RepositoryManagerException

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

the class IndyRepositorySession method sealAndGetTrackingReport.

private TrackedContentDTO sealAndGetTrackingReport(boolean seal) throws RepositoryManagerException {
    TrackedContentDTO report;
    try {
        IndyFoloAdminClientModule foloAdmin = indy.module(IndyFoloAdminClientModule.class);
        if (seal) {
            userLog.info("Sealing tracking record");
            boolean sealed = foloAdmin.sealTrackingRecord(buildContentId);
            if (!sealed) {
                throw new RepositoryManagerException("Failed to seal content-tracking record for: %s.", buildContentId);
            }
        }
        userLog.info("Getting tracking report");
        report = foloAdmin.getTrackingReport(buildContentId);
    } catch (IndyClientException e) {
        throw new RepositoryManagerException("Failed to retrieve tracking report for: %s. Reason: %s", e, buildContentId, e.getMessage());
    }
    if (report == null) {
        throw new RepositoryManagerException("Failed to retrieve tracking report for: %s.", buildContentId);
    }
    return report;
}
Also used : IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) IndyClientException(org.commonjava.indy.client.core.IndyClientException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

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