Search in sources :

Example 1 with SpecialPathManagerImpl

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

the class HttpProxyTest method setup.

@Before
public void setup() throws Exception {
    contentMetadata.clear();
    core.initGalley();
    final TransportManager transports = new TransportManagerImpl(new HttpClientTransport(new HttpImpl(new MemoryPasswordManager())));
    core.withTransportManager(transports);
    core.initMissingComponents();
    final HttproxConfig config = new HttproxConfig();
    config.setEnabled(true);
    proxyPort = config.getPort();
    final BootOptions bootOpts = new BootOptions();
    bootOpts.setBind(HOST);
    storeManager = new MemoryStoreDataManager(true);
    final IndyObjectMapper mapper = new IndyObjectMapper(true);
    final DownloadManager downloadManager = new DefaultDownloadManager(storeManager, core.getTransferManager(), core.getLocationExpander(), new MockInstance<>(new MockContentAdvisor()));
    DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, Executors.newSingleThreadExecutor());
    ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<String, TransferMetadata>("content-metadata", contentMetadata));
    final ContentManager contentManager = new DefaultContentManager(storeManager, downloadManager, mapper, new SpecialPathManagerImpl(), new MemoryNotFoundCache(), contentDigester, Collections.<ContentGenerator>emptySet());
    DataFileManager dfm = new DataFileManager(temp.newFolder(), new DataFileEventManager());
    final TemplatingEngine templates = new TemplatingEngine(new GStringTemplateEngine(), dfm);
    final ContentController contentController = new ContentController(storeManager, contentManager, templates, mapper, new MimeTyper());
    KeycloakConfig kcConfig = new KeycloakConfig();
    kcConfig.setEnabled(false);
    final KeycloakProxyAuthenticator auth = new KeycloakProxyAuthenticator(kcConfig, config);
    ScriptEngine scriptEngine = new ScriptEngine(dfm);
    proxy = new HttpProxy(config, bootOpts, new ProxyAcceptHandler(config, storeManager, contentController, auth, core.getCache(), scriptEngine));
    proxy.start();
}
Also used : DefaultContentManager(org.commonjava.indy.core.content.DefaultContentManager) DownloadManager(org.commonjava.indy.content.DownloadManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) HttpImpl(org.commonjava.maven.galley.transport.htcli.HttpImpl) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) HttproxConfig(org.commonjava.indy.httprox.conf.HttproxConfig) 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) KeycloakProxyAuthenticator(org.commonjava.indy.httprox.keycloak.KeycloakProxyAuthenticator) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) ContentDigester(org.commonjava.indy.content.ContentDigester) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) TransportManagerImpl(org.commonjava.maven.galley.transport.TransportManagerImpl) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) ContentController(org.commonjava.indy.core.ctl.ContentController) DataFileEventManager(org.commonjava.indy.subsys.datafile.change.DataFileEventManager) DefaultContentManager(org.commonjava.indy.core.content.DefaultContentManager) ContentManager(org.commonjava.indy.content.ContentManager) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) GStringTemplateEngine(groovy.text.GStringTemplateEngine) MemoryPasswordManager(org.commonjava.maven.galley.auth.MemoryPasswordManager) BootOptions(org.commonjava.indy.boot.BootOptions) MimeTyper(org.commonjava.indy.util.MimeTyper) ScriptEngine(org.commonjava.indy.subsys.template.ScriptEngine) HttpClientTransport(org.commonjava.maven.galley.transport.htcli.HttpClientTransport) DataFileManager(org.commonjava.indy.subsys.datafile.DataFileManager) TemplatingEngine(org.commonjava.indy.subsys.template.TemplatingEngine) MockContentAdvisor(org.commonjava.indy.test.fixture.core.MockContentAdvisor) TransportManager(org.commonjava.maven.galley.spi.transport.TransportManager) ProxyAcceptHandler(org.commonjava.indy.httprox.handler.ProxyAcceptHandler) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess) KeycloakConfig(org.commonjava.indy.subsys.keycloak.conf.KeycloakConfig) Before(org.junit.Before)

Example 2 with SpecialPathManagerImpl

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

the class GalleyCoreBuilder method initMissingComponents.

public void initMissingComponents() throws GalleyInitException {
    if (transportManager == null) {
        transportManager = new TransportManagerImpl(transports);
    }
    handlerExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("transfer-handlers", true, 4));
    batchExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("transfer-batches", true, 4));
    if (decorator == null) {
        decorator = new NoOpTransferDecorator();
    }
    if (events == null) {
        events = new NoOpFileEventManager();
    }
    if (nfc == null) {
        nfc = new MemoryNotFoundCache();
    }
    if (transportManagerConfig == null) {
        transportManagerConfig = new TransportManagerConfig();
    }
    final DownloadHandler dh = new DownloadHandler(getNfc(), transportManagerConfig, handlerExecutor);
    final UploadHandler uh = new UploadHandler(getNfc(), transportManagerConfig, handlerExecutor);
    final ListingHandler lh = new ListingHandler(getNfc());
    final ExistenceHandler eh = new ExistenceHandler(getNfc());
    if (specialPathManager == null) {
        specialPathManager = new SpecialPathManagerImpl();
    }
    if (pathGenerator == null) {
        pathGenerator = new HashedLocationPathGenerator();
    }
    if (cache == null) {
        if (cacheProviderFactory != null) {
            cache = cacheProviderFactory.create(pathGenerator, decorator, events);
        } else {
            throw new GalleyInitException("No CacheProvider / CacheProviderFactory specified!");
        }
    }
    if (transferManager == null) {
        transferManager = new TransferManagerImpl(transportManager, getCache(), getNfc(), getFileEvents(), dh, uh, lh, eh, specialPathManager, batchExecutor);
    }
    if (locationExpander == null) {
        logger.debug("Initializing default location expander");
        locationExpander = new NoOpLocationExpander();
    }
    if (locationResolver == null) {
        locationResolver = new SimpleUrlLocationResolver(locationExpander, transportManager);
    }
    if (passwordManager == null) {
        passwordManager = new MemoryPasswordManager();
    }
}
Also used : ListingHandler(org.commonjava.maven.galley.internal.xfer.ListingHandler) NoOpTransferDecorator(org.commonjava.maven.galley.io.NoOpTransferDecorator) TransferManagerImpl(org.commonjava.maven.galley.internal.TransferManagerImpl) TransportManagerImpl(org.commonjava.maven.galley.transport.TransportManagerImpl) HashedLocationPathGenerator(org.commonjava.maven.galley.io.HashedLocationPathGenerator) NamedThreadFactory(org.commonjava.cdi.util.weft.NamedThreadFactory) DownloadHandler(org.commonjava.maven.galley.internal.xfer.DownloadHandler) TransportManagerConfig(org.commonjava.maven.galley.config.TransportManagerConfig) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) MemoryPasswordManager(org.commonjava.maven.galley.auth.MemoryPasswordManager) NoOpLocationExpander(org.commonjava.maven.galley.transport.NoOpLocationExpander) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) NoOpFileEventManager(org.commonjava.maven.galley.event.NoOpFileEventManager) SimpleUrlLocationResolver(org.commonjava.maven.galley.transport.SimpleUrlLocationResolver) UploadHandler(org.commonjava.maven.galley.internal.xfer.UploadHandler) ExistenceHandler(org.commonjava.maven.galley.internal.xfer.ExistenceHandler)

Example 3 with SpecialPathManagerImpl

use of org.commonjava.maven.galley.io.SpecialPathManagerImpl 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 4 with SpecialPathManagerImpl

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

the class ChecksummingTransferDecoratorTest method customChecksumReaderFilter.

@Test
public void customChecksumReaderFilter() throws Exception {
    String path = "my-path.txt";
    fixture.setDecorator(new ChecksummingTransferDecorator(new TestDecoratorAdvisor(), new DisabledChecksummingDecoratorAdvisor(), new SpecialPathManagerImpl(), metadataConsumer, new Md5GeneratorFactory()));
    fixture.initMissingComponents();
    fixture.getCache().startReporting();
    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);
    EventMetadata em = new EventMetadata();
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, false);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_NO_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, false, true);
    logger.debug("Removing checksum metadata from consumer");
    metadataConsumer.removeMetadata(txfr);
    em = new EventMetadata().set(DO_CHECKSUMS, ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_AND_WRITE);
    logger.debug("Reading stream with EventMetadata advice: {}", em.get(DO_CHECKSUMS));
    assertRead(txfr, data, em, true, true);
}
Also used : TestDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.testutil.TestDecoratorAdvisor) 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) File(java.io.File) SpecialPathManagerImpl(org.commonjava.maven.galley.io.SpecialPathManagerImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 5 with SpecialPathManagerImpl

use of org.commonjava.maven.galley.io.SpecialPathManagerImpl 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

SpecialPathManagerImpl (org.commonjava.maven.galley.io.SpecialPathManagerImpl)8 MemoryNotFoundCache (org.commonjava.maven.galley.nfc.MemoryNotFoundCache)5 Before (org.junit.Before)4 File (java.io.File)3 DirectContentAccess (org.commonjava.indy.content.DirectContentAccess)3 DefaultContentDigester (org.commonjava.indy.core.content.DefaultContentDigester)3 DefaultContentManager (org.commonjava.indy.core.content.DefaultContentManager)3 DefaultDirectContentAccess (org.commonjava.indy.core.content.DefaultDirectContentAccess)3 DefaultDownloadManager (org.commonjava.indy.core.content.DefaultDownloadManager)3 MemoryStoreDataManager (org.commonjava.indy.mem.data.MemoryStoreDataManager)3 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)3 ChecksummingTransferDecorator (org.commonjava.maven.galley.io.ChecksummingTransferDecorator)3 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)3 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 TransportManagerImpl (org.commonjava.maven.galley.transport.TransportManagerImpl)3 Test (org.junit.Test)3 GStringTemplateEngine (groovy.text.GStringTemplateEngine)2 InputStream (java.io.InputStream)2 ContentDigester (org.commonjava.indy.content.ContentDigester)2