3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 let API_SERVER
= require('utils/rw.js').getSearchParams(window
.location
).api_server
;
20 let HOST
= API_SERVER
;
21 let NODE_PORT
= require('utils/rw.js').getSearchParams(window
.location
).api_port
|| 8000;
22 let DEV_MODE
= require('utils/rw.js').getSearchParams(window
.location
).dev_mode
|| false;
25 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
28 var isSocketOff
= true;
29 var FleetActions
= require('./launchpadFleetActions.js');
30 var Utils
= require('utils/utils.js');
31 import $ from 'jquery';
34 module
.exports = function(Alt
) {
38 remote: function(state
, method
, url
, value
) {
39 return new Promise(function(resolve
, reject
) {
41 // console.log(method + 'ing: "' + value + '" to "' + url + '"');
42 resolve(method
+ 'ing: "' + value
+ '" to "' + url
+ '"')
45 success
: FleetActions
.nsrControlSuccess
,
46 error
: FleetActions
.nsrControlError
50 return new Promise(function(resolve
, reject
) {
52 url
: 'api/nsr?api_server=' + API_SERVER
,
54 beforeSend
: Utils
.addAuthorizationStub
,
55 success: function(data
) {
61 success
: FleetActions
.getNsrInstancesSuccess
,
62 error
: FleetActions
.getNsrInstancesError
65 remote: function(state
, url
) {
66 return new Promise(function(resolve
, reject
) {
68 url
: url
+ '?api_server=' + API_SERVER
,
70 beforeSend
: Utils
.addAuthorizationStub
,
71 success: function(data
) {
74 error: function(error
) {
75 console
.log('There was an error getting the VDU link', error
);
81 success
: FleetActions
.getVDUConsoleLinkSuccess
,
82 error
: FleetActions
.getVDUConsoleLinkError
85 remote: function(d
, id
) {
87 return new Promise(function(resolve
, reject
) {
89 url
: 'api/nsr/' + id
+ '?api_server=' + API_SERVER
,
91 beforeSend
: Utils
.addAuthorizationStub
,
92 success: function(data
) {
98 success
: FleetActions
.deleteNsrInstanceSuccess
,
99 error
: FleetActions
.deleteNsrInstancesError
102 remote: function(state
) {
103 return new Promise(function(resolve
, reject
) {
104 //If socket connection already exists, eat the request.
106 return resolve(false);
109 url
: '/socket-polling',
111 beforeSend
: Utils
.addAuthorizationStub
,
113 url
: 'launchpad/api/nsr?api_server=' + API_SERVER
115 success: function(data
, textStatus
, jqXHR
) {
116 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
118 }).fail(function(xhr
){
119 //Authentication and the handling of fail states should be wrapped up into a connection class.
120 Utils
.checkAuthentication(xhr
.status
);
124 loading
: Alt
.actions
.global
.openNSRSocketLoading
,
125 success
: FleetActions
.openNSRSocketSuccess
,
126 error
: FleetActions
.openNSRError
129 remote: function(state
, id
, status
) {
130 return new Promise(function(resolve
, reject
) {
132 url
: 'api/nsr/' + id
+ '/admin-status?api_server=' + API_SERVER
,
134 beforeSend
: Utils
.addAuthorizationStub
,
138 success: function(data
, textStatus
, jqXHR
) {
144 success
: FleetActions
.setNSRStatusSuccess
,
145 error
: FleetActions
.setNSRStatusError
150 Object
.size = function(obj
) {
154 if (obj
.hasOwnProperty(key
)) size
++;