Search in sources :

Example 1 with StorageManager

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

the class TestApplication method getCacheBackedDao.

private StorageManager getCacheBackedDao(TestConfiguration testConfiguration) {
    StorageProviderConfiguration storageProviderConfiguration = testConfiguration.getStorageProviderConfiguration();
    final StorageManager dao = getStorageManager(storageProviderConfiguration);
    final CacheBuilder cacheBuilder = getGuavaCacheBuilder();
    final Cache<StorableKey, Storable> cache = getCache(dao, cacheBuilder);
    final StorageWriter storageWriter = getStorageWriter(dao);
    return doGetCacheBackedDao(cache, storageWriter);
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) StorableKey(com.hortonworks.registries.storage.StorableKey) CacheBackedStorageManager(com.hortonworks.registries.storage.CacheBackedStorageManager) StorageManager(com.hortonworks.registries.storage.StorageManager) Storable(com.hortonworks.registries.storage.Storable) StorageWriter(com.hortonworks.registries.storage.cache.writer.StorageWriter)

Example 2 with StorageManager

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

the class StreamlineApplication method getStorageManager.

private StorageManager getStorageManager(StorageProviderConfiguration storageProviderConfiguration) {
    final String providerClass = storageProviderConfiguration.getProviderClass();
    StorageManager storageManager = null;
    try {
        storageManager = (StorageManager) Class.forName(providerClass).newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    storageManager.init(storageProviderConfiguration.getProperties());
    return storageManager;
}
Also used : StorageManager(com.hortonworks.registries.storage.StorageManager)

Example 3 with StorageManager

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

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

the class DefaultSchemaRegistry method init.

@Override
public void init(Map<String, Object> props) {
    storageManager.registerStorables(Arrays.asList(SchemaMetadataStorable.class, SchemaVersionStorable.class, SchemaVersionStateStorable.class, SchemaFieldInfoStorable.class, SerDesInfoStorable.class, SchemaSerDesMapping.class, SchemaBranchStorable.class, SchemaBranchVersionMapping.class, HostConfigStorable.class));
    Options options = new Options(props);
    schemaBranchCache = new SchemaBranchCache(options.getMaxSchemaCacheSize(), options.getSchemaExpiryInSecs(), createSchemaBranchFetcher());
    SchemaMetadataFetcher schemaMetadataFetcher = createSchemaMetadataFetcher();
    schemaVersionLifecycleManager = new SchemaVersionLifecycleManager(storageManager, props, schemaMetadataFetcher, schemaBranchCache, haServerNotificationManager);
    Collection<? extends SchemaProvider> schemaProviders = initSchemaProviders(schemaProvidersConfig, schemaVersionLifecycleManager.getSchemaVersionRetriever());
    this.schemaTypeWithProviders = schemaProviders.stream().collect(Collectors.toMap(SchemaProvider::getType, Function.identity()));
    schemaProviderInfos = Collections.unmodifiableList(schemaProviders.stream().map(schemaProvider -> new SchemaProviderInfo(schemaProvider.getType(), schemaProvider.getName(), schemaProvider.getDescription(), schemaProvider.getDefaultSerializerClassName(), schemaProvider.getDefaultDeserializerClassName())).collect(Collectors.toList()));
}
Also used : ObjectMapperUtils(com.hortonworks.registries.schemaregistry.utils.ObjectMapperUtils) SchemaBranchCache(com.hortonworks.registries.schemaregistry.cache.SchemaBranchCache) SchemaVersionLifecycleStateMachineInfo(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStateMachineInfo) Arrays(java.util.Arrays) SchemaBranchNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException) UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) InitializedStateDetails(com.hortonworks.registries.schemaregistry.state.details.InitializedStateDetails) SchemaVersionLifecycleStates(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleStates) QueryParam(com.hortonworks.registries.common.QueryParam) FileStorage(com.hortonworks.registries.common.util.FileStorage) LoggerFactory(org.slf4j.LoggerFactory) Storable(com.hortonworks.registries.storage.Storable) OrderByField(com.hortonworks.registries.storage.OrderByField) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SchemaRegistryCacheType(com.hortonworks.registries.schemaregistry.cache.SchemaRegistryCacheType) Map(java.util.Map) OrderBy(com.hortonworks.registries.storage.search.OrderBy) WhereClause(com.hortonworks.registries.storage.search.WhereClause) IncompatibleSchemaException(com.hortonworks.registries.schemaregistry.errors.IncompatibleSchemaException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) InvalidSchemaException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaException) Collection(java.util.Collection) InvalidSchemaBranchDeletionException(com.hortonworks.registries.schemaregistry.errors.InvalidSchemaBranchDeletionException) SchemaLifecycleException(com.hortonworks.registries.schemaregistry.state.SchemaLifecycleException) IOException(java.io.IOException) UUID(java.util.UUID) SchemaVersionLifecycleContext(com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext) Collectors(java.util.stream.Collectors) MergeInfo(com.hortonworks.registries.schemaregistry.state.details.MergeInfo) SerDesException(com.hortonworks.registries.schemaregistry.serde.SerDesException) SearchQuery(com.hortonworks.registries.storage.search.SearchQuery) List(java.util.List) SchemaVersionInfoCache(com.hortonworks.registries.schemaregistry.cache.SchemaVersionInfoCache) SchemaNotFoundException(com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException) Preconditions(com.google.common.base.Preconditions) SchemaBranchAlreadyExistsException(com.hortonworks.registries.schemaregistry.errors.SchemaBranchAlreadyExistsException) StorableKey(com.hortonworks.registries.storage.StorableKey) StorageManager(com.hortonworks.registries.storage.StorageManager) Collections(java.util.Collections) InputStream(java.io.InputStream) SchemaBranchCache(com.hortonworks.registries.schemaregistry.cache.SchemaBranchCache)

Example 5 with StorageManager

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

the class TestApplication method getCacheBackedDao.

private StorageManager getCacheBackedDao(TestConfiguration testConfiguration) {
    StorageProviderConfiguration storageProviderConfiguration = testConfiguration.getStorageProviderConfiguration();
    final StorageManager dao = getStorageManager(storageProviderConfiguration);
    final CacheBuilder cacheBuilder = getGuavaCacheBuilder();
    final Cache<StorableKey, Storable> cache = getCache(dao, cacheBuilder);
    final StorageWriter storageWriter = getStorageWriter(dao);
    return doGetCacheBackedDao(cache, storageWriter);
}
Also used : CacheBuilder(com.google.common.cache.CacheBuilder) StorableKey(com.hortonworks.registries.storage.StorableKey) CacheBackedStorageManager(com.hortonworks.registries.storage.CacheBackedStorageManager) StorageManager(com.hortonworks.registries.storage.StorageManager) Storable(com.hortonworks.registries.storage.Storable) StorageWriter(com.hortonworks.registries.storage.cache.writer.StorageWriter)

Aggregations

StorageManager (com.hortonworks.registries.storage.StorageManager)14 CacheBackedStorageManager (com.hortonworks.registries.storage.CacheBackedStorageManager)6 Storable (com.hortonworks.registries.storage.Storable)4 StorableKey (com.hortonworks.registries.storage.StorableKey)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 FileStorage (com.hortonworks.registries.common.util.FileStorage)2 HAServerNotificationManager (com.hortonworks.registries.schemaregistry.HAServerNotificationManager)2 TransactionManager (com.hortonworks.registries.storage.TransactionManager)2 StorageWriter (com.hortonworks.registries.storage.cache.writer.StorageWriter)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Before (org.junit.Before)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Preconditions (com.google.common.base.Preconditions)1 QueryParam (com.hortonworks.registries.common.QueryParam)1