From 1c8021fa1daf5207d44d1fb7013a869a91d5e8de Mon Sep 17 00:00:00 2001 From: Shashwat Sharma Date: Mon, 11 Oct 2021 23:33:17 -0700 Subject: [PATCH] Refactor the code and add javadoc Signed-off-by: Shashwat Sharma --- .../io/pravega/schemaregistry/common/NameUtil.java | 10 ++++++---- .../schemaregistry/service/SchemaRegistryService.java | 1 - .../storage/impl/schemas/PravegaKeyValueSchemas.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/io/pravega/schemaregistry/common/NameUtil.java b/common/src/main/java/io/pravega/schemaregistry/common/NameUtil.java index 17e383e5..f93d5f77 100644 --- a/common/src/main/java/io/pravega/schemaregistry/common/NameUtil.java +++ b/common/src/main/java/io/pravega/schemaregistry/common/NameUtil.java @@ -13,7 +13,7 @@ import com.google.common.base.Strings; public class NameUtil { - private static final String DEFAULT_TYPE = "default_type"; + private static final String DEFAULT_TYPE = "default_namespace"; /** * Extracts the name from the fully qualified type name. Name represents the last token after ".". * If the qualified name does not contain "." then the name is same as qualified name. @@ -63,7 +63,8 @@ public static String qualifiedName(String qualifier, String name) { /** * Type value if the 'type' is not null of empty. - * If type is null or empty then the created name is simply 'namespace.groupName'. + * If type is null or empty and the namespace is null or empty created name is 'default_namespace.groupName'. + * If type is null or empty and namespace is not null or empty then created name is 'namespace.groupName'. * * @param type the value provided with API call (schemaInfo.getType()). * @param groupName the name of the group for schema @@ -71,7 +72,8 @@ public static String qualifiedName(String qualifier, String name) { * @return Provided name or Created name for type in SchemaInfo */ public static String createTypeIfAbsent(String type, String groupName, String namespace) { - String nameSpace = Strings.isNullOrEmpty(namespace) ? DEFAULT_TYPE : namespace; - return Strings.isNullOrEmpty(type) ? String.format("%s.%s", nameSpace, groupName) : type; + Preconditions.checkNotNull(groupName, "Group can not be null"); + String typeName = Strings.isNullOrEmpty(namespace) ? DEFAULT_TYPE : namespace; + return Strings.isNullOrEmpty(type) ? String.format("%s.%s", typeName, groupName) : type; } } diff --git a/server/src/main/java/io/pravega/schemaregistry/service/SchemaRegistryService.java b/server/src/main/java/io/pravega/schemaregistry/service/SchemaRegistryService.java index 52b7ea79..04bb0034 100644 --- a/server/src/main/java/io/pravega/schemaregistry/service/SchemaRegistryService.java +++ b/server/src/main/java/io/pravega/schemaregistry/service/SchemaRegistryService.java @@ -813,7 +813,6 @@ private boolean checkCompatibility(SchemaInfo schema, GroupProperties groupPrope } private SchemaInfo normalizeSchemaBinary(SchemaInfo schemaInfo, String group, String namespace) { - Preconditions.checkNotNull(group, "Group can not be null"); // validates and the schema binary. ByteBuffer schemaBinary = schemaInfo.getSchemaData(); boolean isValid = true; diff --git a/server/src/main/java/io/pravega/schemaregistry/storage/impl/schemas/PravegaKeyValueSchemas.java b/server/src/main/java/io/pravega/schemaregistry/storage/impl/schemas/PravegaKeyValueSchemas.java index 75964563..65ac4d4d 100644 --- a/server/src/main/java/io/pravega/schemaregistry/storage/impl/schemas/PravegaKeyValueSchemas.java +++ b/server/src/main/java/io/pravega/schemaregistry/storage/impl/schemas/PravegaKeyValueSchemas.java @@ -134,7 +134,7 @@ private CompletionStage addNewSchemaRecord(SchemaInfo schemaInfo, Schema entries.put(KEY_SERIALIZER.toBytes(new SchemaIdChunkKey(id, i)), new VersionedRecord<>(bytes, null)); } - log.info("Calling update entries for new schema addition"); + log.trace("Call for update entries for new schema addition with schema {}", schemaInfo); return tableStore.updateEntries(SCHEMAS, entries) .thenApply(v -> id); }