mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-22 04:40:59 +02:00
[ONOS-3851] Add skeletal code of Web GUI for Control Plane Manager
Change-Id: I0df9c55daec0b6d9a630aa954808e6c310ba861c
This commit is contained in:
parent
54df73eee8
commit
10a2070bc8
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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.cpman.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 = CpmanUI.class)
|
||||||
|
public class CpmanUI {
|
||||||
|
private static final String CPMAN_ID = "cpman";
|
||||||
|
private static final String CPMAN_TEXT = "Control Plane Manager";
|
||||||
|
private static final String RES_PATH = "gui";
|
||||||
|
private static final ClassLoader CL = CpmanUI.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 CpmanViewMessageHandler());
|
||||||
|
|
||||||
|
// List of application views
|
||||||
|
private final List<UiView> views = ImmutableList.of(
|
||||||
|
new UiView(NETWORK, CPMAN_ID, CPMAN_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");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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.cpman.gui;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import org.onosproject.ui.RequestHandler;
|
||||||
|
import org.onosproject.ui.UiMessageHandler;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CpmanViewMessageHandler class implementation.
|
||||||
|
*/
|
||||||
|
public class CpmanViewMessageHandler extends UiMessageHandler {
|
||||||
|
|
||||||
|
private static final String CPMAN_DATA_REQ = "cpmanDataRequest";
|
||||||
|
private static final String CPMAN_DATA_RESP = "cpmanDataResponse";
|
||||||
|
|
||||||
|
private static final String RANDOM = "random";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<RequestHandler> createRequestHandlers() {
|
||||||
|
return ImmutableSet.of(
|
||||||
|
new CpmanDataRequestHandler()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// handler for sample data requests
|
||||||
|
private final class CpmanDataRequestHandler extends RequestHandler {
|
||||||
|
|
||||||
|
private CpmanDataRequestHandler() {
|
||||||
|
super(CPMAN_DATA_REQ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(long sid, ObjectNode payload) {
|
||||||
|
ObjectNode result = objectNode();
|
||||||
|
Random random = new Random();
|
||||||
|
result.put(RANDOM, random.nextInt(50) + 1);
|
||||||
|
|
||||||
|
sendMessage(CPMAN_DATA_RESP, 0, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web GUI for the control plane manager.
|
||||||
|
*/
|
||||||
|
package org.onosproject.cpman.gui;
|
61
apps/cpman/app/src/main/resources/app/view/cpman/cpman.css
Normal file
61
apps/cpman/app/src/main/resources/app/view/cpman/cpman.css
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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 -- Control Plane Manager -- CSS file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ov-cpman {
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.light #ov-cpman {
|
||||||
|
color: navy;
|
||||||
|
}
|
||||||
|
.dark #ov-cpman {
|
||||||
|
color: #88f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ov-cpman .button-panel {
|
||||||
|
margin: 10px;
|
||||||
|
width: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.light #ov-cpman .button-panel {
|
||||||
|
background-color: #ccf;
|
||||||
|
}
|
||||||
|
.dark #ov-cpman .button-panel {
|
||||||
|
background-color: #444;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ov-cpman .my-button {
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 4px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.light #ov-cpman .my-button {
|
||||||
|
color: white;
|
||||||
|
background-color: #99d;
|
||||||
|
}
|
||||||
|
.dark #ov-cpman .my-button {
|
||||||
|
color: black;
|
||||||
|
background-color: #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ov-cpman .number {
|
||||||
|
font-size: 140%;
|
||||||
|
text-align: right;
|
||||||
|
}
|
17
apps/cpman/app/src/main/resources/app/view/cpman/cpman.html
Normal file
17
apps/cpman/app/src/main/resources/app/view/cpman/cpman.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!-- partial HTML -->
|
||||||
|
<div id="ov-cpman">
|
||||||
|
<div class="button-panel">
|
||||||
|
<div class="my-button" ng-click="getData()">
|
||||||
|
Fetch Data
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="data-panel">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td> Number </td>
|
||||||
|
<td class="number"> {{data.random}} </td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
87
apps/cpman/app/src/main/resources/app/view/cpman/cpman.js
Normal file
87
apps/cpman/app/src/main/resources/app/view/cpman/cpman.js
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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 -- Control Plane Manager View Module
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// injected refs
|
||||||
|
var $log, $scope, wss, ks;
|
||||||
|
|
||||||
|
// constants
|
||||||
|
var dataReq = 'cpmanDataRequest',
|
||||||
|
dataResp = 'cpmanDataResponse';
|
||||||
|
|
||||||
|
function addKeyBindings() {
|
||||||
|
var map = {
|
||||||
|
space: [getData, 'Fetch data from server'],
|
||||||
|
|
||||||
|
_helpFormat: [
|
||||||
|
['space']
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
ks.keyBindings(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getData() {
|
||||||
|
wss.sendEvent(dataReq);
|
||||||
|
}
|
||||||
|
|
||||||
|
function respDataCb(data) {
|
||||||
|
$scope.data = data;
|
||||||
|
$scope.$apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
angular.module('ovCpman', [])
|
||||||
|
.controller('OvCpmanCtrl',
|
||||||
|
['$log', '$scope', 'WebSocketService', 'KeyService',
|
||||||
|
|
||||||
|
function (_$log_, _$scope_, _wss_, _ks_) {
|
||||||
|
$log = _$log_;
|
||||||
|
$scope = _$scope_;
|
||||||
|
wss = _wss_;
|
||||||
|
ks = _ks_;
|
||||||
|
|
||||||
|
var handlers = {};
|
||||||
|
$scope.data = {};
|
||||||
|
|
||||||
|
// data response handler
|
||||||
|
handlers[dataResp] = respDataCb;
|
||||||
|
wss.bindHandlers(handlers);
|
||||||
|
|
||||||
|
addKeyBindings();
|
||||||
|
|
||||||
|
// custom click handler
|
||||||
|
$scope.getData = getData;
|
||||||
|
|
||||||
|
// get data the first time...
|
||||||
|
getData();
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
$scope.$on('$destroy', function () {
|
||||||
|
wss.unbindHandlers(handlers);
|
||||||
|
ks.unbindKeys();
|
||||||
|
$log.log('OvCpmanCtrl has been destroyed');
|
||||||
|
});
|
||||||
|
|
||||||
|
$log.log('OvCpmanCtrl has been created');
|
||||||
|
}]);
|
||||||
|
|
||||||
|
}());
|
1
apps/cpman/app/src/main/resources/gui/css.html
Normal file
1
apps/cpman/app/src/main/resources/gui/css.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<link rel="stylesheet" href="app/view/cpman/cpman.css">
|
1
apps/cpman/app/src/main/resources/gui/js.html
Normal file
1
apps/cpman/app/src/main/resources/gui/js.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<script src="app/view/cpman/cpman.js"></script>
|
Loading…
x
Reference in New Issue
Block a user