Search in sources :

Example 6 with StorageManager

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

the class RefreshHAServerListTask method run.

@Override
public void run() {
    try {
        transactionManager.beginTransaction(TransactionIsolation.SERIALIZABLE);
        Collection<HostConfigStorable> hostConfigStorables = storageManager.<HostConfigStorable>list(HostConfigStorable.NAME_SPACE);
        List<HostConfigStorable> hostConfigWithoutStaleEntries = hostConfigStorables.stream().filter(hostConfigStorable -> {
            if ((System.currentTimeMillis() - hostConfigStorable.getTimestamp()) > 600000) {
                LOG.debug("Removing : {} from list of available servers", hostConfigStorable.getHostUrl());
                storageManager.remove(hostConfigStorable.getStorableKey());
                return false;
            } else {
                return true;
            }
        }).collect(Collectors.toList());
        LOG.debug("Fetched : {} as the latest available servers", Arrays.toString(hostConfigWithoutStaleEntries.toArray()));
        haServerNotificationManager.refreshServerInfo(hostConfigWithoutStaleEntries);
        HostConfigStorable hostConfWithUpdatedTimeStamp = storageManager.get(new HostConfigStorable(haServerNotificationManager.getHomeNodeURL()).getStorableKey());
        if (hostConfWithUpdatedTimeStamp == null) {
            hostConfWithUpdatedTimeStamp = new HostConfigStorable(storageManager.nextId(HostConfigStorable.NAME_SPACE), haServerNotificationManager.getHomeNodeURL(), System.currentTimeMillis());
        } else {
            hostConfWithUpdatedTimeStamp.setTimestamp(System.currentTimeMillis());
        }
        storageManager.addOrUpdate(hostConfWithUpdatedTimeStamp);
        transactionManager.commitTransaction();
    } catch (Exception e) {
        transactionManager.rollbackTransaction();
        throw e;
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Logger(org.slf4j.Logger) TransactionManager(com.hortonworks.registries.storage.TransactionManager) Collection(java.util.Collection) HAServerNotificationManager(com.hortonworks.registries.schemaregistry.HAServerNotificationManager) HostConfigStorable(com.hortonworks.registries.schemaregistry.HostConfigStorable) LoggerFactory(org.slf4j.LoggerFactory) TransactionIsolation(com.hortonworks.registries.common.transaction.TransactionIsolation) TimerTask(java.util.TimerTask) StorageManager(com.hortonworks.registries.storage.StorageManager) Collectors(java.util.stream.Collectors) HostConfigStorable(com.hortonworks.registries.schemaregistry.HostConfigStorable)

Example 7 with StorageManager

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

the class RegistryApplication method getStorageManager.

private StorageManager getStorageManager(StorageProviderConfiguration storageProviderConfiguration) {
    final String providerClass = storageProviderConfiguration.getProviderClass();
    StorageManager storageManager;
    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 8 with StorageManager

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

the class DbFileStorageTest method setUp.

@Before
public void setUp() throws Exception {
    connectionBuilder = new HikariCPConnectionBuilder(HikariBasicConfig.getH2HikariConfig());
    MySqlExecutor queryExecutor = new MySqlExecutor(new ExecutionConfig(-1), connectionBuilder);
    StorageManager jdbcStorageManager = new JdbcStorageManager(queryExecutor);
    transactionManager = (TransactionManager) jdbcStorageManager;
    jdbcStorageManager.registerStorables(StorageUtils.getStorableEntities());
    dbFileStorage = new DbFileStorage();
    dbFileStorage.setStorageManager(jdbcStorageManager);
    runScript("create_fileblob.sql");
}
Also used : HikariCPConnectionBuilder(com.hortonworks.registries.storage.impl.jdbc.connection.HikariCPConnectionBuilder) MySqlExecutor(com.hortonworks.registries.storage.impl.jdbc.provider.mysql.factory.MySqlExecutor) JdbcStorageManager(com.hortonworks.registries.storage.impl.jdbc.JdbcStorageManager) StorageManager(com.hortonworks.registries.storage.StorageManager) ExecutionConfig(com.hortonworks.registries.storage.impl.jdbc.config.ExecutionConfig) JdbcStorageManager(com.hortonworks.registries.storage.impl.jdbc.JdbcStorageManager) Before(org.junit.Before)

Example 9 with StorageManager

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

the class TestApplication 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 : CacheBackedStorageManager(com.hortonworks.registries.storage.CacheBackedStorageManager) StorageManager(com.hortonworks.registries.storage.StorageManager)

Example 10 with StorageManager

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

the class TestApplication method run.

@Override
public void run(TestConfiguration testConfiguration, Environment environment) throws Exception {
    StorageManager storageManager = getCacheBackedDao(testConfiguration);
    final TagService tagService = new CatalogTagService(storageManager);
    final TagCatalogResource tagCatalogResource = new TagCatalogResource(tagService);
    environment.jersey().register(tagCatalogResource);
    environment.jersey().register(MultiPartFeature.class);
}
Also used : CatalogTagService(com.hortonworks.streamline.registries.tag.service.CatalogTagService) TagService(com.hortonworks.streamline.registries.tag.service.TagService) CacheBackedStorageManager(com.hortonworks.registries.storage.CacheBackedStorageManager) StorageManager(com.hortonworks.registries.storage.StorageManager) CatalogTagService(com.hortonworks.streamline.registries.tag.service.CatalogTagService) TagCatalogResource(com.hortonworks.streamline.registries.tag.service.TagCatalogResource)

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