Jian Li

[ONOS-3851] Add skeletal code of Web GUI for Control Plane Manager

Change-Id: I0df9c55daec0b6d9a630aa954808e6c310ba861c
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cpman.gui;
17 +
18 +import com.google.common.collect.ImmutableList;
19 +import org.apache.felix.scr.annotations.Activate;
20 +import org.apache.felix.scr.annotations.Component;
21 +import org.apache.felix.scr.annotations.Deactivate;
22 +import org.apache.felix.scr.annotations.Reference;
23 +import org.apache.felix.scr.annotations.ReferenceCardinality;
24 +import org.apache.felix.scr.annotations.Service;
25 +import org.onosproject.ui.UiExtension;
26 +import org.onosproject.ui.UiExtensionService;
27 +import org.onosproject.ui.UiMessageHandlerFactory;
28 +import org.onosproject.ui.UiView;
29 +import org.slf4j.Logger;
30 +import org.slf4j.LoggerFactory;
31 +
32 +import java.util.List;
33 +
34 +import static org.onosproject.ui.UiView.Category.NETWORK;
35 +
36 +/**
37 + * Mechanism to stream data to the GUI.
38 + */
39 +@Component(immediate = true, enabled = true)
40 +@Service(value = CpmanUI.class)
41 +public class CpmanUI {
42 + private static final String CPMAN_ID = "cpman";
43 + private static final String CPMAN_TEXT = "Control Plane Manager";
44 + private static final String RES_PATH = "gui";
45 + private static final ClassLoader CL = CpmanUI.class.getClassLoader();
46 +
47 + private final Logger log = LoggerFactory.getLogger(getClass());
48 +
49 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
50 + protected UiExtensionService uiExtensionService;
51 +
52 + // Factory for UI message handlers
53 + private final UiMessageHandlerFactory messageHandlerFactory =
54 + () -> ImmutableList.of(new CpmanViewMessageHandler());
55 +
56 + // List of application views
57 + private final List<UiView> views = ImmutableList.of(
58 + new UiView(NETWORK, CPMAN_ID, CPMAN_TEXT)
59 + );
60 +
61 + // Application UI extension
62 + private final UiExtension uiExtension =
63 + new UiExtension.Builder(CL, views)
64 + .messageHandlerFactory(messageHandlerFactory)
65 + .resourcePath(RES_PATH)
66 + .build();
67 +
68 + @Activate
69 + protected void activate() {
70 + uiExtensionService.register(uiExtension);
71 + log.info("Started");
72 + }
73 +
74 + @Deactivate
75 + protected void deactivate() {
76 + uiExtensionService.unregister(uiExtension);
77 + log.info("Stopped");
78 + }
79 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cpman.gui;
17 +
18 +import com.fasterxml.jackson.databind.node.ObjectNode;
19 +import com.google.common.collect.ImmutableSet;
20 +import org.onosproject.ui.RequestHandler;
21 +import org.onosproject.ui.UiMessageHandler;
22 +
23 +import java.util.Collection;
24 +import java.util.Random;
25 +
26 +/**
27 + * CpmanViewMessageHandler class implementation.
28 + */
29 +public class CpmanViewMessageHandler extends UiMessageHandler {
30 +
31 + private static final String CPMAN_DATA_REQ = "cpmanDataRequest";
32 + private static final String CPMAN_DATA_RESP = "cpmanDataResponse";
33 +
34 + private static final String RANDOM = "random";
35 +
36 + @Override
37 + protected Collection<RequestHandler> createRequestHandlers() {
38 + return ImmutableSet.of(
39 + new CpmanDataRequestHandler()
40 + );
41 + }
42 +
43 + // handler for sample data requests
44 + private final class CpmanDataRequestHandler extends RequestHandler {
45 +
46 + private CpmanDataRequestHandler() {
47 + super(CPMAN_DATA_REQ);
48 + }
49 +
50 + @Override
51 + public void process(long sid, ObjectNode payload) {
52 + ObjectNode result = objectNode();
53 + Random random = new Random();
54 + result.put(RANDOM, random.nextInt(50) + 1);
55 +
56 + sendMessage(CPMAN_DATA_RESP, 0, result);
57 + }
58 + }
59 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/**
18 + * Web GUI for the control plane manager.
19 + */
20 +package org.onosproject.cpman.gui;
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Control Plane Manager -- CSS file
19 + */
20 +
21 +#ov-cpman {
22 + padding: 20px;
23 +}
24 +.light #ov-cpman {
25 + color: navy;
26 +}
27 +.dark #ov-cpman {
28 + color: #88f;
29 +}
30 +
31 +#ov-cpman .button-panel {
32 + margin: 10px;
33 + width: 200px;
34 +}
35 +
36 +.light #ov-cpman .button-panel {
37 + background-color: #ccf;
38 +}
39 +.dark #ov-cpman .button-panel {
40 + background-color: #444;
41 +}
42 +
43 +#ov-cpman .my-button {
44 + cursor: pointer;
45 + padding: 4px;
46 + text-align: center;
47 +}
48 +
49 +.light #ov-cpman .my-button {
50 + color: white;
51 + background-color: #99d;
52 +}
53 +.dark #ov-cpman .my-button {
54 + color: black;
55 + background-color: #aaa;
56 +}
57 +
58 +#ov-cpman .number {
59 + font-size: 140%;
60 + text-align: right;
61 +}
...\ No newline at end of file ...\ No newline at end of file
1 +<!-- partial HTML -->
2 +<div id="ov-cpman">
3 + <div class="button-panel">
4 + <div class="my-button" ng-click="getData()">
5 + Fetch Data
6 + </div>
7 + </div>
8 +
9 + <div class="data-panel">
10 + <table>
11 + <tr>
12 + <td> Number </td>
13 + <td class="number"> {{data.random}} </td>
14 + </tr>
15 + </table>
16 + </div>
17 +</div>
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Control Plane Manager View Module
19 + */
20 +(function () {
21 + 'use strict';
22 +
23 + // injected refs
24 + var $log, $scope, wss, ks;
25 +
26 + // constants
27 + var dataReq = 'cpmanDataRequest',
28 + dataResp = 'cpmanDataResponse';
29 +
30 + function addKeyBindings() {
31 + var map = {
32 + space: [getData, 'Fetch data from server'],
33 +
34 + _helpFormat: [
35 + ['space']
36 + ]
37 + };
38 +
39 + ks.keyBindings(map);
40 + }
41 +
42 + function getData() {
43 + wss.sendEvent(dataReq);
44 + }
45 +
46 + function respDataCb(data) {
47 + $scope.data = data;
48 + $scope.$apply();
49 + }
50 +
51 +
52 + angular.module('ovCpman', [])
53 + .controller('OvCpmanCtrl',
54 + ['$log', '$scope', 'WebSocketService', 'KeyService',
55 +
56 + function (_$log_, _$scope_, _wss_, _ks_) {
57 + $log = _$log_;
58 + $scope = _$scope_;
59 + wss = _wss_;
60 + ks = _ks_;
61 +
62 + var handlers = {};
63 + $scope.data = {};
64 +
65 + // data response handler
66 + handlers[dataResp] = respDataCb;
67 + wss.bindHandlers(handlers);
68 +
69 + addKeyBindings();
70 +
71 + // custom click handler
72 + $scope.getData = getData;
73 +
74 + // get data the first time...
75 + getData();
76 +
77 + // cleanup
78 + $scope.$on('$destroy', function () {
79 + wss.unbindHandlers(handlers);
80 + ks.unbindKeys();
81 + $log.log('OvCpmanCtrl has been destroyed');
82 + });
83 +
84 + $log.log('OvCpmanCtrl has been created');
85 + }]);
86 +
87 +}());
1 +<link rel="stylesheet" href="app/view/cpman/cpman.css">
...\ No newline at end of file ...\ No newline at end of file
1 +<script src="app/view/cpman/cpman.js"></script>
...\ No newline at end of file ...\ No newline at end of file