4 * Copyright 2016 RIFT.IO Inc
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 let getSearchParams
= require('utils/rw.js').getSearchParams
;
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;
27 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
31 var TopologyActions
= require('./topologyActions.js');
32 var Utils
= require('utils/utils.js');
33 import $ from 'jquery';
36 openNSRTopologySocket: function() {
38 remote: function(state
, id
) {
39 return new Promise(function(resolve
, reject
) {
40 //If socket connection already exists, eat the request.
42 return resolve(false);
45 url
: '/socket-polling?api_server=' + API_SERVER
,
47 beforeSend
: Utils
.addAuthorizationStub
,
49 url
: '/launchpad/api/nsr/' + id
+ '/compute-topology?api_server=' + API_SERVER
51 success: function(data
, textStatus
, jqXHR
) {
52 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
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
);
60 loading
: TopologyActions
.openNSRTopologySocketLoading
,
61 success
: TopologyActions
.openNSRTopologySocketSuccess
,
62 error
: TopologyActions
.openNSRTopologySocketError
67 remote: function(state
, id
) {
69 return new Promise(function (resolve
, reject
) {
71 url
: '/launchpad/api/nsr/' + id
+ '/compute-topology?api_server=' + API_SERVER
,
73 beforeSend
: Utils
.addAuthorizationStub
,
74 contentType
: "application/json",
75 success: function(data
) {
78 error: function(error
) {
79 console
.log("There was an error getting the compute topology data", error
);
88 success
: TopologyActions
.getNSRTopologySuccess
,
89 error
: TopologyActions
.getNSRTopologyError
,
90 loading
: TopologyActions
.getNSRTopologyLoading
95 remote: function(state
, vnfrID
) {
96 return new Promise(function(resolve
, reject
) {
98 url
: 'passthrough/data/api/operational/vnfr-catalog/vnfr/' + vnfrID
+ '?api_server=' + API_SERVER
,
100 beforeSend
: Utils
.addAuthorizationStub
,
101 success: function(data
) {
107 loading
: TopologyActions
.getRawLoading
,
108 success
: TopologyActions
.getRawSuccess
,
109 error
: TopologyActions
.getRawError
114 remote: function(state
, nsrID
) {
115 return new Promise(function(resolve
, reject
) {
117 url
: 'passthrough/data/api/operational/ns-instance-opdata/nsr/' + nsrID
+ '?api_server=' + API_SERVER
,
119 beforeSend
: Utils
.addAuthorizationStub
,
120 success: function(data
) {
126 loading
: TopologyActions
.getRawLoading
,
127 success
: TopologyActions
.getRawSuccess
,
128 error
: TopologyActions
.getRawError
133 remote: function(state
, vdurID
, vnfrID
) {
134 return new Promise(function(resolve
, reject
) {
136 url
: 'passthrough/data/api/operational/vnfr-catalog/vnfr/' + vnfrID
+ '/vdur/' + vdurID
+ '?api_server=' + API_SERVER
,
138 beforeSend
: Utils
.addAuthorizationStub
,
139 success: function(data
) {
145 loading
: TopologyActions
.getRawLoading
,
146 success
: TopologyActions
.getRawSuccess
,
147 error
: TopologyActions
.getRawError