Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | package org.onosproject.cli; |
| 17 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 21 | import org.onosproject.upgrade.UpgradeAdminService; |
| 22 | import org.onosproject.upgrade.UpgradeService; |
| 23 | |
| 24 | /** |
| 25 | * Commands for managing upgrades. |
| 26 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 27 | @Service |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 28 | @Command(scope = "onos", name = "issu", |
| 29 | description = "Manages upgrades") |
| 30 | public class IssuCommand extends AbstractShellCommand { |
| 31 | |
| 32 | static final String INIT = "init"; |
| 33 | static final String UPGRADE = "upgrade"; |
| 34 | static final String COMMIT = "commit"; |
| 35 | static final String ROLLBACK = "rollback"; |
| 36 | static final String RESET = "reset"; |
| 37 | static final String STATUS = "status"; |
| 38 | static final String VERSION = "version"; |
| 39 | |
| 40 | @Argument(index = 0, name = "command", |
Jon Hall | 83300ca | 2017-11-30 15:25:27 -0800 | [diff] [blame] | 41 | description = "Command name (init|upgrade|commit|rollback|reset|status|version)", |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 42 | required = false, multiValued = false) |
| 43 | String command = null; |
| 44 | |
| 45 | @Override |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 46 | protected void doExecute() { |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 47 | UpgradeService upgradeService = get(UpgradeService.class); |
| 48 | UpgradeAdminService upgradeAdminService = get(UpgradeAdminService.class); |
| 49 | if (command == null) { |
| 50 | print("source=%s, target=%s, status=%s, upgraded=%b, active=%b", |
| 51 | upgradeService.getState().source(), |
| 52 | upgradeService.getState().target(), |
| 53 | upgradeService.getState().status(), |
| 54 | upgradeService.isLocalUpgraded(), |
| 55 | upgradeService.isLocalActive()); |
| 56 | } else if (command.equals(INIT)) { |
| 57 | upgradeAdminService.initialize(); |
| 58 | print("Initialized"); |
| 59 | } else if (command.equals(UPGRADE)) { |
| 60 | upgradeAdminService.upgrade(); |
| 61 | print("Upgraded"); |
| 62 | } else if (command.equals(COMMIT)) { |
| 63 | upgradeAdminService.commit(); |
| 64 | print("Committed version %s", upgradeService.getVersion()); |
| 65 | } else if (command.equals(ROLLBACK)) { |
| 66 | upgradeAdminService.rollback(); |
| 67 | print("Rolled back to version %s", upgradeService.getVersion()); |
| 68 | } else if (command.equals(RESET)) { |
| 69 | upgradeAdminService.reset(); |
| 70 | print("Reset version %s", upgradeService.getVersion()); |
| 71 | } else if (command.equals(STATUS)) { |
| 72 | print("%s", upgradeService.getState().status()); |
| 73 | } else if (command.equals(VERSION)) { |
| 74 | print("%s", upgradeService.getVersion()); |
| 75 | } else { |
| 76 | print("Unsupported command: %s", command); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | } |