You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/08/16 02:52:21 UTC

[GitHub] [pulsar] sijie commented on a change in pull request #4950: Modify rest api post schema compatibility strategy

sijie commented on a change in pull request #4950: Modify rest api post schema compatibility strategy
URL: https://github.com/apache/pulsar/pull/4950#discussion_r314567770
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/v2/SchemasResource.java
 ##########
 @@ -310,31 +310,49 @@ public void postSchema(
     ) {
         validateDestinationAndAdminOperation(tenant, namespace, topic, authoritative);
 
-        pulsar().getSchemaRegistryService().putSchemaIfAbsent(
-            buildSchemaId(tenant, namespace, topic),
-            SchemaData.builder()
-                .data(payload.getSchema().getBytes(Charsets.UTF_8))
-                .isDeleted(false)
-                .timestamp(clock.millis())
-                .type(SchemaType.valueOf(payload.getType()))
-                .user(defaultIfEmpty(clientAppId(), ""))
-                .props(payload.getProperties())
-                .build(),
-            SchemaCompatibilityStrategy.FULL
-        ).thenAccept(version ->
-            response.resume(
-                Response.accepted().entity(
-                    PostSchemaResponse.builder()
-                        .version(version)
-                        .build()
-                ).build()
-            )
-        ).exceptionally(error -> {
-            if (error instanceof IncompatibleSchemaException) {
-                response.resume(Response.status(Response.Status.CONFLICT).build());
-            } else if (error instanceof InvalidSchemaDataException) {
+        NamespaceName namespaceName = NamespaceName.get(tenant, namespace);
+        getNamespacePoliciesAsync(namespaceName).thenAccept(policies -> {
+            SchemaCompatibilityStrategy schemaCompatibilityStrategy = SchemaCompatibilityStrategy
+                    .fromAutoUpdatePolicy(policies.schema_auto_update_compatibility_strategy);
+            pulsar().getSchemaRegistryService().putSchemaIfAbsent(
+                    buildSchemaId(tenant, namespace, topic),
+                    SchemaData.builder()
+                            .data(payload.getSchema().getBytes(Charsets.UTF_8))
+                            .isDeleted(false)
+                            .timestamp(clock.millis())
+                            .type(SchemaType.valueOf(payload.getType()))
+                            .user(defaultIfEmpty(clientAppId(), ""))
+                            .props(payload.getProperties())
+                            .build(),
+                    schemaCompatibilityStrategy
+
+            ).thenAccept(version ->
+                    response.resume(
+                            Response.accepted().entity(
+                                    PostSchemaResponse.builder()
+                                            .version(version)
+                                            .build()
+                            ).build()
+                    )
+            ).exceptionally(error -> {
+                if (error.getCause() instanceof IncompatibleSchemaException) {
+                    response.resume(Response.status(Response.Status.CONFLICT).build());
+                } else if (error instanceof InvalidSchemaDataException) {
+                    response.resume(Response.status(
+                            422, /* Unprocessable Entity */
+                            error.getMessage()
+                    ).build());
+                } else {
+                    response.resume(
+                            Response.serverError().build()
+                    );
+                }
+                return null;
+            });
+        }).exceptionally(error -> {
+            if (error.getCause() instanceof RestException) {
                 response.resume(Response.status(
-                    422, /* Unprocessable Entity */
+                    404, /* Unprocessable Entity */
 
 Review comment:
   if it is RestException, you need to return the status of the RestException, no?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services