You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/08/06 08:20:49 UTC

git commit: letting users to specify tenant ids as a list of comma separated values.

Updated Branches:
  refs/heads/master 8f43b4af8 -> 47055d5c6


letting users to specify tenant ids as a list of comma separated values.


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/47055d5c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/47055d5c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/47055d5c

Branch: refs/heads/master
Commit: 47055d5c6d46cb31251196ed7808f1ccb1e9f877
Parents: 8f43b4a
Author: nirmal070125 <ni...@apache.org>
Authored: Tue Aug 6 11:50:12 2013 +0530
Committer: nirmal070125 <ni...@apache.org>
Committed: Tue Aug 6 11:50:12 2013 +0530

----------------------------------------------------------------------
 .../conf/util/LoadBalancerConfigUtil.java       | 36 ++++++++++-----
 .../common/test/LoadBalancerConfigUtilTest.java | 48 ++++++++++++++++++++
 2 files changed, 73 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/47055d5c/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/conf/util/LoadBalancerConfigUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/conf/util/LoadBalancerConfigUtil.java b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/conf/util/LoadBalancerConfigUtil.java
index 61eceb4..6dbe335 100644
--- a/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/conf/util/LoadBalancerConfigUtil.java
+++ b/components/org.apache.stratos.lb.common/src/main/java/org/apache/stratos/lb/common/conf/util/LoadBalancerConfigUtil.java
@@ -252,17 +252,31 @@ public final class LoadBalancerConfigUtil {
         if (parsedLine[0].equalsIgnoreCase("*")) {
             tenantIds.add(0);
 
-        } else if (parsedLine.length == 1) {
-            try {
-                int tenantId = Integer.parseInt(tenantRange);
-                tenantIds.add(tenantId);
-
-            } catch (NumberFormatException e) {
-                String msg = "Invalid tenant range is specified : " + tenantRange;
-                log.error(msg, e);
-                throw new RuntimeException(msg, e);
-            }
-        } else if (parsedLine.length == 2) {
+		} else if (parsedLine.length == 1) {
+			// if there aren't any hyphens in the string, try to see whether
+			// this is a list of ids
+			parsedLine = tenantRange.trim().split(",");
+			
+			// if there aren't any commas in the string, we assume this to be a
+			// one single integer.
+			if (parsedLine.length == 1) {
+				try {
+					int tenantId = Integer.parseInt(tenantRange);
+					tenantIds.add(tenantId);
+
+				} catch (NumberFormatException e) {
+					String msg = "Invalid tenant range is specified : "
+							+ tenantRange;
+					log.error(msg, e);
+					throw new RuntimeException(msg, e);
+				}
+			} else {
+				for (int i = 0; i < parsedLine.length; i++) {
+					int tenantId = Integer.parseInt(parsedLine[i]);
+					tenantIds.add(tenantId);
+				}
+			}
+		} else if (parsedLine.length == 2) {
             try {
 
                 int startIndex = Integer.parseInt(parsedLine[0]);

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/47055d5c/components/org.apache.stratos.lb.common/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigUtilTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.lb.common/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigUtilTest.java b/components/org.apache.stratos.lb.common/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigUtilTest.java
new file mode 100644
index 0000000..a682bf5
--- /dev/null
+++ b/components/org.apache.stratos.lb.common/src/test/java/org/apache/stratos/lb/common/test/LoadBalancerConfigUtilTest.java
@@ -0,0 +1,48 @@
+/**
+ *  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.stratos.lb.common.test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.stratos.lb.common.conf.util.LoadBalancerConfigUtil;
+
+import junit.framework.TestCase;
+
+public class LoadBalancerConfigUtilTest extends TestCase {
+
+    private List<Integer> tenantList1 = Arrays.asList(1,2,3);
+    private List<Integer> tenantList2 = Arrays.asList(1,6,3,4);
+    private List<Integer> tenantList3 = Arrays.asList(43);
+    private List<Integer> tenantList4 = Arrays.asList(0);
+    
+    @Override
+    protected void setUp() throws Exception {
+
+    }
+    
+    public final void testGetTenantIds() {
+        
+        assertEquals(tenantList1, LoadBalancerConfigUtil.getTenantIds("1-3"));
+        assertEquals(tenantList2, LoadBalancerConfigUtil.getTenantIds("1,6,3,4"));
+        assertEquals(tenantList3, LoadBalancerConfigUtil.getTenantIds("43"));
+        assertEquals(tenantList4, LoadBalancerConfigUtil.getTenantIds("*"));
+    }
+
+}