Search in sources :

Example 1 with TransferOperation

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;
            }
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) TransferOperation(org.commonjava.maven.galley.model.TransferOperation)

Example 2 with TransferOperation

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;
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ArtifactPathInfo(org.commonjava.maven.atlas.ident.util.ArtifactPathInfo) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 3 with TransferOperation

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);
    });
}
Also used : ThreadContext(org.commonjava.cdi.util.weft.ThreadContext) Transfer(org.commonjava.maven.galley.model.Transfer) Logger(org.slf4j.Logger) TransferOperation(org.commonjava.maven.galley.model.TransferOperation)

Example 4 with TransferOperation

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());
}
Also used : InputStream(java.io.InputStream) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) File(java.io.File) Test(org.junit.Test)

Example 5 with TransferOperation

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));
}
Also used : InputStream(java.io.InputStream) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MessageDigest(java.security.MessageDigest) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) File(java.io.File) Test(org.junit.Test)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)8 TransferOperation (org.commonjava.maven.galley.model.TransferOperation)8 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)5 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)5 InputStream (java.io.InputStream)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 IndyDataException (org.commonjava.indy.data.IndyDataException)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 Logger (org.slf4j.Logger)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Decorator (javax.decorator.Decorator)2 Delegate (javax.decorator.Delegate)2 Any (javax.enterprise.inject.Any)2