Search in sources :

Example 46 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class CassandraNotFoundCache method clearMissing.

@Override
@Measure
public void clearMissing(final Location location) {
    StoreKey key = ((KeyedLocation) location).getKey();
    BoundStatement bound = preparedDeleteByStore.bind(key.toString());
    session.execute(bound);
    clearInMemoryCache(location);
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) StoreKey(org.commonjava.indy.model.core.StoreKey) BoundStatement(com.datastax.driver.core.BoundStatement) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 47 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class FoloRecordCache method recordArtifact.

/**
 * Add a new artifact upload/download item to given affected store within a tracked-content record. If the tracked-content record doesn't exist,
 * or doesn't contain the specified affected store, values will be created on-demand.
 * @param entry The TrackedContentEntry which will be cached
 * @return True if a new record was stored, otherwise false
 */
@Override
@Measure
public synchronized boolean recordArtifact(final TrackedContentEntry entry) throws FoloContentException, IndyWorkflowException {
    if (sealedRecordCache.containsKey(entry.getTrackingKey())) {
        throw new FoloContentException("Tracking record: {} is already sealed!", entry.getTrackingKey());
    }
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Adding tracking entry: {}", entry);
    return inProgressRecordCache.executeCache((cache) -> {
        TrackedContentEntry existing = cache.get(entry);
        if (existing != null) {
            existing.merge(entry);
            cache.put(existing, existing);
        } else {
            cache.put(entry, entry);
        }
        return true;
    });
}
Also used : TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 48 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class PromotionManager method promoteToGroup.

@Measure
public GroupPromoteResult promoteToGroup(GroupPromoteRequest request, String user, String baseUrl) throws PromotionException, IndyWorkflowException {
    RequestContextHelper.setContext(PROMOTION_ID, request.getPromotionId());
    RequestContextHelper.setContext(PROMOTION_TYPE, GROUP_PROMOTION);
    RequestContextHelper.setContext(PROMOTION_SOURCE, request.getSource().toString());
    RequestContextHelper.setContext(PROMOTION_TARGET, request.getTargetKey().toString());
    if (!storeManager.hasArtifactStore(request.getSource())) {
        String error = String.format("Cannot promote from missing source: %s", request.getSource());
        logger.warn(error);
        return new GroupPromoteResult(request, error);
    }
    final StoreKey targetKey = getTargetKey(request.getTarget().getName(), request.getTarget().getPackageType());
    if (!storeManager.hasArtifactStore(targetKey)) {
        String error = String.format("No such target group: %s.", request.getTarget());
        logger.warn(error);
        return new GroupPromoteResult(request, error);
    }
    Future<GroupPromoteResult> future = submitGroupPromoteRequest(request, user, baseUrl);
    if (request.isAsync()) {
        return new GroupPromoteResult(request).accepted();
    } else {
        try {
            return future.get();
        } catch (InterruptedException | ExecutionException e) {
            logger.error("Group promotion failed: " + request.getSource() + " -> " + request.getTargetKey(), e);
            throw new PromotionException("Execution of group promotion failed.", e);
        }
    }
}
Also used : GroupPromoteResult(org.commonjava.indy.promote.model.GroupPromoteResult) ExecutionException(java.util.concurrent.ExecutionException) StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 49 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class PromotionValidationTools method readLocalPom.

@Measure
public MavenPomView readLocalPom(final String path, final ValidationRequest request) throws IndyWorkflowException, GalleyMavenException {
    ArtifactRef artifactRef = getArtifact(path);
    if (artifactRef == null) {
        throw new IndyWorkflowException("Invalid artifact path: %s. Could not parse ArtifactRef from path.", path);
    }
    Transfer transfer = retrieve(request.getSourceRepository(), path);
    return pomReader.readLocalPom(artifactRef.asProjectVersionRef(), transfer, MavenPomView.ALL_PROFILES);
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 50 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class KojiBuildAuthority method isAuthorized.

@Measure
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) {
            List<KojiArchiveInfo> archiveList = kojiContentProvider.listArchivesForBuild(build.getId(), session);
            archiveCollection = new KojiBuildArchiveCollection(build, archiveList);
            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) StringUtils.trimToEmpty(org.apache.commons.lang3.StringUtils.trimToEmpty) 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) StringUtils.contains(org.apache.commons.lang3.StringUtils.contains) DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) FORCE_CHECKSUM(org.commonjava.maven.galley.io.ChecksummingTransferDecorator.FORCE_CHECKSUM) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) CacheProducer(org.commonjava.indy.subsys.infinispan.CacheProducer) Map(java.util.Map) 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) ProjectRef(org.commonjava.atlas.maven.ident.ref.ProjectRef) Predicate(java.util.function.Predicate) KojiClient(com.redhat.red.build.koji.KojiClient) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) 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) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

Measure (org.commonjava.o11yphant.metrics.annotation.Measure)65 StoreKey (org.commonjava.indy.model.core.StoreKey)23 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)19 Transfer (org.commonjava.maven.galley.model.Transfer)19 Logger (org.slf4j.Logger)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)16 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)14 IndyDataException (org.commonjava.indy.data.IndyDataException)13 ArrayList (java.util.ArrayList)12 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 HashSet (java.util.HashSet)9 Group (org.commonjava.indy.model.core.Group)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 BoundStatement (com.datastax.driver.core.BoundStatement)6 StoreDataManager (org.commonjava.indy.data.StoreDataManager)6 StoreKey.fromString (org.commonjava.indy.model.core.StoreKey.fromString)6 Query (org.infinispan.query.dsl.Query)6 IOException (java.io.IOException)5 Set (java.util.Set)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5