You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by zh...@apache.org on 2020/05/14 00:16:10 UTC

[servicecomb-pack] branch master updated: Verify the instanceId size

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

zhanglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git


The following commit(s) were added to refs/heads/master by this push:
     new 0ee0bb9  Verify the instanceId size
     new bd0e774  Merge pull request #659 from dengliming/master
0ee0bb9 is described below

commit 0ee0bb96bf43fc19a9dfcab00db2e16a4de3f75a
Author: dengliming <li...@gmail.com>
AuthorDate: Wed May 13 22:45:33 2020 +0800

    Verify the instanceId size
---
 .../org/apache/servicecomb/pack/omega/context/ServiceConfig.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/omega/omega-context/src/main/java/org/apache/servicecomb/pack/omega/context/ServiceConfig.java b/omega/omega-context/src/main/java/org/apache/servicecomb/pack/omega/context/ServiceConfig.java
index 09024e6..d9b0aa0 100644
--- a/omega/omega-context/src/main/java/org/apache/servicecomb/pack/omega/context/ServiceConfig.java
+++ b/omega/omega-context/src/main/java/org/apache/servicecomb/pack/omega/context/ServiceConfig.java
@@ -23,12 +23,14 @@ import java.net.UnknownHostException;
 public class ServiceConfig {
   private final String serviceName;
   private final String instanceId;
+  // Current DB only supports instance id less then 35
+  private static final int MAX_LENGTH = 35;
 
   public ServiceConfig(String serviceName) {
     this(serviceName,null);
   }
 
-  public ServiceConfig(String serviceName,String instanceId) {
+  public ServiceConfig(String serviceName, String instanceId) {
     this.serviceName = serviceName;
     if(instanceId == null || "".equalsIgnoreCase(instanceId.trim())){
       try {
@@ -37,6 +39,10 @@ public class ServiceConfig {
         throw new IllegalStateException(e);
       }
     }else{
+      instanceId = instanceId.trim();
+      if (instanceId.length() > MAX_LENGTH) {
+        throw new IllegalArgumentException(String.format("The instanceId length exceeds maximum length limit [%d].", MAX_LENGTH));
+      }
       this.instanceId = instanceId;
     }
   }