Error message fix on fileManager.job api
[osm/UI.git] / skyquake / plugins / launchpad / src / launchpadFleetSource.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
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;
23
24 if (DEV_MODE) {
25 HOST = window.location.protocol + '//' + window.location.hostname;
26 }
27
28 var isSocketOff = true;
29 var FleetActions = require('./launchpadFleetActions.js');
30 var Utils = require('utils/utils.js');
31 import $ from 'jquery';
32
33
34 module.exports = function(Alt) {
35 //NEW SOURCE
36 return {
37 nsrControl: {
38 remote: function(state, method, url, value) {
39 return new Promise(function(resolve, reject) {
40 // $.ajax({});
41 // console.log(method + 'ing: "' + value + '" to "' + url + '"');
42 resolve(method + 'ing: "' + value + '" to "' + url + '"')
43 });
44 },
45 success: FleetActions.nsrControlSuccess,
46 error: FleetActions.nsrControlError
47 },
48 getNsrInstances: {
49 remote: function() {
50 return new Promise(function(resolve, reject) {
51 $.ajax({
52 url: 'api/nsr?api_server=' + API_SERVER,
53 type: 'GET',
54 beforeSend: Utils.addAuthorizationStub,
55 success: function(data) {
56 resolve(data);
57 }
58 });
59 });
60 },
61 success: FleetActions.getNsrInstancesSuccess,
62 error: FleetActions.getNsrInstancesError
63 },
64 getVDUConsoleLink: {
65 remote: function(state, url) {
66 return new Promise(function(resolve, reject) {
67 $.ajax({
68 url: url + '?api_server=' + API_SERVER,
69 type: 'GET',
70 beforeSend: Utils.addAuthorizationStub,
71 success: function(data) {
72 resolve(data);
73 },
74 error: function(error) {
75 console.log('There was an error getting the VDU link', error);
76 return reject(error);
77 }
78 });
79 });
80 },
81 success: FleetActions.getVDUConsoleLinkSuccess,
82 error: FleetActions.getVDUConsoleLinkError
83 },
84 deleteNsrInstance: {
85 remote: function(d, id) {
86 console.log(id)
87 return new Promise(function(resolve, reject) {
88 $.ajax({
89 url: 'api/nsr/' + id + '?api_server=' + API_SERVER,
90 type: 'DELETE',
91 beforeSend: Utils.addAuthorizationStub,
92 success: function(data) {
93 resolve(data);
94 }
95 });
96 });
97 },
98 success: FleetActions.deleteNsrInstanceSuccess,
99 error: FleetActions.deleteNsrInstancesError
100 } ,
101 openNSRSocket: {
102 remote: function(state) {
103 return new Promise(function(resolve, reject) {
104 //If socket connection already exists, eat the request.
105 if(state.socket) {
106 return resolve(false);
107 }
108 $.ajax({
109 url: '/socket-polling?api_server=' + API_SERVER ,
110 type: 'POST',
111 beforeSend: Utils.addAuthorizationStub,
112 data: {
113 url: 'launchpad/api/nsr?api_server=' + API_SERVER
114 },
115 success: function(data, textStatus, jqXHR) {
116 Utils.checkAndResolveSocketRequest(data, resolve, reject);
117 }
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);
121 });;
122 });
123 },
124 loading: Alt.actions.global.openNSRSocketLoading,
125 success: FleetActions.openNSRSocketSuccess,
126 error: FleetActions.openNSRError
127 },
128 setNSRStatus: {
129 remote: function(state, id, status) {
130 return new Promise(function(resolve, reject) {
131 $.ajax({
132 url: 'api/nsr/' + id + '/admin-status?api_server=' + API_SERVER ,
133 type:'PUT',
134 beforeSend: Utils.addAuthorizationStub,
135 data: {
136 status: status
137 },
138 success: function(data, textStatus, jqXHR) {
139
140 }
141 });
142 });
143 },
144 success: FleetActions.setNSRStatusSuccess,
145 error: FleetActions.setNSRStatusError
146 }
147 }
148 };
149
150 Object.size = function(obj) {
151 var size = 0,
152 key;
153 for (key in obj) {
154 if (obj.hasOwnProperty(key)) size++;
155 }
156 return size;
157 };