Search in sources :

Example 6 with Storable

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

the class SchemaVersionLifecycleManager method getSchemaBranches.

public Set<SchemaBranch> getSchemaBranches(Long schemaVersionId) throws SchemaBranchNotFoundException {
    List<QueryParam> schemaVersionMappingStorableQueryParams = new ArrayList<>();
    Set<SchemaBranch> schemaBranches = new HashSet<>();
    schemaVersionMappingStorableQueryParams.add(new QueryParam(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, schemaVersionId.toString()));
    for (Storable storable : storageManager.find(SchemaBranchVersionMapping.NAMESPACE, schemaVersionMappingStorableQueryParams)) {
        schemaBranches.add(schemaBranchCache.get(SchemaBranchCache.Key.of(((SchemaBranchVersionMapping) storable).getSchemaBranchId())));
    }
    return schemaBranches;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) Storable(com.hortonworks.registries.storage.Storable) HashSet(java.util.HashSet)

Example 7 with Storable

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

the class DefaultSchemaRegistry method addSchemaMetadata.

public Long addSchemaMetadata(SchemaMetadata schemaMetadata, boolean throwErrorIfExists) throws UnsupportedSchemaTypeException {
    SchemaMetadataStorable givenSchemaMetadataStorable = SchemaMetadataStorable.fromSchemaMetadataInfo(new SchemaMetadataInfo(schemaMetadata));
    String type = schemaMetadata.getType();
    if (schemaTypeWithProviders.get(type) == null) {
        throw new UnsupportedSchemaTypeException("Given schema type " + type + " not supported");
    }
    if (!throwErrorIfExists) {
        Storable schemaMetadataStorable = storageManager.get(givenSchemaMetadataStorable.getStorableKey());
        if (schemaMetadataStorable != null) {
            return schemaMetadataStorable.getId();
        }
    }
    final Long nextId = storageManager.nextId(givenSchemaMetadataStorable.getNameSpace());
    givenSchemaMetadataStorable.setId(nextId);
    givenSchemaMetadataStorable.setTimestamp(System.currentTimeMillis());
    storageManager.addOrUpdate(givenSchemaMetadataStorable);
    // Add a schema branch for this metadata
    SchemaBranchStorable schemaBranchStorable = new SchemaBranchStorable(SchemaBranch.MASTER_BRANCH, schemaMetadata.getName(), String.format(SchemaBranch.MASTER_BRANCH_DESC, schemaMetadata.getName()), System.currentTimeMillis());
    schemaBranchStorable.setId(storageManager.nextId(SchemaBranchStorable.NAME_SPACE));
    storageManager.add(schemaBranchStorable);
    return givenSchemaMetadataStorable.getId();
}
Also used : UnsupportedSchemaTypeException(com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException) Storable(com.hortonworks.registries.storage.Storable)

Example 8 with Storable

use of com.hortonworks.registries.storage.Storable 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)

Example 9 with Storable

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

the class GuavaCacheTest method test_get_unexisting_key_null_expected.

@Test
public void test_get_unexisting_key_null_expected() {
    Storable val = cache.get(storableKey);
    Assert.assertNull(val);
}
Also used : Storable(com.hortonworks.registries.storage.Storable) AbstractStorable(com.hortonworks.registries.storage.catalog.AbstractStorable) Test(org.junit.Test)

Example 10 with Storable

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

the class JdbcStorageManagerIntegrationTest method testSearchQueryApi.

@Test
public void testSearchQueryApi() {
    for (StorableTest storableTest : storableTests) {
        storableTest.addAllToStorage();
        String nameSpace = storableTest.getNameSpace();
        SearchQuery searchQuery = SearchQuery.searchFrom(nameSpace).where(WhereClause.begin().contains("name", "info").and().gt("id", 1L).combine()).orderBy(OrderBy.asc("name"));
        Collection<Storable> storablesWithIdGt1 = getStorageManager().search(searchQuery);
        System.out.println("storablesWithIdGt1 = " + storablesWithIdGt1);
        for (Storable storable : storablesWithIdGt1) {
            Assert.assertTrue(storable.getId() > 1L);
        }
        Collection<Storable> allStorables = getStorageManager().list(searchQuery.getNameSpace());
        System.out.println("list = " + allStorables);
        Assert.assertEquals(allStorables.size() - 1, storablesWithIdGt1.size());
    }
}
Also used : SearchQuery(com.hortonworks.registries.storage.search.SearchQuery) StorableTest(com.hortonworks.registries.storage.StorableTest) Storable(com.hortonworks.registries.storage.Storable) AbstractStoreManagerTest(com.hortonworks.registries.storage.AbstractStoreManagerTest) StorableTest(com.hortonworks.registries.storage.StorableTest) Test(org.junit.Test) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest)

Aggregations

Storable (com.hortonworks.registries.storage.Storable)14 StorageManager (com.hortonworks.registries.storage.StorageManager)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)3 AbstractStoreManagerTest (com.hortonworks.registries.storage.AbstractStoreManagerTest)3 StorableKey (com.hortonworks.registries.storage.StorableKey)3 StorableTest (com.hortonworks.registries.storage.StorableTest)3 HashSet (java.util.HashSet)3 CacheBuilder (com.google.common.cache.CacheBuilder)2 QueryParam (com.hortonworks.registries.common.QueryParam)2 UnsupportedSchemaTypeException (com.hortonworks.registries.schemaregistry.errors.UnsupportedSchemaTypeException)2 CacheBackedStorageManager (com.hortonworks.registries.storage.CacheBackedStorageManager)2 OrderByField (com.hortonworks.registries.storage.OrderByField)2 PrimaryKey (com.hortonworks.registries.storage.PrimaryKey)2 StorageWriter (com.hortonworks.registries.storage.cache.writer.StorageWriter)2 StorageException (com.hortonworks.registries.storage.exception.StorageException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1