GUI -- Base Cluster View implemented. Bug fixed of table bodies not being wide enough.
Change-Id: Iebf43c87c91404eb443ae1a098b56575ca9959fe
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java
new file mode 100644
index 0000000..b1d4c98f
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/ClusterViewMessageHandler.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.ui.impl;
+
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.onosproject.cluster.ClusterService;
+import org.onosproject.cluster.ControllerNode;
+import org.onosproject.cluster.NodeId;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+
+/**
+ * Message handler for cluster view related messages.
+ */
+public class ClusterViewMessageHandler extends AbstractTabularViewMessageHandler {
+
+ /**
+ * Creates a new message handler for the cluster messages.
+ */
+ protected ClusterViewMessageHandler() {
+ super(ImmutableSet.of("clusterDataRequest"));
+ }
+
+ @Override
+ public void process(ObjectNode message) {
+ ObjectNode payload = payload(message);
+ String sortCol = string(payload, "sortCol", "id");
+ String sortDir = string(payload, "sortDir", "asc");
+
+ ClusterService service = get(ClusterService.class);
+ TableRow[] rows = generateTableRows(service);
+ RowComparator rc =
+ new RowComparator(sortCol, RowComparator.direction(sortDir));
+ Arrays.sort(rows, rc);
+ ArrayNode clusterNodes = generateArrayNode(rows);
+ ObjectNode rootNode = mapper.createObjectNode();
+ rootNode.set("clusters", clusterNodes);
+
+ connection().sendMessage("clusterDataResponse", 0, rootNode);
+ }
+
+ private TableRow[] generateTableRows(ClusterService service) {
+ List<TableRow> list = new ArrayList<>();
+ for (ControllerNode node : service.getNodes()) {
+ list.add(new ControllerNodeTableRow(service, node));
+ }
+ return list.toArray(new TableRow[list.size()]);
+ }
+
+ /**
+ * TableRow implementation for {@link ControllerNode controller nodes}.
+ */
+ private static class ControllerNodeTableRow extends AbstractTableRow {
+
+ private static final String ID = "id";
+ private static final String IP = "ip";
+ private static final String TCP_PORT = "tcp";
+ private static final String STATE = "state";
+ private static final String UPDATED = "updated";
+
+ private static final String[] COL_IDS = {
+ ID, IP, TCP_PORT, STATE, UPDATED
+ };
+
+ public ControllerNodeTableRow(ClusterService service, ControllerNode n) {
+ NodeId id = n.id();
+ DateTime lastUpdated = service.getLastUpdated(id);
+ org.joda.time.format.DateTimeFormatter format = DateTimeFormat.longTime();
+
+ add(ID, id.toString());
+ add(IP, n.ip().toString());
+ add(TCP_PORT, Integer.toString(n.tcpPort()));
+ add(STATE, service.getState(id).toString());
+ add(UPDATED, format.print(lastUpdated));
+ }
+
+ @Override
+ protected String[] columnIds() {
+ return COL_IDS;
+ }
+ }
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
index 469287e..080f5e3 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/UiExtensionManager.java
@@ -61,6 +61,7 @@
new UiView("host", "Hosts"),
new UiView("app", "Applications"),
new UiView("intent", "Intents"),
+ new UiView("cluster", "Cluster Nodes"),
new UiView("sample", "Sample"));
UiMessageHandlerFactory messageHandlerFactory =
() -> ImmutableList.of(
@@ -68,7 +69,8 @@
new DeviceViewMessageHandler(),
new HostViewMessageHandler(),
new ApplicationViewMessageHandler(),
- new IntentViewMessageHandler()
+ new IntentViewMessageHandler(),
+ new ClusterViewMessageHandler()
);
return new UiExtension(coreViews, messageHandlerFactory, "core",
UiExtensionManager.class.getClassLoader());