Bug 209
[osm/UI.git] / skyquake / plugins / launchpad / src / recordViewer / recordViewSource.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 import RecordViewActions from './recordViewActions.js';
19 let Utils = require('utils/utils.js');
20 import $ from 'jquery';
21 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
22 let HOST = API_SERVER;
23 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
24 let DEV_MODE = require('utils/rw.js').getSearchParams(window.location).dev_mode || false;
25
26 if (DEV_MODE) {
27 HOST = window.location.protocol + '//' + window.location.hostname;
28 }
29
30 export default {
31 getNSR() {
32 return {
33 remote: function(state, recordID) {
34 return new Promise(function(resolve, reject) {
35 $.ajax({
36 url: 'api/nsr/' + recordID + '?api_server=' + API_SERVER,
37 type: 'GET',
38 beforeSend: Utils.addAuthorizationStub,
39 success: function(data) {
40 resolve(data);
41 }
42 }).fail(function(xhr) {
43 //Authentication and the handling of fail states should be wrapped up into a connection class.
44 Utils.checkAuthentication(xhr.status);
45 });;
46 });
47 },
48 loading: RecordViewActions.getNSRLoading,
49 success: RecordViewActions.getNSRSuccess,
50 error: RecordViewActions.getNSRError
51 };
52 },
53 getRawVNFR() {
54 return {
55 remote: function(state, vnfrID) {
56 return new Promise(function(resolve, reject) {
57 $.ajax({
58 url: 'passthrough/data/api/operational/vnfr-catalog/vnfr/' + vnfrID + '?api_server=' + API_SERVER,
59 type: 'GET',
60 beforeSend: Utils.addAuthorizationStub,
61 success: function(data) {
62 resolve(data);
63 }
64 });
65 })
66 },
67 loading: RecordViewActions.getRawLoading,
68 success: RecordViewActions.getRawSuccess,
69 error: RecordViewActions.getRawError
70 }
71 },
72 getRawNSR() {
73 return {
74 remote: function(state, nsrID) {
75 return new Promise(function(resolve, reject) {
76 $.ajax({
77 url: 'passthrough/data/api/operational/ns-instance-opdata/nsr/' + nsrID + '?api_server=' + API_SERVER,
78 type: 'GET',
79 beforeSend: Utils.addAuthorizationStub,
80 success: function(data) {
81 resolve(data);
82 }
83 });
84 })
85 },
86 loading: RecordViewActions.getRawLoading,
87 success: RecordViewActions.getRawSuccess,
88 error: RecordViewActions.getRawError
89 }
90 },
91 getNSRSocket() {
92 return {
93 remote(state, recordID) {
94 return new Promise(function(resolve, reject) {
95 console.log('Getting NSR Socket');
96 $.ajax({
97 url: '/socket-polling?api_server=' + API_SERVER,
98 type: 'POST',
99 beforeSend: Utils.addAuthorizationStub,
100 data: {
101 url: '/launchpad/api/nsr/' + recordID + '?api_server=' + API_SERVER,
102 },
103 success: function(data) {
104 Utils.checkAndResolveSocketRequest(data, resolve, reject);
105 }
106 });
107 })
108 },
109 loading: RecordViewActions.getNSRSocketLoading,
110 success: RecordViewActions.getNSRSocketSuccess,
111 error: RecordViewActions.getNSRSocketError
112 }
113 },
114 getConfigJobSocket() {
115 return {
116 remote(state, recordID) {
117 return new Promise(function(resolve, reject) {
118 console.log('Getting Job Socket');
119 $.ajax({
120 url: '/socket-polling?api_server=' + API_SERVER,
121 type: 'POST',
122 beforeSend: Utils.addAuthorizationStub,
123 data: {
124 url: '/launchpad/api/nsr/' + recordID + '?api_server=' + API_SERVER,
125 },
126 success: function(data) {
127 Utils.checkAndResolveSocketRequest(data, resolve, reject);
128 }
129 });
130 })
131 },
132 success: RecordViewActions.getConfigSocketJobSuccess,
133 error: RecordViewActions.getConfigSocketJobError
134 }
135 },
136 getVNFRSocket() {
137 return {
138 remote(state) {
139 return new Promise(function(resolve, reject) {
140 console.log('Getting VNFR Socket for: ' + state.recordID);
141 $.ajax({
142 url: '/socket-polling?api_server=' + API_SERVER,
143 type: 'POST',
144 beforeSend: Utils.addAuthorizationStub,
145 data: {
146 url: '/launchpad/api/vnfr/' + state.recordID + '?api_server=' + API_SERVER,
147 },
148 success: function(data) {
149 Utils.checkAndResolveSocketRequest(data, resolve, reject);
150 }
151 });
152 })
153 },
154 loading: RecordViewActions.getVNFRSocketLoading,
155 success: RecordViewActions.getVNFRSocketSuccess,
156 error: RecordViewActions.getVNFRSocketError
157 }
158 },
159 execNsConfigPrimitive() {
160 return {
161 remote(state, payload) {
162 return new Promise(function(resolve, reject) {
163 $.ajax({
164 url: 'api/exec-ns-service-primitive?api_server=' + API_SERVER,
165 type: 'POST',
166 data: payload,
167 dataType: 'json',
168 beforeSend: Utils.addAuthorizationStub,
169 success: function(data) {
170 resolve(data);
171 }
172 });
173 })
174 },
175 loading: RecordViewActions.execNsConfigPrimitiveLoading,
176 success: RecordViewActions.execNsConfigPrimitiveSuccess,
177 error: RecordViewActions.execNsConfigPrimitiveError
178 }
179 },
180 createScalingGroupInstance() {
181 return {
182 remote(state, params) {
183 return new Promise(function(resolve, reject) {
184 $.ajax({
185 url: 'api/nsr/' + params.nsr_id + '/' + params.scaling_group_id + '/instance' + '?api_server=' + API_SERVER,
186 type: 'POST',
187 beforeSend: Utils.addAuthorizationStub,
188 success: function(data) {
189 resolve(data);
190 }
191 });
192 })
193 },
194 loading: RecordViewActions.createScalingGroupInstanceLoading,
195 success: RecordViewActions.createScalingGroupInstanceSuccess,
196 error: RecordViewActions.createScalingGroupInstanceError
197 }
198 },
199 deleteScalingGroupInstance() {
200 return {
201 remote(state, params) {
202 return new Promise(function(resolve, reject) {
203 $.ajax({
204 url: 'api/nsr/' + params.nsr_id + '/' + params.scaling_group_id + '/instance/' + params.scaling_instance_index + '?api_server=' + API_SERVER,
205 type: 'DELETE',
206 beforeSend: Utils.addAuthorizationStub,
207 success: function(data) {
208 resolve(data);
209 }
210 });
211 })
212 },
213 loading: RecordViewActions.deleteScalingGroupInstanceLoading,
214 success: RecordViewActions.deleteScalingGroupInstanceSuccess,
215 error: RecordViewActions.deleteScalingGroupInstanceError
216 }
217 },
218 createVirtualLink() {
219 return {
220 remote(state, params) {
221 return new Promise(function(resolve, reject) {
222 $.ajax({
223 url: 'api/nsr/' + params.nsr_id + '/vld' + '?api_server=' + API_SERVER,
224 type: 'POST',
225 beforeSend: Utils.addAuthorizationStub,
226 success: function(data) {
227 resolve(data);
228 }
229 });
230 })
231 },
232 loading: RecordViewActions.createVirtualLinkLoading,
233 success: RecordViewActions.createVirtualLinkSuccess,
234 error: RecordViewActions.createVirtualLinkError
235 }
236 },
237 deleteVirtualLink() {
238 return {
239 remote(state, params) {
240 return new Promise(function(resolve, reject) {
241 $.ajax({
242 url: 'api/nsr/' + params.nsr_id + '/vld/' + params.vldId + '?api_server=' + API_SERVER,
243 type: 'DELETE',
244 beforeSend: Utils.addAuthorizationStub,
245 success: function(data) {
246 resolve(data);
247 }
248 });
249 })
250 },
251 loading: RecordViewActions.deleteVirtualLinkLoading,
252 success: RecordViewActions.deleteVirtualLinkSuccess,
253 error: RecordViewActions.deleteVirtualLinkError
254 }
255 },
256 editVirtualLink() {
257 return {
258 remote(state, params) {
259 return new Promise(function(resolve, reject) {
260 $.ajax({
261 url: 'api/nsr/' + params.nsr_id + '/vld/' + params.vldId + '?api_server=' + API_SERVER,
262 type: 'PUT',
263 beforeSend: Utils.addAuthorizationStub,
264 success: function(data) {
265 resolve(data);
266 }
267 });
268 })
269 },
270 loading: RecordViewActions.editVirtualLinkLoading,
271 success: RecordViewActions.editVirtualLinkSuccess,
272 error: RecordViewActions.editVirtualLinkError
273 }
274 }
275 }