[ONOS-6375] Add skeleton code for Web GUI of mapping management app
Change-Id: I95079e6ac422591e6d5afed59b97d2a248573770
diff --git a/apps/mappingmanagement/web/BUCK b/apps/mappingmanagement/web/BUCK
index 6794372..e45f88c 100644
--- a/apps/mappingmanagement/web/BUCK
+++ b/apps/mappingmanagement/web/BUCK
@@ -17,5 +17,5 @@
api_title = 'Mapping Management App API',
api_version = '1.0',
api_description = 'REST API for ONOS Mapping Management App',
- api_package = 'org.onosproject.mapping.web',
+ api_package = 'org.onosproject.mapping.web.api',
)
diff --git a/apps/mappingmanagement/web/pom.xml b/apps/mappingmanagement/web/pom.xml
index bd5cc38..65af845 100644
--- a/apps/mappingmanagement/web/pom.xml
+++ b/apps/mappingmanagement/web/pom.xml
@@ -35,7 +35,7 @@
<api.description>
APIs for interacting with the LISP Mapping Management application.
</api.description>
- <api.package>org.onosproject.mapping.web</api.package>
+ <api.package>org.onosproject.mapping.web.api</api.package>
</properties>
<dependencies>
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebApplication.java
similarity index 95%
rename from apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
rename to apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebApplication.java
index ec1c61a..8caa2b6 100644
--- a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebApplication.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.mapping.web;
+package org.onosproject.mapping.web.api;
import org.onlab.rest.AbstractWebApplication;
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebResource.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebResource.java
similarity index 98%
rename from apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebResource.java
rename to apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebResource.java
index 5c38390..6a9acd1 100644
--- a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebResource.java
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/MappingsWebResource.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.mapping.web;
+package org.onosproject.mapping.web.api;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/package-info.java
similarity index 64%
copy from apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
copy to apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/package-info.java
index ec1c61a..f2ee575 100644
--- a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/api/package-info.java
@@ -13,18 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.mapping.web;
-
-import org.onlab.rest.AbstractWebApplication;
-
-import java.util.Set;
-
/**
- * Mapping management REST APIs web application.
+ * REST APIs for the mapping management app.
*/
-public class MappingsWebApplication extends AbstractWebApplication {
- @Override
- public Set<Class<?>> getClasses() {
- return getClasses(MappingsWebResource.class);
- }
-}
+package org.onosproject.mapping.web.api;
\ No newline at end of file
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsUI.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsUI.java
new file mode 100644
index 0000000..300133c
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsUI.java
@@ -0,0 +1,79 @@
+/*
+ * 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.mapping.web.gui;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static org.onosproject.ui.UiView.Category.NETWORK;
+
+/**
+ * Mechanism to stream data to the GUI.
+ */
+@Component(immediate = true, enabled = true)
+@Service(value = MappingsUI.class)
+public class MappingsUI {
+ private static final String MAPPING_ID = "mapping";
+ private static final String MAPPING_TEXT = "Mapping Management";
+ private static final String RES_PATH = "gui";
+ private static final ClassLoader CL = MappingsUI.class.getClassLoader();
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected UiExtensionService uiExtensionService;
+
+ // Factory for UI message handlers
+ private final UiMessageHandlerFactory messageHandlerFactory =
+ () -> ImmutableList.of(new MappingsViewMessageHandler());
+
+ // List of application views
+ private final List<UiView> views = ImmutableList.of(
+ new UiView(NETWORK, MAPPING_ID, MAPPING_TEXT)
+ );
+
+ // Application UI extension
+ private final UiExtension uiExtension =
+ new UiExtension.Builder(CL, views)
+ .messageHandlerFactory(messageHandlerFactory)
+ .resourcePath(RES_PATH)
+ .build();
+
+ @Activate
+ protected void activate() {
+ uiExtensionService.register(uiExtension);
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ uiExtensionService.unregister(uiExtension);
+ log.info("Stopped");
+ }
+}
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsViewMessageHandler.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsViewMessageHandler.java
new file mode 100644
index 0000000..67b570e
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/MappingsViewMessageHandler.java
@@ -0,0 +1,85 @@
+/*
+ * 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.mapping.web.gui;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.mapping.MappingEntry;
+import org.onosproject.mapping.MappingService;
+import org.onosproject.net.DeviceId;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.table.TableModel;
+import org.onosproject.ui.table.TableRequestHandler;
+
+import java.util.Collection;
+
+import static org.onosproject.mapping.MappingStore.Type.MAP_DATABASE;
+
+/**
+ * Message handler for mapping management view related messages.
+ */
+public class MappingsViewMessageHandler extends UiMessageHandler {
+
+ private static final String MAPPING_DATA_REQ = "mappingDataRequest";
+ private static final String MAPPING_DATA_RESP = "mappingDataResponse";
+ private static final String MAPPINGS = "mappings";
+
+ private static final String ID = "id";
+
+ private static final String[] COL_IDS = {ID};
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(new MappingMessageRequest());
+ }
+
+ private final class MappingMessageRequest extends TableRequestHandler {
+
+ private static final String NO_ROWS_MESSAGE = "No mappings found";
+
+ private MappingMessageRequest() {
+ super(MAPPING_DATA_REQ, MAPPING_DATA_RESP, MAPPINGS);
+ }
+
+ @Override
+ protected String[] getColumnIds() {
+ return COL_IDS;
+ }
+
+ @Override
+ protected String noRowsMessage(ObjectNode payload) {
+ return NO_ROWS_MESSAGE;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ String uri = string(payload, "devId");
+ if (!Strings.isNullOrEmpty(uri)) {
+ DeviceId deviceId = DeviceId.deviceId(uri);
+ MappingService ms = get(MappingService.class);
+ for (MappingEntry mapping : ms.getMappingEntries(MAP_DATABASE, deviceId)) {
+ populateRow(tm.addRow(), mapping);
+ }
+ }
+ }
+
+ private void populateRow(TableModel.Row row, MappingEntry mapping) {
+ row.cell(ID, mapping.id().value());
+ }
+ }
+}
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/package-info.java
similarity index 64%
copy from apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
copy to apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/package-info.java
index ec1c61a..39122e6 100644
--- a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
+++ b/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/gui/package-info.java
@@ -13,18 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.mapping.web;
-
-import org.onlab.rest.AbstractWebApplication;
-
-import java.util.Set;
-
/**
- * Mapping management REST APIs web application.
+ * Web GUI for the mapping management app.
*/
-public class MappingsWebApplication extends AbstractWebApplication {
- @Override
- public Set<Class<?>> getClasses() {
- return getClasses(MappingsWebResource.class);
- }
-}
+package org.onosproject.mapping.web.gui;
\ No newline at end of file
diff --git a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.css
similarity index 61%
copy from apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
copy to apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.css
index ec1c61a..7b5018b 100644
--- a/apps/mappingmanagement/web/src/main/java/org/onosproject/mapping/web/MappingsWebApplication.java
+++ b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.css
@@ -13,18 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.onosproject.mapping.web;
-import org.onlab.rest.AbstractWebApplication;
-
-import java.util.Set;
-
-/**
- * Mapping management REST APIs web application.
+/*
+ ONOS GUI -- Mapping Management -- CSS file
*/
-public class MappingsWebApplication extends AbstractWebApplication {
- @Override
- public Set<Class<?>> getClasses() {
- return getClasses(MappingsWebResource.class);
- }
+
+#ov-mapping {
+ padding: 20px;
+ position: relative;
+}
+.light #ov-mapping {
+ color: navy;
+}
+.dark #ov-mapping {
+ color: #88f;
+}
+
+#ov-mapping .button-panel {
+ margin: 10px;
+ width: 200px;
+}
+
+.light #ov-mapping .button-panel {
+ background-color: #ccf;
+}
+.dark #ov-mapping .button-panel {
+ background-color: #444;
}
diff --git a/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.html b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.html
new file mode 100644
index 0000000..1b82ca5
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.html
@@ -0,0 +1,3 @@
+<!-- partial HTML -->
+<div id="ov-mapping">
+</div>
diff --git a/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.js b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.js
new file mode 100644
index 0000000..00262f9
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/resources/app/view/mapping/mapping.js
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+/*
+ ONOS GUI -- Mapping Management View Module
+ */
+(function () {
+ 'use strict';
+
+ // injected references
+ var $log, $scope, $location;
+
+ angular.module('ovMapping', [])
+ .controller('OvMappingCtrl',
+ ['$log', '$scope', '$location',
+
+ function (_$log_, _$scope_, _$location_) {
+ var params;
+ $log = _$log_;
+ $scope = _$scope_;
+ $location = _$location_;
+
+ $log.log('OvMappingCtrl has been created');
+ }]);
+}());
diff --git a/apps/mappingmanagement/web/src/main/resources/gui/css.html b/apps/mappingmanagement/web/src/main/resources/gui/css.html
new file mode 100644
index 0000000..7b22ae3
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/resources/gui/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/mapping/mapping.css">
\ No newline at end of file
diff --git a/apps/mappingmanagement/web/src/main/resources/gui/js.html b/apps/mappingmanagement/web/src/main/resources/gui/js.html
new file mode 100644
index 0000000..23df18f
--- /dev/null
+++ b/apps/mappingmanagement/web/src/main/resources/gui/js.html
@@ -0,0 +1 @@
+<script src="app/view/mapping/mapping.js"></script>
\ No newline at end of file
diff --git a/apps/mappingmanagement/web/src/main/webapp/WEB-INF/web.xml b/apps/mappingmanagement/web/src/main/webapp/WEB-INF/web.xml
index 6b3a65c..aa79ec7 100644
--- a/apps/mappingmanagement/web/src/main/webapp/WEB-INF/web.xml
+++ b/apps/mappingmanagement/web/src/main/webapp/WEB-INF/web.xml
@@ -44,7 +44,7 @@
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
- <param-value>org.onosproject.mapping.web.MappingsWebApplication</param-value>
+ <param-value>org.onosproject.mapping.web.api.MappingsWebApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
diff --git a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/MappingsWebResourceTest.java b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/MappingsWebResourceTest.java
index 79290d3..f149906 100644
--- a/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/MappingsWebResourceTest.java
+++ b/apps/mappingmanagement/web/src/test/java/org/onosproject/mapping/web/MappingsWebResourceTest.java
@@ -54,6 +54,7 @@
import org.onosproject.mapping.codec.MappingTreatmentCodec;
import org.onosproject.mapping.codec.MappingValueCodec;
import org.onosproject.mapping.instructions.MappingInstruction;
+import org.onosproject.mapping.web.api.MappingsWebApplication;
import org.onosproject.net.DefaultDevice;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;