GUI -- Base Cluster View implemented. Bug fixed of table bodies not being wide enough.

Change-Id: Iebf43c87c91404eb443ae1a098b56575ca9959fe
diff --git a/web/gui/pom.xml b/web/gui/pom.xml
index cd31dd4..283a961 100644
--- a/web/gui/pom.xml
+++ b/web/gui/pom.xml
@@ -90,7 +90,8 @@
                             org.onlab.osgi.*,
                             org.onlab.packet.*,
                             org.onlab.rest.*,
-                            org.onosproject.*
+                            org.onosproject.*,
+                            org.joda.time.*
                         </Import-Package>
                         <Web-ContextPath>${web.context}</Web-ContextPath>
                     </instructions>
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());
diff --git a/web/gui/src/main/resources/core/css.html b/web/gui/src/main/resources/core/css.html
index f29b3e1..ff2e904 100644
--- a/web/gui/src/main/resources/core/css.html
+++ b/web/gui/src/main/resources/core/css.html
@@ -4,3 +4,4 @@
 <link rel="stylesheet" href="app/view/host/host.css">
 <link rel="stylesheet" href="app/view/app/app.css">
 <link rel="stylesheet" href="app/view/intent/intent.css">
+<link rel="stylesheet" href="app/view/cluster/cluster.css">
diff --git a/web/gui/src/main/resources/core/js.html b/web/gui/src/main/resources/core/js.html
index 68df55b..8d6d87d 100644
--- a/web/gui/src/main/resources/core/js.html
+++ b/web/gui/src/main/resources/core/js.html
@@ -15,4 +15,5 @@
 <script src="app/view/host/host.js"></script>
 <script src="app/view/app/app.js"></script>
 <script src="app/view/intent/intent.js"></script>
+<script src="app/view/cluster/cluster.js"></script>
 <script src="app/view/sample/sample.js"></script>
diff --git a/web/gui/src/main/webapp/app/fw/widget/table.js b/web/gui/src/main/webapp/app/fw/widget/table.js
index eb05bdf..81edaa0 100644
--- a/web/gui/src/main/webapp/app/fw/widget/table.js
+++ b/web/gui/src/main/webapp/app/fw/widget/table.js
@@ -83,7 +83,8 @@
 
         tHeaders.each(function (d, i) {
             var thElement = d3.select(this),
-                tdElement = t.select('td:nth-of-type(' + (i + 1) + ')'),
+                tr = t.select('tr:nth-of-type(2)'),
+                tdElement = tr.select('td:nth-of-type(' + (i + 1) + ')'),
                 custWidth = thElement.attr(colWidth);
 
             if (custWidth) {
@@ -105,9 +106,10 @@
             tableHeight = fs.windowSize(mast.mastHeight() + totalHeight).height;
 
         thead.style('display', 'block');
-        tbody.style({'display': 'block',
-            'height': (tableHeight + 'px'),
-            'overflow': 'auto'
+        tbody.style({
+            display: 'block',
+            height: tableHeight + 'px',
+            overflow: 'auto'
         });
     }
 
diff --git a/web/gui/src/main/webapp/app/view/cluster/cluster.css b/web/gui/src/main/webapp/app/view/cluster/cluster.css
new file mode 100644
index 0000000..5025062
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/cluster/cluster.css
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/*
+ ONOS GUI -- Cluster View -- CSS file
+ */
+
+#ov-cluster td {
+}
\ No newline at end of file
diff --git a/web/gui/src/main/webapp/app/view/cluster/cluster.html b/web/gui/src/main/webapp/app/view/cluster/cluster.html
new file mode 100644
index 0000000..b6c015b
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/cluster/cluster.html
@@ -0,0 +1,52 @@
+<!--
+  ~ 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.
+  -->
+
+<!-- Cluster partial HTML -->
+<div id="ov-cluster">
+    <h2>Cluster Nodes ({{ctrl.tableData.length}} total)</h2>
+    <table class="summary-list"
+           onos-fixed-header
+           onos-sortable-header
+           sort-callback="sortCallback(requestParams)">
+        <thead>
+        <tr>
+            <th colId="id" sortable>ID </th>
+            <th colId="ip" sortable>IP Address </th>
+            <th colId="tcp" sortable>TCP Port </th>
+            <th colId="state" sortable>State </th>
+            <th colId="updated" sortable>Last Updated </th>
+        </tr>
+        </thead>
+
+        <tbody>
+        <tr ng-hide="ctrl.tableData.length">
+            <td class="nodata" colspan="5">
+                No Cluster Nodes found
+            </td>
+        </tr>
+
+        <tr ng-repeat="node in ctrl.tableData"
+            ng-repeat-done>
+            <td>{{node.id}}</td>
+            <td>{{node.ip}}</td>
+            <td>{{node.tcp}}</td>
+            <td>{{node.state}}</td>
+            <td>{{node.updated}}</td>
+        </tr>
+        </tbody>
+    </table>
+
+</div>
diff --git a/web/gui/src/main/webapp/app/view/cluster/cluster.js b/web/gui/src/main/webapp/app/view/cluster/cluster.js
new file mode 100644
index 0000000..0f4a4f8
--- /dev/null
+++ b/web/gui/src/main/webapp/app/view/cluster/cluster.js
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+/*
+ ONOS GUI -- Cluster View Module
+ */
+
+(function () {
+    'use strict';
+
+    angular.module('ovCluster', [])
+        .controller('OvClusterCtrl',
+        ['$log', '$scope', 'TableBuilderService',
+
+            function ($log, $scope, tbs) {
+                tbs.buildTable({
+                    self: this,
+                    scope: $scope,
+                    tag: 'cluster'
+                });
+
+                $log.log('OvClusterCtrl has been created');
+            }]);
+}());
diff --git a/web/gui/src/main/webapp/app/view/intent/intent.css b/web/gui/src/main/webapp/app/view/intent/intent.css
index 47ea2aa..4aac0bb 100644
--- a/web/gui/src/main/webapp/app/view/intent/intent.css
+++ b/web/gui/src/main/webapp/app/view/intent/intent.css
@@ -18,24 +18,24 @@
  ONOS GUI -- Intent View -- CSS file
  */
 
-.light #ov-intent tr:nth-child(6n + 1),
 .light #ov-intent tr:nth-child(6n + 2),
-.light #ov-intent tr:nth-child(6n + 3) {
+.light #ov-intent tr:nth-child(6n + 3),
+.light #ov-intent tr:nth-child(6n + 4) {
     background-color: #eee;
 }
-.light #ov-intent tr:nth-child(6n + 4),
 .light #ov-intent tr:nth-child(6n + 5),
-.light #ov-intent tr:nth-child(6n) {
+.light #ov-intent tr:nth-child(6n + 6),
+.light #ov-intent tr:nth-child(6n + 1) {
     background-color: #ddd;
 }
-.dark #ov-intent tr:nth-child(6n + 1),
 .dark #ov-intent tr:nth-child(6n + 2),
-.dark #ov-intent tr:nth-child(6n + 3) {
+.dark #ov-intent tr:nth-child(6n + 3),
+.dark #ov-intent tr:nth-child(6n + 4) {
     background-color: #444;
 }
-.dark #ov-intent tr:nth-child(6n + 4),
 .dark #ov-intent tr:nth-child(6n + 5),
-.dark #ov-intent tr:nth-child(6n) {
+.dark #ov-intent tr:nth-child(6n + 6),
+.dark #ov-intent tr:nth-child(6n + 1) {
     background-color: #333;
 }
 
diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html
index 3a335a7..5d78257 100644
--- a/web/gui/src/main/webapp/index.html
+++ b/web/gui/src/main/webapp/index.html
@@ -113,6 +113,7 @@
     <script src="app/view/host/host.js"></script>
     <script src="app/view/app/app.js"></script>
     <script src="app/view/intent/intent.js"></script>
+    <script src="app/view/cluster/cluster.js"></script>
     <script src="app/view/sample/sample.js"></script>
     <!-- {INJECTED-JAVASCRIPT-END} -->
 
@@ -124,6 +125,7 @@
     <link rel="stylesheet" href="app/view/host/host.css">
     <link rel="stylesheet" href="app/view/app/app.css">
     <link rel="stylesheet" href="app/view/intent/intent.css">
+    <link rel="stylesheet" href="app/view/cluster/cluster.css">
     <link rel="stylesheet" href="app/view/sample/sample.css">
     <!-- {INJECTED-STYLESHEETS-END} -->
 
diff --git a/web/gui/src/main/webapp/onos.js b/web/gui/src/main/webapp/onos.js
index ad73fc8..3777f4b 100644
--- a/web/gui/src/main/webapp/onos.js
+++ b/web/gui/src/main/webapp/onos.js
@@ -41,6 +41,7 @@
         'host',
         'app',
         'intent',
+        'cluster',
         'sample',
         // {INJECTED-VIEW-IDS-END}