blob: 04e3ad924e9c81743bc646cde3e702a3e62e4778 [file] [log] [blame]
Jordan Halterman980a8c12017-09-22 18:01:19 -07001/*
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 */
16package org.onosproject.cli;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.lifecycle.Service;
Jordan Halterman980a8c12017-09-22 18:01:19 -070021import org.onosproject.upgrade.UpgradeAdminService;
22import org.onosproject.upgrade.UpgradeService;
23
24/**
25 * Commands for managing upgrades.
26 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070027@Service
Jordan Halterman980a8c12017-09-22 18:01:19 -070028@Command(scope = "onos", name = "issu",
29 description = "Manages upgrades")
30public 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 Hall83300ca2017-11-30 15:25:27 -080041 description = "Command name (init|upgrade|commit|rollback|reset|status|version)",
Jordan Halterman980a8c12017-09-22 18:01:19 -070042 required = false, multiValued = false)
43 String command = null;
44
45 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070046 protected void doExecute() {
Jordan Halterman980a8c12017-09-22 18:01:19 -070047 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}