From fcffdc7e8775001a4587246465f2d7a84d8d19cd Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:23:53 -0700 Subject: [PATCH 1/8] Rename fields to groupName, name, content. --- .../SchemaRegistryAsyncClient.java | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) 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..19be30836fccd 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); @@ -133,6 +133,7 @@ Mono> registerSchemaWithResponse(String schemaGroup, /** * Gets the schema properties of the schema associated with the unique schemaId. + * * @param schemaId The unique identifier of the schema. * * @return The {@link SchemaProperties} associated with the given {@code schemaId}. @@ -148,10 +149,10 @@ public Mono getSchema(String schemaId) { /** * Gets the schema properties of the schema associated with the unique schemaId. + * * @param schemaId 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 schemaId} along with the HTTP response. */ Mono> getSchemaWithResponse(String schemaId) { return FluxUtil.withContext(context -> getSchemaWithResponse(schemaId, context)); @@ -180,7 +181,7 @@ Mono> getSchemaWithResponse(String schemaId, Context 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); @@ -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(), @@ -283,7 +285,7 @@ void clearCache() { 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; } } From d93b0129960d219bedac260f8dc753643062ac7c Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:28:19 -0700 Subject: [PATCH 2/8] Renaming schemaId to -> id. --- .../SchemaRegistryAsyncClient.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 19be30836fccd..3e0352e0b7392 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 @@ -132,19 +132,19 @@ Mono> registerSchemaWithResponse(String groupName, St } /** - * Gets the schema properties of the schema associated with the unique schemaId. + * Gets the schema properties of the schema associated with the unique schema id. * - * @param schemaId The unique identifier of the schema. + * @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); } /** From 984fc6c912400f0dc92504223c31c9aa65c43e83 Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:28:30 -0700 Subject: [PATCH 3/8] Update error message in Builder. --- .../data/schemaregistry/SchemaRegistryClientBuilder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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() From 4062948582cee7f11aed2628d3555a2d8cafe985 Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:31:14 -0700 Subject: [PATCH 4/8] Renaming fields in sync client -> groupName, name, content, id. --- .../schemaregistry/SchemaRegistryClient.java | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) 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..90a157199f204 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,53 +38,57 @@ 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. + * + * @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 SchemaProperties getSchema(String schemaId) { - return this.asyncClient.getSchema(schemaId).block(); + public SchemaProperties getSchema(String id) { + return this.asyncClient.getSchema(id).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. + * + * @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(); @@ -93,17 +97,16 @@ Response getSchemaWithResponse(String schemaId, Context contex /** * 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(); + public String getSchemaId(String groupName, String name, String content, SerializationType serializationType) { + return this.asyncClient.getSchemaId(groupName, name, content, serializationType).block(); } /** @@ -114,6 +117,7 @@ public String getSchemaId(String schemaGroup, String schemaName, String schemaSt * @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, From 8f3999ad56b6a56aa0e41aef9006a95862cbd6fb Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:31:40 -0700 Subject: [PATCH 5/8] Remove withResponse methods. --- .../schemaregistry/SchemaRegistryClient.java | 54 ------------------- 1 file changed, 54 deletions(-) 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 90a157199f204..e427368cfd997 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 @@ -6,8 +6,6 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; -import com.azure.core.http.rest.Response; -import com.azure.core.util.Context; import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SerializationType; @@ -51,25 +49,6 @@ public SchemaProperties registerSchema(String groupName, String name, String con 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 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 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 schema id. * @@ -82,18 +61,6 @@ public SchemaProperties getSchema(String id) { return this.asyncClient.getSchema(id).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(); - } - /** * Gets the schema identifier associated with the given schema. * @@ -108,25 +75,4 @@ Response getSchemaWithResponse(String schemaId, Context contex public String getSchemaId(String groupName, String name, String content, SerializationType serializationType) { return this.asyncClient.getSchemaId(groupName, name, content, 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(); - } } From 50045c41067fbd26124531bc0fa51886b994d62d Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:33:12 -0700 Subject: [PATCH 6/8] Remove withResponse methods. --- .../schemaregistry/SchemaRegistryAsyncClient.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) 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 3e0352e0b7392..7fb6e3bb86489 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 @@ -98,8 +98,7 @@ public Mono registerSchema(String groupName, String name, Stri * * @return The schema properties on successful registration of the schema. */ - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> registerSchemaWithResponse(String groupName, String name, String content, + Mono> registerSchemaWithResponse(String groupName, String name, String content, SerializationType serializationType) { return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, content, serializationType, context)); @@ -276,15 +275,6 @@ Mono> getSchemaIdWithResponse(String groupName, String name, St }); } - /** - * Explicit call to clear all caches. - */ - void clearCache() { - idCache.clear(); - schemaStringCache.clear(); - typeParserMap.clear(); - } - private static String getSchemaStringCacheKey(String groupName, String name, String content) { return groupName + name + content; } From 0adaf890b1c9450463c9927eb1701ff370899d6e Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 12:33:38 -0700 Subject: [PATCH 7/8] Rename to id. --- .../SchemaRegistryAsyncClient.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 7fb6e3bb86489..6dd8603631d2d 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 @@ -147,19 +147,19 @@ public Mono getSchema(String id) { } /** - * Gets the schema properties of the schema associated with the unique schemaId. + * Gets the schema properties of the schema associated with the unique schema id. * - * @param schemaId The unique identifier of the schema. + * @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,7 +175,7 @@ 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()); @@ -183,9 +183,9 @@ Mono> getSchemaWithResponse(String schemaId, Context 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(), From 5381662350a67adcf168d7571bcc44df93459710 Mon Sep 17 00:00:00 2001 From: Connie Date: Thu, 2 Sep 2021 14:11:58 -0700 Subject: [PATCH 8/8] Add back registerSchemaWithResponse. --- .../SchemaRegistryAsyncClient.java | 3 ++- .../schemaregistry/SchemaRegistryClient.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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 6dd8603631d2d..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 @@ -98,7 +98,8 @@ public Mono registerSchema(String groupName, String name, Stri * * @return The schema properties on successful registration of the schema. */ - Mono> registerSchemaWithResponse(String groupName, String name, String content, + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> registerSchemaWithResponse(String groupName, String name, String content, SerializationType serializationType) { return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, content, serializationType, context)); 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 e427368cfd997..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 @@ -6,6 +6,8 @@ import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceClient; import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; import com.azure.data.schemaregistry.models.SchemaProperties; import com.azure.data.schemaregistry.models.SerializationType; @@ -49,6 +51,25 @@ public SchemaProperties registerSchema(String groupName, String name, String con 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 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 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 schema id. *