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);
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations