Search in sources :

Example 56 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class ImpliedReposQueryDelegate method maybeFilter.

private List<ArtifactStore> maybeFilter(String groupName, List<ArtifactStore> delegateResult) {
    Logger logger = LoggerFactory.getLogger(getClass());
    if (delegateResult == null || delegateResult.isEmpty() || config.isEnabledForGroup(groupName)) {
        logger.trace("Implied repositories are enabled for group: '{}'. Returning all membership from delegate result.", groupName);
        return delegateResult;
    }
    logger.trace("Filtering stores with metadata: '{}' value of '{}' from membership results", METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
    List<ArtifactStore> result = new ArrayList<>();
    delegateResult.stream().filter((store) -> !IMPLIED_REPO_ORIGIN.equals(store.getMetadata(METADATA_ORIGIN))).forEach((store) -> result.add(store));
    return result;
}
Also used : ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) StringUtils(org.apache.commons.lang.StringUtils) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IMPLIED_REPO_ORIGIN(org.commonjava.indy.implrepo.data.ImpliedReposStoreDataManagerDecorator.IMPLIED_REPO_ORIGIN) LoggerFactory(org.slf4j.LoggerFactory) METADATA_ORIGIN(org.commonjava.indy.model.core.ArtifactStore.METADATA_ORIGIN) DelegatingArtifactStoreQuery(org.commonjava.indy.data.DelegatingArtifactStoreQuery) Set(java.util.Set) Collectors(java.util.stream.Collectors) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) ImpliedRepoConfig(org.commonjava.indy.implrepo.conf.ImpliedRepoConfig) Collections(java.util.Collections) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger)

Example 57 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class ImpliedRepoMetadataManager method addImpliedMetadata.

// TODO: Need to deal with pre-existing implications.
public void addImpliedMetadata(final ArtifactStore origin, final List<ArtifactStore> implied) throws ImpliedReposException {
    try {
        final List<StoreKey> impliedKeys = new ArrayList<>(implied.size());
        for (final ArtifactStore store : implied) {
            impliedKeys.add(store.getKey());
            updateImpliedBy(store, origin);
        }
        origin.setMetadata(IMPLIED_STORES, mapper.writeValueAsString(new ImpliedRemotesWrapper(impliedKeys)));
    } catch (final JsonProcessingException e) {
        throw new ImpliedReposException("Failed to serialize implied stores: %s to JSON: %s. Error: %s", e, implied, origin.getKey(), e.getMessage());
    }
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ImpliedReposException(org.commonjava.indy.implrepo.ImpliedReposException)

Example 58 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class KojiBuildAuthority method isAuthorized.

@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_BUILDAUTHORITY_ISAUTHORIZED + IndyMetricsNames.METER)))
public boolean isAuthorized(String path, EventMetadata eventMetadata, ProjectRef ref, KojiBuildInfo build, KojiSessionInfo session, Map<Integer, KojiBuildArchiveCollection> seenBuildArchives) throws KojiClientException {
    ArtifactStore authoritativeStore = getAuthoritativeStore();
    if (authoritativeStore != null) {
        KojiBuildArchiveCollection archiveCollection = seenBuildArchives.get(build.getId());
        if (archiveCollection == null) {
            archiveCollection = kojiClient.listArchivesForBuild(build, session);
            seenBuildArchives.put(build.getId(), archiveCollection);
        }
        if (archiveCollection == null) {
            throw new KojiClientException("Failed to retrieve archives for build: %s", build);
        }
        // @formatter:off
        Predicate<KojiArchiveInfo> archiveInfoFilter = (archive) -> EXCLUDED_FILE_ENDINGS.stream().allMatch(ending -> !archive.getFilename().endsWith(ending));
        List<KojiArchiveInfo> sortedArchives = archiveCollection.getArchives().stream().filter(archiveInfoFilter).sorted((a1, a2) -> {
            TypePriority t1 = TypePriority.get(a1.getExtension());
            TypePriority t2 = TypePriority.get(a2.getExtension());
            return Integer.valueOf(t1.ordinal()).compareTo(t2.ordinal());
        }).collect(Collectors.toList());
        for (KojiArchiveInfo archive : sortedArchives) {
            try {
                if (isMavenArtifact(archive)) {
                    // skip non-Maven artifacts
                    continue;
                }
                if (containsPlaceholders(archive)) {
                    return false;
                }
                String artifactPath = ArtifactPathUtils.formatArtifactPath(archive.asArtifact(), typeMapper);
                String md5 = checksumArtifact(authoritativeStore, artifactPath, eventMetadata);
                if (isNotBlank(md5)) {
                    //FIXME: not sure if all koji archives are using md5 as checksum type for maven build
                    String kojiMd5 = archive.getChecksum();
                    Logger logger = LoggerFactory.getLogger(getClass());
                    logger.info("Checking checksum for {} (path: {}) in auth store {}, auth store checksum:{}, koji build check sum:{}", ref, path, authoritativeStore, md5, kojiMd5);
                    if (!md5.equals(kojiMd5)) {
                        // if checksum is not the same, it means the artifact in koji is DIFFERENT from the one in the authoritative store. Reject this.
                        return false;
                    }
                }
            } catch (Exception e) {
                Logger logger = LoggerFactory.getLogger(getClass());
                logger.error("SHOULD NEVER HAPPEN: Failed to transform artifact to path: " + e.getMessage(), e);
            }
        }
    }
    return true;
}
Also used : Arrays(java.util.Arrays) ContentDigester(org.commonjava.indy.content.ContentDigester) LoggerFactory(org.slf4j.LoggerFactory) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) HashMap(java.util.HashMap) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) FORCE_CHECKSUM(org.commonjava.maven.galley.io.ChecksummingTransferDecorator.FORCE_CHECKSUM) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) MetricNamed(org.commonjava.indy.measure.annotation.MetricNamed) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Map(java.util.Map) StringUtils.trimToEmpty(org.apache.commons.lang.StringUtils.trimToEmpty) ContentDigest(org.commonjava.maven.galley.io.checksum.ContentDigest) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) KojiClientException(com.redhat.red.build.koji.KojiClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) ArtifactPathUtils(org.commonjava.maven.galley.maven.util.ArtifactPathUtils) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Predicate(java.util.function.Predicate) KojiClient(com.redhat.red.build.koji.KojiClient) StringUtils.contains(org.apache.commons.lang.StringUtils.contains) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StringUtils.isNotBlank(org.apache.commons.lang.StringUtils.isNotBlank) IndyMetricsKojiNames(org.commonjava.indy.koji.metrics.IndyMetricsKojiNames) IOUtils(org.apache.commons.io.IOUtils) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) Measure(org.commonjava.indy.measure.annotation.Measure) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) IndyMetricsNames(org.commonjava.indy.IndyMetricsNames) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) ApplicationScoped(javax.enterprise.context.ApplicationScoped) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) Collections(java.util.Collections) TRUE(java.lang.Boolean.TRUE) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) InputStream(java.io.InputStream) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Logger(org.slf4j.Logger) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiClientException(com.redhat.red.build.koji.KojiClientException) IOException(java.io.IOException) IndyDataException(org.commonjava.indy.data.IndyDataException) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics)

Example 59 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore 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 60 with ArtifactStore

use of org.commonjava.indy.model.core.ArtifactStore in project indy by Commonjava.

the class ImpliedRepoMaintainer method loadMemberStores.

private List<ArtifactStore> loadMemberStores(final Group group, final ImpliedRepoMaintJob job) throws IndyDataException {
    final List<StoreKey> constituents = new ArrayList<>(group.getConstituents());
    final List<ArtifactStore> members = new ArrayList<>(constituents.size());
    for (final StoreKey memberKey : constituents) {
        ArtifactStore store = job.currentStores.get(memberKey);
        if (store == null) {
            store = storeManager.getArtifactStore(memberKey);
        }
        if (store == null) {
            logger.warn("Store not found for key: {} (member of: {})", memberKey, group.getKey());
            continue;
        }
        members.add(store);
    }
    return members;
}
Also used : ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8