use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method createSchemaBranch.
@Override
public SchemaBranch createSchemaBranch(Long schemaVersionId, SchemaBranch schemaBranch) throws SchemaBranchAlreadyExistsException, SchemaNotFoundException {
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path("versionsById/" + schemaVersionId + "/branch");
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(schemaBranch), Response.class);
}
});
int status = response.getStatus();
if (status == Response.Status.OK.getStatusCode()) {
String msg = response.readEntity(String.class);
SchemaBranch returnedSchemaBranch = readEntity(msg, SchemaBranch.class);
return returnedSchemaBranch;
} else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
throw new SchemaNotFoundException(response.readEntity(String.class));
} else if (status == Response.Status.CONFLICT.getStatusCode()) {
throw new SchemaBranchAlreadyExistsException(response.readEntity(String.class));
} else {
throw new RuntimeException(response.readEntity(String.class));
}
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaVersionLifecycleManager method createSchemaVersionLifeCycleContext.
public SchemaVersionLifecycleContext createSchemaVersionLifeCycleContext(Long schemaVersionId, SchemaVersionLifecycleState schemaVersionLifecycleState) throws SchemaNotFoundException {
// get the current state from storage for the given versionID
// we can use a query to get max value for the column for a given schema-version-id but StorageManager does not
// have API to take custom queries.
List<QueryParam> queryParams = new ArrayList<>();
queryParams.add(new QueryParam(SchemaVersionStateStorable.SCHEMA_VERSION_ID, schemaVersionId.toString()));
queryParams.add(new QueryParam(SchemaVersionStateStorable.STATE, schemaVersionLifecycleState.getId().toString()));
Collection<SchemaVersionStateStorable> schemaVersionStates = storageManager.find(SchemaVersionStateStorable.NAME_SPACE, queryParams, Collections.singletonList(OrderByField.of(SchemaVersionStateStorable.SEQUENCE, true)));
if (schemaVersionStates.isEmpty()) {
throw new SchemaNotFoundException("No schema versions found with id " + schemaVersionId);
}
SchemaVersionStateStorable stateStorable = schemaVersionStates.iterator().next();
SchemaVersionService schemaVersionService = createSchemaVersionService();
SchemaVersionLifecycleContext context = new SchemaVersionLifecycleContext(stateStorable.getSchemaVersionId(), stateStorable.getSequence(), schemaVersionService, schemaVersionLifecycleStateMachine, customSchemaStateExecutor);
context.setDetails(stateStorable.getDetails());
return context;
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException 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.schemaregistry.errors.SchemaNotFoundException 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.schemaregistry.errors.SchemaNotFoundException in project registry by hortonworks.
the class SchemaVersionLifecycleManager method getAllVersions.
public Collection<SchemaVersionInfo> getAllVersions(final String schemaName) throws SchemaNotFoundException {
List<QueryParam> queryParams = Collections.singletonList(new QueryParam(SchemaVersionStorable.NAME, schemaName));
SchemaMetadataInfo schemaMetadataInfo = getSchemaMetadataInfo(schemaName);
if (schemaMetadataInfo == null) {
throw new SchemaNotFoundException("Schema not found with name " + schemaName);
}
Collection<SchemaVersionStorable> storables = storageManager.find(SchemaVersionStorable.NAME_SPACE, queryParams, Collections.singletonList(OrderByField.of(SchemaVersionStorable.VERSION, true)));
List<SchemaVersionInfo> schemaVersionInfos;
if (storables != null && !storables.isEmpty()) {
schemaVersionInfos = storables.stream().map(SchemaVersionStorable::toSchemaVersionInfo).collect(Collectors.toList());
} else {
schemaVersionInfos = Collections.emptyList();
}
return schemaVersionInfos;
}
Aggregations