Search in sources :

Example 1 with BootOptions

use of org.commonjava.propulsor.boot.BootOptions in project indy by Commonjava.

the class IndyDeployer method deploy.

@Override
public void deploy(BootOptions bootOptions) throws DeployException {
    final DeploymentInfo di = indyDeployment.getDeployment(bootOptions.getContextPath()).setContextPath("/");
    final DeploymentManager dm = Servlets.defaultContainer().addDeployment(di);
    Collection<String> list = Servlets.defaultContainer().listDeployments();
    logger.info("List deployments: {}", list);
    dm.deploy();
    try {
        Integer port = bootOptions.getPort();
        if (port < 1) {
            logger.info("Looking for open Undertow port...");
            final AtomicReference<Exception> errorHolder = new AtomicReference<>();
            final AtomicReference<Integer> usingPort = new AtomicReference<>();
            server = PortFinder.findPortFor(16, (foundPort) -> {
                usingPort.set(foundPort);
                try {
                    return buildAndStartUndertow(dm, foundPort, bootOptions.getBind(), restConfig);
                } catch (Exception e) {
                    errorHolder.set(e);
                }
                return null;
            });
            Exception e = errorHolder.get();
            if (e != null) {
                throw e;
            }
            bootOptions.setPort(usingPort.get());
        } else {
            logger.info("Start Undertow server, bind: {}, port: {}", bootOptions.getBind(), port);
            server = buildAndStartUndertow(dm, port, bootOptions.getBind(), restConfig);
        }
        logger.info("Indy listening on {}:{}\n\n", bootOptions.getBind(), bootOptions.getPort());
    } catch (Exception e) {
        logger.error("Deploy failed", e);
        throw new DeployException("Deploy failed", e);
    }
}
Also used : Predicates(io.undertow.predicate.Predicates) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) ServletException(javax.servlet.ServletException) HttpServerExchange(io.undertow.server.HttpServerExchange) LoggerFactory(org.slf4j.LoggerFactory) ContentEncodingRepository(io.undertow.server.handlers.encoding.ContentEncodingRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) Undertow(io.undertow.Undertow) DeployException(org.commonjava.propulsor.deploy.DeployException) Servlets(io.undertow.servlet.Servlets) Inject(javax.inject.Inject) HashSet(java.util.HashSet) BootOptions(org.commonjava.propulsor.boot.BootOptions) DeflateEncodingProvider(io.undertow.server.handlers.encoding.DeflateEncodingProvider) GzipEncodingProvider(io.undertow.server.handlers.encoding.GzipEncodingProvider) Deployer(org.commonjava.propulsor.deploy.Deployer) UndertowOptions(io.undertow.UndertowOptions) Logger(org.slf4j.Logger) Collection(java.util.Collection) PortFinder(org.commonjava.propulsor.boot.PortFinder) Set(java.util.Set) MimeTyper(org.commonjava.indy.util.MimeTyper) DeploymentManager(io.undertow.servlet.api.DeploymentManager) ApplicationContent(org.commonjava.indy.util.ApplicationContent) EncodingHandler(io.undertow.server.handlers.encoding.EncodingHandler) Predicate(io.undertow.predicate.Predicate) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) DeploymentManager(io.undertow.servlet.api.DeploymentManager) DeployException(org.commonjava.propulsor.deploy.DeployException) AtomicReference(java.util.concurrent.atomic.AtomicReference) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServletException(javax.servlet.ServletException) DeployException(org.commonjava.propulsor.deploy.DeployException)

Example 2 with BootOptions

use of org.commonjava.propulsor.boot.BootOptions in project indy by Commonjava.

the class JaxRsBooter method main.

public static void main(final String[] args) {
    setDefaultUncaughtExceptionHandler();
    BootOptions boot;
    try {
        boot = loadFromSysProps("indy", BOOT_DEFAULTS_PROP, HOME_PROP);
    } catch (final BootException e) {
        e.printStackTrace();
        System.err.printf("ERROR: %s", e.getMessage());
        System.exit(ERR_LOAD_BOOT_OPTIONS);
        return;
    }
    try {
        if (boot.parseArgs(args)) {
            Booter booter = new JaxRsBooter();
            booter.runAndWait(boot);
        }
    } catch (final BootException e) {
        e.printStackTrace();
        System.err.printf("ERROR: %s", e.getMessage());
        System.exit(ERR_START);
    }
}
Also used : BootException(org.commonjava.propulsor.boot.BootException) BootOptions(org.commonjava.propulsor.boot.BootOptions) Booter(org.commonjava.propulsor.boot.Booter)

Example 3 with BootOptions

use of org.commonjava.propulsor.boot.BootOptions 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 DefaultIndyConfiguration indyConfig = new DefaultIndyConfiguration();
    indyConfig.setNotFoundCacheTimeoutSeconds(1);
    final ExpiringMemoryNotFoundCache nfc = new ExpiringMemoryNotFoundCache(indyConfig);
    WeftExecutorService rescanService = new PoolWeftExecutorService("test-rescan-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    final DownloadManager downloadManager = new DefaultDownloadManager(storeManager, core.getTransferManager(), core.getLocationExpander(), new MockInstance<>(new MockContentAdvisor()), nfc, rescanService);
    WeftExecutorService contentAccessService = new PoolWeftExecutorService("test-content-access-executor", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, contentAccessService);
    ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<>("content-metadata", contentMetadata));
    final ContentManager contentManager = new DefaultContentManager(storeManager, downloadManager, mapper, new SpecialPathManagerImpl(), new MemoryNotFoundCache(), contentDigester, new ContentGeneratorManager());
    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);
    WeftExecutorService transferService = new PoolWeftExecutorService("test-mitm-transfers", (ThreadPoolExecutor) Executors.newCachedThreadPool(), 2, 10f, false, null, null);
    ProxyTransfersExecutor handler = new ProxyTransfersExecutor(transferService);
    IndyTraceConfiguration itc = new IndyTraceConfiguration();
    TraceManager tm = new TraceManager(new OtelTracePlugin(itc, itc), new SpanFieldsDecorator(Collections.emptyList()), itc);
    proxy = new HttpProxy(config, bootOpts, new ProxyAcceptHandler(config, storeManager, contentController, auth, core.getCache(), scriptEngine, new MDCManager(), null, null, new CacheProducer(null, cacheManager, null), handler, tm));
    proxy.start();
}
Also used : PoolWeftExecutorService(org.commonjava.cdi.util.weft.PoolWeftExecutorService) DefaultContentManager(org.commonjava.indy.core.content.DefaultContentManager) SpanFieldsDecorator(org.commonjava.o11yphant.trace.SpanFieldsDecorator) DownloadManager(org.commonjava.indy.content.DownloadManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) TraceManager(org.commonjava.o11yphant.trace.TraceManager) 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) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) KeycloakProxyAuthenticator(org.commonjava.indy.httprox.keycloak.KeycloakProxyAuthenticator) OtelTracePlugin(org.commonjava.o11yphant.otel.OtelTracePlugin) ProxyTransfersExecutor(org.commonjava.indy.httprox.handler.ProxyTransfersExecutor) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) DefaultIndyConfiguration(org.commonjava.indy.conf.DefaultIndyConfiguration) 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) ExpiringMemoryNotFoundCache(org.commonjava.indy.core.inject.ExpiringMemoryNotFoundCache) MemoryNotFoundCache(org.commonjava.maven.galley.nfc.MemoryNotFoundCache) ExpiringMemoryNotFoundCache(org.commonjava.indy.core.inject.ExpiringMemoryNotFoundCache) GStringTemplateEngine(groovy.text.GStringTemplateEngine) MemoryPasswordManager(org.commonjava.maven.galley.auth.MemoryPasswordManager) BootOptions(org.commonjava.propulsor.boot.BootOptions) MimeTyper(org.commonjava.indy.util.MimeTyper) ScriptEngine(org.commonjava.indy.subsys.template.ScriptEngine) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) PoolWeftExecutorService(org.commonjava.cdi.util.weft.PoolWeftExecutorService) CacheProducer(org.commonjava.indy.subsys.infinispan.CacheProducer) HttpClientTransport(org.commonjava.maven.galley.transport.htcli.HttpClientTransport) MDCManager(org.commonjava.indy.bind.jaxrs.MDCManager) DataFileManager(org.commonjava.indy.subsys.datafile.DataFileManager) TemplatingEngine(org.commonjava.indy.subsys.template.TemplatingEngine) MockContentAdvisor(org.commonjava.indy.test.fixture.core.MockContentAdvisor) IndyTraceConfiguration(org.commonjava.indy.subsys.honeycomb.config.IndyTraceConfiguration) TransportManager(org.commonjava.maven.galley.spi.transport.TransportManager) ContentGeneratorManager(org.commonjava.indy.core.content.ContentGeneratorManager) 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 4 with BootOptions

use of org.commonjava.propulsor.boot.BootOptions in project indy by Commonjava.

the class CoreServerFixture method newBootOptions.

private static BootOptions newBootOptions(final File bootDefaults, final String indyHome) {
    final Properties properties = System.getProperties();
    properties.setProperty("indy.home", indyHome);
    System.setProperties(properties);
    try {
        final BootOptions options = new BootOptions("indy", indyHome, bootDefaults);
        options.setPort(findOpenPort(MAX_PORTGEN_TRIES));
        return options;
    } catch (IOException | InterpolationException e) {
        throw new IllegalStateException("Cannot start core Indy server with the given configuration: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) Properties(java.util.Properties) BootOptions(org.commonjava.propulsor.boot.BootOptions)

Aggregations

BootOptions (org.commonjava.propulsor.boot.BootOptions)4 MimeTyper (org.commonjava.indy.util.MimeTyper)2 GStringTemplateEngine (groovy.text.GStringTemplateEngine)1 Undertow (io.undertow.Undertow)1 UndertowOptions (io.undertow.UndertowOptions)1 Predicate (io.undertow.predicate.Predicate)1 Predicates (io.undertow.predicate.Predicates)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 ContentEncodingRepository (io.undertow.server.handlers.encoding.ContentEncodingRepository)1 DeflateEncodingProvider (io.undertow.server.handlers.encoding.DeflateEncodingProvider)1 EncodingHandler (io.undertow.server.handlers.encoding.EncodingHandler)1 GzipEncodingProvider (io.undertow.server.handlers.encoding.GzipEncodingProvider)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 Set (java.util.Set)1