Search in sources :

Example 1 with StorageManagerAware

use of com.hortonworks.registries.storage.StorageManagerAware 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 2 with StorageManagerAware

use of com.hortonworks.registries.storage.StorageManagerAware in project streamline by hortonworks.

the class StreamlineApplication method getJarStorage.

private FileStorage getJarStorage(StreamlineConfiguration configuration, StorageManager storageManager) {
    FileStorage fileStorage = null;
    try {
        fileStorage = ReflectionHelper.newInstance(configuration.getFileStorageConfiguration().getClassName());
        fileStorage.init(configuration.getFileStorageConfiguration().getProperties());
        if (fileStorage instanceof StorageManagerAware) {
            ((StorageManagerAware) fileStorage).setStorageManager(storageManager);
        }
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new RuntimeException(e);
    }
    return fileStorage;
}
Also used : StorageManagerAware(com.hortonworks.registries.storage.StorageManagerAware) FileStorage(com.hortonworks.registries.common.util.FileStorage)

Example 3 with StorageManagerAware

use of com.hortonworks.registries.storage.StorageManagerAware in project registry by hortonworks.

the class RegistryApplication method registerResources.

private void registerResources(Environment environment, RegistryConfiguration registryConfiguration) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    storageManager = getStorageManager(registryConfiguration.getStorageProviderConfiguration());
    if (storageManager instanceof TransactionManager)
        transactionManager = (TransactionManager) storageManager;
    else
        transactionManager = new NOOPTransactionManager();
    FileStorage fileStorage = getJarStorage(registryConfiguration.getFileStorageConfiguration());
    List<ModuleConfiguration> modules = registryConfiguration.getModules();
    List<Object> resourcesToRegister = new ArrayList<>();
    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>());
        }
        moduleRegistration.init(moduleConfiguration.getConfig(), fileStorage);
        if (moduleRegistration instanceof StorageManagerAware) {
            LOG.info("Module [{}] is StorageManagerAware and setting StorageManager.", moduleName);
            StorageManagerAware storageManagerAware = (StorageManagerAware) moduleRegistration;
            storageManagerAware.setStorageManager(storageManager);
        }
        if (moduleRegistration instanceof LeadershipAware) {
            LOG.info("Module [{}] is registered for LeadershipParticipant registration.", moduleName);
            LeadershipAware leadershipAware = (LeadershipAware) moduleRegistration;
            leadershipAware.setLeadershipParticipant(leadershipParticipantRef);
        }
        if (moduleRegistration instanceof HAServersAware) {
            LOG.info("Module [{}] is registered for HAServersAware registration.");
            HAServersAware leadershipAware = (HAServersAware) moduleRegistration;
            leadershipAware.setHAServerConfigManager(haServerNotificationManager);
        }
        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);
    environment.jersey().register(new TransactionEventListener(transactionManager));
}
Also used : ModuleConfiguration(com.hortonworks.registries.common.ModuleConfiguration) ArrayList(java.util.ArrayList) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionEventListener(com.hortonworks.registries.storage.transaction.TransactionEventListener) LeadershipAware(com.hortonworks.registries.common.ha.LeadershipAware) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) TransactionManager(com.hortonworks.registries.storage.TransactionManager) StorageManagerAware(com.hortonworks.registries.storage.StorageManagerAware) FileStorage(com.hortonworks.registries.common.util.FileStorage) ModuleRegistration(com.hortonworks.registries.common.ModuleRegistration) HAServersAware(com.hortonworks.registries.schemaregistry.HAServersAware)

Aggregations

FileStorage (com.hortonworks.registries.common.util.FileStorage)3 StorageManagerAware (com.hortonworks.registries.storage.StorageManagerAware)3 NOOPTransactionManager (com.hortonworks.registries.storage.NOOPTransactionManager)2 TransactionManager (com.hortonworks.registries.storage.TransactionManager)2 TransactionEventListener (com.hortonworks.registries.storage.transaction.TransactionEventListener)2 ArrayList (java.util.ArrayList)2 ModuleConfiguration (com.hortonworks.registries.common.ModuleConfiguration)1 ModuleRegistration (com.hortonworks.registries.common.ModuleRegistration)1 LeadershipAware (com.hortonworks.registries.common.ha.LeadershipAware)1 HAServersAware (com.hortonworks.registries.schemaregistry.HAServersAware)1 Storable (com.hortonworks.registries.storage.Storable)1 StorageManager (com.hortonworks.registries.storage.StorageManager)1 TransactionManagerAware (com.hortonworks.registries.storage.TransactionManagerAware)1 ModuleRegistration (com.hortonworks.streamline.common.ModuleRegistration)1 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)1 StreamlineKerberosRequestFilter (com.hortonworks.streamline.streams.security.authentication.StreamlineKerberosRequestFilter)1 DefaultStreamlineAuthorizer (com.hortonworks.streamline.streams.security.impl.DefaultStreamlineAuthorizer)1 SecurityCatalogService (com.hortonworks.streamline.streams.security.service.SecurityCatalogService)1 AuthorizerConfiguration (com.hortonworks.streamline.webservice.configurations.AuthorizerConfiguration)1 ModuleConfiguration (com.hortonworks.streamline.webservice.configurations.ModuleConfiguration)1