Committed by
Gerrit Code Review
[ONOS-4015] Enhance Region CLI to support add/update NodeIds sets
Change-Id: I559b5cd3213e8e7ae69bdbbefdc8a1a9a1655b49
Showing
3 changed files
with
35 additions
and
12 deletions
... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; | ... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; |
18 | import com.google.common.collect.BiMap; | 18 | import com.google.common.collect.BiMap; |
19 | import com.google.common.collect.HashBiMap; | 19 | import com.google.common.collect.HashBiMap; |
20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
21 | +import com.google.common.collect.Sets; | ||
21 | import org.apache.karaf.shell.commands.Argument; | 22 | import org.apache.karaf.shell.commands.Argument; |
22 | import org.apache.karaf.shell.commands.Command; | 23 | import org.apache.karaf.shell.commands.Command; |
23 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
... | @@ -28,7 +29,6 @@ import org.onosproject.net.region.RegionId; | ... | @@ -28,7 +29,6 @@ import org.onosproject.net.region.RegionId; |
28 | 29 | ||
29 | import java.util.List; | 30 | import java.util.List; |
30 | import java.util.Set; | 31 | import java.util.Set; |
31 | -import java.util.stream.Collectors; | ||
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Add a new region. | 34 | * Add a new region. |
... | @@ -53,22 +53,33 @@ public class RegionAddCommand extends AbstractShellCommand { | ... | @@ -53,22 +53,33 @@ public class RegionAddCommand extends AbstractShellCommand { |
53 | required = true, multiValued = false) | 53 | required = true, multiValued = false) |
54 | String name = null; | 54 | String name = null; |
55 | 55 | ||
56 | - @Argument(index = 2, name = "type", description = "Region Type", | 56 | + @Argument(index = 2, name = "type", description = "Region Type (CONTINENT|" + |
57 | + "COUNTRY|METRO|CAMPUS|BUILDING|FLOOR|ROOM|RACK|LOGICAL_GROUP)", | ||
57 | required = true, multiValued = false) | 58 | required = true, multiValued = false) |
58 | String type = null; | 59 | String type = null; |
59 | 60 | ||
60 | - @Argument(index = 3, name = "masters", description = "Region Master", | 61 | + @Argument(index = 3, name = "masters", description = "Region Master, a set " + |
62 | + "of nodeIds should be split with '/' delimiter (e.g., 1 2 3 / 4 5 6)", | ||
61 | required = true, multiValued = true) | 63 | required = true, multiValued = true) |
62 | - List<String> masters = null; | 64 | + List<String> masterArgs = null; |
63 | 65 | ||
64 | @Override | 66 | @Override |
65 | protected void execute() { | 67 | protected void execute() { |
66 | RegionAdminService service = get(RegionAdminService.class); | 68 | RegionAdminService service = get(RegionAdminService.class); |
67 | RegionId regionId = RegionId.regionId(id); | 69 | RegionId regionId = RegionId.regionId(id); |
68 | - Set<NodeId> nodeIds = | 70 | + |
69 | - masters.stream().map(s -> NodeId.nodeId(s)).collect(Collectors.toSet()); | ||
70 | List<Set<NodeId>> masters = Lists.newArrayList(); | 71 | List<Set<NodeId>> masters = Lists.newArrayList(); |
72 | + Set<NodeId> nodeIds = Sets.newHashSet(); | ||
73 | + for (String masterArg : masterArgs) { | ||
74 | + if (masterArg.equals("/")) { | ||
75 | + masters.add(nodeIds); | ||
76 | + nodeIds = Sets.newHashSet(); | ||
77 | + } else { | ||
78 | + nodeIds.add(NodeId.nodeId(masterArg)); | ||
79 | + } | ||
80 | + } | ||
71 | masters.add(nodeIds); | 81 | masters.add(nodeIds); |
82 | + | ||
72 | service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters); | 83 | service.createRegion(regionId, name, REGION_TYPE_MAP.get(type), masters); |
73 | print("Region successfully added."); | 84 | print("Region successfully added."); |
74 | } | 85 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; | ... | @@ -18,6 +18,7 @@ package org.onosproject.cli.net; |
18 | import com.google.common.collect.BiMap; | 18 | import com.google.common.collect.BiMap; |
19 | import com.google.common.collect.HashBiMap; | 19 | import com.google.common.collect.HashBiMap; |
20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
21 | +import com.google.common.collect.Sets; | ||
21 | import org.apache.karaf.shell.commands.Argument; | 22 | import org.apache.karaf.shell.commands.Argument; |
22 | import org.apache.karaf.shell.commands.Command; | 23 | import org.apache.karaf.shell.commands.Command; |
23 | import org.onosproject.cli.AbstractShellCommand; | 24 | import org.onosproject.cli.AbstractShellCommand; |
... | @@ -29,7 +30,6 @@ import org.onosproject.net.region.RegionService; | ... | @@ -29,7 +30,6 @@ import org.onosproject.net.region.RegionService; |
29 | 30 | ||
30 | import java.util.List; | 31 | import java.util.List; |
31 | import java.util.Set; | 32 | import java.util.Set; |
32 | -import java.util.stream.Collectors; | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Update an existing region. | 35 | * Update an existing region. |
... | @@ -54,13 +54,15 @@ public class RegionUpdateCommand extends AbstractShellCommand { | ... | @@ -54,13 +54,15 @@ public class RegionUpdateCommand extends AbstractShellCommand { |
54 | required = true, multiValued = false) | 54 | required = true, multiValued = false) |
55 | String name = null; | 55 | String name = null; |
56 | 56 | ||
57 | - @Argument(index = 2, name = "type", description = "Region Type", | 57 | + @Argument(index = 2, name = "type", description = "Region Type (CONTINENT|" + |
58 | + "COUNTRY|METRO|CAMPUS|BUILDING|FLOOR|ROOM|RACK|LOGICAL_GROUP)", | ||
58 | required = true, multiValued = false) | 59 | required = true, multiValued = false) |
59 | String type = null; | 60 | String type = null; |
60 | 61 | ||
61 | - @Argument(index = 3, name = "masters", description = "Region Master", | 62 | + @Argument(index = 3, name = "masters", description = "Region Master, a set " + |
63 | + "of nodeIds should be split with '/' delimiter (e.g., 1 2 3 / 4 5 6)", | ||
62 | required = true, multiValued = true) | 64 | required = true, multiValued = true) |
63 | - List<String> masters = null; | 65 | + List<String> masterArgs = null; |
64 | 66 | ||
65 | @Override | 67 | @Override |
66 | protected void execute() { | 68 | protected void execute() { |
... | @@ -73,10 +75,18 @@ public class RegionUpdateCommand extends AbstractShellCommand { | ... | @@ -73,10 +75,18 @@ public class RegionUpdateCommand extends AbstractShellCommand { |
73 | return; | 75 | return; |
74 | } | 76 | } |
75 | 77 | ||
76 | - Set<NodeId> nodeIds = | ||
77 | - masters.stream().map(s -> NodeId.nodeId(s)).collect(Collectors.toSet()); | ||
78 | List<Set<NodeId>> masters = Lists.newArrayList(); | 78 | List<Set<NodeId>> masters = Lists.newArrayList(); |
79 | + Set<NodeId> nodeIds = Sets.newHashSet(); | ||
80 | + for (String masterArg : masterArgs) { | ||
81 | + if (masterArg.equals("/")) { | ||
82 | + masters.add(nodeIds); | ||
83 | + nodeIds = Sets.newHashSet(); | ||
84 | + } else { | ||
85 | + nodeIds.add(NodeId.nodeId(masterArg)); | ||
86 | + } | ||
87 | + } | ||
79 | masters.add(nodeIds); | 88 | masters.add(nodeIds); |
89 | + | ||
80 | regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters); | 90 | regionAdminService.updateRegion(regionId, name, REGION_TYPE_MAP.get(type), masters); |
81 | print("Region with id %s is successfully updated.", regionId); | 91 | print("Region with id %s is successfully updated.", regionId); |
82 | } | 92 | } | ... | ... |
... | @@ -568,6 +568,7 @@ | ... | @@ -568,6 +568,7 @@ |
568 | <null/> | 568 | <null/> |
569 | <null/> | 569 | <null/> |
570 | <ref component-id="regionTypeCompleter"/> | 570 | <ref component-id="regionTypeCompleter"/> |
571 | + <ref component-id="nodeIdCompleter"/> | ||
571 | </completers> | 572 | </completers> |
572 | </command> | 573 | </command> |
573 | <command> | 574 | <command> |
... | @@ -576,6 +577,7 @@ | ... | @@ -576,6 +577,7 @@ |
576 | <ref component-id="regionIdCompleter"/> | 577 | <ref component-id="regionIdCompleter"/> |
577 | <null/> | 578 | <null/> |
578 | <ref component-id="regionTypeCompleter"/> | 579 | <ref component-id="regionTypeCompleter"/> |
580 | + <ref component-id="nodeIdCompleter"/> | ||
579 | </completers> | 581 | </completers> |
580 | </command> | 582 | </command> |
581 | <command> | 583 | <command> | ... | ... |
-
Please register or login to post a comment