liubao68 commented on a change in pull request #691: [SCB-546] refactor the 
schemas registry logic
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/691#discussion_r186642768
 
 

 ##########
 File path: 
service-registry/src/main/java/org/apache/servicecomb/serviceregistry/task/MicroserviceRegisterTask.java
 ##########
 @@ -136,19 +140,48 @@ private boolean checkSchemaIdSet() {
   }
 
   private boolean registerSchemas() {
+    List<GetSchemaResponse> existSchemas = 
srClient.getSchemas(microservice.getServiceId());
     for (Entry<String, String> entry : microservice.getSchemaMap().entrySet()) 
{
       String schemaId = entry.getKey();
       String content = entry.getValue();
-
-      boolean exists = srClient.isSchemaExist(microservice.getServiceId(), 
schemaId);
-      LOGGER.info("schemaId {} exists {}", schemaId, exists);
+      GetSchemaResponse existSchema = extractSchema(schemaId, existSchemas);
+      boolean exists = existSchema == null ? false : true;
+      LOGGER.info("schemaId [{}] exists {}", schemaId, exists);
       if (!exists) {
         if (!srClient.registerSchema(microservice.getServiceId(), schemaId, 
content)) {
           return false;
         }
+      } else {
+        String curSchemaSumary = existSchema.getSummary();
+        String schemaSummary = Hashing.md5().newHasher().putString(content, 
Charsets.UTF_8).hash().toString();
+        if (!schemaSummary.equals(curSchemaSumary)) {
+          if (microservice.getInstance().getEnvironment().startsWith("dev")) {
+            LOGGER.info(
+                "schemaId [{}]'s content changes and the current enviroment is 
development, so re-register it!",
+                schemaId);
+            srClient.registerSchema(microservice.getServiceId(), schemaId, 
content);
+          } else {
+            throw new RuntimeException("schemaId [" + schemaId
+                + "] exists, but schema's content changes and the current 
enviroment is production, program will stop!\n"
+                + "If you are developing now, you can set 
-Dinstance_description.environment=prod in program start config!");
+          }
+        }
 
 Review comment:
   Schema [schemaId] exists in service center, but the content does not match 
the local content and which means there are interface change and you need to 
increment microservice version before deploying. And you can configure 
instance_description.environment=development to work in debug mode and ignore 
this error.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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