You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by du...@apache.org on 2022/07/31 06:47:19 UTC

[rocketmq-schema-registry] 32/34: simplify get and delete api

This is an automated email from the ASF dual-hosted git repository.

duhengforever pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-schema-registry.git

commit 264e5e91bf75df0af56a04e6a20b408b65e81d10
Author: fan <wa...@xiaomi.com>
AuthorDate: Sun Jul 31 14:02:49 2022 +0800

    simplify get and delete api
---
 .../registry/common/dto/DeleteSchemeResponse.java  | 41 +++++++++++++
 .../common/dto/GetSchemaBySubjectResponse.java     | 70 ++++++++++++++++++++++
 .../registry/core/api/v1/SchemaController.java     | 12 ++--
 .../registry/core/service/SchemaService.java       |  6 +-
 .../registry/core/service/SchemaServiceImpl.java   | 14 ++---
 5 files changed, 129 insertions(+), 14 deletions(-)

diff --git a/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/DeleteSchemeResponse.java b/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/DeleteSchemeResponse.java
new file mode 100644
index 0000000..7418958
--- /dev/null
+++ b/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/DeleteSchemeResponse.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.schema.registry.common.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class DeleteSchemeResponse extends BaseDto {
+    private static final long serialVersionUID = 5487372544128191038L;
+
+    @ApiModelProperty(value = "Deleted schema id")
+    private long schemaId;
+
+    @ApiModelProperty(value = "Deleted schema id")
+    private long version;
+
+}
diff --git a/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/GetSchemaBySubjectResponse.java b/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/GetSchemaBySubjectResponse.java
new file mode 100644
index 0000000..e70a02c
--- /dev/null
+++ b/common/src/main/java/org/apache/rocketmq/schema/registry/common/dto/GetSchemaBySubjectResponse.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.rocketmq.schema.registry.common.dto;
+
+import org.apache.rocketmq.schema.registry.common.QualifiedName;
+import org.apache.rocketmq.schema.registry.common.model.Dependency;
+import org.apache.rocketmq.schema.registry.common.model.SchemaRecordInfo;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class GetSchemaBySubjectResponse extends BaseDto {
+    private static final long serialVersionUID = -4612593696179069203L;
+
+    @ApiModelProperty(value = "Schema dependency")
+    private String subjectFullName;
+
+    @ApiModelProperty(value = "Schema full name")
+    private String schemaFullName;
+
+    @ApiModelProperty(value = "Schema id")
+    private long schemaId;
+
+    @ApiModelProperty(value = "Schema version")
+    private long version;
+
+    @ApiModelProperty(value = "Schema idl")
+    private String idl;
+
+    @ApiModelProperty(value = "Schema dependency")
+    private Dependency dependency;
+
+    @ApiModelProperty(value = "Schema type")
+    private SchemaType type;
+
+    public GetSchemaBySubjectResponse(QualifiedName name, SchemaRecordInfo schemaRecordInfo) {
+        this.subjectFullName = name.subjectFullName();
+        this.schemaId = schemaRecordInfo.getSchemaId();
+        this.version = schemaRecordInfo.getVersion();
+        this.idl = schemaRecordInfo.getIdl();
+        this.dependency = schemaRecordInfo.getDependency();
+        this.type = schemaRecordInfo.getType();
+    }
+
+}
diff --git a/core/src/main/java/org/apache/rocketmq/schema/registry/core/api/v1/SchemaController.java b/core/src/main/java/org/apache/rocketmq/schema/registry/core/api/v1/SchemaController.java
index 40749dc..96bdd5a 100644
--- a/core/src/main/java/org/apache/rocketmq/schema/registry/core/api/v1/SchemaController.java
+++ b/core/src/main/java/org/apache/rocketmq/schema/registry/core/api/v1/SchemaController.java
@@ -26,6 +26,8 @@ import java.net.HttpURLConnection;
 import java.util.List;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.schema.registry.common.QualifiedName;
+import org.apache.rocketmq.schema.registry.common.dto.DeleteSchemeResponse;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaBySubjectResponse;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaRequest;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaResponse;
 import org.apache.rocketmq.schema.registry.common.dto.SchemaDto;
@@ -182,7 +184,7 @@ public class SchemaController {
             )
         }
         )
-    public SchemaDto deleteSchema(
+    public DeleteSchemeResponse deleteSchema(
         @ApiParam(value = "The cluster of the subject", required = true)
         @PathVariable(value = "cluster-name") final String cluster,
         @ApiParam(value = "The tenant of the schema", required = true)
@@ -219,7 +221,7 @@ public class SchemaController {
             )
         }
         )
-    public SchemaDto deleteSchema(
+    public DeleteSchemeResponse deleteSchema(
         @ApiParam(value = "The cluster of the subject", required = true)
         @PathVariable(value = "cluster-name") final String cluster,
         @ApiParam(value = "The tenant of the schema", required = true)
@@ -329,7 +331,7 @@ public class SchemaController {
             )
         }
         )
-    public SchemaRecordDto getSchemaBySubject(
+    public GetSchemaBySubjectResponse getSchemaBySubject(
         @ApiParam(value = "The name of the subject", required = true)
         @PathVariable(value = "subject-name") String subject
     ) {
@@ -355,7 +357,7 @@ public class SchemaController {
             )
         }
         )
-    public SchemaRecordDto getSchemaBySubject(
+    public GetSchemaBySubjectResponse getSchemaBySubject(
         @ApiParam(value = "The cluster of the subject", required = true)
         @PathVariable(value = "cluster-name") final String cluster,
         @ApiParam(value = "The tenant of the schema", required = true)
@@ -391,7 +393,7 @@ public class SchemaController {
             )
         }
         )
-    public SchemaRecordDto getSchemaBySubject(
+    public GetSchemaBySubjectResponse getSchemaBySubject(
         @ApiParam(value = "The cluster of the subject", required = true)
         @PathVariable(value = "cluster-name") final String cluster,
         @ApiParam(value = "The tenant of the schema", required = true)
diff --git a/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaService.java b/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaService.java
index b32a2fb..a21ae54 100644
--- a/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaService.java
+++ b/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaService.java
@@ -20,6 +20,8 @@ package org.apache.rocketmq.schema.registry.core.service;
 import java.util.List;
 import org.apache.rocketmq.schema.registry.common.QualifiedName;
 import org.apache.rocketmq.schema.registry.common.dto.BaseDto;
+import org.apache.rocketmq.schema.registry.common.dto.DeleteSchemeResponse;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaBySubjectResponse;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaRequest;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaResponse;
 import org.apache.rocketmq.schema.registry.common.dto.SchemaRecordDto;
@@ -52,7 +54,7 @@ public interface SchemaService<T extends BaseDto> {
      * @param qualifiedName tenant / name of the schema
      * @return deleted schema object
      */
-    T delete(QualifiedName qualifiedName);
+    DeleteSchemeResponse delete(QualifiedName qualifiedName);
 
     /**
      * Query the schema object with the given name.
@@ -68,7 +70,7 @@ public interface SchemaService<T extends BaseDto> {
      * @param qualifiedName subject of the schema binding
      * @return schema object with the schemaName
      */
-    SchemaRecordDto getBySubject(QualifiedName qualifiedName);
+    GetSchemaBySubjectResponse getBySubject(QualifiedName qualifiedName);
 
     /**
      * Query the schema object with the given subject name.
diff --git a/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaServiceImpl.java b/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaServiceImpl.java
index c883ac9..b8c62dd 100644
--- a/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaServiceImpl.java
+++ b/core/src/main/java/org/apache/rocketmq/schema/registry/core/service/SchemaServiceImpl.java
@@ -26,6 +26,8 @@ import org.apache.rocketmq.schema.registry.common.QualifiedName;
 import org.apache.rocketmq.schema.registry.common.auth.AccessControlService;
 import org.apache.rocketmq.schema.registry.common.context.RequestContext;
 import org.apache.rocketmq.schema.registry.common.context.RequestContextManager;
+import org.apache.rocketmq.schema.registry.common.dto.DeleteSchemeResponse;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaBySubjectResponse;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaRequest;
 import org.apache.rocketmq.schema.registry.common.dto.RegisterSchemaResponse;
 import org.apache.rocketmq.schema.registry.common.dto.SchemaDto;
@@ -188,20 +190,20 @@ public class SchemaServiceImpl implements SchemaService<SchemaDto> {
      * {@inheritDoc}
      */
     @Override
-    public SchemaDto delete(QualifiedName qualifiedName) {
+    public DeleteSchemeResponse delete(QualifiedName qualifiedName) {
         final RequestContext requestContext = RequestContextManager.getContext();
         log.info("delete request context: " + requestContext);
 
         this.accessController.checkPermission("", qualifiedName.getTenant(), SchemaOperation.DELETE);
 
-        SchemaInfo current = storageServiceProxy.get(qualifiedName, config.isCacheEnabled());
+        SchemaRecordInfo current = storageServiceProxy.getBySubject(qualifiedName, config.isCacheEnabled());
         if (current == null) {
             throw new SchemaNotFoundException("Schema " + qualifiedName + " not exist, ignored update.");
         }
 
         log.info("delete schema {}", qualifiedName);
         storageServiceProxy.delete(qualifiedName);
-        return storageUtil.convertToSchemaDto(current);
+        return new DeleteSchemeResponse(current.getSchemaId(), current.getVersion());
     }
 
     // TODO add get last record query
@@ -231,11 +233,10 @@ public class SchemaServiceImpl implements SchemaService<SchemaDto> {
      * {@inheritDoc}
      */
     @Override
-    public SchemaRecordDto getBySubject(QualifiedName qualifiedName) {
+    public GetSchemaBySubjectResponse getBySubject(QualifiedName qualifiedName) {
         final RequestContext requestContext = RequestContextManager.getContext();
         log.info("register get request context: " + requestContext);
 
-//        CommonUtil.validateName(qualifiedName);
         this.accessController.checkPermission("", qualifiedName.getSubject(), SchemaOperation.GET);
 
         SchemaRecordInfo recordInfo = storageServiceProxy.getBySubject(qualifiedName, config.isCacheEnabled());
@@ -244,7 +245,7 @@ public class SchemaServiceImpl implements SchemaService<SchemaDto> {
         }
 
         log.info("get schema by subject: {}", qualifiedName.getSubject());
-        return storageUtil.convertToSchemaRecordDto(recordInfo);
+        return new GetSchemaBySubjectResponse(qualifiedName, recordInfo);
     }
 
     @Override
@@ -252,7 +253,6 @@ public class SchemaServiceImpl implements SchemaService<SchemaDto> {
         final RequestContext requestContext = RequestContextManager.getContext();
         log.info("register get request context: " + requestContext);
 
-        //        CommonUtil.validateName(qualifiedName);
         this.accessController.checkPermission("", qualifiedName.getSubject(), SchemaOperation.GET);
 
         List<SchemaRecordInfo> recordInfos = storageServiceProxy.listBySubject(qualifiedName, config.isCacheEnabled());