[ONOS-7054] Implement prototype of ISSU protocol
Change-Id: Id543c0de9c97b68f977c824cbc987b35d81beb2d
diff --git a/cli/src/main/java/org/onosproject/cli/IssuCommand.java b/cli/src/main/java/org/onosproject/cli/IssuCommand.java
new file mode 100644
index 0000000..1f0cb36
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/IssuCommand.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.upgrade.UpgradeAdminService;
+import org.onosproject.upgrade.UpgradeService;
+
+/**
+ * Commands for managing upgrades.
+ */
+@Command(scope = "onos", name = "issu",
+ description = "Manages upgrades")
+public class IssuCommand extends AbstractShellCommand {
+
+ static final String INIT = "init";
+ static final String UPGRADE = "upgrade";
+ static final String COMMIT = "commit";
+ static final String ROLLBACK = "rollback";
+ static final String RESET = "reset";
+ static final String STATUS = "status";
+ static final String VERSION = "version";
+
+ @Argument(index = 0, name = "command",
+ description = "Command name (init|upgrade|commit|rollback|status|version)",
+ required = false, multiValued = false)
+ String command = null;
+
+ @Override
+ protected void execute() {
+ UpgradeService upgradeService = get(UpgradeService.class);
+ UpgradeAdminService upgradeAdminService = get(UpgradeAdminService.class);
+ if (command == null) {
+ print("source=%s, target=%s, status=%s, upgraded=%b, active=%b",
+ upgradeService.getState().source(),
+ upgradeService.getState().target(),
+ upgradeService.getState().status(),
+ upgradeService.isLocalUpgraded(),
+ upgradeService.isLocalActive());
+ } else if (command.equals(INIT)) {
+ upgradeAdminService.initialize();
+ print("Initialized");
+ } else if (command.equals(UPGRADE)) {
+ upgradeAdminService.upgrade();
+ print("Upgraded");
+ } else if (command.equals(COMMIT)) {
+ upgradeAdminService.commit();
+ print("Committed version %s", upgradeService.getVersion());
+ } else if (command.equals(ROLLBACK)) {
+ upgradeAdminService.rollback();
+ print("Rolled back to version %s", upgradeService.getVersion());
+ } else if (command.equals(RESET)) {
+ upgradeAdminService.reset();
+ print("Reset version %s", upgradeService.getVersion());
+ } else if (command.equals(STATUS)) {
+ print("%s", upgradeService.getState().status());
+ } else if (command.equals(VERSION)) {
+ print("%s", upgradeService.getVersion());
+ } else {
+ print("Unsupported command: %s", command);
+ }
+ }
+
+}
diff --git a/cli/src/main/java/org/onosproject/cli/NodesListCommand.java b/cli/src/main/java/org/onosproject/cli/NodesListCommand.java
index bf53219..5a55c99 100644
--- a/cli/src/main/java/org/onosproject/cli/NodesListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/NodesListCommand.java
@@ -22,8 +22,8 @@
import org.apache.karaf.shell.commands.Command;
import org.joda.time.DateTime;
import org.onlab.util.Tools;
-import org.onosproject.cluster.ClusterAdminService;
import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.MembershipAdminService;
import org.onosproject.core.Version;
import org.onosproject.utils.Comparators;
@@ -44,7 +44,7 @@
@Override
protected void execute() {
- ClusterAdminService service = get(ClusterAdminService.class);
+ MembershipAdminService service = get(MembershipAdminService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, Comparators.NODE_COMPARATOR);
if (outputJson()) {
@@ -68,7 +68,7 @@
}
// Produces JSON structure.
- private JsonNode json(ClusterAdminService service, List<ControllerNode> nodes) {
+ private JsonNode json(MembershipAdminService service, List<ControllerNode> nodes) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
ControllerNode self = service.getLocalNode();
diff --git a/cli/src/main/java/org/onosproject/cli/net/PartitionsListCommand.java b/cli/src/main/java/org/onosproject/cli/net/PartitionsListCommand.java
index 0922d39..c9df46a 100644
--- a/cli/src/main/java/org/onosproject/cli/net/PartitionsListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/PartitionsListCommand.java
@@ -66,7 +66,7 @@
boolean first = true;
for (String member : Ordering.natural().sortedCopy(info.members())) {
if (first) {
- print(SERVER_FMT, info.name(), info.term(), member,
+ print(SERVER_FMT, info.id(), info.term(), member,
member.equals(info.leader()) ? "*" : "");
first = false;
} else {
@@ -130,7 +130,7 @@
info.members().forEach(members::add);
// Complete the partition attributes and add it to the array
- partition.put("name", info.name())
+ partition.put("name", info.id().toString())
.put("term", info.term())
.put("leader", info.leader());
partitions.add(partition);