use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class TimeoutEventListener method onFileStorageEvent.
public void onFileStorageEvent(@Observes final FileStorageEvent event) {
final StoreKey key = getKey(event);
if (key == null) {
return;
}
final Transfer transfer = event.getTransfer();
final TransferOperation type = event.getType();
switch(type) {
case UPLOAD:
{
try {
scheduleManager.setSnapshotTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to clean up metadata / set snapshot timeouts related to: " + transfer, e);
}
break;
}
case DOWNLOAD:
{
try {
scheduleManager.setProxyTimeouts(key, transfer.getPath());
} catch (final IndySchedulerException e) {
logger.error("Failed to clean up metadata / set proxy-cache timeouts related to: " + transfer, e);
}
break;
}
default:
{
break;
}
}
}
use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class FoloPomDownloadListener method onFileUpload.
public void onFileUpload(@Observes final FileStorageEvent event) {
// check for a TransferOperation of DOWNLOAD
final TransferOperation op = event.getType();
if (op != TransferOperation.DOWNLOAD) {
logger.trace("Not a download transfer operation. No pom existence check performed.");
return;
}
// check if it is a path that doesn't end in with ".pom"
final Transfer transfer = event.getTransfer();
if (transfer == null) {
logger.trace("No transfer. No pom existence check performed.");
return;
}
String txfrPath = transfer.getPath();
if (txfrPath.endsWith(".pom")) {
logger.trace("This is a pom download.");
return;
}
// use ArtifactPathInfo to parse into a GAV, just to verify that it's looking at an artifact download
ArtifactPathInfo artPathInfo = ArtifactPathInfo.parse(txfrPath);
if (artPathInfo == null) {
logger.trace("Not an artifact download ({}). No pom existence check performed.", txfrPath);
return;
}
// verify that the associated .pom file exists
String pomFilename = String.format("%s-%s.pom", artPathInfo.getArtifactId(), artPathInfo.getVersion());
ConcreteResource pomResource = transfer.getResource().getParent().getChild(pomFilename);
if (cacheProvider.exists(pomResource)) {
logger.trace("Pom {} already exists.", cacheProvider.getFilePath(pomResource));
return;
}
// trigger pom download by requesting it from the same repository as the original artifact
StoreKey storeKey = StoreKey.fromString(transfer.getLocation().getName());
ArtifactStore store;
try {
store = storeManager.getArtifactStore(storeKey);
} catch (final IndyDataException ex) {
logger.error("Error retrieving artifactStore with key " + storeKey, ex);
return;
}
try {
logger.debug("Downloading POM as automatic response to associated artifact download: {}/{}", storeKey, pomResource.getPath());
contentManager.retrieve(store, pomResource.getPath(), event.getEventMetadata());
} catch (final IndyWorkflowException ex) {
logger.error("Error while retrieving pom artifact " + pomResource.getPath() + " from store " + store, ex);
return;
}
}
use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.
the class RelatePomStorageListener method onPomStorage.
public void onPomStorage(@Observes final FileStorageEvent event) {
final Logger logger = LoggerFactory.getLogger(getClass());
if (!config.isEnabled()) {
logger.debug("Relate Add-on is not enabled.");
return;
}
logger.debug("FILE STORAGE: {}", event);
final TransferOperation op = event.getType();
if (op != TransferOperation.UPLOAD && op != TransferOperation.DOWNLOAD) {
logger.debug("Not a download/upload transfer operation. No .rel generation.");
return;
}
ThreadContext threadContext = ThreadContext.getContext(false);
if (threadContext != null) {
Object obj = threadContext.get(REL_DIRECT_GENERATING);
if (obj != null) {
logger.debug("Direct .rel generation in progress. Ignore POM storage event. ");
return;
}
}
final Transfer transfer = event.getTransfer();
executor.execute(() -> {
relateGenerationManager.generateRelationshipFile(transfer, op);
});
}
use of org.commonjava.maven.galley.model.TransferOperation in project galley by Commonjava.
the class ChecksummingTransferDecoratorTest method noChecksumOnReadWhenChecksumsAreDisabledForReads.
@Test
public void noChecksumOnReadWhenChecksumsAreDisabledForReads() throws Exception {
fixture.setDecorator(new ChecksummingTransferDecorator(Collections.<TransferOperation>emptySet(), new SpecialPathManagerImpl(), false, false, metadataConsumer, new Md5GeneratorFactory()));
fixture.initMissingComponents();
fixture.getCache().startReporting();
String path = "my-path.txt";
final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), path));
File f = new File(temp.getRoot(), "cache/test:uri");
f = new File(f, path);
byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
FileUtils.writeByteArrayToFile(f, data);
logger.info("Opening transfer input stream");
EventMetadata forceEventMetadata = new EventMetadata();
try (InputStream stream = txfr.openInputStream(false, forceEventMetadata)) {
logger.info("Reading stream");
byte[] resultData = IOUtils.toByteArray(stream);
logger.debug("Result is {} bytes", resultData.length);
assertThat(Arrays.equals(resultData, data), equalTo(true));
}
logger.debug("Verifying .md5 file is missing");
final Transfer md5Txfr = txfr.getSiblingMeta(".md5");
assertThat(md5Txfr.exists(), equalTo(false));
logger.debug("Verifying MD5 in metadata consumer is missing");
TransferMetadata metadata = metadataConsumer.getMetadata(txfr);
assertThat(metadata, nullValue());
}
use of org.commonjava.maven.galley.model.TransferOperation in project galley by Commonjava.
the class ChecksummingTransferDecoratorTest method forceChecksumOnReadWhenChecksumsAreDisabledForReads.
@Test
public void forceChecksumOnReadWhenChecksumsAreDisabledForReads() throws Exception {
fixture.setDecorator(new ChecksummingTransferDecorator(Collections.<TransferOperation>emptySet(), new SpecialPathManagerImpl(), false, false, metadataConsumer, new Md5GeneratorFactory()));
fixture.initMissingComponents();
fixture.getCache().startReporting();
String path = "my-path.txt";
final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), path));
File f = new File(temp.getRoot(), "cache/test:uri");
f = new File(f, path);
byte[] data = "This is a test with a bunch of data and some other stuff, in a big box sealed with chewing gum".getBytes();
FileUtils.writeByteArrayToFile(f, data);
logger.info("Opening transfer input stream");
EventMetadata forceEventMetadata = new EventMetadata().set(FORCE_CHECKSUM, TRUE);
try (InputStream stream = txfr.openInputStream(false, forceEventMetadata)) {
logger.info("Reading stream");
byte[] resultData = IOUtils.toByteArray(stream);
logger.debug("Result is {} bytes", resultData.length);
assertThat(Arrays.equals(resultData, data), equalTo(true));
}
final MessageDigest md = MessageDigest.getInstance("MD5");
md.update(data);
final byte[] digest = md.digest();
final String digestHex = Hex.encodeHexString(digest);
logger.debug("Verifying MD5 in metadata consumer");
TransferMetadata metadata = metadataConsumer.getMetadata(txfr);
assertThat(metadata, notNullValue());
Map<ContentDigest, String> digests = metadata.getDigests();
assertThat(digests, CoreMatchers.<Map<ContentDigest, String>>notNullValue());
assertThat(digests.get(MD5), equalTo(digestHex));
}
Aggregations