Showing
4 changed files
with
83 additions
and
5 deletions
1 | +package org.onlab.onos.cli; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.commands.Argument; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.cluster.ClusterAdminService; | ||
6 | +import org.onlab.onos.cluster.NodeId; | ||
7 | +import org.onlab.packet.IpPrefix; | ||
8 | + | ||
9 | +/** | ||
10 | + * Adds a new controller cluster node. | ||
11 | + */ | ||
12 | +@Command(scope = "onos", name = "add-node", | ||
13 | + description = "Adds a new controller cluster node") | ||
14 | +public class NodeAddCommand extends AbstractShellCommand { | ||
15 | + | ||
16 | + @Argument(index = 0, name = "nodeId", description = "Node ID", | ||
17 | + required = true, multiValued = false) | ||
18 | + String nodeId = null; | ||
19 | + | ||
20 | + @Argument(index = 1, name = "ip", description = "Node IP address", | ||
21 | + required = true, multiValued = false) | ||
22 | + String ip = null; | ||
23 | + | ||
24 | + @Argument(index = 2, name = "tcpPort", description = "Node TCP listen port", | ||
25 | + required = false, multiValued = false) | ||
26 | + int tcpPort = 9876; | ||
27 | + | ||
28 | + @Override | ||
29 | + protected void execute() { | ||
30 | + ClusterAdminService service = get(ClusterAdminService.class); | ||
31 | + service.addNode(new NodeId(nodeId), IpPrefix.valueOf(ip), tcpPort); | ||
32 | + } | ||
33 | + | ||
34 | +} |
1 | +package org.onlab.onos.cli; | ||
2 | + | ||
3 | +import org.apache.karaf.shell.commands.Argument; | ||
4 | +import org.apache.karaf.shell.commands.Command; | ||
5 | +import org.onlab.onos.cluster.ClusterAdminService; | ||
6 | +import org.onlab.onos.cluster.NodeId; | ||
7 | + | ||
8 | +/** | ||
9 | + * Removes a controller cluster node. | ||
10 | + */ | ||
11 | +@Command(scope = "onos", name = "remove-node", | ||
12 | + description = "Removes a new controller cluster node") | ||
13 | +public class NodeRemoveCommand extends AbstractShellCommand { | ||
14 | + | ||
15 | + @Argument(index = 0, name = "nodeId", description = "Node ID", | ||
16 | + required = true, multiValued = false) | ||
17 | + String nodeId = null; | ||
18 | + | ||
19 | + @Override | ||
20 | + protected void execute() { | ||
21 | + ClusterAdminService service = get(ClusterAdminService.class); | ||
22 | + service.removeNode(new NodeId(nodeId)); | ||
23 | + } | ||
24 | + | ||
25 | +} |
... | @@ -5,6 +5,12 @@ | ... | @@ -5,6 +5,12 @@ |
5 | <action class="org.onlab.onos.cli.NodesListCommand"/> | 5 | <action class="org.onlab.onos.cli.NodesListCommand"/> |
6 | </command> | 6 | </command> |
7 | <command> | 7 | <command> |
8 | + <action class="org.onlab.onos.cli.NodeAddCommand"/> | ||
9 | + </command> | ||
10 | + <command> | ||
11 | + <action class="org.onlab.onos.cli.NodeRemoveCommand"/> | ||
12 | + </command> | ||
13 | + <command> | ||
8 | <action class="org.onlab.onos.cli.MastersListCommand"/> | 14 | <action class="org.onlab.onos.cli.MastersListCommand"/> |
9 | <completers> | 15 | <completers> |
10 | <ref component-id="clusterIdCompleter"/> | 16 | <ref component-id="clusterIdCompleter"/> | ... | ... |
... | @@ -54,6 +54,15 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> | ... | @@ -54,6 +54,15 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> |
54 | } | 54 | } |
55 | 55 | ||
56 | /** | 56 | /** |
57 | + * Returns the number of message stream in custody of the loop. | ||
58 | + * | ||
59 | + * @return number of message streams | ||
60 | + */ | ||
61 | + public int streamCount() { | ||
62 | + return streams.size(); | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
57 | * Creates a new message stream backed by the specified socket channel. | 66 | * Creates a new message stream backed by the specified socket channel. |
58 | * | 67 | * |
59 | * @param byteChannel backing byte channel | 68 | * @param byteChannel backing byte channel |
... | @@ -182,9 +191,10 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> | ... | @@ -182,9 +191,10 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> |
182 | * with a pending accept operation. | 191 | * with a pending accept operation. |
183 | * | 192 | * |
184 | * @param channel backing socket channel | 193 | * @param channel backing socket channel |
194 | + * @return newly accepted message stream | ||
185 | */ | 195 | */ |
186 | - public void acceptStream(SocketChannel channel) { | 196 | + public S acceptStream(SocketChannel channel) { |
187 | - createAndAdmit(channel, SelectionKey.OP_READ); | 197 | + return createAndAdmit(channel, SelectionKey.OP_READ); |
188 | } | 198 | } |
189 | 199 | ||
190 | 200 | ||
... | @@ -193,9 +203,10 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> | ... | @@ -193,9 +203,10 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> |
193 | * with a pending connect operation. | 203 | * with a pending connect operation. |
194 | * | 204 | * |
195 | * @param channel backing socket channel | 205 | * @param channel backing socket channel |
206 | + * @return newly connected message stream | ||
196 | */ | 207 | */ |
197 | - public void connectStream(SocketChannel channel) { | 208 | + public S connectStream(SocketChannel channel) { |
198 | - createAndAdmit(channel, SelectionKey.OP_CONNECT); | 209 | + return createAndAdmit(channel, SelectionKey.OP_CONNECT); |
199 | } | 210 | } |
200 | 211 | ||
201 | /** | 212 | /** |
... | @@ -205,12 +216,14 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> | ... | @@ -205,12 +216,14 @@ public abstract class IOLoop<M extends Message, S extends MessageStream<M>> |
205 | * @param channel socket channel | 216 | * @param channel socket channel |
206 | * @param op pending operations mask to be applied to the selection | 217 | * @param op pending operations mask to be applied to the selection |
207 | * key as a set of initial interestedOps | 218 | * key as a set of initial interestedOps |
219 | + * @return newly created message stream | ||
208 | */ | 220 | */ |
209 | - private synchronized void createAndAdmit(SocketChannel channel, int op) { | 221 | + private synchronized S createAndAdmit(SocketChannel channel, int op) { |
210 | S stream = createStream(channel); | 222 | S stream = createStream(channel); |
211 | streams.add(stream); | 223 | streams.add(stream); |
212 | newStreamRequests.add(new NewStreamRequest(stream, channel, op)); | 224 | newStreamRequests.add(new NewStreamRequest(stream, channel, op)); |
213 | selector.wakeup(); | 225 | selector.wakeup(); |
226 | + return stream; | ||
214 | } | 227 | } |
215 | 228 | ||
216 | /** | 229 | /** | ... | ... |
-
Please register or login to post a comment