diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java index d605c57b25ff9..7c2225f859356 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java @@ -73,17 +73,17 @@ public final class SchemaRegistryAsyncClient { * Registers a new schema in the specified schema group with the given schema name. If the schema name already * exists in this schema group, a new version with the updated schema string will be registered. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * * @return The {@link SchemaProperties} of a successfully registered schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono registerSchema( - String schemaGroup, String schemaName, String schemaString, SerializationType serializationType) { - return registerSchemaWithResponse(schemaGroup, schemaName, schemaString, serializationType) + public Mono registerSchema(String groupName, String name, String content, + SerializationType serializationType) { + return registerSchemaWithResponse(groupName, name, content, serializationType) .map(Response::getValue); } @@ -91,39 +91,39 @@ public Mono registerSchema( * Registers a new schema in the specified schema group with the given schema name. If the schema name already * exists in this schema group, a new version with the updated schema string will be registered. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * * @return The schema properties on successful registration of the schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerSchemaWithResponse(String schemaGroup, String schemaName, - String schemaString, SerializationType serializationType) { - return FluxUtil.withContext(context -> registerSchemaWithResponse(schemaGroup, schemaName, schemaString, + public Mono> registerSchemaWithResponse(String groupName, String name, String content, + SerializationType serializationType) { + return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, content, serializationType, context)); } - Mono> registerSchemaWithResponse(String schemaGroup, String schemaName, - String schemaString, SerializationType serializationType, Context context) { + Mono> registerSchemaWithResponse(String groupName, String name, String content, + SerializationType serializationType, Context context) { logger.verbose("Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'", - schemaGroup, schemaName, serializationType, schemaString); + groupName, name, serializationType, content); - return this.restService.getSchemas().registerWithResponseAsync(schemaGroup, schemaName, - com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, schemaString) + return this.restService.getSchemas().registerWithResponseAsync(groupName, name, + com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, content) .handle((response, sink) -> { SchemaId schemaId = response.getValue(); SchemaProperties registered = new SchemaProperties(schemaId.getId(), serializationType, - schemaName, - schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING)); + name, + content.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING)); - schemaStringCache.putIfAbsent(getSchemaStringCacheKey(schemaGroup, schemaName, schemaString), + schemaStringCache.putIfAbsent(getSchemaStringCacheKey(groupName, name, content), registered); idCache.putIfAbsent(schemaId.getId(), registered); - logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); + logger.verbose("Cached schema string. Group: '{}', name: '{}'", groupName, name); SimpleResponse schemaRegistryObjectSimpleResponse = new SimpleResponse<>( response.getRequest(), response.getStatusCode(), response.getHeaders(), registered); @@ -132,34 +132,35 @@ Mono> registerSchemaWithResponse(String schemaGroup, } /** - * Gets the schema properties of the schema associated with the unique schemaId. - * @param schemaId The unique identifier of the schema. + * Gets the schema properties of the schema associated with the unique schema id. + * + * @param id The unique identifier of the schema. * - * @return The {@link SchemaProperties} associated with the given {@code schemaId}. + * @return The {@link SchemaProperties} associated with the given {@code id}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchema(String schemaId) { - if (idCache.containsKey(schemaId)) { - logger.verbose("Cache hit for schema id '{}'", schemaId); - return Mono.fromCallable(() -> idCache.get(schemaId)); + public Mono getSchema(String id) { + if (idCache.containsKey(id)) { + logger.verbose("Cache hit for schema id '{}'", id); + return Mono.fromCallable(() -> idCache.get(id)); } - return getSchemaWithResponse(schemaId).map(Response::getValue); + return getSchemaWithResponse(id).map(Response::getValue); } /** - * Gets the schema properties of the schema associated with the unique schemaId. - * @param schemaId The unique identifier of the schema. + * Gets the schema properties of the schema associated with the unique schema id. + * + * @param id The unique identifier of the schema. * - * @return The {@link SchemaProperties} associated with the given {@code schemaId} along with the HTTP - * response. + * @return The {@link SchemaProperties} associated with the given {@code id} along with the HTTP response. */ - Mono> getSchemaWithResponse(String schemaId) { - return FluxUtil.withContext(context -> getSchemaWithResponse(schemaId, context)); + Mono> getSchemaWithResponse(String id) { + return FluxUtil.withContext(context -> getSchemaWithResponse(id, context)); } - Mono> getSchemaWithResponse(String schemaId, Context context) { - Objects.requireNonNull(schemaId, "'schemaId' should not be null"); - return this.restService.getSchemas().getByIdWithResponseAsync(schemaId) + Mono> getSchemaWithResponse(String id, Context context) { + Objects.requireNonNull(id, "'id' should not be null"); + return this.restService.getSchemas().getByIdWithResponseAsync(id) .handle((response, sink) -> { final SerializationType serializationType = SerializationType.fromString(response.getDeserializedHeaders().getSchemaType()); @@ -175,17 +176,17 @@ Mono> getSchemaWithResponse(String schemaId, Context final String schemaGroup = matcher.group("schemaGroup"); final String schemaName = matcher.group("schemaName"); - final SchemaProperties schemaObject = new SchemaProperties(schemaId, + final SchemaProperties schemaObject = new SchemaProperties(id, serializationType, schemaName, response.getValue()); final String schemaCacheKey = getSchemaStringCacheKey(schemaGroup, schemaName, - new String(response.getValue(), SCHEMA_REGISTRY_SERVICE_ENCODING)); + new String(response.getValue(), SCHEMA_REGISTRY_SERVICE_ENCODING)); schemaStringCache.putIfAbsent(schemaCacheKey, schemaObject); - idCache.putIfAbsent(schemaId, schemaObject); + idCache.putIfAbsent(id, schemaObject); - logger.verbose("Cached schema object. Path: '{}'", schemaId); + logger.verbose("Cached schema object. Path: '{}'", id); SimpleResponse schemaResponse = new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -199,73 +200,74 @@ Mono> getSchemaWithResponse(String schemaId, Context * Gets the schema identifier associated with the given schema. Gets a cached value if it exists, otherwise makes a * call to the service. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * * @return The unique identifier for this schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getSchemaId(String schemaGroup, String schemaName, String schemaString, + public Mono getSchemaId(String groupName, String name, String content, SerializationType serializationType) { - String schemaStringCacheKey = getSchemaStringCacheKey(schemaGroup, schemaName, schemaString); + String schemaStringCacheKey = getSchemaStringCacheKey(groupName, name, content); if (schemaStringCache.containsKey(schemaStringCacheKey)) { return Mono.fromCallable(() -> { - logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); + logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", groupName, name); return schemaStringCache.get(schemaStringCacheKey).getSchemaId(); }); } - return getSchemaIdWithResponse(schemaGroup, schemaName, schemaString, serializationType) + return getSchemaIdWithResponse(groupName, name, content, serializationType) .map(response -> response.getValue()); } /** * Gets the schema identifier associated with the given schema. Always makes a call to the service. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * * @return The unique identifier for this schema. */ - Mono> getSchemaIdWithResponse(String schemaGroup, String schemaName, String schemaString, + Mono> getSchemaIdWithResponse(String groupName, String name, String content, SerializationType serializationType) { return FluxUtil.withContext(context -> - getSchemaIdWithResponse(schemaGroup, schemaName, schemaString, serializationType, context)); + getSchemaIdWithResponse(groupName, name, content, serializationType, context)); } /** * Gets the schema id associated with the schema name a string representation of the schema. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * @param context Context to pass along with this request. + * * @return A mono that completes with the schema id. */ - Mono> getSchemaIdWithResponse(String schemaGroup, String schemaName, String schemaString, + Mono> getSchemaIdWithResponse(String groupName, String name, String content, SerializationType serializationType, Context context) { return this.restService.getSchemas() - .queryIdByContentWithResponseAsync(schemaGroup, schemaName, - com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, schemaString) + .queryIdByContentWithResponseAsync(groupName, name, + com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, content) .handle((response, sink) -> { SchemaId schemaId = response.getValue(); - SchemaProperties properties = new SchemaProperties(schemaId.getId(), serializationType, schemaName, - schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING)); + SchemaProperties properties = new SchemaProperties(schemaId.getId(), serializationType, name, + content.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING)); schemaStringCache.putIfAbsent( - getSchemaStringCacheKey(schemaGroup, schemaName, schemaString), properties); + getSchemaStringCacheKey(groupName, name, content), properties); idCache.putIfAbsent(schemaId.getId(), properties); - logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName); + logger.verbose("Cached schema string. Group: '{}', name: '{}'", groupName, name); SimpleResponse schemaIdResponse = new SimpleResponse<>( response.getRequest(), response.getStatusCode(), @@ -274,16 +276,7 @@ Mono> getSchemaIdWithResponse(String schemaGroup, String schema }); } - /** - * Explicit call to clear all caches. - */ - void clearCache() { - idCache.clear(); - schemaStringCache.clear(); - typeParserMap.clear(); - } - - private static String getSchemaStringCacheKey(String schemaGroup, String schemaName, String schemaString) { - return schemaGroup + schemaName + schemaString; + private static String getSchemaStringCacheKey(String groupName, String name, String content) { + return groupName + name + content; } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java index ee8ba224401a3..3cefd207ee6b2 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClient.java @@ -38,91 +38,62 @@ public final class SchemaRegistryClient { * Registers a new schema in the specified schema group with the given schema name. If the schema name already * exists in this schema group, a new version with the updated schema string will be registered. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. + * * @return The schema properties on successful registration of the schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaProperties registerSchema(String schemaGroup, String schemaName, String schemaString, - SerializationType serializationType) { - return this.asyncClient.registerSchema(schemaGroup, schemaName, schemaString, serializationType).block(); + public SchemaProperties registerSchema(String groupName, String name, String content, + SerializationType serializationType) { + return this.asyncClient.registerSchema(groupName, name, content, serializationType).block(); } /** * Registers a new schema in the specified schema group with the given schema name. If the schema name already * exists in this schema group, a new version with the updated schema string will be registered. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * @param context The context to pass to the Http pipeline. + * * @return The schema properties on successful registration of the schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response registerSchemaWithResponse(String schemaGroup, String schemaName, - String schemaString, SerializationType serializationType, Context context) { - return this.asyncClient.registerSchemaWithResponse(schemaGroup, schemaName, schemaString, serializationType, + public Response registerSchemaWithResponse(String groupName, String name, String content, + SerializationType serializationType, Context context) { + return this.asyncClient.registerSchemaWithResponse(groupName, name, content, serializationType, context).block(); } /** - * Gets the schema properties of the schema associated with the unique schemaId. - * @param schemaId The unique identifier of the schema. + * Gets the schema properties of the schema associated with the unique schema id. * - * @return The {@link SchemaProperties} associated with the given {@code schemaId}. + * @param id The unique identifier of the schema. + * + * @return The {@link SchemaProperties} associated with the given {@code id}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public SchemaProperties getSchema(String schemaId) { - return this.asyncClient.getSchema(schemaId).block(); - } - - /** - * Gets the schema properties of the schema associated with the unique schemaId. - * @param schemaId The unique identifier of the schema. - * @param context The context to pass to the Http pipeline. - * @return The {@link SchemaProperties} associated with the given {@code schemaId} along with the HTTP - * response. - */ - Response getSchemaWithResponse(String schemaId, Context context) { - return this.asyncClient.getSchemaWithResponse(schemaId, context).block(); + public SchemaProperties getSchema(String id) { + return this.asyncClient.getSchema(id).block(); } /** * Gets the schema identifier associated with the given schema. * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. + * @param groupName The schema group. + * @param name The schema name. + * @param content The string representation of the schema. * @param serializationType The serialization type of this schema. * * @return The unique identifier for this schema. */ @ServiceMethod(returns = ReturnType.SINGLE) - public String getSchemaId(String schemaGroup, String schemaName, String schemaString, - SerializationType serializationType) { - return this.asyncClient.getSchemaId(schemaGroup, schemaName, schemaString, serializationType).block(); - } - - /** - * Gets the schema identifier associated with the given schema. - * - * @param schemaGroup The schema group. - * @param schemaName The schema name. - * @param schemaString The string representation of the schema. - * @param serializationType The serialization type of this schema. - * @param context The context to pass to the Http pipeline. - * @return The unique identifier for this schema. - */ - Response getSchemaIdWithResponse(String schemaGroup, String schemaName, String schemaString, - SerializationType serializationType, Context context) { - return this.asyncClient - .getSchemaIdWithResponse(schemaGroup, schemaName, schemaString, serializationType, context).block(); - } - - void clearCache() { - this.asyncClient.clearCache(); + public String getSchemaId(String groupName, String name, String content, SerializationType serializationType) { + return this.asyncClient.getSchemaId(groupName, name, content, serializationType).block(); } } diff --git a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java index 5b2bc0d7e5e69..24bd02e72cbaf 100644 --- a/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java +++ b/sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryClientBuilder.java @@ -277,8 +277,9 @@ public SchemaRegistryClientBuilder addPolicy(HttpPipelinePolicy policy) { * credential} are not set. */ public SchemaRegistryAsyncClient buildAsyncClient() { - Objects.requireNonNull(credential, "'credential' cannot be null"); - Objects.requireNonNull(endpoint, "'endpoint' cannot be null"); + Objects.requireNonNull(credential, + "'credential' cannot be null and must be set via builder.credential(TokenCredential)"); + Objects.requireNonNull(endpoint, "'endpoint' cannot be null and must be set in the builder.endpoint(String)"); Configuration buildConfiguration = (configuration == null) ? Configuration.getGlobalConfiguration()