Luji7 | fb663ae | 2016-09-14 22:47:09 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Luji7 | a5777c5 | 2016-09-15 00:07:33 +0800 | [diff] [blame] | 16 | var templateParameters = { |
Luji7 | 56c2439 | 2016-09-15 00:37:15 +0800 | [diff] [blame] | 17 | templateName: '', |
| 18 | parameters: [] |
| 19 | }; |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 20 | |
| 21 | var service_instance_insert_index = 0; |
| 22 | |
Luji7 | 56c2439 | 2016-09-15 00:37:15 +0800 | [diff] [blame] | 23 | var lcmHandler = function(){ |
| 24 | this._addOwnEvents(); |
| 25 | }; |
| 26 | |
| 27 | lcmHandler.prototype = { |
| 28 | _addOwnEvents : function () { |
| 29 | $('a[data-toggle="tab"]').on('show.bs.tab', this.beforeParameterTabShow); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 30 | $('#createNS').click(this.okAction); |
Luji7 | 56c2439 | 2016-09-15 00:37:15 +0800 | [diff] [blame] | 31 | }, |
| 32 | beforeParameterTabShow : function (event) { |
| 33 | renderTemplateParametersTab(); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 34 | }, |
| 35 | okAction : function (event) { |
| 36 | var serviceInstance = { |
| 37 | serviceTemplateId: $('#svcTempl').val(), |
| 38 | serviceName: $('#svcName').val(), |
| 39 | serviceDescription: $('#svcDesc').val(), |
| 40 | serviceParameters: collectServiceParameters(templateParameters) |
| 41 | } |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 42 | var gatewayService = '/openoapi/servicegateway/v1/services'; |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 43 | var serviceTemplate = fetchServiceTemplateBy(serviceInstance.serviceTemplateId); |
| 44 | if(serviceTemplate === undefined) { |
| 45 | return; |
| 46 | } |
| 47 | if(serviceTemplate.csarType === 'GSAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 48 | serviceInstance.serviceInstanceId = createGsoServiceInstance(gatewayService, serviceInstance); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 49 | }else if(serviceTemplate.csarType === 'NSAR' || serviceTemplate.csarType === 'NFAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 50 | serviceInstance.serviceInstanceId = createNfvoServiceInstance(gatewayService, serviceInstance); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 51 | }else if(serviceTemplate.csarType === 'SSAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 52 | serviceInstance.serviceInstanceId = createSdnoServiceInstance(gatewayService, serviceInstance); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 53 | } |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 54 | if(serviceInstance.serviceInstanceId === undefined) { |
| 55 | return; |
| 56 | } |
| 57 | updateTable(serviceInstance); |
Luji7 | 56c2439 | 2016-09-15 00:37:15 +0800 | [diff] [blame] | 58 | } |
Luji7 | a5777c5 | 2016-09-15 00:07:33 +0800 | [diff] [blame] | 59 | }; |
| 60 | |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 61 | function collectServiceParameters(parameters) { |
| 62 | var serviceParameters = {}; |
| 63 | var i; |
| 64 | for( i = 0; i < parameters.length; i += 1) { |
| 65 | serviceParameters[parameters.name] = $('#' + parameters[i].id).val(); |
| 66 | } |
| 67 | return serviceParameters; |
| 68 | } |
| 69 | |
| 70 | function fetchServiceTemplateBy(templateId) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 71 | var serviceTemplateUri = '/openoapi/catalog/v1/servicetemplates/'+ templateId; |
| 72 | var template; |
| 73 | $.ajax({ |
| 74 | type : "GET", |
| 75 | async: false, |
| 76 | url : serviceTemplateUri, |
| 77 | contentType : "application/json", |
| 78 | dataType : "json", |
| 79 | success : function(jsonResp) { |
| 80 | template = { |
| 81 | name: jsonResp.templateName, |
| 82 | gsarId: jsonResp.csarId |
| 83 | } |
| 84 | }, |
| 85 | error : function(xhr, ajaxOptions, thrownError) { |
| 86 | alert("Error on page : " + xhr.responseText); |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 87 | } |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 88 | }); |
| 89 | if(template === undefined) { |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 90 | return template; |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 91 | } |
| 92 | var queryCsarUri = '/openoapi/catalog/v1/csars/' + template.gsarId; |
| 93 | $.ajax({ |
| 94 | type : "GET", |
| 95 | async: false, |
| 96 | url : queryCsarUri, |
| 97 | contentType : "application/json", |
| 98 | dataType : "json", |
| 99 | success : function(jsonResp) { |
| 100 | template.csarType = jsonResp.type |
| 101 | }, |
| 102 | error : function(xhr, ajaxOptions, thrownError) { |
| 103 | alert("Error on page : " + xhr.responseText); |
| 104 | } |
| 105 | }); |
| 106 | return template; |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Luji7 | a5777c5 | 2016-09-15 00:07:33 +0800 | [diff] [blame] | 109 | function renderTemplateParametersTab() { |
| 110 | templateParameters = fetchTemplateParameterDefinitions(templateParameters); |
| 111 | var components = transfromToComponents(templateParameters.parameters); |
| 112 | document.getElementById("parameterTab").innerHTML = components; |
| 113 | } |
| 114 | |
| 115 | function fetchTemplateParameterDefinitions(parameters) { |
Luji7 | 56c2439 | 2016-09-15 00:37:15 +0800 | [diff] [blame] | 116 | var serviceTemplate = parameters.templateName; |
Luji7 | a5777c5 | 2016-09-15 00:07:33 +0800 | [diff] [blame] | 117 | var currentServiceTemplate = $("#svcTempl").val(); |
| 118 | // Do not need to fetch template parameters if template do not change in UI. |
| 119 | if(serviceTemplate === currentServiceTemplate) { |
| 120 | return; |
| 121 | } |
| 122 | var queryParametersUri = '/openoapi/catalog/v1/servicetemplates/' + currentServiceTemplate + '/parameters'; |
| 123 | var inputParameters = []; |
| 124 | $.ajax({ |
| 125 | type : "GET", |
| 126 | async: false, |
| 127 | url : queryParametersUri, |
| 128 | contentType : "application/json", |
| 129 | dataType : "json", |
| 130 | success : function(jsonResp) { |
| 131 | var inputs = jsonResp.inputs; |
| 132 | var i; |
| 133 | for( i = 0; i < inputs.length; i += 1) { |
| 134 | inputParameters[i] = { |
| 135 | name: inputs[i].name, |
| 136 | type: inputs[i].type, |
| 137 | description: inputs[i].description, |
| 138 | defaultValue: inputs[i].defaultValue, |
| 139 | required: inputs[i].required, |
| 140 | id: 'parameter_' + i, |
| 141 | value: inputs[i].defaultValue |
| 142 | }; |
| 143 | } |
| 144 | }, |
| 145 | error : function(xhr, ajaxOptions, thrownError) { |
| 146 | alert("Error on page : " + xhr.responseText); |
| 147 | } |
| 148 | }); |
| 149 | return { name: currentServiceTemplate, parameters: inputParameters }; |
| 150 | } |
| 151 | |
| 152 | function transfromToComponents(parameters) { |
| 153 | var components = ''; |
| 154 | var i; |
| 155 | for( i = 0; i < parameters.length; i += 1) { |
| 156 | var component = '<div class="form-group">' + |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 157 | '<label class="col-sm-3 control-label">' + |
| 158 | '<span>' + parameters[i].description + '</span>' + generateRequiredLabel(parameters[i]) + |
| 159 | '</label>' + |
| 160 | '<div class="col-sm-7">' + |
| 161 | '<input type="text" id="'+ parameters[i].id +'" name="parameter description" class="form-control" placeholder="' + |
| 162 | parameters[i].description + '" value="'+ parameters[i].value +'" />' + |
| 163 | '</div></div>'; |
| 164 | components = components + component; |
| 165 | } |
| 166 | return components; |
Luji7 | a5777c5 | 2016-09-15 00:07:33 +0800 | [diff] [blame] | 167 | } |
| 168 | |
Luji7 | 17050c3 | 2016-09-15 01:04:10 +0800 | [diff] [blame] | 169 | function generateRequiredLabel(parameter) { |
| 170 | var requiredLabel = ''; |
| 171 | if(parameter.required === 'true') { |
| 172 | requiredLabel = '<span class="required">*</span>'; |
| 173 | } |
| 174 | return requiredLabel; |
| 175 | } |
| 176 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 177 | function createGsoServiceInstance(gatewayService, serviceInstance) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 178 | var gsoLcmUri = '/openoapi/lifecyclemgr/v1/services'; |
| 179 | var parameter = { |
| 180 | 'name': serviceInstance.serviceName, |
| 181 | 'description': serviceInstance.serviceDescription, |
| 182 | 'serviceDefId': serviceTemplate.gsarId, |
| 183 | 'templatedId': serviceInstance.serviceTemplateId, |
| 184 | 'templateName': serviceTemplate.templateName, |
| 185 | 'getewayUri': gsoLcmUrl, |
| 186 | 'parameters': serviceInstance.serviceParameters |
| 187 | }; |
| 188 | var serviceInstanceId; |
| 189 | $.ajax({ |
| 190 | type : "POST", |
| 191 | async: false, |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 192 | url : gatewayService, |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 193 | contentType : "application/json", |
| 194 | dataType : "json", |
| 195 | data : JSON.stringify(parameter), |
| 196 | success : function(jsonResp) { |
| 197 | if(jsonResp.result.errorCode != '200') { |
| 198 | alert("Create service instance Error!"); |
| 199 | return; |
| 200 | } |
| 201 | serviceInstanceId = jsonResp.serviceId; |
| 202 | }, |
| 203 | error : function(xhr, ajaxOptions, thrownError) { |
| 204 | alert("Error on page : " + xhr.responseText); |
| 205 | } |
| 206 | }); |
| 207 | return serviceInstanceId; |
Luji7 | fb663ae | 2016-09-14 22:47:09 +0800 | [diff] [blame] | 208 | } |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 209 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 210 | function createNfvoServiceInstance(gatewayService, serviceInstance) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 211 | var nfvoLcmNsUrl = '/openoapi/nslcm/v1.0/ns'; |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 212 | createServiceInstance(gatewayService, nfvoLcmNsUrl, serviceInstance); |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 213 | } |
| 214 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 215 | function createServiceInstance(gatewayService, gatewayUri, serviceInstance) { |
| 216 | var nsInstanceId = createNetworkService(gatewayService, gatewayUri, serviceInstance); |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 217 | if(nsInstanceId === undefined) { |
| 218 | return; |
| 219 | } |
| 220 | instantiateNetworkService(gatewayUri, nsInstanceId, serviceInstance); |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 221 | } |
| 222 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 223 | function createNetworkService(gatewayService, gatewayUri, serviceInstance) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 224 | var parameter = { |
| 225 | 'nsdId': serviceInstance.serviceTemplateId, |
| 226 | 'nsName': serviceInstance.serviceName, |
| 227 | 'description': serviceInstance.serviceDescription, |
| 228 | 'gatewayUri': gatewayUri, |
| 229 | 'parameters': serviceInstance.serviceParameters |
| 230 | }; |
| 231 | var nsInstanceId; |
| 232 | $.ajax({ |
| 233 | type : "POST", |
| 234 | async: false, |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 235 | url : gatewayService, |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 236 | contentType : "application/json", |
| 237 | dataType : "json", |
| 238 | data : JSON.stringify(parameter), |
| 239 | success : function(jsonResp) { |
| 240 | nsInstanceId = jsonResp.nsInstanceId; |
| 241 | }, |
| 242 | error : function(xhr, ajaxOptions, thrownError) { |
| 243 | alert("Error on page : " + xhr.responseText); |
| 244 | } |
| 245 | }); |
| 246 | return nsInstanceId; |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | function instantiateNetworkService(gatewayUri, nsInstanceId, serviceInstance) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 250 | var initNsUrl = gatewayUri + '/' + nsInstanceId + '/Instantiate' |
| 251 | var parameter = { |
| 252 | 'gatewayUri': initNsUrl, |
| 253 | 'nsInstanceId': nsInstanceId, |
| 254 | 'additionalParamForNs': serviceInstance.serviceParameters |
| 255 | }; |
| 256 | var result = false; |
| 257 | $.ajax({ |
| 258 | type : "POST", |
| 259 | async: false, |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 260 | url : gatewayService, |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 261 | contentType : "application/json", |
| 262 | dataType : "json", |
| 263 | data : JSON.stringify(parameter), |
| 264 | success : function(jsonResp) { |
| 265 | result = true; |
| 266 | }, |
| 267 | error : function(xhr, ajaxOptions, thrownError) { |
| 268 | alert("Error on page : " + xhr.responseText); |
| 269 | } |
| 270 | }); |
| 271 | return result; |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 272 | } |
Luji7 | 55c653d | 2016-09-14 23:36:30 +0800 | [diff] [blame] | 273 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 274 | function createSdnoServiceInstance(gatewayService, serviceInstance) { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 275 | var sdnoLcmNsUrl = '/openoapi/sdnonslcm/v1.0/ns'; |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 276 | createServiceInstance(gatewayService, sdnoLcmNsUrl, serviceInstance); |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | function updateTable(serviceInstance) { |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 280 | appendOenRow(); |
| 281 | addDeleteEventRegistration(); |
| 282 | } |
| 283 | |
| 284 | function appendOenRow() { |
Luji7 | 988a509 | 2016-09-15 10:44:36 +0800 | [diff] [blame] | 285 | var index = service_instance_insert_index; |
| 286 | var creator = ''; |
| 287 | $('#sai').append('<tr id="service_instance_' + index + '"></tr>'); |
| 288 | $("#service_instance_" + index).html('<td><div class="DataTables_sort_wrapper openo-ellipsis "><span id="service_name" class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element ">'+ serviceInstance.serviceName + '</span></td>' + |
| 289 | '<td><span class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element ">'+ serviceInstance.templateName + '</span></td>' + |
| 290 | '<td class="service_template_id"><span class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element ">'+ serviceInstance.serviceTemplateId + '</span><input type="hidden" value="'+serviceInstance.serviceInstanceId+'"/></td>' + |
| 291 | '<td><span class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element ">'+ formatDate(new Date()) + '</span></td>' + |
| 292 | '<td><span class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element ">'+ creator + '</span></td>' + |
| 293 | '<td><button class="data_delete_action"><img id="delete_action" class="openo-table-th-sorticon overflow_elip leftHeaderAlign openo-table-disable-element " src="images/delete.png"></img></button></td>'); |
| 294 | service_instance_insert_index += 1; |
| 295 | } |
| 296 | |
| 297 | function formatDate(date) { |
| 298 | var year = date.getFullYear(); |
| 299 | var month = date.getMonth() + 1; |
| 300 | var day = date.getDate(); |
| 301 | var hh = date.getHours(); |
| 302 | var mm = date.getMinutes(); |
| 303 | var ss = date.getSeconds(); |
| 304 | return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; |
Luji7 | 55c653d | 2016-09-14 23:36:30 +0800 | [diff] [blame] | 305 | } |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 306 | |
| 307 | function addDeleteEventRegistration() { |
| 308 | $(".data_delete_action").click(function(event) { |
| 309 | var trElement = $(this).parents("tr")[0]; |
| 310 | var tdElement = $(trElement).children("td.service_template_id")[0]; |
| 311 | var spanElement = $(tdElement).children("span")[0]; |
| 312 | var templateId = $(spanElement).text(); |
| 313 | var inputElement = $(tdElement).children("input")[0]; |
| 314 | var instanceId = $(inputElement).val(); |
| 315 | var result = deleteServiceInstance(templateId, instanceId); |
| 316 | if(result) { |
| 317 | trElement.remove(); |
| 318 | alert("Service instance deleted successfully!"); |
| 319 | } |
| 320 | }); |
| 321 | } |
| 322 | |
| 323 | function deleteServiceInstance(templateId, instanceId) { |
| 324 | var serviceTemplate = fetchServiceTemplateBy(templateId); |
| 325 | if(serviceTemplate === undefined) { |
| 326 | return; |
| 327 | } |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 328 | var gatewayService = '/openoapi/servicegateway/v1/services'; |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 329 | var result = false; |
| 330 | if(serviceTemplate.csarType === 'GSAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 331 | result = deleteGsoServiceInstance(gatewayService, instanceId); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 332 | }else if(serviceTemplate.csarType === 'NSAR' || serviceTemplate.csarType === 'NFAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 333 | result = deleteNfvoServiceInstance(gatewayService, instanceId); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 334 | }else if(serviceTemplate.csarType === 'SSAR') { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 335 | result = deleteSdnoServiceInstance(gatewayService, instanceId); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 336 | } |
| 337 | return result; |
| 338 | } |
| 339 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 340 | function deleteGsoServiceInstance(gatewayService, instanceId) { |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 341 | var gsoLcmUrl = '/openoapi/lifecyclemgr/v1/services/'+ instanceId; |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 342 | return sendDeleteRequest(gatewayService, gsoLcmUrl); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 343 | } |
| 344 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 345 | function deleteNfvoServiceInstance(gatewayService, instanceId) { |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 346 | var nfvoNsUrl = '/openoapi/nslcm/v1.0/ns/' + instanceId; |
| 347 | var nfvoNsTerminateUrl = nfvoNsUrl +'/terminate'; |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 348 | var result = sendDeleteRequest(gatewayService, nfvoNsTerminateUrl); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 349 | if(result) { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 350 | result = sendDeleteRequest(gatewayService, nfvoNsUrl); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 351 | } |
| 352 | return result; |
| 353 | } |
| 354 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 355 | function deleteSdnoServiceInstance(gatewayService, instanceId) { |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 356 | var sdnoNsUrl = '/openoapi/sdnonslcm/v1.0/ns/' + instanceId; |
| 357 | var sdnoNsTerminateUrl = sdnoNsUrl + '/terminate'; |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 358 | var result = sendDeleteRequest(gatewayService, sdnoNsTerminateUrl); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 359 | if(result) { |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 360 | result = sendDeleteRequest(gatewayService, sdnoNsUrl); |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 361 | } |
| 362 | return result; |
| 363 | } |
| 364 | |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 365 | function sendDeleteRequest(gatewayService, url) { |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 366 | var parameter = { |
| 367 | URL: url |
| 368 | }; |
| 369 | var result = false; |
| 370 | $.ajax({ |
| 371 | type : "DELETE", |
| 372 | async: false, |
Luji7 | c4e8e73 | 2016-09-15 11:28:45 +0800 | [diff] [blame^] | 373 | url : gatewayService, |
Luji7 | f7f15a6 | 2016-09-15 11:05:07 +0800 | [diff] [blame] | 374 | contentType : "application/json", |
| 375 | dataType : "json", |
| 376 | data : JSON.stringify(parameter), |
| 377 | success : function(jsonResp) { |
| 378 | result = true; |
| 379 | }, |
| 380 | error : function(xhr, ajaxOptions, thrownError) { |
| 381 | alert("Error on page : " + xhr.responseText); |
| 382 | } |
| 383 | }); |
| 384 | return result; |
| 385 | } |