Search in sources :

Example 11 with RepositoryManagerException

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

the class RepositoryManagerDriver method createBuildRepository.

/**
 * Use the Indy client API to setup global and build-set level repos and groups, then setup the repo/group needed
 * for this build. Calculate the URL to use for resolving artifacts using the Indy Folo API (Folo is an artifact
 * activity-tracker). Return a new session ({@link IndyRepositorySession}) containing this information.
 *
 * @throws RepositoryManagerException In the event one or more repositories or groups can't be created to support
 *         the build (or product, or shared-releases).
 */
@Override
public RepositorySession createBuildRepository(BuildExecution buildExecution, String accessToken, String serviceAccountToken, RepositoryType repositoryType, Map<String, String> genericParameters, boolean brewPullActive) throws RepositoryManagerException {
    Indy indy = init(accessToken);
    Indy serviceAccountIndy = init(serviceAccountToken);
    String packageType = getIndyPackageTypeKey(repositoryType);
    String buildId = buildExecution.getBuildContentId();
    try {
        setupBuildRepos(buildExecution, packageType, serviceAccountIndy, genericParameters, brewPullActive);
    } catch (IndyClientException e) {
        logger.debug("Failed to setup repository or repository group for this build");
        throw new RepositoryManagerException("Failed to setup repository or repository group for this build: %s", e, e.getMessage());
    }
    // since we're setting up a group/hosted repo per build, we can pin the tracking ID to the build repo ID.
    String url;
    String deployUrl;
    try {
        // manually initialize the tracking record, just in case (somehow) nothing gets downloaded/uploaded.
        indy.module(IndyFoloAdminClientModule.class).initReport(buildId);
        StoreKey groupKey = new StoreKey(packageType, StoreType.group, buildId);
        url = indy.module(IndyFoloContentClientModule.class).trackingUrl(buildId, groupKey);
        StoreKey hostedKey = new StoreKey(packageType, StoreType.hosted, buildId);
        deployUrl = indy.module(IndyFoloContentClientModule.class).trackingUrl(buildId, hostedKey);
        if (INDY_SIDECAR_ENABLED) {
            logger.info("Indy sidecar feature enabled: replacing Indy host with Indy sidecar host");
            try {
                url = UrlUtils.replaceHostInUrl(url, INDY_SIDECAR_URL);
                deployUrl = UrlUtils.replaceHostInUrl(deployUrl, INDY_SIDECAR_URL);
            } catch (MalformedURLException e) {
                throw new RuntimeException(String.format("Indy sidecar url ('%s') or Indy urls ('%s', '%s') are malformed!", INDY_SIDECAR_URL, url, deployUrl));
            }
        }
        logger.info("Using '{}' for {} repository access in build: {}", url, packageType, buildId);
    } catch (IndyClientException e) {
        logger.debug("Failed to retrieve Indy client module for the artifact tracker");
        throw new RepositoryManagerException("Failed to retrieve Indy client module for the artifact tracker: %s", e, e.getMessage());
    }
    boolean tempBuild = buildExecution.isTempBuild();
    String buildPromotionTarget = tempBuild ? TEMP_BUILD_PROMOTION_TARGET : BUILD_PROMOTION_TARGET;
    BuildCategory buildCategory = getBuildCategory(genericParameters);
    ArtifactFilter artifactFilter = new ArtifactFilterImpl(ignoredPathPatternsPromotion, ignoredPathPatternsData, ignoredRepoPatterns);
    return new IndyRepositorySession(indy, serviceAccountIndy, buildId, packageType, new IndyRepositoryConnectionInfo(url, deployUrl), artifactFilter, buildPromotionTarget, buildCategory, tempBuild);
}
Also used : MalformedURLException(java.net.MalformedURLException) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyFoloAdminClientModule(org.commonjava.indy.folo.client.IndyFoloAdminClientModule) BuildCategory(org.jboss.pnc.enums.BuildCategory) Indy(org.commonjava.indy.client.core.Indy) IndyClientException(org.commonjava.indy.client.core.IndyClientException)

Example 12 with RepositoryManagerException

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

the class IndyRepositorySession method promoteDownloads.

/**
 * Promotes by path downloads captured in given map. The key in the map is promotion target store key. The value is
 * another map, where key is promotion source store key and value is list of paths to be promoted.
 *
 * @param depMap dependencies map
 * @throws RepositoryManagerException in case of an unexpected error during promotion
 * @throws PromotionValidationException when the promotion process results in an error due to validation failure
 */
private void promoteDownloads(Map<StoreKey, Map<StoreKey, Set<String>>> depMap) throws RepositoryManagerException, PromotionValidationException {
    for (Map.Entry<StoreKey, Map<StoreKey, Set<String>>> targetToSources : depMap.entrySet()) {
        StoreKey target = targetToSources.getKey();
        for (Map.Entry<StoreKey, Set<String>> sourceToPaths : targetToSources.getValue().entrySet()) {
            StoreKey source = sourceToPaths.getKey();
            PathsPromoteRequest req = new PathsPromoteRequest(source, target, sourceToPaths.getValue()).setPurgeSource(false);
            // set read-only only the generic http proxy hosted repos, not shared-imports
            boolean readonly = !isTempBuild && GENERIC_PKG_KEY.equals(target.getPackageType());
            StopWatch stopWatchDoPromote = StopWatch.createStarted();
            try {
                logger.info("BEGIN: doPromoteByPath: source: '{}', target: '{}', readonly: {}", req.getSource().toString(), req.getTarget().toString(), readonly);
                userLog.info("Promoting {} dependencies from {} to {}", req.getPaths().size(), req.getSource(), req.getTarget());
                doPromoteByPath(req, false, readonly);
                logger.info("END: doPromoteByPath: source: '{}', target: '{}', readonly: {}, took: {} seconds", req.getSource().toString(), req.getTarget().toString(), readonly, stopWatchDoPromote.getTime(TimeUnit.SECONDS));
            } catch (RepositoryManagerException ex) {
                logger.info("END: doPromoteByPath: source: '{}', target: '{}', readonly: {}, took: {} seconds", req.getSource().toString(), req.getTarget().toString(), readonly, stopWatchDoPromote.getTime(TimeUnit.SECONDS));
                throw ex;
            }
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PathsPromoteRequest(org.commonjava.indy.promote.model.PathsPromoteRequest) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) Map(java.util.Map) HashMap(java.util.HashMap) StoreKey(org.commonjava.indy.model.core.StoreKey) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 13 with RepositoryManagerException

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

the class IndyRepositorySession method getDownloadsTargetRepository.

private TargetRepository getDownloadsTargetRepository(TrackedContentEntryDTO download, IndyContentClientModule content) throws RepositoryManagerException {
    String identifier;
    String repoPath;
    StoreKey source = download.getStoreKey();
    RepositoryType repoType = toRepoType(source.getPackageType());
    if (repoType == RepositoryType.MAVEN || repoType == RepositoryType.NPM) {
        identifier = "indy-" + repoType.name().toLowerCase();
        repoPath = getTargetRepositoryPath(download, content);
    } else if (repoType == RepositoryType.GENERIC_PROXY) {
        identifier = "indy-http";
        repoPath = getGenericTargetRepositoryPath(source);
    } else {
        throw new RepositoryManagerException("Repository type " + repoType + " is not supported by Indy repo manager driver.");
    }
    if (!repoPath.endsWith("/")) {
        repoPath += '/';
    }
    return TargetRepository.newBuilder().identifier(identifier).repositoryType(repoType).repositoryPath(repoPath).temporaryRepo(false).build();
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 14 with RepositoryManagerException

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

the class IndyRepositorySession method getUploadsTargetRepository.

private TargetRepository getUploadsTargetRepository(RepositoryType repoType, IndyContentClientModule content) throws RepositoryManagerException {
    StoreKey storeKey;
    String identifier;
    if (repoType == RepositoryType.MAVEN) {
        storeKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildPromotionTarget);
        identifier = ReposiotryIdentifier.INDY_MAVEN;
    } else if (repoType == RepositoryType.NPM) {
        storeKey = new StoreKey(NPM_PKG_KEY, StoreType.hosted, buildPromotionTarget);
        identifier = ReposiotryIdentifier.INDY_NPM;
    } else {
        throw new RepositoryManagerException("Repository type " + repoType + " is not supported for uploads by Indy repo manager driver.");
    }
    String repoPath = "/api/" + content.contentPath(storeKey);
    if (!repoPath.endsWith("/")) {
        repoPath += '/';
    }
    return TargetRepository.newBuilder().identifier(identifier).repositoryType(repoType).repositoryPath(repoPath).temporaryRepo(isTempBuild).build();
}
Also used : RepositoryManagerException(org.jboss.pnc.spi.repositorymanager.RepositoryManagerException) StoreKey(org.commonjava.indy.model.core.StoreKey)

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