Yuta HIGUCHI | 60731cb | 2014-11-11 01:34:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cli; |
Yuta HIGUCHI | 60731cb | 2014-11-11 01:34:46 -0800 | [diff] [blame] | 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.cluster.ControllerNode; |
| 21 | import org.onosproject.cluster.DefaultControllerNode; |
| 22 | import org.onosproject.cluster.NodeId; |
| 23 | import org.onosproject.store.service.DatabaseAdminService; |
Yuta HIGUCHI | 60731cb | 2014-11-11 01:34:46 -0800 | [diff] [blame] | 24 | import org.onlab.packet.IpAddress; |
| 25 | |
| 26 | /** |
| 27 | * Adds a new controller cluster node. |
| 28 | */ |
| 29 | @Command(scope = "onos", name = "tablet-add", |
| 30 | description = "Adds a new member to tablet") |
| 31 | public class TabletAddCommand extends AbstractShellCommand { |
| 32 | |
| 33 | @Argument(index = 0, name = "nodeId", description = "Node ID", |
| 34 | required = true, multiValued = false) |
| 35 | String nodeId = null; |
| 36 | |
| 37 | // TODO context aware completer to get IP from ClusterService? |
| 38 | @Argument(index = 1, name = "ip", description = "Node IP address", |
| 39 | required = true, multiValued = false) |
| 40 | String ip = null; |
| 41 | |
| 42 | @Argument(index = 2, name = "tcpPort", description = "Node TCP listen port", |
| 43 | required = false, multiValued = false) |
| 44 | int tcpPort = 9876; |
| 45 | |
| 46 | // TODO add tablet name argument when we support multiple tablets |
| 47 | |
| 48 | @Override |
| 49 | protected void execute() { |
| 50 | DatabaseAdminService service = get(DatabaseAdminService.class); |
| 51 | ControllerNode node = new DefaultControllerNode(new NodeId(nodeId), |
| 52 | IpAddress.valueOf(ip), |
| 53 | tcpPort); |
| 54 | service.addMember(node); |
| 55 | } |
| 56 | } |