Search in sources :

Example 41 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ProxyResponseWriter method getRepository.

private RemoteRepository getRepository(final URL url) throws IndyDataException {
    int port = url.getPort();
    if (port < 1) {
        port = url.getDefaultPort();
    }
    String name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + '_' + port;
    final String baseUrl = String.format("%s://%s:%s/", url.getProtocol(), url.getHost(), port);
    ArtifactStoreQuery<RemoteRepository> query = storeManager.query().packageType(GENERIC_PKG_KEY).storeType(RemoteRepository.class);
    RemoteRepository remote = query.getRemoteRepositoryByUrl(baseUrl);
    if (remote == null) {
        logger.debug("Looking for remote repo with name: {}", name);
        remote = query.getByName(name);
        // if repo with this name already exists, it has a different url, so we need to use a different name
        int i = 1;
        while (remote != null) {
            name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + "_" + i++;
            logger.debug("Looking for remote repo with name: {}", name);
            remote = query.getByName(name);
        }
    }
    if (remote == null) {
        logger.debug("Creating remote repository for HTTProx request: {}", url);
        final UrlInfo info = new UrlInfo(url.toExternalForm());
        if (repoCreator == null) {
            throw new IndyDataException("No valid instance of ProxyRepositoryCreator. Cannot auto-create remote proxy to: '{}'", baseUrl);
        }
        final UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
        remote = repoCreator.create(name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
        remote.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
        final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
        storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
    }
    return remote;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) UrlInfo(org.commonjava.indy.util.UrlInfo) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) UserPass(org.commonjava.indy.subsys.http.util.UserPass) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 42 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class KojiContentManagerDecorator method adjustTargetGroup.

private Group adjustTargetGroup(final RemoteRepository buildRepo, final Group group) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    // try to lookup the group -> targetGroup mapping in config, using the
    // entry-point group as the lookup key. If that returns null, the targetGroup is
    // the entry-point group.
    Group targetGroup = group;
    boolean isBinaryBuild = KOJI_ORIGIN_BINARY.equals(buildRepo.getMetadata(ArtifactStore.METADATA_ORIGIN));
    String targetName = isBinaryBuild ? config.getTargetBinaryGroup(group.getName()) : config.getTargetGroup(group.getName());
    if (targetName != null) {
        try {
            targetGroup = storeDataManager.query().packageType(group.getPackageType()).getGroup(targetName);
        } catch (IndyDataException e) {
            throw new IndyWorkflowException("Cannot lookup koji-addition target group: %s (source group: %s). Reason: %s", e, targetName, group.getName(), e.getMessage());
        }
    }
    logger.info("Adding Koji build proxy: {} to group: {}", buildRepo.getKey(), targetGroup.getKey());
    // Append the new remote repo as a member of the targetGroup.
    targetGroup.addConstituent(buildRepo);
    try {
        final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding remote repository for Koji build: " + buildRepo.getMetadata(NVR));
        storeDataManager.storeArtifactStore(targetGroup, changeSummary, false, true, new EventMetadata());
    } catch (IndyDataException e) {
        throw new IndyWorkflowException("Cannot store target-group: %s changes for: %s. Error: %s", e, targetGroup.getName(), buildRepo.getMetadata(NVR), e.getMessage());
    }
    logger.info("Retrieving GAV: {} from: {}", buildRepo.getMetadata(CREATION_TRIGGER_GAV), buildRepo);
    return targetGroup;
// TODO: how to index it for the group...?
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Logger(org.slf4j.Logger) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 43 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class KojiOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> repos;
    try {
        repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    repos.forEach((repo) -> {
        if (repo.getDescription() != null && repo.getDescription().contains("Koji build")) {
            repo.setMetadata(METADATA_ORIGIN, KOJI_ORIGIN);
            toStore.add(repo);
        }
    });
    final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding Koji origin metadata");
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with Koji origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
        }
    }
    return !toStore.isEmpty();
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 44 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ImpliedRepoMaintainer method processImpliedRepos.

private boolean processImpliedRepos(final ImpliedRepoMaintJob job) {
    final Set<StoreKey> processed = new HashSet<>();
    // implications. Reachable means they could be in nested groups.
    for (final ArtifactStore member : job.reachableMembers) {
        processed.add(member.getKey());
    }
    logger.debug("Preset processed-implications to reachable members:\n  {}", new JoinString("\n  ", processed));
    int lastLen = 0;
    boolean changed = false;
    job.added = new ArrayList<>();
    // As soon as we go an iteration without adding a new member, we've captured everything.
    do {
        lastLen = job.members.size();
        for (final ArtifactStore member : new ArrayList<>(job.members)) {
            logger.debug("Processing member: {} for implied repos within group: {}", member.getKey(), job.group.getKey());
            processed.add(member.getKey());
            List<StoreKey> implied;
            try {
                implied = metadataManager.getStoresImpliedBy(member);
            } catch (final ImpliedReposException e) {
                logger.error("Failed to retrieve implied-store metadata for: " + member.getKey(), e);
                continue;
            }
            if (implied == null || implied.isEmpty()) {
                continue;
            }
            implied.removeAll(processed);
            for (final StoreKey key : implied) {
                logger.debug("Found implied store: {} not already in group: {}", key, job.group.getKey());
                ArtifactStore impliedStore;
                try {
                    impliedStore = storeManager.getArtifactStore(key);
                } catch (final IndyDataException e) {
                    logger.error("Failed to retrieve store: " + key + " implied by: " + member.getKey(), e);
                    continue;
                }
                logger.info("Adding: {} to group: {} (implied by POMs in: {})", key, job.group.getKey(), member.getKey());
                processed.add(key);
                job.added.add(key);
                job.group.addConstituent(key);
                job.members.add(impliedStore);
                changed = true;
            }
        }
    } while (job.members.size() > lastLen);
    return changed;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 45 with IndyDataException

use of org.commonjava.indy.data.IndyDataException in project indy by Commonjava.

the class ImpliedRepoMaintainer method initJob.

private boolean initJob(final ImpliedRepoMaintJob job) {
    // we might be able to fix the repo-removal problem too.
    if (!(job.store instanceof Group)) {
        logger.debug("ImpliedRepoMaint: Ignoring non-group: {}", job.store.getKey());
        return false;
    }
    if (!config.isEnabledForGroup(job.store.getName())) {
        logger.debug("ImpliedRepoMaint: Implied repositories not enabled for group: {}", job.store.getKey());
        return false;
    }
    logger.debug("Processing group: {} for stores implied by membership which are not yet in the membership", job.store.getName());
    job.group = (Group) job.store;
    try {
        // getOrderedStoresInGroup(), but we can't use persisted info...
        job.members = loadMemberStores(job.group, job);
        // getOrderedConcreteStores(), but we can't use the persisted info...
        final LinkedHashSet<ArtifactStore> reachable = new LinkedHashSet<>(job.members.size());
        for (final ArtifactStore member : job.members) {
            if (member instanceof Group) {
                reachable.addAll(loadMemberStores((Group) member, job));
            } else {
                reachable.add(member);
            }
        }
        job.reachableMembers = new ArrayList<>(reachable);
        logger.debug("For group: {}\n Members: {}\n  Reachable Concrete Members: {}", job.group.getKey(), job.members, job.reachableMembers);
    } catch (final IndyDataException e) {
        logger.error("Failed to retrieve member stores for group: " + job.group.getName(), e);
    }
    if (job.members == null) {
        logger.debug("ImpliedRepoMaint: Group: {} has no membership", job.store.getKey());
        return false;
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Aggregations

IndyDataException (org.commonjava.indy.data.IndyDataException)75 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)50 StoreKey (org.commonjava.indy.model.core.StoreKey)30 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)26 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)24 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)24 Transfer (org.commonjava.maven.galley.model.Transfer)19 ArrayList (java.util.ArrayList)17 Group (org.commonjava.indy.model.core.Group)17 IOException (java.io.IOException)16 Logger (org.slf4j.Logger)16 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)14 HashSet (java.util.HashSet)10 List (java.util.List)7 StoreType (org.commonjava.indy.model.core.StoreType)7 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)7 HostedRepository (org.commonjava.indy.model.core.HostedRepository)6 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)6 ContentGenerator (org.commonjava.indy.content.ContentGenerator)5 InputStream (java.io.InputStream)4