From c5a99dc2da307c04e7735a375f79214c8580bfb2 Mon Sep 17 00:00:00 2001 From: chengfan Date: Sun, 8 Jan 2017 19:28:29 +0800 Subject: [PATCH] [ONOS-4136] Implement Partitions View. show partition info in table format Change-Id: I5df276ab092715249f97ff118d0012da09789f49 --- .../ui/impl/PartitionViewMessageHandler.java | 122 ++++++++++++++++++ .../ui/impl/UiExtensionManager.java | 4 +- .../webapp/app/view/partition/partition.css | 38 ++++++ .../webapp/app/view/partition/partition.html | 44 +++++++ .../webapp/app/view/partition/partition.js | 36 ++++++ web/gui/src/main/webapp/index.html | 2 + 6 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 web/gui/src/main/java/org/onosproject/ui/impl/PartitionViewMessageHandler.java create mode 100644 web/gui/src/main/webapp/app/view/partition/partition.css create mode 100644 web/gui/src/main/webapp/app/view/partition/partition.html create mode 100644 web/gui/src/main/webapp/app/view/partition/partition.js diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/PartitionViewMessageHandler.java b/web/gui/src/main/java/org/onosproject/ui/impl/PartitionViewMessageHandler.java new file mode 100644 index 0000000000..7633c2a4b7 --- /dev/null +++ b/web/gui/src/main/java/org/onosproject/ui/impl/PartitionViewMessageHandler.java @@ -0,0 +1,122 @@ +/* + * Copyright 2017-present 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.ObjectNode; +import com.google.common.collect.ImmutableSet; +import org.onosproject.store.primitives.PartitionAdminService; +import org.onosproject.store.service.PartitionInfo; +import org.onosproject.ui.RequestHandler; +import org.onosproject.ui.UiMessageHandler; +import org.onosproject.ui.table.CellFormatter; +import org.onosproject.ui.table.TableModel; +import org.onosproject.ui.table.TableRequestHandler; + +import java.util.Collection; +import java.util.List; + +/** + * Message handler for partition view related messages. + */ +public class PartitionViewMessageHandler extends UiMessageHandler { + private static final String PARTITION_DATA_REQ = "partitionDataRequest"; + private static final String PARTITION_DATA_RESP = "partitionDataResponse"; + private static final String PARTITIONS = "partitions"; + + private static final String NAME = "name"; + private static final String TERM = "term"; + private static final String LEADER = "leader"; + private static final String MEMBERS = "members"; + + private static final String[] COL_IDS = {NAME, TERM, LEADER, MEMBERS}; + + @Override + protected Collection createRequestHandlers() { + return ImmutableSet.of(new PartitionDataHandler()); + } + + private final class PartitionDataHandler extends TableRequestHandler { + private static final String NO_ROWS_MESSAGE = "No partitions found"; + + private PartitionDataHandler() { + super(PARTITION_DATA_REQ, PARTITION_DATA_RESP, PARTITIONS); + } + + @Override + protected String[] getColumnIds() { + return COL_IDS; + } + + @Override + protected String noRowsMessage(ObjectNode payload) { + return NO_ROWS_MESSAGE; + } + + @Override + protected String defaultColumnId() { + return NAME; + } + + @Override + protected TableModel createTableModel() { + TableModel tm = super.createTableModel(); + tm.setFormatter(MEMBERS, new MembersFormatter()); + return tm; + } + + @Override + protected void populateTable(TableModel tm, ObjectNode payload) { + PartitionAdminService ps = get(PartitionAdminService.class); + for (PartitionInfo partition : ps.partitionInfo()) { + populateRow(tm.addRow(), partition); + } + } + + private void populateRow(TableModel.Row row, PartitionInfo p) { + row.cell(NAME, p.name()) + .cell(TERM, p.term()) + .cell(LEADER, p.leader()) + .cell(MEMBERS, p.members()); + } + + private final class MembersFormatter implements CellFormatter { + private static final String COMMA = ", "; + + @Override + public String format(Object value) { + List members = (List) value; + if (members.isEmpty()) { + return "(No members for this partition)"; + } + StringBuilder sb = new StringBuilder(); + for (String m : members) { + sb.append(m).append(COMMA); + } + removeTrailingComma(sb); + + return sb.toString(); + } + + private StringBuilder removeTrailingComma(StringBuilder sb) { + int pos = sb.lastIndexOf(COMMA); + sb.delete(pos, sb.length()); + return sb; + } + } + } +} 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 17188cb560..0d511a34b4 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 @@ -130,6 +130,7 @@ public class UiExtensionManager new UiView(PLATFORM, "settings", "Settings", "nav_settings"), new UiView(PLATFORM, "cluster", "Cluster Nodes", "nav_cluster"), new UiView(PLATFORM, "processor", "Packet Processors", "nav_processors"), + new UiView(PLATFORM, "partition", "Partitions", "nav_partitions"), new UiView(NETWORK, "topo", "Topology", "nav_topo"), // FIXME: leave commented out for now, while still under development @@ -166,7 +167,8 @@ public class UiExtensionManager new SettingsViewMessageHandler(), new ClusterViewMessageHandler(), new ProcessorViewMessageHandler(), - new TunnelViewMessageHandler() + new TunnelViewMessageHandler(), + new PartitionViewMessageHandler() ); UiTopoOverlayFactory topoOverlayFactory = diff --git a/web/gui/src/main/webapp/app/view/partition/partition.css b/web/gui/src/main/webapp/app/view/partition/partition.css new file mode 100644 index 0000000000..1ff0447d0a --- /dev/null +++ b/web/gui/src/main/webapp/app/view/partition/partition.css @@ -0,0 +1,38 @@ +/* + * Copyright 2015-present 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 -- Partition View (layout) -- CSS file + */ + +#ov-partition h2 { + display: inline-block; +} + +#ov-partition div.ctrl-btns { +} + +#ov-partition td { + text-align: center; +} +#ov-partition td.right { + text-align: right; +} +#ov-partition td.bands { + text-align: left; + padding-left: 36px; + opacity: 0.65; +} diff --git a/web/gui/src/main/webapp/app/view/partition/partition.html b/web/gui/src/main/webapp/app/view/partition/partition.html new file mode 100644 index 0000000000..06494ed9dc --- /dev/null +++ b/web/gui/src/main/webapp/app/view/partition/partition.html @@ -0,0 +1,44 @@ + +
+
+

Partitions ({{tableData.length}} total)

+
+
+
+
+ +
+
+ + + + + + + +
Name Term Leader Members
+
+ +
+ + + + + + + + + + + +
+ {{annots.no_rows_msg}} +
{{partition.name}}{{partition.term}}{{partition.leader}}{{partition.members}}
+
+
+
diff --git a/web/gui/src/main/webapp/app/view/partition/partition.js b/web/gui/src/main/webapp/app/view/partition/partition.js new file mode 100644 index 0000000000..11c9a85700 --- /dev/null +++ b/web/gui/src/main/webapp/app/view/partition/partition.js @@ -0,0 +1,36 @@ +/* + * Copyright 2015-present 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 -- Partition View Module + */ + +(function () { + 'use strict'; + + angular.module('ovPartition', []) + .controller('OvPartitionCtrl', + ['$log', '$scope', '$sce', 'FnService', 'TableBuilderService', + + function ($log, $scope, $sce, fs, tbs) { + tbs.buildTable({ + scope: $scope, + tag: 'partition' + }); + + $log.log('OvPartitionCtrl has been created'); + }]); +}()); diff --git a/web/gui/src/main/webapp/index.html b/web/gui/src/main/webapp/index.html index 79542fa9b7..a3b47ca516 100644 --- a/web/gui/src/main/webapp/index.html +++ b/web/gui/src/main/webapp/index.html @@ -197,6 +197,7 @@ + @@ -223,6 +224,7 @@ +