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 | */ |
| 16 | function createGsoServiceInstance(s1ServiceUrl, serviceInstance) { |
| 17 | var gsoLcmUri = '/openoapi/lifecyclemgr/v1/services'; |
| 18 | var parameter = { |
| 19 | 'name': serviceInstance.serviceName, |
| 20 | 'description': serviceInstance.serviceDescription, |
| 21 | 'serviceDefId': serviceTemplate.gsarId, |
| 22 | 'templatedId': serviceInstance.serviceTemplateId, |
| 23 | 'templateName': serviceTemplate.templateName, |
| 24 | 'getewayUri': gsoLcmUrl, |
| 25 | 'parameters': serviceInstance.serviceParameters |
| 26 | }; |
| 27 | var serviceInstanceId; |
| 28 | $.ajax({ |
| 29 | type : "POST", |
| 30 | async: false, |
| 31 | url : s1ServiceUrl, |
| 32 | contentType : "application/json", |
| 33 | dataType : "json", |
| 34 | data : JSON.stringify(parameter), |
| 35 | success : function(jsonResp) { |
| 36 | if(jsonResp.result.errorCode != '200') { |
| 37 | alert("Create service instance Error!"); |
| 38 | return; |
| 39 | } |
| 40 | serviceInstanceId = jsonResp.serviceId; |
| 41 | }, |
| 42 | error : function(xhr, ajaxOptions, thrownError) { |
| 43 | alert("Error on page : " + xhr.responseText); |
| 44 | } |
| 45 | }); |
| 46 | return serviceInstanceId; |
| 47 | } |
Luji7 | e5e0884 | 2016-09-14 23:10:07 +0800 | [diff] [blame] | 48 | |
| 49 | function createNfvoServiceInstance(s1ServiceUrl, serviceInstance) { |
| 50 | var nfvoLcmNsUrl = '/openoapi/nslcm/v1.0/ns'; |
| 51 | createServiceInstance(s1ServiceUrl, nfvoLcmNsUrl, serviceInstance); |
| 52 | } |
| 53 | |
| 54 | function createServiceInstance(s1ServiceUrl, gatewayUri, serviceInstance) { |
| 55 | var nsInstanceId = createNetworkService(s1ServiceUrl, gatewayUri, serviceInstance); |
| 56 | if(nsInstanceId === undefined) { |
| 57 | return; |
| 58 | } |
| 59 | instantiateNetworkService(gatewayUri, nsInstanceId, serviceInstance); |
| 60 | } |
| 61 | |
| 62 | function createNetworkService(s1ServiceUrl, gatewayUri, serviceInstance) { |
| 63 | var parameter = { |
| 64 | 'nsdId': serviceInstance.serviceTemplateId, |
| 65 | 'nsName': serviceInstance.serviceName, |
| 66 | 'description': serviceInstance.serviceDescription, |
| 67 | 'gatewayUri': gatewayUri, |
| 68 | 'parameters': serviceInstance.serviceParameters |
| 69 | }; |
| 70 | var nsInstanceId; |
| 71 | $.ajax({ |
| 72 | type : "POST", |
| 73 | async: false, |
| 74 | url : s1ServiceUrl, |
| 75 | contentType : "application/json", |
| 76 | dataType : "json", |
| 77 | data : JSON.stringify(parameter), |
| 78 | success : function(jsonResp) { |
| 79 | nsInstanceId = jsonResp.nsInstanceId; |
| 80 | }, |
| 81 | error : function(xhr, ajaxOptions, thrownError) { |
| 82 | alert("Error on page : " + xhr.responseText); |
| 83 | } |
| 84 | }); |
| 85 | return nsInstanceId; |
| 86 | } |
| 87 | |
| 88 | function instantiateNetworkService(gatewayUri, nsInstanceId, serviceInstance) { |
| 89 | var initNsUrl = gatewayUri + '/' + nsInstanceId + '/Instantiate' |
| 90 | var parameter = { |
| 91 | 'gatewayUri': initNsUrl, |
| 92 | 'nsInstanceId': nsInstanceId, |
| 93 | 'additionalParamForNs': serviceInstance.serviceParameters |
| 94 | }; |
| 95 | var result = false; |
| 96 | $.ajax({ |
| 97 | type : "POST", |
| 98 | async: false, |
| 99 | url : s1ServiceUrl, |
| 100 | contentType : "application/json", |
| 101 | dataType : "json", |
| 102 | data : JSON.stringify(parameter), |
| 103 | success : function(jsonResp) { |
| 104 | result = true; |
| 105 | }, |
| 106 | error : function(xhr, ajaxOptions, thrownError) { |
| 107 | alert("Error on page : " + xhr.responseText); |
| 108 | } |
| 109 | }); |
| 110 | return result; |
| 111 | } |
Luji7 | 55c653d | 2016-09-14 23:36:30 +0800 | [diff] [blame^] | 112 | |
| 113 | function createSdnoServiceInstance(s1ServiceUrl, serviceInstance) { |
| 114 | var sdnoLcmNsUrl = '/openoapi/sdnonslcm/v1.0/ns'; |
| 115 | createServiceInstance(s1ServiceUrl, sdnoLcmNsUrl, serviceInstance); |
| 116 | } |