Search in sources :

Example 1 with DefaultServerFactory

use of io.dropwizard.server.DefaultServerFactory in project irontest by zheng-wang.

the class IronTestApplication method createSystemResources.

private void createSystemResources(IronTestConfiguration configuration, Environment environment) {
    final DBIFactory dbiFactory = new DBIFactory();
    final DBI jdbi = dbiFactory.build(environment, configuration.getSystemDatabase(), "systemDatabase");
    // create DAO objects
    final FolderDAO folderDAO = jdbi.onDemand(FolderDAO.class);
    final EnvironmentDAO environmentDAO = jdbi.onDemand(EnvironmentDAO.class);
    final EndpointDAO endpointDAO = jdbi.onDemand(EndpointDAO.class);
    final TestcaseDAO testcaseDAO = jdbi.onDemand(TestcaseDAO.class);
    final TeststepDAO teststepDAO = jdbi.onDemand(TeststepDAO.class);
    final AssertionDAO assertionDAO = jdbi.onDemand(AssertionDAO.class);
    final UtilsDAO utilsDAO = jdbi.onDemand(UtilsDAO.class);
    final FolderTreeNodeDAO folderTreeNodeDAO = jdbi.onDemand(FolderTreeNodeDAO.class);
    final UserDefinedPropertyDAO udpDAO = jdbi.onDemand(UserDefinedPropertyDAO.class);
    final DataTableColumnDAO dataTableColumnDAO = jdbi.onDemand(DataTableColumnDAO.class);
    final DataTableCellDAO dataTableCellDAO = jdbi.onDemand(DataTableCellDAO.class);
    final TestcaseRunDAO testcaseRunDAO = jdbi.onDemand(TestcaseRunDAO.class);
    final TestcaseIndividualRunDAO testcaseIndividualRunDAO = jdbi.onDemand(TestcaseIndividualRunDAO.class);
    final TeststepRunDAO teststepRunDAO = jdbi.onDemand(TeststepRunDAO.class);
    UserDAO userDAO = null;
    if (isInTeamMode(configuration)) {
        userDAO = jdbi.onDemand(UserDAO.class);
    }
    AppInfo appInfo = new AppInfo();
    if (isInTeamMode(configuration)) {
        appInfo.setAppMode(AppMode.TEAM);
        // ignore bindHost
        DefaultServerFactory server = (DefaultServerFactory) configuration.getServerFactory();
        List<ConnectorFactory> applicationConnectors = server.getApplicationConnectors();
        HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) applicationConnectors.get(0);
        httpConnectorFactory.setBindHost(null);
        // turn on user authentication and authorization
        environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<SimplePrincipal>().setAuthenticator(new ResourceAuthenticator(userDAO)).setAuthorizer(new ResourceAuthorizer()).buildAuthFilter()));
        environment.jersey().register(RolesAllowedDynamicFeature.class);
        environment.jersey().register(new AuthResponseFilter());
    }
    // create database tables
    // order is important!!! (there are foreign keys linking them)
    folderDAO.createSequenceIfNotExists();
    folderDAO.createTableIfNotExists();
    folderDAO.insertARootNodeIfNotExists();
    environmentDAO.createSequenceIfNotExists();
    environmentDAO.createTableIfNotExists();
    endpointDAO.createSequenceIfNotExists();
    endpointDAO.createTableIfNotExists();
    testcaseDAO.createSequenceIfNotExists();
    testcaseDAO.createTableIfNotExists();
    teststepDAO.createSequenceIfNotExists();
    teststepDAO.createTableIfNotExists();
    assertionDAO.createSequenceIfNotExists();
    assertionDAO.createTableIfNotExists();
    udpDAO.createSequenceIfNotExists();
    udpDAO.createTableIfNotExists();
    dataTableColumnDAO.createSequenceIfNotExists();
    dataTableColumnDAO.createTableIfNotExists();
    dataTableCellDAO.createSequenceIfNotExists();
    dataTableCellDAO.createTableIfNotExists();
    testcaseRunDAO.createSequenceIfNotExists();
    testcaseRunDAO.createTableIfNotExists();
    testcaseIndividualRunDAO.createSequenceIfNotExists();
    testcaseIndividualRunDAO.createTableIfNotExists();
    teststepRunDAO.createSequenceIfNotExists();
    teststepRunDAO.createTableIfNotExists();
    if (isInTeamMode(configuration)) {
        userDAO.createSequenceIfNotExists();
        userDAO.createTableIfNotExists();
        userDAO.insertBuiltinAdminUserIfNotExists();
    }
    // register APIs
    environment.jersey().register(new SystemResource(appInfo));
    environment.jersey().register(new ManagedEndpointResource(appInfo, endpointDAO));
    environment.jersey().register(new TestcaseResource(testcaseDAO, teststepDAO));
    environment.jersey().register(new FolderResource(folderDAO));
    environment.jersey().register(new FolderTreeNodeResource(folderTreeNodeDAO));
    environment.jersey().register(new TeststepResource(appInfo, teststepDAO, udpDAO, utilsDAO));
    environment.jersey().register(new WSDLResource());
    environment.jersey().register(new EnvironmentResource(environmentDAO));
    environment.jersey().register(new TestcaseRunResource(testcaseDAO, udpDAO, teststepDAO, utilsDAO, testcaseRunDAO, teststepRunDAO));
    environment.jersey().register(new AssertionResource(udpDAO, teststepDAO, utilsDAO));
    environment.jersey().register(new UDPResource(udpDAO));
    environment.jersey().register(new DataTableResource(utilsDAO));
    if (isInTeamMode(configuration)) {
        environment.jersey().register(new UserResource(userDAO));
    }
    // if turned on in config.yml, register jersey LoggingFilter (used for logging Iron Test resource oriented HTTP API requests and responses)
    DefaultLoggingFactory defaultLoggingFactory = (DefaultLoggingFactory) configuration.getLoggingFactory();
    if (defaultLoggingFactory.getLoggers().containsKey(LoggingFilter.class.getName())) {
        environment.jersey().register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true));
    }
    // register exception mappers
    environment.jersey().register(new IronTestLoggingExceptionMapper());
}
Also used : ResourceAuthenticator(io.irontest.auth.ResourceAuthenticator) LoggingFilter(org.glassfish.jersey.filter.LoggingFilter) DefaultLoggingFactory(io.dropwizard.logging.DefaultLoggingFactory) DBI(org.skife.jdbi.v2.DBI) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ConnectorFactory(io.dropwizard.jetty.ConnectorFactory) BasicCredentialAuthFilter(io.dropwizard.auth.basic.BasicCredentialAuthFilter) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) ResourceAuthorizer(io.irontest.auth.ResourceAuthorizer) AuthResponseFilter(io.irontest.auth.AuthResponseFilter) AppInfo(io.irontest.models.AppInfo) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) SimplePrincipal(io.irontest.auth.SimplePrincipal) DBIFactory(io.dropwizard.jdbi.DBIFactory) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory)

Example 2 with DefaultServerFactory

use of io.dropwizard.server.DefaultServerFactory in project streamline by hortonworks.

the class StreamlineApplication method registerResources.

private void registerResources(StreamlineConfiguration configuration, Environment environment, Subject subject) throws ConfigException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    StorageManager storageManager = getDao(configuration);
    TransactionManager transactionManager;
    if (storageManager instanceof TransactionManager) {
        transactionManager = (TransactionManager) storageManager;
    } else {
        transactionManager = new NOOPTransactionManager();
    }
    environment.jersey().register(new TransactionEventListener(transactionManager, true));
    Collection<Class<? extends Storable>> streamlineEntities = getStorableEntities();
    storageManager.registerStorables(streamlineEntities);
    LOG.info("Registered streamline entities {}", streamlineEntities);
    FileStorage fileStorage = this.getJarStorage(configuration, storageManager);
    int appPort = ((HttpConnectorFactory) ((DefaultServerFactory) configuration.getServerFactory()).getApplicationConnectors().get(0)).getPort();
    String catalogRootUrl = configuration.getCatalogRootUrl().replaceFirst("8080", appPort + "");
    List<ModuleConfiguration> modules = configuration.getModules();
    List<Object> resourcesToRegister = new ArrayList<>();
    // add StreamlineConfigResource
    resourcesToRegister.add(new StreamlineConfigurationResource(configuration));
    // authorizer
    StreamlineAuthorizer authorizer;
    AuthorizerConfiguration authorizerConf = configuration.getAuthorizerConfiguration();
    SecurityCatalogService securityCatalogService = new SecurityCatalogService(storageManager);
    if (authorizerConf != null) {
        authorizer = ((Class<StreamlineAuthorizer>) Class.forName(authorizerConf.getClassName())).newInstance();
        Map<String, Object> authorizerConfig = new HashMap<>();
        authorizerConfig.put(DefaultStreamlineAuthorizer.CONF_CATALOG_SERVICE, securityCatalogService);
        authorizerConfig.put(DefaultStreamlineAuthorizer.CONF_ADMIN_PRINCIPALS, authorizerConf.getAdminPrincipals());
        authorizer.init(authorizerConfig);
        String filterClazzName = authorizerConf.getContainerRequestFilter();
        ContainerRequestFilter filter;
        if (StringUtils.isEmpty(filterClazzName)) {
            // default
            filter = new StreamlineKerberosRequestFilter();
        } else {
            filter = ((Class<ContainerRequestFilter>) Class.forName(filterClazzName)).newInstance();
        }
        LOG.info("Registering ContainerRequestFilter: {}", filter.getClass().getCanonicalName());
        environment.jersey().register(filter);
    } else {
        LOG.info("Authorizer config not set, setting noop authorizer");
        String noopAuthorizerClassName = "com.hortonworks.streamline.streams.security.impl.NoopAuthorizer";
        authorizer = ((Class<StreamlineAuthorizer>) Class.forName(noopAuthorizerClassName)).newInstance();
    }
    for (ModuleConfiguration moduleConfiguration : modules) {
        String moduleName = moduleConfiguration.getName();
        String moduleClassName = moduleConfiguration.getClassName();
        LOG.info("Registering module [{}] with class [{}]", moduleName, moduleClassName);
        ModuleRegistration moduleRegistration = (ModuleRegistration) Class.forName(moduleClassName).newInstance();
        if (moduleConfiguration.getConfig() == null) {
            moduleConfiguration.setConfig(new HashMap<String, Object>());
        }
        if (moduleName.equals(Constants.CONFIG_STREAMS_MODULE)) {
            moduleConfiguration.getConfig().put(Constants.CONFIG_CATALOG_ROOT_URL, catalogRootUrl);
        }
        Map<String, Object> initConfig = new HashMap<>(moduleConfiguration.getConfig());
        initConfig.put(Constants.CONFIG_AUTHORIZER, authorizer);
        initConfig.put(Constants.CONFIG_SECURITY_CATALOG_SERVICE, securityCatalogService);
        initConfig.put(Constants.CONFIG_SUBJECT, subject);
        if ((initConfig.get("proxyUrl") != null) && (configuration.getHttpProxyUrl() == null || configuration.getHttpProxyUrl().isEmpty())) {
            LOG.warn("Please move proxyUrl, proxyUsername and proxyPassword configuration properties under streams module to httpProxyUrl, " + "httpProxyUsername and httpProxyPassword respectively at top level in your streamline.yaml");
            configuration.setHttpProxyUrl((String) initConfig.get("proxyUrl"));
            configuration.setHttpProxyUsername((String) initConfig.get("proxyUsername"));
            configuration.setHttpProxyPassword((String) initConfig.get("proxyPassword"));
        }
        // pass http proxy information from top level config to each module. Up to them how they want to use it. Currently used in StreamsModule
        initConfig.put(Constants.CONFIG_HTTP_PROXY_URL, configuration.getHttpProxyUrl());
        initConfig.put(Constants.CONFIG_HTTP_PROXY_USERNAME, configuration.getHttpProxyUsername());
        initConfig.put(Constants.CONFIG_HTTP_PROXY_PASSWORD, configuration.getHttpProxyPassword());
        moduleRegistration.init(initConfig, fileStorage);
        if (moduleRegistration instanceof StorageManagerAware) {
            LOG.info("Module [{}] is StorageManagerAware and setting StorageManager.", moduleName);
            StorageManagerAware storageManagerAware = (StorageManagerAware) moduleRegistration;
            storageManagerAware.setStorageManager(storageManager);
        }
        if (moduleRegistration instanceof TransactionManagerAware) {
            LOG.info("Module [{}] is TransactionManagerAware and setting TransactionManager.", moduleName);
            TransactionManagerAware transactionManagerAware = (TransactionManagerAware) moduleRegistration;
            transactionManagerAware.setTransactionManager(transactionManager);
        }
        resourcesToRegister.addAll(moduleRegistration.getResources());
    }
    LOG.info("Registering resources to Jersey environment: [{}]", resourcesToRegister);
    for (Object resource : resourcesToRegister) {
        environment.jersey().register(resource);
    }
    environment.jersey().register(MultiPartFeature.class);
    final ErrorPageErrorHandler errorPageErrorHandler = new ErrorPageErrorHandler();
    errorPageErrorHandler.addErrorPage(Response.Status.UNAUTHORIZED.getStatusCode(), "/401.html");
    environment.getApplicationContext().setErrorHandler(errorPageErrorHandler);
}
Also used : ErrorPageErrorHandler(org.eclipse.jetty.servlet.ErrorPageErrorHandler) HashMap(java.util.HashMap) StorageManager(com.hortonworks.registries.storage.StorageManager) ArrayList(java.util.ArrayList) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) DefaultStreamlineAuthorizer(com.hortonworks.streamline.streams.security.impl.DefaultStreamlineAuthorizer) Storable(com.hortonworks.registries.storage.Storable) AuthorizerConfiguration(com.hortonworks.streamline.webservice.configurations.AuthorizerConfiguration) ModuleConfiguration(com.hortonworks.streamline.webservice.configurations.ModuleConfiguration) StreamlineKerberosRequestFilter(com.hortonworks.streamline.streams.security.authentication.StreamlineKerberosRequestFilter) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionEventListener(com.hortonworks.registries.storage.transaction.TransactionEventListener) StreamlineConfigurationResource(com.hortonworks.streamline.webservice.resources.StreamlineConfigurationResource) SecurityCatalogService(com.hortonworks.streamline.streams.security.service.SecurityCatalogService) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionManager(com.hortonworks.registries.storage.TransactionManager) StorageManagerAware(com.hortonworks.registries.storage.StorageManagerAware) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) TransactionManagerAware(com.hortonworks.registries.storage.TransactionManagerAware) FileStorage(com.hortonworks.registries.common.util.FileStorage) ModuleRegistration(com.hortonworks.streamline.common.ModuleRegistration) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory)

Example 3 with DefaultServerFactory

use of io.dropwizard.server.DefaultServerFactory in project dropwizard by dropwizard.

the class DropwizardAppExtensionRandomPortsConfigOverrideTest method supportsRandomPortsConfigAttributeOverrides.

@Test
void supportsRandomPortsConfigAttributeOverrides() {
    DefaultServerFactory serverFactory = (DefaultServerFactory) EXTENSION.getConfiguration().getServerFactory();
    assertThat(serverFactory.getApplicationConnectors().stream().map(HttpConnectorFactory.class::cast)).extracting(HttpConnectorFactory::getPort).containsExactly(0);
    assertThat(serverFactory.getAdminConnectors().stream().map(HttpConnectorFactory.class::cast)).extracting(HttpConnectorFactory::getPort).containsExactly(0);
}
Also used : DefaultServerFactory(io.dropwizard.server.DefaultServerFactory) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultServerFactory

use of io.dropwizard.server.DefaultServerFactory in project irontest by zheng-wang.

the class IronTestApplication method createSystemResources.

private void createSystemResources(IronTestConfiguration configuration, Environment environment, Jdbi systemDBJdbi, WireMockServer wireMockServer) {
    systemDBJdbi.registerArgument(new PropertiesArgumentFactory());
    systemDBJdbi.registerArgument(new EndpointPropertiesArgumentFactory());
    // create DAO objects
    final VersionDAO versionDAO = systemDBJdbi.onDemand(VersionDAO.class);
    final FolderDAO folderDAO = systemDBJdbi.onDemand(FolderDAO.class);
    final EnvironmentDAO environmentDAO = systemDBJdbi.onDemand(EnvironmentDAO.class);
    final EndpointDAO endpointDAO = systemDBJdbi.onDemand(EndpointDAO.class);
    final TestcaseDAO testcaseDAO = systemDBJdbi.onDemand(TestcaseDAO.class);
    final TeststepDAO teststepDAO = systemDBJdbi.onDemand(TeststepDAO.class);
    final AssertionDAO assertionDAO = systemDBJdbi.onDemand(AssertionDAO.class);
    final PropertyExtractorDAO propertyExtractorDAO = systemDBJdbi.onDemand(PropertyExtractorDAO.class);
    final UtilsDAO utilsDAO = systemDBJdbi.onDemand(UtilsDAO.class);
    final FolderTreeNodeDAO folderTreeNodeDAO = systemDBJdbi.onDemand(FolderTreeNodeDAO.class);
    final UserDefinedPropertyDAO udpDAO = systemDBJdbi.onDemand(UserDefinedPropertyDAO.class);
    final DataTableDAO dataTableDAO = systemDBJdbi.onDemand(DataTableDAO.class);
    final DataTableColumnDAO dataTableColumnDAO = systemDBJdbi.onDemand(DataTableColumnDAO.class);
    final DataTableCellDAO dataTableCellDAO = systemDBJdbi.onDemand(DataTableCellDAO.class);
    final TestcaseRunDAO testcaseRunDAO = systemDBJdbi.onDemand(TestcaseRunDAO.class);
    final TestcaseIndividualRunDAO testcaseIndividualRunDAO = systemDBJdbi.onDemand(TestcaseIndividualRunDAO.class);
    final TeststepRunDAO teststepRunDAO = systemDBJdbi.onDemand(TeststepRunDAO.class);
    final HTTPStubMappingDAO httpStubMappingDAO = systemDBJdbi.onDemand(HTTPStubMappingDAO.class);
    UserDAO userDAO = null;
    if (isInTeamMode(configuration)) {
        userDAO = systemDBJdbi.onDemand(UserDAO.class);
    }
    AppInfo appInfo = new AppInfo();
    if (isInTeamMode(configuration)) {
        appInfo.setAppMode(AppMode.TEAM);
        // ignore bindHost
        DefaultServerFactory server = (DefaultServerFactory) configuration.getServerFactory();
        List<ConnectorFactory> applicationConnectors = server.getApplicationConnectors();
        HttpConnectorFactory httpConnectorFactory = (HttpConnectorFactory) applicationConnectors.get(0);
        httpConnectorFactory.setBindHost(null);
        // turn on user authentication and authorization
        environment.jersey().register(new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<SimplePrincipal>().setAuthenticator(new ResourceAuthenticator(userDAO)).setAuthorizer(new ResourceAuthorizer()).buildAuthFilter()));
        environment.jersey().register(RolesAllowedDynamicFeature.class);
        environment.jersey().register(new AuthResponseFilter());
    }
    // create database tables
    // keep the order!!! (there are foreign keys linking some of them)
    versionDAO.createTableIfNotExists();
    versionDAO.insertVersionIfNotExists();
    folderDAO.createSequenceIfNotExists();
    folderDAO.createTableIfNotExists();
    folderDAO.insertARootNodeIfNotExists();
    environmentDAO.createSequenceIfNotExists();
    environmentDAO.createTableIfNotExists();
    endpointDAO.createSequenceIfNotExists();
    endpointDAO.createTableIfNotExists();
    testcaseDAO.createSequenceIfNotExists();
    testcaseDAO.createTableIfNotExists();
    teststepDAO.createSequenceIfNotExists();
    teststepDAO.createTableIfNotExists();
    assertionDAO.createSequenceIfNotExists();
    assertionDAO.createTableIfNotExists();
    propertyExtractorDAO.createSequenceIfNotExists();
    propertyExtractorDAO.createTableIfNotExists();
    udpDAO.createSequenceIfNotExists();
    udpDAO.createTableIfNotExists();
    dataTableColumnDAO.createSequenceIfNotExists();
    dataTableColumnDAO.createTableIfNotExists();
    dataTableColumnDAO.insertCaptionColumnForTestcasesWithoutDataTableColumn();
    dataTableCellDAO.createSequenceIfNotExists();
    dataTableCellDAO.createTableIfNotExists();
    testcaseRunDAO.createSequenceIfNotExists();
    testcaseRunDAO.createTableIfNotExists();
    testcaseIndividualRunDAO.createSequenceIfNotExists();
    testcaseIndividualRunDAO.createTableIfNotExists();
    teststepRunDAO.createSequenceIfNotExists();
    teststepRunDAO.createTableIfNotExists();
    httpStubMappingDAO.createSequenceIfNotExists();
    httpStubMappingDAO.createTableIfNotExists();
    if (isInTeamMode(configuration)) {
        userDAO.createSequenceIfNotExists();
        userDAO.createTableIfNotExists();
        userDAO.insertBuiltinAdminUserIfNotExists();
    }
    // register APIs
    environment.jersey().register(new SystemResource(appInfo));
    environment.jersey().register(new ManagedEndpointResource(appInfo, endpointDAO));
    environment.jersey().register(new TestcaseResource(testcaseDAO, teststepDAO));
    environment.jersey().register(new FolderResource(folderDAO, testcaseDAO));
    environment.jersey().register(new FolderTreeNodeResource(folderTreeNodeDAO));
    environment.jersey().register(new TeststepResource(appInfo, teststepDAO, udpDAO, utilsDAO, dataTableDAO, assertionDAO));
    environment.jersey().register(new WSDLResource());
    environment.jersey().register(new EnvironmentResource(environmentDAO));
    environment.jersey().register(new TestcaseRunResource(testcaseDAO, utilsDAO, testcaseRunDAO, teststepRunDAO, wireMockServer));
    environment.jersey().register(new AssertionResource(udpDAO, teststepDAO, dataTableDAO, assertionDAO));
    environment.jersey().register(new UDPResource(udpDAO));
    environment.jersey().register(new DataTableResource(dataTableDAO, dataTableColumnDAO, dataTableCellDAO));
    environment.jersey().register(new HTTPStubResource(httpStubMappingDAO, wireMockServer, udpDAO, dataTableDAO));
    environment.jersey().register(new MockServerResource(wireMockServer));
    environment.jersey().register(new PropertyExtractorResource(udpDAO, dataTableDAO, propertyExtractorDAO));
    if (isInTeamMode(configuration)) {
        environment.jersey().register(new UserResource(userDAO));
    }
    // if turned on in config.yml, register jersey LoggingFilter (used for logging Iron Test resource oriented HTTP API requests and responses)
    DefaultLoggingFactory defaultLoggingFactory = (DefaultLoggingFactory) configuration.getLoggingFactory();
    if (defaultLoggingFactory.getLoggers().containsKey(LoggingFilter.class.getName())) {
        environment.jersey().register(new LoggingFilter(Logger.getLogger(LoggingFilter.class.getName()), true));
    }
    // register exception mappers
    environment.jersey().register(new IronTestLoggingExceptionMapper());
}
Also used : ResourceAuthenticator(io.irontest.auth.ResourceAuthenticator) DefaultLoggingFactory(io.dropwizard.logging.DefaultLoggingFactory) BasicCredentialAuthFilter(io.dropwizard.auth.basic.BasicCredentialAuthFilter) AuthDynamicFeature(io.dropwizard.auth.AuthDynamicFeature) ResourceAuthorizer(io.irontest.auth.ResourceAuthorizer) AuthResponseFilter(io.irontest.auth.AuthResponseFilter) AppInfo(io.irontest.models.AppInfo) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory) LoggingFilter(org.glassfish.jersey.filter.LoggingFilter) HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) ConnectorFactory(io.dropwizard.jetty.ConnectorFactory) SimplePrincipal(io.irontest.auth.SimplePrincipal)

Example 5 with DefaultServerFactory

use of io.dropwizard.server.DefaultServerFactory in project atlasdb by palantir.

the class TimeLockServerConfiguration method computeNumberOfAvailableThreads.

private int computeNumberOfAvailableThreads() {
    Preconditions.checkState(getServerFactory() instanceof DefaultServerFactory, "Unexpected serverFactory instance on TimeLockServerConfiguration.");
    DefaultServerFactory serverFactory = (DefaultServerFactory) getServerFactory();
    int maxServerThreads = serverFactory.getMaxThreads();
    Preconditions.checkNotNull(serverFactory.getApplicationConnectors(), "applicationConnectors of TimeLockServerConfiguration must not be null.");
    Preconditions.checkState(serverFactory.getApplicationConnectors().get(0) instanceof HttpConnectorFactory, "applicationConnectors of TimeLockServerConfiguration must have a HttpConnectorFactory instance.");
    HttpConnectorFactory connectorFactory = (HttpConnectorFactory) serverFactory.getApplicationConnectors().get(0);
    int selectorThreads = connectorFactory.getSelectorThreads();
    int acceptorThreads = connectorFactory.getAcceptorThreads();
    // TODO(gmaretic): consider reserving numClients more threads or something similar for unlocks
    return maxServerThreads - selectorThreads - acceptorThreads - 1;
}
Also used : HttpConnectorFactory(io.dropwizard.jetty.HttpConnectorFactory) DefaultServerFactory(io.dropwizard.server.DefaultServerFactory)

Aggregations

DefaultServerFactory (io.dropwizard.server.DefaultServerFactory)6 HttpConnectorFactory (io.dropwizard.jetty.HttpConnectorFactory)5 AuthDynamicFeature (io.dropwizard.auth.AuthDynamicFeature)2 BasicCredentialAuthFilter (io.dropwizard.auth.basic.BasicCredentialAuthFilter)2 ConnectorFactory (io.dropwizard.jetty.ConnectorFactory)2 DefaultLoggingFactory (io.dropwizard.logging.DefaultLoggingFactory)2 AuthResponseFilter (io.irontest.auth.AuthResponseFilter)2 ResourceAuthenticator (io.irontest.auth.ResourceAuthenticator)2 ResourceAuthorizer (io.irontest.auth.ResourceAuthorizer)2 SimplePrincipal (io.irontest.auth.SimplePrincipal)2 AppInfo (io.irontest.models.AppInfo)2 LoggingFilter (org.glassfish.jersey.filter.LoggingFilter)2 FileStorage (com.hortonworks.registries.common.util.FileStorage)1 NOOPTransactionManager (com.hortonworks.registries.storage.NOOPTransactionManager)1 Storable (com.hortonworks.registries.storage.Storable)1 StorageManager (com.hortonworks.registries.storage.StorageManager)1 StorageManagerAware (com.hortonworks.registries.storage.StorageManagerAware)1 TransactionManager (com.hortonworks.registries.storage.TransactionManager)1 TransactionManagerAware (com.hortonworks.registries.storage.TransactionManagerAware)1 TransactionEventListener (com.hortonworks.registries.storage.transaction.TransactionEventListener)1