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

 ##########
 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:
   OK, I will change it then return the response status

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to