use of io.hops.hopsworks.exceptions.SchemaException in project hopsworks by logicalclocks.
the class SubjectsController method deleteSubject.
public List<Integer> deleteSubject(Project project, String subject) throws SchemaException, KafkaException {
validateSubject(subject, false);
if (!projectTopicsFacade.findTopicsBySubject(project, subject).isEmpty()) {
throw new KafkaException(RESTCodes.KafkaErrorCode.SCHEMA_IN_USE, Level.FINE, "project=" + project.getName() + ", subject=" + subject);
}
List<Integer> versions = getSubjectVersions(project, subject);
Integer deleted = subjectsFacade.deleteSubject(project, subject);
if (versions.size() != deleted) {
throw new SchemaException(RESTCodes.SchemaRegistryErrorCode.INTERNAL_SERVER_ERROR, Level.FINE, "error deleting " + "subject. versions=" + Arrays.toString(versions.toArray()) + ", but deleted " + deleted + " items.");
}
subjectsCompatibilityFacade.getSubjectCompatibility(project, subject).ifPresent(sc -> subjectsCompatibilityFacade.remove(sc));
return versions;
}
use of io.hops.hopsworks.exceptions.SchemaException in project hopsworks by logicalclocks.
the class SubjectsController method isCompatible.
private boolean isCompatible(Project project, String subject, Schema schema) throws SchemaException {
SchemaCompatibility sc = getSubjectOrProjectCompatibility(project, subject);
if (sc.equals(SchemaCompatibility.NONE)) {
return true;
}
SchemaValidator validator = getSchemaValidator(sc);
List<Schema> previousSchemas = subjectsFacade.findSubjectByName(project, subject).stream().sorted(Comparator.comparing(Subjects::getVersion).reversed()).map(s -> new Schema.Parser().parse(s.getSchema().getSchema())).collect(Collectors.toList());
try {
validator.validate(schema, previousSchemas);
} catch (SchemaValidationException e) {
return false;
}
return true;
}
use of io.hops.hopsworks.exceptions.SchemaException in project hopsworks by logicalclocks.
the class KafkaResource method getSubjectVersions.
@ApiOperation(value = "Get list of versions of a registered subject.")
@GET
@Path("/subjects/{subject}/versions")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getSubjectVersions(@PathParam("subject") String subject, @Context SecurityContext sc) {
try {
List<Integer> versions = subjectsController.getSubjectVersions(project, subject);
String array = Arrays.toString(versions.toArray());
GenericEntity<String> entity = new GenericEntity<String>(array) {
};
return Response.ok().entity(entity).build();
} catch (SchemaException e) {
SchemaRegistryError error = new SchemaRegistryError(e.getErrorCode().getCode(), e.getErrorCode().getMessage());
return Response.status(e.getErrorCode().getRespStatus()).entity(error).build();
}
}
use of io.hops.hopsworks.exceptions.SchemaException in project hopsworks by logicalclocks.
the class KafkaResource method deleteSubject.
@ApiOperation(value = "Delete a subject with all its versions and its compatibility if exists.")
@DELETE
@Path("/subjects/{subject}")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response deleteSubject(@PathParam("subject") String subject, @Context SecurityContext sc) throws KafkaException {
try {
List<Integer> versions = subjectsController.deleteSubject(project, subject);
String array = Arrays.toString(versions.toArray());
GenericEntity<String> entity = new GenericEntity<String>(array) {
};
return Response.ok().entity(entity).build();
} catch (SchemaException e) {
SchemaRegistryError error = new SchemaRegistryError(e.getErrorCode().getCode(), e.getErrorCode().getMessage());
return Response.status(e.getErrorCode().getRespStatus()).entity(error).build();
}
}
use of io.hops.hopsworks.exceptions.SchemaException in project hopsworks by logicalclocks.
the class KafkaResource method getSchema.
@ApiOperation(value = "Get avro schema of a subject and version.")
@GET
@Path("/subjects/{subject}/versions/{version}/schema")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.KAFKA }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getSchema(@PathParam("subject") String subject, @PathParam("version") String version, @Context SecurityContext sc) {
try {
SubjectDTO dto = subjectsController.getSubjectDetails(project, subject, version);
GenericEntity<String> entity = new GenericEntity<String>(dto.getSchema()) {
};
return Response.ok().entity(entity).build();
} catch (SchemaException e) {
SchemaRegistryError error = new SchemaRegistryError(e.getErrorCode().getCode(), e.getErrorCode().getMessage());
return Response.status(e.getErrorCode().getRespStatus()).entity(error).build();
}
}
Aggregations