NOTICKET: Merging OSM/master to OSM/projects
[osm/UI.git] / skyquake / plugins / launchpad / src / topologyView / topologySource.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 let getSearchParams = require('utils/rw.js').getSearchParams;
20
21 var API_SERVER = getSearchParams(window.location).api_server;
22 let HOST = API_SERVER;
23 let NODE_PORT = getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
24 let DEV_MODE = getSearchParams(window.location).dev_mode || false;
25
26 if (DEV_MODE) {
27 HOST = window.location.protocol + '//' + window.location.hostname;
28 }
29
30
31 var TopologyActions = require('./topologyActions.js');
32 var Utils = require('utils/utils.js');
33 import $ from 'jquery';
34
35 export default {
36 openNSRTopologySocket: function() {
37 return {
38 remote: function(state, id) {
39 return new Promise(function(resolve, reject) {
40 //If socket connection already exists, eat the request.
41 if(state.socket) {
42 return resolve(false);
43 }
44 $.ajax({
45 url: '/socket-polling?api_server=' + API_SERVER,
46 type: 'POST',
47 beforeSend: Utils.addAuthorizationStub,
48 data: {
49 url: '/launchpad/api/nsr/' + id + '/compute-topology?api_server=' + API_SERVER
50 },
51 success: function(data, textStatus, jqXHR) {
52 Utils.checkAndResolveSocketRequest(data, resolve, reject);
53 }
54 }).fail(function(xhr){
55 //Authentication and the handling of fail states should be wrapped up into a connection class.
56 Utils.checkAuthentication(xhr.status);
57 });;
58 });
59 },
60 loading: TopologyActions.openNSRTopologySocketLoading,
61 success: TopologyActions.openNSRTopologySocketSuccess,
62 error: TopologyActions.openNSRTopologySocketError
63 };
64 },
65 getNSRTopology() {
66 return {
67 remote: function(state, id) {
68 id = 0;
69 return new Promise(function (resolve, reject) {
70 $.ajax({
71 url: '/launchpad/api/nsr/' + id + '/compute-topology?api_server=' + API_SERVER,
72 type: 'GET',
73 beforeSend: Utils.addAuthorizationStub,
74 contentType: "application/json",
75 success: function(data) {
76 resolve(data);
77 },
78 error: function(error) {
79 console.log("There was an error getting the compute topology data", error);
80 reject(error);
81 }
82 });
83 });
84 },
85 local() {
86 return null;
87 },
88 success: TopologyActions.getNSRTopologySuccess,
89 error: TopologyActions.getNSRTopologyError,
90 loading: TopologyActions.getNSRTopologyLoading
91 }
92 },
93 getRawVNFR() {
94 return {
95 remote: function(state, vnfrID) {
96 return new Promise(function(resolve, reject) {
97 $.ajax({
98 url: 'passthrough/data/api/operational/vnfr-catalog/vnfr/' + vnfrID + '?api_server=' + API_SERVER,
99 type: 'GET',
100 beforeSend: Utils.addAuthorizationStub,
101 success: function(data) {
102 resolve(data);
103 }
104 });
105 })
106 },
107 loading: TopologyActions.getRawLoading,
108 success: TopologyActions.getRawSuccess,
109 error: TopologyActions.getRawError
110 }
111 },
112 getRawNSR() {
113 return {
114 remote: function(state, nsrID) {
115 return new Promise(function(resolve, reject) {
116 $.ajax({
117 url: 'passthrough/data/api/operational/ns-instance-opdata/nsr/' + nsrID + '?api_server=' + API_SERVER,
118 type: 'GET',
119 beforeSend: Utils.addAuthorizationStub,
120 success: function(data) {
121 resolve(data);
122 }
123 });
124 })
125 },
126 loading: TopologyActions.getRawLoading,
127 success: TopologyActions.getRawSuccess,
128 error: TopologyActions.getRawError
129 }
130 },
131 getRawVDUR() {
132 return {
133 remote: function(state, vdurID, vnfrID) {
134 return new Promise(function(resolve, reject) {
135 $.ajax({
136 url: 'passthrough/data/api/operational/vnfr-catalog/vnfr/' + vnfrID + '/vdur/' + vdurID + '?api_server=' + API_SERVER,
137 type: 'GET',
138 beforeSend: Utils.addAuthorizationStub,
139 success: function(data) {
140 resolve(data);
141 }
142 });
143 })
144 },
145 loading: TopologyActions.getRawLoading,
146 success: TopologyActions.getRawSuccess,
147 error: TopologyActions.getRawError
148 }
149 },
150 }