Simon Hunt
Committed by Gerrit Code Review

GUI -- Created skeleton for WebSocketService.

- re-worked UrlFnService.

Change-Id: Ia1184dfd5639a7e1ef2dad54580057e74b1d9fd2
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
22 22
23 var $log; 23 var $log;
24 24
25 - var urlSuffix = '/onos/ui/rs/';
26 -
27 -
28 25
29 // TODO: remove temporary test code 26 // TODO: remove temporary test code
30 var fakeData = { 27 var fakeData = {
...@@ -119,7 +116,7 @@ ...@@ -119,7 +116,7 @@
119 callback(getFakeData(url)); 116 callback(getFakeData(url));
120 return; 117 return;
121 } 118 }
122 - var fullUrl = ufs.urlPrefix() + urlSuffix + url; 119 + var fullUrl = ufs.rsUrl(url);
123 120
124 $http.get(fullUrl).then(function (response) { 121 $http.get(fullUrl).then(function (response) {
125 // success 122 // success
......
...@@ -20,15 +20,43 @@ ...@@ -20,15 +20,43 @@
20 (function () { 20 (function () {
21 'use strict'; 21 'use strict';
22 22
23 + var uiContext = '/onos/ui/',
24 + rsSuffix = uiContext + 'rs/',
25 + wsSuffix = uiContext + 'ws/';
26 +
23 angular.module('onosRemote') 27 angular.module('onosRemote')
24 .factory('UrlFnService', ['$location', function ($loc) { 28 .factory('UrlFnService', ['$location', function ($loc) {
25 29
26 - function urlPrefix() { 30 + function matchSecure(protocol) {
27 - return $loc.protocol() + '://' + $loc.host() + ':' + $loc.port(); 31 + var p = $loc.protocol(),
32 + secure = (p === 'https' || p === 'wss');
33 + return secure ? protocol + 's' : protocol;
34 + }
35 +
36 + function urlBase(protocol) {
37 + return matchSecure(protocol) + '://' +
38 + $loc.host() + ':' + $loc.port();
39 + }
40 +
41 + function httpPrefix(suffix) {
42 + return urlBase('http') + suffix;
43 + }
44 +
45 + function wsPrefix(suffix) {
46 + return urlBase('ws') + suffix;
47 + }
48 +
49 + function rsUrl(path) {
50 + return httpPrefix(rsSuffix) + path;
51 + }
52 +
53 + function wsUrl(path) {
54 + return wsPrefix(wsSuffix) + path;
28 } 55 }
29 56
30 return { 57 return {
31 - urlPrefix: urlPrefix 58 + rsUrl: rsUrl,
59 + wsUrl: wsUrl
32 }; 60 };
33 }]); 61 }]);
34 62
......
1 +/*
2 + * Copyright 2015 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 -- Remote -- Web Socket Service
19 + */
20 +(function () {
21 + 'use strict';
22 +
23 + angular.module('onosRemote')
24 + .factory('WebSocketService', ['$location', 'UrlFnService',
25 + function ($loc, ufs) {
26 +
27 + // creates a web socket for the given path, returning a "handle"
28 + function createWebSocket(path) {
29 + return {
30 + path: ufs.wsUrl(path)
31 + // TODO: complete implementation...
32 + };
33 + }
34 +
35 + return {
36 + createWebSocket: createWebSocket
37 + };
38 + }]);
39 +
40 +}());
1 +/*
2 + * Copyright 2015 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 -- Remote -- Web Socket Event Service
19 + */
20 +(function () {
21 + 'use strict';
22 +
23 + angular.module('onosRemote')
24 + .factory('WsEventService', ['$location', function ($loc) {
25 +
26 + return {
27 + tbd: function () {}
28 + };
29 + }]);
30 +
31 +}());
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
52 <script src="fw/remote/remote.js"></script> 52 <script src="fw/remote/remote.js"></script>
53 <script src="fw/remote/urlfn.js"></script> 53 <script src="fw/remote/urlfn.js"></script>
54 <script src="fw/remote/rest.js"></script> 54 <script src="fw/remote/rest.js"></script>
55 + <script src="fw/remote/websocket.js"></script>
56 + <script src="fw/remote/wsevent.js"></script>
55 57
56 <!-- Framework and library stylesheets included here --> 58 <!-- Framework and library stylesheets included here -->
57 <!-- TODO: use a single catenated-minified file here --> 59 <!-- TODO: use a single catenated-minified file here -->
......
...@@ -23,11 +23,12 @@ ...@@ -23,11 +23,12 @@
23 23
24 var moduleDependencies = [ 24 var moduleDependencies = [
25 'onosUtil', 25 'onosUtil',
26 - 'onosSvg' 26 + 'onosSvg',
27 + 'onosRemote'
27 ]; 28 ];
28 29
29 // references to injected services etc. 30 // references to injected services etc.
30 - var $log, ks, zs, gs, ms; 31 + var $log, ks, zs, gs, ms, wss;
31 32
32 // DOM elements 33 // DOM elements
33 var ovtopo, svg, defs, zoomLayer, map; 34 var ovtopo, svg, defs, zoomLayer, map;
...@@ -128,6 +129,15 @@ ...@@ -128,6 +129,15 @@
128 //showCallibrationPoints(); 129 //showCallibrationPoints();
129 } 130 }
130 131
132 + // --- Web Socket Connection -----------------------------------------
133 +
134 + function setUpWebSocket() {
135 + var wsHandle = wss.createWebSocket('topology');
136 + $log.log('created web socket', wsHandle);
137 + // TODO: complete implementation
138 +
139 + }
140 +
131 // --- Controller Definition ----------------------------------------- 141 // --- Controller Definition -----------------------------------------
132 142
133 angular.module('ovTopo', moduleDependencies) 143 angular.module('ovTopo', moduleDependencies)
...@@ -135,14 +145,16 @@ ...@@ -135,14 +145,16 @@
135 .controller('OvTopoCtrl', [ 145 .controller('OvTopoCtrl', [
136 '$log', 146 '$log',
137 'KeyService', 'ZoomService', 'GlyphService', 'MapService', 147 'KeyService', 'ZoomService', 'GlyphService', 'MapService',
148 + 'WebSocketService',
138 149
139 - function (_$log_, _ks_, _zs_, _gs_, _ms_) { 150 + function (_$log_, _ks_, _zs_, _gs_, _ms_, _wss_) {
140 var self = this; 151 var self = this;
141 $log = _$log_; 152 $log = _$log_;
142 ks = _ks_; 153 ks = _ks_;
143 zs = _zs_; 154 zs = _zs_;
144 gs = _gs_; 155 gs = _gs_;
145 ms = _ms_; 156 ms = _ms_;
157 + wss = _wss_;
146 158
147 self.notifyResize = function () { 159 self.notifyResize = function () {
148 svgResized(svg.style('width'), svg.style('height')); 160 svgResized(svg.style('width'), svg.style('height'));
...@@ -156,6 +168,7 @@ ...@@ -156,6 +168,7 @@
156 setUpDefs(); 168 setUpDefs();
157 setUpZoom(); 169 setUpZoom();
158 setUpMap(); 170 setUpMap();
171 + setUpWebSocket();
159 172
160 $log.log('OvTopoCtrl has been created'); 173 $log.log('OvTopoCtrl has been created');
161 }]); 174 }]);
......
...@@ -20,14 +20,16 @@ ...@@ -20,14 +20,16 @@
20 describe('factory: fw/remote/urlfn.js', function () { 20 describe('factory: fw/remote/urlfn.js', function () {
21 var $log, $loc, ufs, fs; 21 var $log, $loc, ufs, fs;
22 22
23 + var protocol, host, port;
24 +
23 beforeEach(module('onosRemote')); 25 beforeEach(module('onosRemote'));
24 26
25 beforeEach(module(function($provide) { 27 beforeEach(module(function($provide) {
26 $provide.factory('$location', function (){ 28 $provide.factory('$location', function (){
27 return { 29 return {
28 - protocol: function () { return 'http'; }, 30 + protocol: function () { return protocol; },
29 - host: function () { return 'foo'; }, 31 + host: function () { return host; },
30 - port: function () { return '80'; } 32 + port: function () { return port; }
31 }; 33 };
32 }) 34 })
33 })); 35 }));
...@@ -39,17 +41,39 @@ describe('factory: fw/remote/urlfn.js', function () { ...@@ -39,17 +41,39 @@ describe('factory: fw/remote/urlfn.js', function () {
39 fs = FnService; 41 fs = FnService;
40 })); 42 }));
41 43
44 + function setLoc(prot, h, p) {
45 + protocol = prot;
46 + host = h;
47 + port = p;
48 + }
49 +
42 it('should define UrlFnService', function () { 50 it('should define UrlFnService', function () {
43 expect(ufs).toBeDefined(); 51 expect(ufs).toBeDefined();
44 }); 52 });
45 53
46 it('should define api functions', function () { 54 it('should define api functions', function () {
47 expect(fs.areFunctions(ufs, [ 55 expect(fs.areFunctions(ufs, [
48 - 'urlPrefix' 56 + 'rsUrl', 'wsUrl'
49 ])).toBeTruthy(); 57 ])).toBeTruthy();
50 }); 58 });
51 59
52 - it('should build the url prefix', function () { 60 + it('should return the correct (http) RS url', function () {
53 - expect(ufs.urlPrefix()).toEqual('http://foo:80'); 61 + setLoc('http', 'foo', '123');
62 + expect(ufs.rsUrl('path')).toEqual('http://foo:123/onos/ui/rs/path');
63 + });
64 +
65 + it('should return the correct (https) RS url', function () {
66 + setLoc('https', 'foo', '123');
67 + expect(ufs.rsUrl('path')).toEqual('https://foo:123/onos/ui/rs/path');
68 + });
69 +
70 + it('should return the correct (ws) WS url', function () {
71 + setLoc('http', 'foo', '123');
72 + expect(ufs.wsUrl('path')).toEqual('ws://foo:123/onos/ui/ws/path');
73 + });
74 +
75 + it('should return the correct (wss) WS url', function () {
76 + setLoc('https', 'foo', '123');
77 + expect(ufs.wsUrl('path')).toEqual('wss://foo:123/onos/ui/ws/path');
54 }); 78 });
55 }); 79 });
......