Skip to content

Commit 31e3a04

Browse files
authored
Update schema registry API names (Azure#23886)
* Rename fields to groupName, name, content. * Renaming schemaId to -> id. * Update error message in Builder. * Renaming fields in sync client -> groupName, name, content, id. * Remove withResponse methods for cached methods.
1 parent d4b4fb7 commit 31e3a04

File tree

3 files changed

+96
-131
lines changed

3 files changed

+96
-131
lines changed

sdk/schemaregistry/azure-data-schemaregistry/src/main/java/com/azure/data/schemaregistry/SchemaRegistryAsyncClient.java

Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -73,57 +73,57 @@ public final class SchemaRegistryAsyncClient {
7373
* Registers a new schema in the specified schema group with the given schema name. If the schema name already
7474
* exists in this schema group, a new version with the updated schema string will be registered.
7575
*
76-
* @param schemaGroup The schema group.
77-
* @param schemaName The schema name.
78-
* @param schemaString The string representation of the schema.
76+
* @param groupName The schema group.
77+
* @param name The schema name.
78+
* @param content The string representation of the schema.
7979
* @param serializationType The serialization type of this schema.
8080
*
8181
* @return The {@link SchemaProperties} of a successfully registered schema.
8282
*/
8383
@ServiceMethod(returns = ReturnType.SINGLE)
84-
public Mono<SchemaProperties> registerSchema(
85-
String schemaGroup, String schemaName, String schemaString, SerializationType serializationType) {
86-
return registerSchemaWithResponse(schemaGroup, schemaName, schemaString, serializationType)
84+
public Mono<SchemaProperties> registerSchema(String groupName, String name, String content,
85+
SerializationType serializationType) {
86+
return registerSchemaWithResponse(groupName, name, content, serializationType)
8787
.map(Response::getValue);
8888
}
8989

9090
/**
9191
* Registers a new schema in the specified schema group with the given schema name. If the schema name already
9292
* exists in this schema group, a new version with the updated schema string will be registered.
9393
*
94-
* @param schemaGroup The schema group.
95-
* @param schemaName The schema name.
96-
* @param schemaString The string representation of the schema.
94+
* @param groupName The schema group.
95+
* @param name The schema name.
96+
* @param content The string representation of the schema.
9797
* @param serializationType The serialization type of this schema.
9898
*
9999
* @return The schema properties on successful registration of the schema.
100100
*/
101101
@ServiceMethod(returns = ReturnType.SINGLE)
102-
public Mono<Response<SchemaProperties>> registerSchemaWithResponse(String schemaGroup, String schemaName,
103-
String schemaString, SerializationType serializationType) {
104-
return FluxUtil.withContext(context -> registerSchemaWithResponse(schemaGroup, schemaName, schemaString,
102+
public Mono<Response<SchemaProperties>> registerSchemaWithResponse(String groupName, String name, String content,
103+
SerializationType serializationType) {
104+
return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, content,
105105
serializationType, context));
106106
}
107107

108-
Mono<Response<SchemaProperties>> registerSchemaWithResponse(String schemaGroup, String schemaName,
109-
String schemaString, SerializationType serializationType, Context context) {
108+
Mono<Response<SchemaProperties>> registerSchemaWithResponse(String groupName, String name, String content,
109+
SerializationType serializationType, Context context) {
110110
logger.verbose("Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'",
111-
schemaGroup, schemaName, serializationType, schemaString);
111+
groupName, name, serializationType, content);
112112

113-
return this.restService.getSchemas().registerWithResponseAsync(schemaGroup, schemaName,
114-
com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, schemaString)
113+
return this.restService.getSchemas().registerWithResponseAsync(groupName, name,
114+
com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, content)
115115
.handle((response, sink) -> {
116116
SchemaId schemaId = response.getValue();
117117
SchemaProperties registered = new SchemaProperties(schemaId.getId(),
118118
serializationType,
119-
schemaName,
120-
schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING));
119+
name,
120+
content.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING));
121121

122-
schemaStringCache.putIfAbsent(getSchemaStringCacheKey(schemaGroup, schemaName, schemaString),
122+
schemaStringCache.putIfAbsent(getSchemaStringCacheKey(groupName, name, content),
123123
registered);
124124
idCache.putIfAbsent(schemaId.getId(), registered);
125125

126-
logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName);
126+
logger.verbose("Cached schema string. Group: '{}', name: '{}'", groupName, name);
127127
SimpleResponse<SchemaProperties> schemaRegistryObjectSimpleResponse = new SimpleResponse<>(
128128
response.getRequest(), response.getStatusCode(),
129129
response.getHeaders(), registered);
@@ -132,34 +132,35 @@ Mono<Response<SchemaProperties>> registerSchemaWithResponse(String schemaGroup,
132132
}
133133

134134
/**
135-
* Gets the schema properties of the schema associated with the unique schemaId.
136-
* @param schemaId The unique identifier of the schema.
135+
* Gets the schema properties of the schema associated with the unique schema id.
136+
*
137+
* @param id The unique identifier of the schema.
137138
*
138-
* @return The {@link SchemaProperties} associated with the given {@code schemaId}.
139+
* @return The {@link SchemaProperties} associated with the given {@code id}.
139140
*/
140141
@ServiceMethod(returns = ReturnType.SINGLE)
141-
public Mono<SchemaProperties> getSchema(String schemaId) {
142-
if (idCache.containsKey(schemaId)) {
143-
logger.verbose("Cache hit for schema id '{}'", schemaId);
144-
return Mono.fromCallable(() -> idCache.get(schemaId));
142+
public Mono<SchemaProperties> getSchema(String id) {
143+
if (idCache.containsKey(id)) {
144+
logger.verbose("Cache hit for schema id '{}'", id);
145+
return Mono.fromCallable(() -> idCache.get(id));
145146
}
146-
return getSchemaWithResponse(schemaId).map(Response::getValue);
147+
return getSchemaWithResponse(id).map(Response::getValue);
147148
}
148149

149150
/**
150-
* Gets the schema properties of the schema associated with the unique schemaId.
151-
* @param schemaId The unique identifier of the schema.
151+
* Gets the schema properties of the schema associated with the unique schema id.
152+
*
153+
* @param id The unique identifier of the schema.
152154
*
153-
* @return The {@link SchemaProperties} associated with the given {@code schemaId} along with the HTTP
154-
* response.
155+
* @return The {@link SchemaProperties} associated with the given {@code id} along with the HTTP response.
155156
*/
156-
Mono<Response<SchemaProperties>> getSchemaWithResponse(String schemaId) {
157-
return FluxUtil.withContext(context -> getSchemaWithResponse(schemaId, context));
157+
Mono<Response<SchemaProperties>> getSchemaWithResponse(String id) {
158+
return FluxUtil.withContext(context -> getSchemaWithResponse(id, context));
158159
}
159160

160-
Mono<Response<SchemaProperties>> getSchemaWithResponse(String schemaId, Context context) {
161-
Objects.requireNonNull(schemaId, "'schemaId' should not be null");
162-
return this.restService.getSchemas().getByIdWithResponseAsync(schemaId)
161+
Mono<Response<SchemaProperties>> getSchemaWithResponse(String id, Context context) {
162+
Objects.requireNonNull(id, "'id' should not be null");
163+
return this.restService.getSchemas().getByIdWithResponseAsync(id)
163164
.handle((response, sink) -> {
164165
final SerializationType serializationType =
165166
SerializationType.fromString(response.getDeserializedHeaders().getSchemaType());
@@ -175,17 +176,17 @@ Mono<Response<SchemaProperties>> getSchemaWithResponse(String schemaId, Context
175176

176177
final String schemaGroup = matcher.group("schemaGroup");
177178
final String schemaName = matcher.group("schemaName");
178-
final SchemaProperties schemaObject = new SchemaProperties(schemaId,
179+
final SchemaProperties schemaObject = new SchemaProperties(id,
179180
serializationType,
180181
schemaName,
181182
response.getValue());
182183
final String schemaCacheKey = getSchemaStringCacheKey(schemaGroup, schemaName,
183-
new String(response.getValue(), SCHEMA_REGISTRY_SERVICE_ENCODING));
184+
new String(response.getValue(), SCHEMA_REGISTRY_SERVICE_ENCODING));
184185

185186
schemaStringCache.putIfAbsent(schemaCacheKey, schemaObject);
186-
idCache.putIfAbsent(schemaId, schemaObject);
187+
idCache.putIfAbsent(id, schemaObject);
187188

188-
logger.verbose("Cached schema object. Path: '{}'", schemaId);
189+
logger.verbose("Cached schema object. Path: '{}'", id);
189190

190191
SimpleResponse<SchemaProperties> schemaResponse = new SimpleResponse<>(
191192
response.getRequest(), response.getStatusCode(),
@@ -199,73 +200,74 @@ Mono<Response<SchemaProperties>> getSchemaWithResponse(String schemaId, Context
199200
* Gets the schema identifier associated with the given schema. Gets a cached value if it exists, otherwise makes a
200201
* call to the service.
201202
*
202-
* @param schemaGroup The schema group.
203-
* @param schemaName The schema name.
204-
* @param schemaString The string representation of the schema.
203+
* @param groupName The schema group.
204+
* @param name The schema name.
205+
* @param content The string representation of the schema.
205206
* @param serializationType The serialization type of this schema.
206207
*
207208
* @return The unique identifier for this schema.
208209
*/
209210
@ServiceMethod(returns = ReturnType.SINGLE)
210-
public Mono<String> getSchemaId(String schemaGroup, String schemaName, String schemaString,
211+
public Mono<String> getSchemaId(String groupName, String name, String content,
211212
SerializationType serializationType) {
212213

213-
String schemaStringCacheKey = getSchemaStringCacheKey(schemaGroup, schemaName, schemaString);
214+
String schemaStringCacheKey = getSchemaStringCacheKey(groupName, name, content);
214215

215216
if (schemaStringCache.containsKey(schemaStringCacheKey)) {
216217
return Mono.fromCallable(() -> {
217-
logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", schemaGroup, schemaName);
218+
logger.verbose("Cache hit schema string. Group: '{}', name: '{}'", groupName, name);
218219
return schemaStringCache.get(schemaStringCacheKey).getSchemaId();
219220
});
220221
}
221222

222-
return getSchemaIdWithResponse(schemaGroup, schemaName, schemaString, serializationType)
223+
return getSchemaIdWithResponse(groupName, name, content, serializationType)
223224
.map(response -> response.getValue());
224225
}
225226

226227
/**
227228
* Gets the schema identifier associated with the given schema. Always makes a call to the service.
228229
*
229-
* @param schemaGroup The schema group.
230-
* @param schemaName The schema name.
231-
* @param schemaString The string representation of the schema.
230+
* @param groupName The schema group.
231+
* @param name The schema name.
232+
* @param content The string representation of the schema.
232233
* @param serializationType The serialization type of this schema.
233234
*
234235
* @return The unique identifier for this schema.
235236
*/
236-
Mono<Response<String>> getSchemaIdWithResponse(String schemaGroup, String schemaName, String schemaString,
237+
Mono<Response<String>> getSchemaIdWithResponse(String groupName, String name, String content,
237238
SerializationType serializationType) {
238239

239240
return FluxUtil.withContext(context ->
240-
getSchemaIdWithResponse(schemaGroup, schemaName, schemaString, serializationType, context));
241+
getSchemaIdWithResponse(groupName, name, content, serializationType, context));
241242
}
242243

243244
/**
244245
* Gets the schema id associated with the schema name a string representation of the schema.
245246
*
246-
* @param schemaGroup The schema group.
247-
* @param schemaName The schema name.
248-
* @param schemaString The string representation of the schema.
247+
* @param groupName The schema group.
248+
* @param name The schema name.
249+
* @param content The string representation of the schema.
249250
* @param serializationType The serialization type of this schema.
250251
* @param context Context to pass along with this request.
252+
*
251253
* @return A mono that completes with the schema id.
252254
*/
253-
Mono<Response<String>> getSchemaIdWithResponse(String schemaGroup, String schemaName, String schemaString,
255+
Mono<Response<String>> getSchemaIdWithResponse(String groupName, String name, String content,
254256
SerializationType serializationType, Context context) {
255257

256258
return this.restService.getSchemas()
257-
.queryIdByContentWithResponseAsync(schemaGroup, schemaName,
258-
com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, schemaString)
259+
.queryIdByContentWithResponseAsync(groupName, name,
260+
com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, content)
259261
.handle((response, sink) -> {
260262
SchemaId schemaId = response.getValue();
261-
SchemaProperties properties = new SchemaProperties(schemaId.getId(), serializationType, schemaName,
262-
schemaString.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING));
263+
SchemaProperties properties = new SchemaProperties(schemaId.getId(), serializationType, name,
264+
content.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING));
263265

264266
schemaStringCache.putIfAbsent(
265-
getSchemaStringCacheKey(schemaGroup, schemaName, schemaString), properties);
267+
getSchemaStringCacheKey(groupName, name, content), properties);
266268
idCache.putIfAbsent(schemaId.getId(), properties);
267269

268-
logger.verbose("Cached schema string. Group: '{}', name: '{}'", schemaGroup, schemaName);
270+
logger.verbose("Cached schema string. Group: '{}', name: '{}'", groupName, name);
269271

270272
SimpleResponse<String> schemaIdResponse = new SimpleResponse<>(
271273
response.getRequest(), response.getStatusCode(),
@@ -274,16 +276,7 @@ Mono<Response<String>> getSchemaIdWithResponse(String schemaGroup, String schema
274276
});
275277
}
276278

277-
/**
278-
* Explicit call to clear all caches.
279-
*/
280-
void clearCache() {
281-
idCache.clear();
282-
schemaStringCache.clear();
283-
typeParserMap.clear();
284-
}
285-
286-
private static String getSchemaStringCacheKey(String schemaGroup, String schemaName, String schemaString) {
287-
return schemaGroup + schemaName + schemaString;
279+
private static String getSchemaStringCacheKey(String groupName, String name, String content) {
280+
return groupName + name + content;
288281
}
289282
}

0 commit comments

Comments
 (0)