use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.
the class DefaultSchemaRegistry method createSchemaBranch.
@Override
public SchemaBranch createSchemaBranch(Long schemaVersionId, SchemaBranch schemaBranch) throws SchemaBranchAlreadyExistsException, SchemaNotFoundException {
Preconditions.checkNotNull(schemaBranch.getName(), "Schema branch name can't be null");
SchemaVersionInfo schemaVersionInfo = schemaVersionLifecycleManager.getSchemaVersionInfo(new SchemaIdVersion(schemaVersionId));
SchemaBranchKey schemaBranchKey = new SchemaBranchKey(schemaBranch.getName(), schemaVersionInfo.getName());
SchemaBranch existingSchemaBranch = null;
try {
existingSchemaBranch = schemaBranchCache.get(SchemaBranchCache.Key.of(schemaBranchKey));
} catch (SchemaBranchNotFoundException e) {
// Ignore this error
}
if (existingSchemaBranch != null)
throw new SchemaBranchAlreadyExistsException(String.format("A schema branch with name : '%s' already exists", schemaBranch.getName()));
SchemaBranchStorable schemaBranchStorable = SchemaBranchStorable.from(schemaBranch);
schemaBranchStorable.setSchemaMetadataName(schemaVersionInfo.getName());
schemaBranchStorable.setId(storageManager.nextId(SchemaBranchStorable.NAME_SPACE));
storageManager.add(schemaBranchStorable);
SchemaBranch persistedSchemaBranch;
try {
persistedSchemaBranch = schemaBranchCache.get(SchemaBranchCache.Key.of(schemaBranchKey));
} catch (SchemaBranchNotFoundException e) {
throw new RuntimeException(String.format("Failed to fetch persisted schema branch : '%s' from the database", schemaBranch.getName()));
}
SchemaBranchVersionMapping schemaBranchVersionMapping = new SchemaBranchVersionMapping(persistedSchemaBranch.getId(), schemaVersionInfo.getId());
storageManager.add(schemaBranchVersionMapping);
return persistedSchemaBranch;
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.
the class DefaultSchemaRegistry method getSchemaBranch.
private SchemaBranch getSchemaBranch(SchemaBranchKey schemaBranchKey) throws SchemaBranchNotFoundException {
List<QueryParam> queryParams = new ArrayList<>();
queryParams.add(new QueryParam(SchemaBranchStorable.NAME, schemaBranchKey.getSchemaBranchName()));
queryParams.add(new QueryParam(SchemaBranchStorable.SCHEMA_METADATA_NAME, schemaBranchKey.getSchemaMetadataName()));
Collection<SchemaBranchStorable> schemaBranchStorables = storageManager.find(SchemaBranchStorable.NAME_SPACE, queryParams);
if (schemaBranchStorables == null || schemaBranchStorables.isEmpty())
throw new SchemaBranchNotFoundException(String.format("Schema branch with key : %s not found", schemaBranchKey));
else if (schemaBranchStorables.size() > 1)
throw new SchemaBranchNotFoundException(String.format("Failed to unique determine a schema branch with key : %s", schemaBranchKey));
return schemaBranchStorables.iterator().next().toSchemaBranch();
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.
the class SchemaBranchLifeCycleTest method addSchemaVersionToBranch.
@Test
public void addSchemaVersionToBranch() throws IOException, SchemaBranchNotFoundException, InvalidSchemaException, SchemaNotFoundException, IncompatibleSchemaException, SchemaBranchAlreadyExistsException {
SchemaMetadata schemaMetadata = addSchemaMetadata(testNameRule.getMethodName(), SchemaCompatibility.NONE);
SchemaIdVersion masterSchemaIdVersion1 = addSchemaVersion(SchemaBranch.MASTER_BRANCH, schemaMetadata, "/device.avsc");
SchemaBranch schemaBranch1 = addSchemaBranch("BRANCH1", schemaMetadata, masterSchemaIdVersion1.getSchemaVersionId());
addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-incompat.avsc");
addSchemaVersion(schemaBranch1.getName(), schemaMetadata, "/device-compat.avsc");
Collection<SchemaVersionInfo> schemaBranch1VersionInfos = schemaRegistryClient.getAllVersions(schemaBranch1.getName(), schemaMetadata.getName());
Collection<SchemaVersionInfo> masterSchemaVersionInfos = schemaRegistryClient.getAllVersions(schemaMetadata.getName());
Assert.assertTrue(masterSchemaVersionInfos.size() == 1);
Assert.assertTrue(schemaBranch1VersionInfos.size() == 3);
Long versionsInInitiatedState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.INITIATED.getId())).count();
Long versionsInEnabledState = schemaBranch1VersionInfos.stream().filter(schemaVersionInfo -> schemaVersionInfo.getStateId().equals(SchemaVersionLifecycleStates.ENABLED.getId())).count();
Assert.assertTrue(versionsInInitiatedState == 2);
Assert.assertTrue(versionsInEnabledState == 1);
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.
the class SchemaRegistryClient method deleteSchemaBranch.
@Override
public void deleteSchemaBranch(Long schemaBranchId) throws SchemaBranchNotFoundException, InvalidSchemaBranchDeletionException {
WebTarget target = currentSchemaRegistryTargets().schemasTarget.path("branch/" + schemaBranchId);
Response response = Subject.doAs(subject, new PrivilegedAction<Response>() {
@Override
public Response run() {
return target.request().delete();
}
});
int status = response.getStatus();
if (status == Response.Status.NOT_FOUND.getStatusCode()) {
throw new SchemaBranchNotFoundException(response.readEntity(String.class));
} else if (status == Response.Status.BAD_REQUEST.getStatusCode()) {
throw new InvalidSchemaBranchDeletionException(response.readEntity(String.class));
} else if (status != Response.Status.OK.getStatusCode()) {
throw new RuntimeException(response.readEntity(String.class));
}
}
use of com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException in project registry by hortonworks.
the class SchemaRegistryResource method getAllSchemaVersions.
@GET
@Path("/schemas/{name}/versions")
@ApiOperation(value = "Get all the versions of the schema for the given schema name)", response = SchemaVersionInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA)
@Timed
@UnitOfWork
public Response getAllSchemaVersions(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @QueryParam("branch") @DefaultValue(MASTER_BRANCH) String schemaBranchName, @QueryParam("states") List<Byte> stateIds) {
Response response;
try {
Collection<SchemaVersionInfo> schemaVersionInfos = schemaRegistry.getAllVersions(schemaBranchName, schemaName, stateIds);
if (schemaVersionInfos != null) {
response = WSUtils.respondEntities(schemaVersionInfos, Response.Status.OK);
} else {
LOG.info("No schemas found with schemakey: [{}]", schemaName);
response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName);
}
} catch (SchemaBranchNotFoundException e) {
return WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, e.getMessage());
} catch (Exception ex) {
LOG.error("Encountered error while getting all schema versions for schemakey [{}]", schemaName, ex);
response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage());
}
return response;
}
Aggregations