Search in sources :

Example 1 with TransferMetadata

use of org.commonjava.maven.galley.io.checksum.TransferMetadata in project indy by Commonjava.

the class DefaultContentDigester method removeMetadata.

@Override
public void removeMetadata(final Transfer transfer) {
    String cacheKey = generateCacheKey(transfer);
    TransferMetadata meta = metadataCache.remove(cacheKey);
    logger.trace("Removing TransferMetadata for: {}\n{}", cacheKey, meta);
}
Also used : TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata)

Example 2 with TransferMetadata

use of org.commonjava.maven.galley.io.checksum.TransferMetadata in project galley by Commonjava.

the class TestMetadataConsumer method getMetadata.

public TransferMetadata getMetadata(Transfer transfer) {
    TransferMetadata transferMetadata = metadata.get(transfer);
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("Returning metadata: {} for transfer: {}", transferMetadata, transfer);
    return transferMetadata;
}
Also used : TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) Logger(org.slf4j.Logger)

Example 3 with TransferMetadata

use of org.commonjava.maven.galley.io.checksum.TransferMetadata in project indy by Commonjava.

the class KojiBuildAuthority method checksumArtifact.

private String checksumArtifact(ArtifactStore store, String path, EventMetadata eventMetadata) {
    final Logger logger = LoggerFactory.getLogger(getClass());
    try {
        if (directContentAccess.exists(store, path)) {
            String md5Path = path + ".md5";
            Transfer md5 = directContentAccess.retrieveRaw(store, md5Path, eventMetadata);
            if (md5 != null && md5.exists()) {
                try (InputStream in = md5.openInputStream(true)) {
                    return IOUtils.toString(in).trim();
                } catch (IOException e) {
                    logger.warn("Error reading MD5 checksum for transfer of path {} in store {}, error is {}", md5Path, store, e.getMessage());
                }
            } else {
                EventMetadata forcedEventMetadata = new EventMetadata(eventMetadata).set(FORCE_CHECKSUM, TRUE);
                final TransferMetadata artifactData = contentDigester.digest(store.getKey(), path, forcedEventMetadata);
                if (artifactData != null) {
                    return artifactData.getDigests().get(ContentDigest.MD5);
                }
            }
        }
    } catch (IndyWorkflowException e) {
        logger.warn("Error happened when calculate md5 checksum for transfer of path {} in store {}, error is {}", path, store, e.getMessage());
    }
    return null;
}
Also used : TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) InputStream(java.io.InputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException) Logger(org.slf4j.Logger) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 4 with TransferMetadata

use of org.commonjava.maven.galley.io.checksum.TransferMetadata in project indy by Commonjava.

the class KojiMavenMetadataProviderTest method initKojiClient.

private void initKojiClient(String exchangeName, boolean verifyArtifacts) throws IOException, GalleyInitException, IndyDataException, KojiClientException {
    StoreDataManager storeDataManager = new MemoryStoreDataManager(true);
    if (verifyArtifacts) {
        RemoteRepository verifyRepo = new RemoteRepository(MAVEN_PKG_KEY, VERIFY_REPO, server.formatUrl(VERIFY_BASEPATH));
        storeDataManager.storeArtifactStore(verifyRepo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding verification repo"), false, true, new EventMetadata());
        kojiConfig.setArtifactAuthorityStore(new StoreKey(MAVEN_PKG_KEY, remote, VERIFY_REPO).toString());
    }
    String resourceBase = "koji-metadata/" + exchangeName;
    configureKojiServer(server, KOJI_BASEPATH, counter, resourceBase, verifyArtifacts, VERIFY_BASEPATH);
    kojiClient = new KojiClient(kojiConfig, new MemoryPasswordManager(), Executors.newCachedThreadPool());
    GalleyCore galley = new GalleyCoreBuilder(new FileCacheProviderFactory(temp.newFolder("cache"))).withEnabledTransports(new HttpClientTransport(new HttpImpl(new org.commonjava.maven.galley.auth.MemoryPasswordManager()), new IndyObjectMapper(true), new GlobalHttpConfiguration(), null, null)).build();
    WeftExecutorService rescanService = new PoolWeftExecutorService("test-rescan-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    DownloadManager downloadManager = new DefaultDownloadManager(storeDataManager, galley.getTransferManager(), new IndyLocationExpander(storeDataManager), rescanService);
    WeftExecutorService contentAccessService = new PoolWeftExecutorService("test-content-access-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    DirectContentAccess directContentAccess = new DefaultDirectContentAccess(downloadManager, contentAccessService);
    DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, contentAccessService);
    ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<String, TransferMetadata>("content-metadata", contentMetadata));
    KojiBuildAuthority buildAuthority = new KojiBuildAuthority(kojiConfig, new StandardTypeMapper(), kojiClient, storeDataManager, contentDigester, directContentAccess, cacheManager);
    WeftExecutorService kojiMDService = new PoolWeftExecutorService("test-koji-metadata-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    provider = new KojiMavenMetadataProvider(this.cache, kojiClient, buildAuthority, kojiConfig, kojiMDService, cacheManager);
}
Also used : PoolWeftExecutorService(org.commonjava.cdi.util.weft.PoolWeftExecutorService) GalleyCoreBuilder(org.commonjava.maven.galley.GalleyCoreBuilder) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DownloadManager(org.commonjava.indy.content.DownloadManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) HttpImpl(org.commonjava.maven.galley.transport.htcli.HttpImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) IndyLocationExpander(org.commonjava.indy.content.IndyLocationExpander) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) StoreDataManager(org.commonjava.indy.data.StoreDataManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) ContentDigester(org.commonjava.indy.content.ContentDigester) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) GalleyCore(org.commonjava.maven.galley.GalleyCore) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) FileCacheProviderFactory(org.commonjava.maven.galley.cache.FileCacheProviderFactory) MemoryPasswordManager(org.commonjava.util.jhttpc.auth.MemoryPasswordManager) StoreKey(org.commonjava.indy.model.core.StoreKey) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) PoolWeftExecutorService(org.commonjava.cdi.util.weft.PoolWeftExecutorService) HttpClientTransport(org.commonjava.maven.galley.transport.htcli.HttpClientTransport) GlobalHttpConfiguration(org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiClient(com.redhat.red.build.koji.KojiClient) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess)

Example 5 with TransferMetadata

use of org.commonjava.maven.galley.io.checksum.TransferMetadata in project indy by Commonjava.

the class EventAuditListener method transformFileEvent.

private void transformFileEvent(org.commonjava.maven.galley.event.FileEvent event, FileEvent fileEvent) {
    EventMetadata metadata = event.getEventMetadata();
    final TrackingKey trackingKey = (TrackingKey) metadata.get(EventConstants.TRACKING_KEY);
    if (trackingKey == null) {
        logger.trace("No tracking key. Skip audit.");
        return;
    }
    Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer. Skip audit.");
        return;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        logger.trace("Not in a keyed location: {}", transfer);
        return;
    }
    try {
        final KeyedLocation keyedLocation = (KeyedLocation) location;
        final StoreKey affectedStore = keyedLocation.getKey();
        if (affectedStore.getType() == group) {
            logger.trace("Not auditing content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", affectedStore);
            return;
        }
        final String path = transfer.getPath();
        fileEvent.setTargetPath(path);
        // TODO figure out what's the NodeId
        fileEvent.setNodeId(indyConfig.getNodeId());
        fileEvent.setSessionId(trackingKey.getId());
        fileEvent.setTimestamp(new Date());
        TransferMetadata artifactData = contentDigester.digest(affectedStore, path, metadata);
        fileEvent.setMd5(artifactData.getDigests().get(ContentDigest.MD5));
        fileEvent.setSha1(artifactData.getDigests().get(ContentDigest.SHA_1));
        fileEvent.setChecksum(artifactData.getDigests().get(ContentDigest.SHA_256));
        fileEvent.setSize(artifactData.getSize());
        fileEvent.setStoreKey(affectedStore.toString());
        Map<String, String> extra = new HashMap<>();
        if (event instanceof FileStorageEvent) {
            extra.put(EventConstants.STORE_EFFECT, ((FileStorageEvent) event).getType().name());
        }
        if (StoreType.remote == affectedStore.getType()) {
            final RemoteRepository repo = (RemoteRepository) storeManager.getArtifactStore(affectedStore);
            if (repo != null) {
                fileEvent.setSourceLocation(repo.getUrl());
                fileEvent.setSourcePath(transfer.getPath());
            }
        }
        // TODO fix this, it should be the url of indy, or recalculate it in AuditQuery side.
        fileEvent.setTargetLocation("");
        fileEvent.setExtra(extra);
    } catch (final IndyWorkflowException | IndyDataException e) {
        logger.error(String.format("Failed to transform file event. Reason: %s", e.getMessage()), e);
    }
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) FileStorageEvent(org.commonjava.maven.galley.event.FileStorageEvent) HashMap(java.util.HashMap) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Date(java.util.Date) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) IndyDataException(org.commonjava.indy.data.IndyDataException) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Aggregations

TransferMetadata (org.commonjava.maven.galley.io.checksum.TransferMetadata)12 Transfer (org.commonjava.maven.galley.model.Transfer)7 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)6 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 IndyDataException (org.commonjava.indy.data.IndyDataException)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 PoolWeftExecutorService (org.commonjava.cdi.util.weft.PoolWeftExecutorService)2 WeftExecutorService (org.commonjava.cdi.util.weft.WeftExecutorService)2 ContentDigester (org.commonjava.indy.content.ContentDigester)2 DirectContentAccess (org.commonjava.indy.content.DirectContentAccess)2 IndyLocationExpander (org.commonjava.indy.content.IndyLocationExpander)2 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)2 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)2 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)2 IndyObjectMapper (org.commonjava.indy.model.core.io.IndyObjectMapper)2 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2