Skip to content

Commit 6bb5653

Browse files
authored
Renaming methods/classes based on review. (Azure#24474)
* Rename endpoint to fullyQualifiedNamespace. * Add SchemaRegistryVersion[ * Setting service version. * Exposing getFullyQualifiedNamespace. * Use constant for API version * Using ServiceVersion. * Making class final. * Rename to SchemaFormat. * Updating schema format usages. * Fixing revapi suppression.
1 parent edfedd9 commit 6bb5653

File tree

24 files changed

+259
-170
lines changed

24 files changed

+259
-170
lines changed

eng/code-quality-reports/src/main/resources/revapi/revapi.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,10 @@
171171
"justification": "azure-cosmos classes are allowed to be exposed by dependencies using them."
172172
},
173173
{
174-
"code": "java.class.externalClassExposedInAPI",
175-
"new": "class com.azure.data.schemaregistry.SchemaRegistryAsyncClient",
176-
"justification": "This is a preview release"
177-
},
178-
{
179-
"code": "java.class.externalClassExposedInAPI",
180-
"new": "class com.azure.data.schemaregistry.models.SchemaProperties",
181-
"justification": "This is a preview release"
182-
},
183-
{
184-
"code": "java.class.externalClassExposedInAPI",
185-
"new": "class com.azure.data.schemaregistry.models.SerializationType",
186-
"justification": "This is a preview release"
174+
"regex": true,
175+
"code": "java\\.class\\.externalClassExposedInAPI",
176+
"new": "(class|enum) com\\.azure\\.data\\.schemaregistry\\..+",
177+
"justification": "azure-data-schemaregistry-avro depends on the schema registry classes."
187178
},
188179
{
189180
"regex": true,

sdk/schemaregistry/azure-data-schemaregistry-avro/src/main/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import com.azure.core.util.serializer.ObjectSerializer;
88
import com.azure.core.util.serializer.TypeReference;
99
import com.azure.data.schemaregistry.SchemaRegistryAsyncClient;
10+
import com.azure.data.schemaregistry.models.SchemaFormat;
1011
import com.azure.data.schemaregistry.models.SchemaProperties;
11-
import com.azure.data.schemaregistry.models.SerializationType;
1212
import org.apache.avro.Schema;
1313
import reactor.core.publisher.Mono;
1414

@@ -198,11 +198,11 @@ public Mono<Void> serializeAsync(OutputStream outputStream, Object object) {
198198
private Mono<String> maybeRegisterSchema(String schemaGroup, String schemaName, String schemaString) {
199199
if (this.autoRegisterSchemas) {
200200
return this.schemaRegistryClient
201-
.registerSchema(schemaGroup, schemaName, schemaString, SerializationType.AVRO)
201+
.registerSchema(schemaGroup, schemaName, schemaString, SchemaFormat.AVRO)
202202
.map(SchemaProperties::getSchemaId);
203203
} else {
204204
return this.schemaRegistryClient.getSchemaId(
205-
schemaGroup, schemaName, schemaString, SerializationType.AVRO);
205+
schemaGroup, schemaName, schemaString, SchemaFormat.AVRO);
206206
}
207207
}
208208

sdk/schemaregistry/azure-data-schemaregistry-avro/src/samples/java/com/azure/data/schemaregistry/avro/ReadmeSamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public SchemaRegistryAvroSerializer createAvroSchemaRegistrySerializer() {
3232
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
3333

3434
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
35-
.endpoint("{schema-registry-endpoint")
35+
.fullyQualifiedNamespace("{schema-registry-endpoint")
3636
.credential(tokenCredential)
3737
.buildAsyncClient();
3838

sdk/schemaregistry/azure-data-schemaregistry-avro/src/samples/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroDeserilizationSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void main(String[] args) throws IOException {
3131
// Create the schema registry async client
3232
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
3333
.credential(tokenCredential)
34-
.endpoint("{schema-registry-endpoint}")
34+
.fullyQualifiedNamespace("{schema-registry-endpoint}")
3535
.buildAsyncClient();
3636

3737
// Create the serializer instance by configuring the serializer with the schema registry client and

sdk/schemaregistry/azure-data-schemaregistry-avro/src/samples/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializationSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static void main(String[] args) {
2929
// Create the schema registry async client
3030
SchemaRegistryAsyncClient schemaRegistryAsyncClient = new SchemaRegistryClientBuilder()
3131
.credential(tokenCredential)
32-
.endpoint("{schema-registry-endpoint}")
32+
.fullyQualifiedNamespace("{schema-registry-endpoint}")
3333
.buildAsyncClient();
3434

3535
// Create the serializer instance by configuring the serializer with the schema registry client and

sdk/schemaregistry/azure-data-schemaregistry-avro/src/test/java/com/azure/data/schemaregistry/avro/SchemaRegistryAvroSerializerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import com.azure.data.schemaregistry.SchemaRegistryAsyncClient;
88
import com.azure.data.schemaregistry.avro.generatedtestsources.PlayingCard;
99
import com.azure.data.schemaregistry.avro.generatedtestsources.PlayingCardSuit;
10+
import com.azure.data.schemaregistry.models.SchemaFormat;
1011
import com.azure.data.schemaregistry.models.SchemaProperties;
11-
import com.azure.data.schemaregistry.models.SerializationType;
1212
import org.apache.avro.Schema;
1313
import org.apache.avro.generic.GenericData;
1414
import org.apache.avro.io.DecoderFactory;
@@ -88,11 +88,11 @@ void testRegistryGuidPrefixedToPayload() throws IOException {
8888
final PlayingCard playingCard = new PlayingCard(true, 10, PlayingCardSuit.DIAMONDS);
8989
final Schema playingClassSchema = PlayingCard.getClassSchema();
9090
final byte[] schemaBytes = playingClassSchema.toString().getBytes(StandardCharsets.UTF_8);
91-
final SchemaProperties registered = new SchemaProperties(MOCK_GUID, SerializationType.AVRO,
91+
final SchemaProperties registered = new SchemaProperties(MOCK_GUID, SchemaFormat.AVRO,
9292
playingClassSchema.getFullName(), schemaBytes);
9393

9494
when(client.getSchemaId(MOCK_SCHEMA_GROUP, registered.getSchemaName(), playingClassSchema.toString(),
95-
SerializationType.AVRO)).thenReturn(Mono.just(MOCK_GUID));
95+
SchemaFormat.AVRO)).thenReturn(Mono.just(MOCK_GUID));
9696

9797
final SchemaRegistryAvroSerializer serializer = new SchemaRegistryAvroSerializer(client, avroSerializer,
9898
MOCK_SCHEMA_GROUP, false);
@@ -145,7 +145,7 @@ void testGetSchemaAndDeserialize() throws IOException {
145145
DECODER_FACTORY);
146146
final PlayingCard playingCard = new PlayingCard(true, 10, PlayingCardSuit.DIAMONDS);
147147
final Schema playingClassSchema = PlayingCard.getClassSchema();
148-
final SchemaProperties registered = new SchemaProperties(MOCK_GUID, SerializationType.AVRO,
148+
final SchemaProperties registered = new SchemaProperties(MOCK_GUID, SchemaFormat.AVRO,
149149
playingClassSchema.getFullName(), playingClassSchema.toString().getBytes(StandardCharsets.UTF_8));
150150
final SchemaRegistryAvroSerializer serializer = new SchemaRegistryAvroSerializer(client, decoder,
151151
MOCK_SCHEMA_GROUP, true);

sdk/schemaregistry/azure-data-schemaregistry/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ String schemaContent = "{\n"
119119
+ " ]\n"
120120
+ "}";
121121
SchemaProperties schemaProperties = schemaRegistryClient.registerSchema("{schema-group}", "{schema-name}",
122-
schemaContent, SerializationType.AVRO);
122+
schemaContent, SerializationFormat.AVRO);
123123
System.out.println("Registered schema: " + schemaProperties.getSchemaId());
124124
```
125125

@@ -164,7 +164,7 @@ String schemaContent = "{\n"
164164
+ " ]\n"
165165
+ "}";
166166
String schemaId = schemaRegistryClient.getSchemaId("{schema-group}", "{schema-name}",
167-
schemaContent, SerializationType.AVRO);
167+
schemaContent, SerializationFormat.AVRO);
168168
System.out.println("Retreived schema id: " + schemaId);
169169
```
170170

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

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import com.azure.core.util.logging.ClientLogger;
1414
import com.azure.data.schemaregistry.implementation.AzureSchemaRegistry;
1515
import com.azure.data.schemaregistry.implementation.models.SchemaId;
16+
import com.azure.data.schemaregistry.models.SchemaFormat;
1617
import com.azure.data.schemaregistry.models.SchemaProperties;
17-
import com.azure.data.schemaregistry.models.SerializationType;
1818
import reactor.core.publisher.Mono;
1919

2020
import java.net.URI;
@@ -54,21 +54,30 @@ public final class SchemaRegistryAsyncClient {
5454
this.restService = restService;
5555
}
5656

57+
/**
58+
* Gets the fully qualified namespace of the Schema Registry instance.
59+
*
60+
* @return The fully qualified namespace of the Schema Registry instance.
61+
*/
62+
public String getFullyQualifiedNamespace() {
63+
return this.restService.getEndpoint();
64+
}
65+
5766
/**
5867
* Registers a new schema in the specified schema group with the given schema name. If the schema name already
5968
* exists in this schema group, a new version with the updated schema string will be registered.
6069
*
6170
* @param groupName The schema group.
6271
* @param name The schema name.
6372
* @param content The string representation of the schema.
64-
* @param serializationType The serialization type of this schema.
73+
* @param schemaFormat The serialization type of this schema.
6574
*
6675
* @return The {@link SchemaProperties} of a successfully registered schema.
6776
*/
6877
@ServiceMethod(returns = ReturnType.SINGLE)
6978
public Mono<SchemaProperties> registerSchema(String groupName, String name, String content,
70-
SerializationType serializationType) {
71-
return registerSchemaWithResponse(groupName, name, content, serializationType)
79+
SchemaFormat schemaFormat) {
80+
return registerSchemaWithResponse(groupName, name, content, schemaFormat)
7281
.map(Response::getValue);
7382
}
7483

@@ -79,28 +88,28 @@ public Mono<SchemaProperties> registerSchema(String groupName, String name, Stri
7988
* @param groupName The schema group.
8089
* @param name The schema name.
8190
* @param content The string representation of the schema.
82-
* @param serializationType The serialization type of this schema.
91+
* @param schemaFormat The serialization type of this schema.
8392
*
8493
* @return The schema properties on successful registration of the schema.
8594
*/
8695
@ServiceMethod(returns = ReturnType.SINGLE)
8796
public Mono<Response<SchemaProperties>> registerSchemaWithResponse(String groupName, String name, String content,
88-
SerializationType serializationType) {
97+
SchemaFormat schemaFormat) {
8998
return FluxUtil.withContext(context -> registerSchemaWithResponse(groupName, name, content,
90-
serializationType, context));
99+
schemaFormat, context));
91100
}
92101

93102
Mono<Response<SchemaProperties>> registerSchemaWithResponse(String groupName, String name, String content,
94-
SerializationType serializationType, Context context) {
103+
SchemaFormat schemaFormat, Context context) {
95104
logger.verbose("Registering schema. Group: '{}', name: '{}', serialization type: '{}', payload: '{}'",
96-
groupName, name, serializationType, content);
105+
groupName, name, schemaFormat, content);
97106

98107
return this.restService.getSchemas().registerWithResponseAsync(groupName, name,
99108
com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO, content)
100109
.handle((response, sink) -> {
101110
SchemaId schemaId = response.getValue();
102111
SchemaProperties registered = new SchemaProperties(schemaId.getId(),
103-
serializationType,
112+
schemaFormat,
104113
name,
105114
content.getBytes(SCHEMA_REGISTRY_SERVICE_ENCODING));
106115

@@ -139,8 +148,8 @@ Mono<Response<SchemaProperties>> getSchemaWithResponse(String id, Context contex
139148
Objects.requireNonNull(id, "'id' should not be null");
140149
return this.restService.getSchemas().getByIdWithResponseAsync(id)
141150
.handle((response, sink) -> {
142-
final SerializationType serializationType =
143-
SerializationType.fromString(response.getDeserializedHeaders().getSchemaType());
151+
final SchemaFormat schemaFormat =
152+
SchemaFormat.fromString(response.getDeserializedHeaders().getSchemaType());
144153
final URI location = URI.create(response.getDeserializedHeaders().getLocation());
145154
final Matcher matcher = SCHEMA_PATTERN.matcher(location.getPath());
146155

@@ -153,7 +162,7 @@ Mono<Response<SchemaProperties>> getSchemaWithResponse(String id, Context contex
153162

154163
final String schemaName = matcher.group("schemaName");
155164
final SchemaProperties schemaObject = new SchemaProperties(id,
156-
serializationType,
165+
schemaFormat,
157166
schemaName,
158167
response.getValue());
159168
final SimpleResponse<SchemaProperties> schemaResponse = new SimpleResponse<>(
@@ -171,14 +180,14 @@ Mono<Response<SchemaProperties>> getSchemaWithResponse(String id, Context contex
171180
* @param groupName The schema group.
172181
* @param name The schema name.
173182
* @param content The string representation of the schema.
174-
* @param serializationType The serialization type of this schema.
183+
* @param schemaFormat The serialization type of this schema.
175184
*
176185
* @return The unique identifier for this schema.
177186
*/
178187
@ServiceMethod(returns = ReturnType.SINGLE)
179188
public Mono<String> getSchemaId(String groupName, String name, String content,
180-
SerializationType serializationType) {
181-
return getSchemaIdWithResponse(groupName, name, content, serializationType)
189+
SchemaFormat schemaFormat) {
190+
return getSchemaIdWithResponse(groupName, name, content, schemaFormat)
182191
.map(response -> response.getValue());
183192
}
184193

@@ -188,16 +197,16 @@ public Mono<String> getSchemaId(String groupName, String name, String content,
188197
* @param groupName The schema group.
189198
* @param name The schema name.
190199
* @param content The string representation of the schema.
191-
* @param serializationType The serialization type of this schema.
200+
* @param schemaFormat The serialization type of this schema.
192201
*
193202
* @return The unique identifier for this schema.
194203
*/
195204
@ServiceMethod(returns = ReturnType.SINGLE)
196205
public Mono<Response<String>> getSchemaIdWithResponse(String groupName, String name, String content,
197-
SerializationType serializationType) {
206+
SchemaFormat schemaFormat) {
198207

199208
return FluxUtil.withContext(context ->
200-
getSchemaIdWithResponse(groupName, name, content, serializationType, context));
209+
getSchemaIdWithResponse(groupName, name, content, schemaFormat, context));
201210
}
202211

203212
/**
@@ -206,16 +215,16 @@ public Mono<Response<String>> getSchemaIdWithResponse(String groupName, String n
206215
* @param groupName The schema group.
207216
* @param name The schema name.
208217
* @param content The string representation of the schema.
209-
* @param serializationType The serialization type of this schema.
218+
* @param schemaFormat The serialization type of this schema.
210219
* @param context Context to pass along with this request.
211220
*
212221
* @return A mono that completes with the schema id.
213222
*/
214223
Mono<Response<String>> getSchemaIdWithResponse(String groupName, String name, String content,
215-
SerializationType serializationType, Context context) {
224+
SchemaFormat schemaFormat, Context context) {
216225

217226
return this.restService.getSchemas()
218-
.queryIdByContentWithResponseAsync(groupName, name, getSerialization(serializationType), content)
227+
.queryIdByContentWithResponseAsync(groupName, name, getSerialization(schemaFormat), content)
219228
.handle((response, sink) -> {
220229
SchemaId schemaId = response.getValue();
221230
SimpleResponse<String> schemaIdResponse = new SimpleResponse<>(
@@ -229,18 +238,18 @@ Mono<Response<String>> getSchemaIdWithResponse(String groupName, String name, St
229238
/**
230239
* Gets the matching implementation class serialization type.
231240
*
232-
* @param serializationType Model serialization type.
241+
* @param schemaFormat Model serialization type.
233242
*
234243
* @return Implementation serialization type.
235244
*
236245
* @throws UnsupportedOperationException if the serialization type is not supported.
237246
*/
238247
private static com.azure.data.schemaregistry.implementation.models.SerializationType getSerialization(
239-
SerializationType serializationType) {
240-
if (serializationType == SerializationType.AVRO) {
248+
SchemaFormat schemaFormat) {
249+
if (schemaFormat == SchemaFormat.AVRO) {
241250
return com.azure.data.schemaregistry.implementation.models.SerializationType.AVRO;
242251
} else {
243-
throw new UnsupportedOperationException("Serialization type is not supported: " + serializationType);
252+
throw new UnsupportedOperationException("Serialization type is not supported: " + schemaFormat);
244253
}
245254
}
246255
}

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import com.azure.core.annotation.ServiceMethod;
99
import com.azure.core.http.rest.Response;
1010
import com.azure.core.util.Context;
11+
import com.azure.data.schemaregistry.models.SchemaFormat;
1112
import com.azure.data.schemaregistry.models.SchemaProperties;
12-
import com.azure.data.schemaregistry.models.SerializationType;
1313

1414
/**
1515
* HTTP-based client that interacts with Azure Schema Registry service to store and retrieve schemas on demand.
@@ -34,21 +34,30 @@ public final class SchemaRegistryClient {
3434
this.asyncClient = asyncClient;
3535
}
3636

37+
/**
38+
* Gets the fully qualified namespace of the Schema Registry instance.
39+
*
40+
* @return The fully qualified namespace of the Schema Registry instance.
41+
*/
42+
public String getFullyQualifiedNamespace() {
43+
return asyncClient.getFullyQualifiedNamespace();
44+
}
45+
3746
/**
3847
* Registers a new schema in the specified schema group with the given schema name. If the schema name already
3948
* exists in this schema group, a new version with the updated schema string will be registered.
4049
*
4150
* @param groupName The schema group.
4251
* @param name The schema name.
4352
* @param content The string representation of the schema.
44-
* @param serializationType The serialization type of this schema.
53+
* @param schemaFormat The serialization type of this schema.
4554
*
4655
* @return The schema properties on successful registration of the schema.
4756
*/
4857
@ServiceMethod(returns = ReturnType.SINGLE)
4958
public SchemaProperties registerSchema(String groupName, String name, String content,
50-
SerializationType serializationType) {
51-
return this.asyncClient.registerSchema(groupName, name, content, serializationType).block();
59+
SchemaFormat schemaFormat) {
60+
return this.asyncClient.registerSchema(groupName, name, content, schemaFormat).block();
5261
}
5362

5463
/**
@@ -58,15 +67,15 @@ public SchemaProperties registerSchema(String groupName, String name, String con
5867
* @param groupName The schema group.
5968
* @param name The schema name.
6069
* @param content The string representation of the schema.
61-
* @param serializationType The serialization type of this schema.
70+
* @param schemaFormat The serialization type of this schema.
6271
* @param context The context to pass to the Http pipeline.
6372
*
6473
* @return The schema properties on successful registration of the schema.
6574
*/
6675
@ServiceMethod(returns = ReturnType.SINGLE)
6776
public Response<SchemaProperties> registerSchemaWithResponse(String groupName, String name, String content,
68-
SerializationType serializationType, Context context) {
69-
return this.asyncClient.registerSchemaWithResponse(groupName, name, content, serializationType,
77+
SchemaFormat schemaFormat, Context context) {
78+
return this.asyncClient.registerSchemaWithResponse(groupName, name, content, schemaFormat,
7079
context).block();
7180
}
7281

@@ -88,12 +97,12 @@ public SchemaProperties getSchema(String id) {
8897
* @param groupName The schema group.
8998
* @param name The schema name.
9099
* @param content The string representation of the schema.
91-
* @param serializationType The serialization type of this schema.
100+
* @param schemaFormat The serialization type of this schema.
92101
*
93102
* @return The unique identifier for this schema.
94103
*/
95104
@ServiceMethod(returns = ReturnType.SINGLE)
96-
public String getSchemaId(String groupName, String name, String content, SerializationType serializationType) {
97-
return this.asyncClient.getSchemaId(groupName, name, content, serializationType).block();
105+
public String getSchemaId(String groupName, String name, String content, SchemaFormat schemaFormat) {
106+
return this.asyncClient.getSchemaId(groupName, name, content, schemaFormat).block();
98107
}
99108
}

0 commit comments

Comments
 (0)