Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 8e57fd5 | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 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 | */ |
| 16 | |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 17 | package org.opencord.cordvtn.cli; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 18 | |
| 19 | import org.apache.karaf.shell.commands.Argument; |
| 20 | import org.apache.karaf.shell.commands.Command; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
alshabib | b4d3171 | 2016-06-01 18:51:03 -0700 | [diff] [blame] | 22 | import org.opencord.cordvtn.impl.CordVtnNodeManager; |
Hyunsun Moon | fd5a24e | 2016-10-19 19:15:48 -0700 | [diff] [blame^] | 23 | import org.opencord.cordvtn.api.node.CordVtnNode; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 24 | |
| 25 | import java.util.NoSuchElementException; |
| 26 | |
| 27 | /** |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 28 | * Initializes nodes for CordVtn service. |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 29 | */ |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 30 | @Command(scope = "onos", name = "cordvtn-node-init", |
| 31 | description = "Initializes nodes for CORD VTN service") |
| 32 | public class CordVtnNodeInitCommand extends AbstractShellCommand { |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 33 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 34 | @Argument(index = 0, name = "hostnames", description = "Hostname(s)", |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 35 | required = true, multiValued = true) |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 36 | private String[] hostnames = null; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 37 | |
| 38 | @Override |
| 39 | protected void execute() { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 40 | CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 41 | |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 42 | for (String hostname : hostnames) { |
| 43 | CordVtnNode node; |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 44 | try { |
Hyunsun Moon | cb79944 | 2016-01-15 20:03:18 -0800 | [diff] [blame] | 45 | node = nodeManager.getNodes() |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 46 | .stream() |
| 47 | .filter(n -> n.hostname().equals(hostname)) |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 48 | .findFirst().get(); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 49 | } catch (NoSuchElementException e) { |
Hyunsun Moon | 4edb017 | 2015-11-07 22:08:43 -0800 | [diff] [blame] | 50 | print("Unable to find %s", hostname); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 51 | continue; |
| 52 | } |
| 53 | |
Hyunsun Moon | ff55e81 | 2016-03-10 12:40:16 -0800 | [diff] [blame] | 54 | nodeManager.addOrUpdateNode(node); |
Hyunsun Moon | 838b19b | 2015-10-18 18:23:15 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |