blob: e2ff991d084a1cec02e9569fbff11ec33511cc6a [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
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.upgrade.UpgradeAdminService;
21import org.onosproject.upgrade.UpgradeService;
22
23/**
24 * Commands for managing upgrades.
25 */
26@Command(scope = "onos", name = "issu",
27 description = "Manages upgrades")
28public class IssuCommand extends AbstractShellCommand {
29
30 static final String INIT = "init";
31 static final String UPGRADE = "upgrade";
32 static final String COMMIT = "commit";
33 static final String ROLLBACK = "rollback";
34 static final String RESET = "reset";
35 static final String STATUS = "status";
36 static final String VERSION = "version";
37
38 @Argument(index = 0, name = "command",
Jon Hall83300ca2017-11-30 15:25:27 -080039 description = "Command name (init|upgrade|commit|rollback|reset|status|version)",
Jordan Halterman980a8c12017-09-22 18:01:19 -070040 required = false, multiValued = false)
41 String command = null;
42
43 @Override
44 protected void execute() {
45 UpgradeService upgradeService = get(UpgradeService.class);
46 UpgradeAdminService upgradeAdminService = get(UpgradeAdminService.class);
47 if (command == null) {
48 print("source=%s, target=%s, status=%s, upgraded=%b, active=%b",
49 upgradeService.getState().source(),
50 upgradeService.getState().target(),
51 upgradeService.getState().status(),
52 upgradeService.isLocalUpgraded(),
53 upgradeService.isLocalActive());
54 } else if (command.equals(INIT)) {
55 upgradeAdminService.initialize();
56 print("Initialized");
57 } else if (command.equals(UPGRADE)) {
58 upgradeAdminService.upgrade();
59 print("Upgraded");
60 } else if (command.equals(COMMIT)) {
61 upgradeAdminService.commit();
62 print("Committed version %s", upgradeService.getVersion());
63 } else if (command.equals(ROLLBACK)) {
64 upgradeAdminService.rollback();
65 print("Rolled back to version %s", upgradeService.getVersion());
66 } else if (command.equals(RESET)) {
67 upgradeAdminService.reset();
68 print("Reset version %s", upgradeService.getVersion());
69 } else if (command.equals(STATUS)) {
70 print("%s", upgradeService.getState().status());
71 } else if (command.equals(VERSION)) {
72 print("%s", upgradeService.getVersion());
73 } else {
74 print("Unsupported command: %s", command);
75 }
76 }
77
78}