use of com.hortonworks.registries.storage.StorableKey in project registry by hortonworks.
the class SchemaVersionLifecycleManager method storeSchemaVersionState.
private void storeSchemaVersionState(SchemaVersionLifecycleContext schemaVersionLifecycleContext) throws SchemaNotFoundException {
// store versions state, sequence
SchemaVersionStateStorable stateStorable = new SchemaVersionStateStorable();
Long schemaVersionId = schemaVersionLifecycleContext.getSchemaVersionId();
byte stateId = schemaVersionLifecycleContext.getState().getId();
stateStorable.setSchemaVersionId(schemaVersionId);
stateStorable.setSequence(schemaVersionLifecycleContext.getSequence() + 1);
stateStorable.setStateId(stateId);
stateStorable.setTimestamp(System.currentTimeMillis());
stateStorable.setDetails(schemaVersionLifecycleContext.getDetails());
stateStorable.setId(storageManager.nextId(SchemaVersionStateStorable.NAME_SPACE));
storageManager.add(stateStorable);
// store latest state in versions entity
StorableKey storableKey = new StorableKey(SchemaVersionStorable.NAME_SPACE, SchemaVersionStorable.getPrimaryKey(schemaVersionId));
SchemaVersionStorable versionedSchema = storageManager.get(storableKey);
if (versionedSchema == null) {
throw new SchemaNotFoundException("No Schema version exists with id " + schemaVersionId);
}
versionedSchema.setState(stateId);
storageManager.addOrUpdate(versionedSchema);
// invalidate schema version from cache
SchemaVersionInfoCache.Key schemaVersionCacheKey = SchemaVersionInfoCache.Key.of(new SchemaIdVersion(schemaVersionId));
invalidateSchemaInAllHAServer(schemaVersionCacheKey);
}
use of com.hortonworks.registries.storage.StorableKey in project registry by hortonworks.
the class SchemaVersionLifecycleManager method deleteSchemaVersionBranchMapping.
private void deleteSchemaVersionBranchMapping(Long schemaVersionId) throws SchemaNotFoundException, SchemaLifecycleException {
List<QueryParam> schemaVersionMappingStorableQueryParams = Lists.newArrayList();
schemaVersionMappingStorableQueryParams.add(new QueryParam(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, schemaVersionId.toString()));
List<OrderByField> orderByFields = new ArrayList<>();
orderByFields.add(OrderByField.of(SchemaBranchVersionMapping.SCHEMA_VERSION_INFO_ID, false));
Collection<SchemaBranchVersionMapping> storables = storageManager.find(SchemaBranchVersionMapping.NAMESPACE, schemaVersionMappingStorableQueryParams, orderByFields);
if (storables == null || storables.isEmpty()) {
LOG.debug("No need to delete schema version mapping as the database did a cascade delete");
return;
}
if (storables.size() > 1) {
List<String> branchNamesTiedToSchema = storables.stream().map(storable -> schemaBranchCache.get(SchemaBranchCache.Key.of(storable.getSchemaBranchId())).getName()).collect(Collectors.toList());
throw new SchemaLifecycleException(String.format("Schema version with id : '%s' is tied with more than one branch : '%s' ", schemaVersionId.toString(), Arrays.toString(branchNamesTiedToSchema.toArray())));
}
storageManager.remove(new StorableKey(SchemaBranchVersionMapping.NAMESPACE, storables.iterator().next().getPrimaryKey()));
}
use of com.hortonworks.registries.storage.StorableKey in project registry by hortonworks.
the class SchemaVersionLifecycleManager method fetchSchemaVersionInfo.
private SchemaVersionInfo fetchSchemaVersionInfo(Long id) throws SchemaNotFoundException {
StorableKey storableKey = new StorableKey(SchemaVersionStorable.NAME_SPACE, SchemaVersionStorable.getPrimaryKey(id));
SchemaVersionStorable versionedSchema = storageManager.get(storableKey);
if (versionedSchema == null) {
throw new SchemaNotFoundException("No Schema version exists with id " + id);
}
return versionedSchema.toSchemaVersionInfo();
}
use of com.hortonworks.registries.storage.StorableKey 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);
}
use of com.hortonworks.registries.storage.StorableKey in project registry by hortonworks.
the class MySqlSelectQueryTest method testSelectQueryWithOrderBy.
@Test
public void testSelectQueryWithOrderBy() throws Exception {
List<OrderByField> orderByFields = Arrays.asList(OrderByField.of("foo", true), OrderByField.of("bar"));
MySqlSelectQuery mySqlSelectQuery = new MySqlSelectQuery("topic", orderByFields);
String parametrizedSql = mySqlSelectQuery.getParametrizedSql();
Assert.assertEquals("SELECT * FROM topic ORDER BY `foo` DESC, ORDER BY `bar` ASC", parametrizedSql);
Map<Schema.Field, Object> fieldToObjectMap = new HashMap<>();
fieldToObjectMap.put(new Schema.Field("foo", Schema.Type.LONG), 1);
mySqlSelectQuery = new MySqlSelectQuery(new StorableKey(nameSpace, new PrimaryKey(fieldToObjectMap)), orderByFields);
parametrizedSql = mySqlSelectQuery.getParametrizedSql();
Assert.assertEquals("SELECT * FROM topic WHERE `foo` = ? ORDER BY `foo` DESC, ORDER BY `bar` ASC", parametrizedSql);
}
Aggregations