[ONOS-4015] Enhance Region CLI to support add/update NodeIds sets

Change-Id: I559b5cd3213e8e7ae69bdbbefdc8a1a9a1655b49
diff --git a/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java b/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
index 0c6d252..aeb6f45 100644
--- a/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/RegionAddCommand.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
@@ -28,7 +29,6 @@
 
 import java.util.List;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 /**
  * Add a new region.
@@ -53,22 +53,33 @@
             required = true, multiValued = false)
     String name = null;
 
-    @Argument(index = 2, name = "type", description = "Region Type",
+    @Argument(index = 2, name = "type", description = "Region Type (CONTINENT|" +
+            "COUNTRY|METRO|CAMPUS|BUILDING|FLOOR|ROOM|RACK|LOGICAL_GROUP)",
             required = true, multiValued = false)
     String type = null;
 
-    @Argument(index = 3, name = "masters", description = "Region Master",
+    @Argument(index = 3, name = "masters", description = "Region Master, a set " +
+            "of nodeIds should be split with '/' delimiter (e.g., 1 2 3 / 4 5 6)",
             required = true, multiValued = true)
-    List<String> masters = null;
+    List<String> masterArgs = null;
 
     @Override
     protected void execute() {
         RegionAdminService service = get(RegionAdminService.class);
         RegionId regionId = RegionId.regionId(id);
-        Set<NodeId> nodeIds =
-                masters.stream().map(s -> NodeId.nodeId(s)).collect(Collectors.toSet());
+
         List<Set<NodeId>> masters = Lists.newArrayList();
+        Set<NodeId> nodeIds = Sets.newHashSet();
+        for (String masterArg : masterArgs) {
+            if (masterArg.equals("/")) {
+                masters.add(nodeIds);
+                nodeIds = Sets.newHashSet();
+            } else {
+                nodeIds.add(NodeId.nodeId(masterArg));
+            }
+        }
         masters.add(nodeIds);
+
         service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
         print("Region successfully added.");
     }
diff --git a/cli/src/main/java/org/onosproject/cli/net/RegionUpdateCommand.java b/cli/src/main/java/org/onosproject/cli/net/RegionUpdateCommand.java
index f395491..243007c 100644
--- a/cli/src/main/java/org/onosproject/cli/net/RegionUpdateCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/RegionUpdateCommand.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import org.apache.karaf.shell.commands.Argument;
 import org.apache.karaf.shell.commands.Command;
 import org.onosproject.cli.AbstractShellCommand;
@@ -29,7 +30,6 @@
 
 import java.util.List;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 /**
  * Update an existing region.
@@ -54,13 +54,15 @@
             required = true, multiValued = false)
     String name = null;
 
-    @Argument(index = 2, name = "type", description = "Region Type",
+    @Argument(index = 2, name = "type", description = "Region Type (CONTINENT|" +
+            "COUNTRY|METRO|CAMPUS|BUILDING|FLOOR|ROOM|RACK|LOGICAL_GROUP)",
             required = true, multiValued = false)
     String type = null;
 
-    @Argument(index = 3, name = "masters", description = "Region Master",
+    @Argument(index = 3, name = "masters", description = "Region Master, a set " +
+    "of nodeIds should be split with '/' delimiter (e.g., 1 2 3 / 4 5 6)",
             required = true, multiValued = true)
-    List<String> masters = null;
+    List<String> masterArgs = null;
 
     @Override
     protected void execute() {
@@ -73,10 +75,18 @@
             return;
         }
 
-        Set<NodeId> nodeIds =
-                masters.stream().map(s -> NodeId.nodeId(s)).collect(Collectors.toSet());
         List<Set<NodeId>> masters = Lists.newArrayList();
+        Set<NodeId> nodeIds = Sets.newHashSet();
+        for (String masterArg : masterArgs) {
+            if (masterArg.equals("/")) {
+                masters.add(nodeIds);
+                nodeIds = Sets.newHashSet();
+            } else {
+                nodeIds.add(NodeId.nodeId(masterArg));
+            }
+        }
         masters.add(nodeIds);
+
         regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters);
         print("Region with id %s is successfully updated.", regionId);
     }
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 9329c28..cd3f573 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -568,6 +568,7 @@
                 <null/>
                 <null/>
                 <ref component-id="regionTypeCompleter"/>
+                <ref component-id="nodeIdCompleter"/>
             </completers>
         </command>
         <command>
@@ -576,6 +577,7 @@
                 <ref component-id="regionIdCompleter"/>
                 <null/>
                 <ref component-id="regionTypeCompleter"/>
+                <ref component-id="nodeIdCompleter"/>
             </completers>
         </command>
         <command>