@POST @Path("/serdes") @ApiOperation(value = "Add a Serializer/Deserializer into the Schema Registry", response = Long.class, tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response addSerDes(@ApiParam(value = "Serializer/Deserializer information to be registered", required = true) SerDesPair serDesPair, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> _addSerDesInfo(serDesPair)); }
@GET @Path("/serdes/{id}") @ApiOperation(value = "Get a Serializer for the given serializer id", response = SerDesInfo.class, tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response getSerDes(@ApiParam(value = "Serializer identifier", required = true) @PathParam("id") Long serializerId) { return _getSerDesInfo(serializerId); }
@FormDataParam("description") final String description, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> { Response response; SchemaVersion schemaVersion = null; schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description); response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo); } catch (IOException ex) { LOG.error("Encountered error while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex, ex);
@Context UriInfo uriInfo, @Context HttpHeaders httpHeaders) { return handleLeaderAction(uriInfo, () -> { Response response; try { schemaMetadata.trim(); checkValueAsNullOrEmpty("Schema name", schemaMetadata.getName()); checkValueAsNullOrEmpty("Schema type", schemaMetadata.getType()); checkValidNames(schemaMetadata.getName()); boolean throwErrorIfExists = isThrowErrorIfExists(httpHeaders); Long schemaId = schemaRegistry.addSchemaMetadata(schemaMetadata, throwErrorIfExists); response = WSUtils.respondEntity(schemaId, Response.Status.CREATED);
@POST @Path("/schemas/{name}/mapping/{serDesId}") @ApiOperation(value = "Bind the given Serializer/Deserializer to the schema identified by the schema name", tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response mapSchemaWithSerDes(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Serializer/deserializer identifier", required = true) @PathParam("serDesId") Long serDesId, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> { Response response; try { schemaRegistry.mapSchemaWithSerDes(schemaName, serDesId); response = WSUtils.respondEntity(true, Response.Status.OK); } catch (Exception ex) { response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } return response; }); }
@GET @Path("/search/schemas") @ApiOperation(value = "Search for schemas containing the given name and description", notes = "Search the schemas for given name and description, return a list of schemas that contain the field.", response = SchemaMetadataInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response findSchemas(@Context UriInfo uriInfo) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); try { Collection<SchemaMetadataInfo> schemaMetadataInfos = findSchemaMetadataInfos(queryParameters); return WSUtils.respondEntities(schemaMetadataInfos, Response.Status.OK); } catch (Exception ex) { LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
@Override public List<Object> getResources() { Collection<Map<String, Object>> schemaProviders = (Collection<Map<String, Object>>) config.get(SCHEMA_PROVIDERS); DefaultSchemaRegistry schemaRegistry = new DefaultSchemaRegistry(storageManager, fileStorage, schemaProviders, haServerNotificationManager); schemaRegistry.init(config); SchemaRegistryVersion schemaRegistryVersion = SchemaRegistryServiceInfo.get().version(); LOG.info("SchemaRegistry is starting with {}", schemaRegistryVersion); SchemaRegistryResource schemaRegistryResource = new SchemaRegistryResource(schemaRegistry, leadershipParticipant, schemaRegistryVersion); ConfluentSchemaRegistryCompatibleResource confluentSchemaRegistryResource = new ConfluentSchemaRegistryCompatibleResource(schemaRegistry, leadershipParticipant); return Arrays.asList(schemaRegistryResource, confluentSchemaRegistryResource); }
@GET @Path("/search/schemas/fields") @ApiOperation(value = "Search for schemas containing the given field names", notes = "Search the schemas for given field names and return a list of schemas that contain the field.", response = SchemaVersionKey.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response findSchemasByFields(@Context UriInfo uriInfo) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); try { Collection<SchemaVersionKey> schemaVersionKeys = schemaRegistry.findSchemasByFields(buildSchemaFieldQuery(queryParameters)); return WSUtils.respondEntities(schemaVersionKeys, Response.Status.OK); } catch (Exception ex) { LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
private Collection<SchemaMetadataInfo> findSchemaMetadataInfos(MultivaluedMap<String, String> queryParameters) { Collection<SchemaMetadataInfo> schemaMetadataInfos; // name and description for now, complex queries are supported by backend and front end can send the json // query for those complex queries. if (queryParameters.containsKey(SchemaMetadataStorable.NAME) || queryParameters.containsKey(SchemaMetadataStorable.DESCRIPTION)) { String name = queryParameters.getFirst(SchemaMetadataStorable.NAME); String description = queryParameters.getFirst(SchemaMetadataStorable.DESCRIPTION); WhereClause whereClause = WhereClause.begin() .contains(SchemaMetadataStorable.NAME, name) .or() .contains(SchemaMetadataStorable.DESCRIPTION, description) .combine(); //todo refactor orderby field in DefaultSchemaRegistry#search APIs merge with these APIs String orderByFieldStr = queryParameters.getFirst(ORDER_BY_FIELDS_PARAM_NAME); schemaMetadataInfos = schemaRegistry.searchSchemas(whereClause, getOrderByFields(orderByFieldStr)); } else { schemaMetadataInfos = Collections.emptyList(); } return schemaMetadataInfos; }
@Context UriInfo uriInfo, @Context HttpHeaders httpHeaders) { return handleLeaderAction(uriInfo, () -> { Response response; try { schemaMetadata.trim(); checkValueAsNullOrEmpty("Schema name", schemaMetadata.getName()); checkValueAsNullOrEmpty("Schema type", schemaMetadata.getType()); checkValidNames(schemaMetadata.getName()); boolean throwErrorIfExists = isThrowErrorIfExists(httpHeaders); Long schemaId = schemaRegistry.addSchemaMetadata(schemaMetadata, throwErrorIfExists); response = WSUtils.respondEntity(schemaId, Response.Status.CREATED);
@POST @Path("/schemas/{name}/mapping/{serDesId}") @ApiOperation(value = "Bind the given Serializer/Deserializer to the schema identified by the schema name", tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response mapSchemaWithSerDes(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Serializer/deserializer identifier", required = true) @PathParam("serDesId") Long serDesId, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> { Response response; try { schemaRegistry.mapSchemaWithSerDes(schemaName, serDesId); response = WSUtils.respondEntity(true, Response.Status.OK); } catch (Exception ex) { response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } return response; }); }
@GET @Path("/search/schemas") @ApiOperation(value = "Search for schemas containing the given name and description", notes = "Search the schemas for given name and description, return a list of schemas that contain the field.", response = SchemaMetadataInfo.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response findSchemas(@Context UriInfo uriInfo) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); try { Collection<SchemaMetadataInfo> schemaMetadataInfos = findSchemaMetadataInfos(queryParameters); return WSUtils.respondEntities(schemaMetadataInfos, Response.Status.OK); } catch (Exception ex) { LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
@Override public List<Object> getResources() { Collection<Map<String, Object>> schemaProviders = (Collection<Map<String, Object>>) config.get(SCHEMA_PROVIDERS); DefaultSchemaRegistry schemaRegistry = new DefaultSchemaRegistry(storageManager, fileStorage, schemaProviders, haServerNotificationManager, new SchemaLockManager(transactionManager)); schemaRegistry.init(config); SchemaRegistryVersion schemaRegistryVersion = SchemaRegistryServiceInfo.get().version(); LOG.info("SchemaRegistry is starting with {}", schemaRegistryVersion); SchemaRegistryResource schemaRegistryResource = new SchemaRegistryResource(schemaRegistry, leadershipParticipant, schemaRegistryVersion); ConfluentSchemaRegistryCompatibleResource confluentSchemaRegistryResource = new ConfluentSchemaRegistryCompatibleResource(schemaRegistry, leadershipParticipant); return Arrays.asList(schemaRegistryResource, confluentSchemaRegistryResource); }
@GET @Path("/search/schemas/fields") @ApiOperation(value = "Search for schemas containing the given field names", notes = "Search the schemas for given field names and return a list of schemas that contain the field.", response = SchemaVersionKey.class, responseContainer = "List", tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response findSchemasByFields(@Context UriInfo uriInfo) { MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); try { Collection<SchemaVersionKey> schemaVersionKeys = schemaRegistry.findSchemasByFields(buildSchemaFieldQuery(queryParameters)); return WSUtils.respondEntities(schemaVersionKeys, Response.Status.OK); } catch (Exception ex) { LOG.error("Encountered error while finding schemas for given fields [{}]", queryParameters, ex); return WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } }
private Collection<SchemaMetadataInfo> findSchemaMetadataInfos(MultivaluedMap<String, String> queryParameters) { Collection<SchemaMetadataInfo> schemaMetadataInfos; // name and description for now, complex queries are supported by backend and front end can send the json // query for those complex queries. if (queryParameters.containsKey(SchemaMetadataStorable.NAME) || queryParameters.containsKey(SchemaMetadataStorable.DESCRIPTION)) { String name = queryParameters.getFirst(SchemaMetadataStorable.NAME); String description = queryParameters.getFirst(SchemaMetadataStorable.DESCRIPTION); WhereClause whereClause = WhereClause.begin() .contains(SchemaMetadataStorable.NAME, name) .or() .contains(SchemaMetadataStorable.DESCRIPTION, description) .combine(); //todo refactor orderby field in DefaultSchemaRegistry#search APIs merge with these APIs String orderByFieldStr = queryParameters.getFirst(ORDER_BY_FIELDS_PARAM_NAME); schemaMetadataInfos = schemaRegistry.searchSchemas(whereClause, getOrderByFields(orderByFieldStr)); } else { schemaMetadataInfos = Collections.emptyList(); } return schemaMetadataInfos; }
@POST @Path("/serdes") @ApiOperation(value = "Add a Serializer/Deserializer into the Schema Registry", response = Long.class, tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response addSerDes(@ApiParam(value = "Serializer/Deserializer information to be registered", required = true) SerDesPair serDesPair, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> _addSerDesInfo(serDesPair)); }
@FormDataParam("description") final String description, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> { Response response; SchemaVersion schemaVersion = null; schemaVersion = new SchemaVersion(IOUtils.toString(inputStream, "UTF-8"), description); response = addSchemaVersion(schemaBranchName, schemaName, schemaVersion, uriInfo); } catch (IOException ex) { LOG.error("Encountered error while adding schema [{}] with key [{}]", schemaVersion, schemaName, ex, ex);
@POST @Path("/schemas/{name}") @ApiOperation(value = "Updates schema information for the given schema name", response = SchemaMetadataInfo.class, tags = OPERATION_GROUP_SCHEMA) @Timed @UnitOfWork public Response updateSchemaInfo(@ApiParam(value = "Schema name", required = true) @PathParam("name") String schemaName, @ApiParam(value = "Schema to be added to the registry", required = true) SchemaMetadata schemaMetadata, @Context UriInfo uriInfo) { return handleLeaderAction(uriInfo, () -> { Response response; try { SchemaMetadataInfo schemaMetadataInfo = schemaRegistry.updateSchemaMetadata(schemaName, schemaMetadata); if (schemaMetadataInfo != null) { response = WSUtils.respondEntity(schemaMetadataInfo, Response.Status.OK); } else { response = WSUtils.respond(Response.Status.NOT_FOUND, CatalogResponse.ResponseMessage.ENTITY_NOT_FOUND, schemaName); } } catch (IllegalArgumentException ex) { LOG.error("Expected parameter is invalid", schemaName, schemaMetadata, ex); response = WSUtils.respond(Response.Status.BAD_REQUEST, CatalogResponse.ResponseMessage.BAD_REQUEST_PARAM_MISSING, ex.getMessage()); } catch (Exception ex) { LOG.error("Encountered error while retrieving SchemaInfo with name: [{}]", schemaName, ex); response = WSUtils.respond(Response.Status.INTERNAL_SERVER_ERROR, CatalogResponse.ResponseMessage.EXCEPTION, ex.getMessage()); } return response; }); }
MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); try { Collection<SchemaMetadataInfo> schemaMetadataInfos = findSchemaMetadataInfos(uriInfo.getQueryParameters()); List<AggregatedSchemaMetadataInfo> aggregatedSchemaMetadataInfos = new ArrayList<>(); for (SchemaMetadataInfo schemaMetadataInfo : schemaMetadataInfos) {
@GET @Path("/serdes/{id}") @ApiOperation(value = "Get a Serializer for the given serializer id", response = SerDesInfo.class, tags = OPERATION_GROUP_SERDE) @Timed @UnitOfWork public Response getSerDes(@ApiParam(value = "Serializer identifier", required = true) @PathParam("id") Long serializerId) { return _getSerDesInfo(serializerId); }