From f7f15a6731de67bbced76acb53e497e56f65610b Mon Sep 17 00:00:00 2001 From: Luji7 Date: Thu, 15 Sep 2016 11:05:07 +0800 Subject: delete service instance Change-Id: I0d242b2444c80de666d265839e5908effb988ac0 Signed-off-by: Luji7 --- openo-portal/portal-lifecyclemgr/js/gsolcm.js | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) (limited to 'openo-portal') diff --git a/openo-portal/portal-lifecyclemgr/js/gsolcm.js b/openo-portal/portal-lifecyclemgr/js/gsolcm.js index 6827127e..a3390a7d 100644 --- a/openo-portal/portal-lifecyclemgr/js/gsolcm.js +++ b/openo-portal/portal-lifecyclemgr/js/gsolcm.js @@ -277,6 +277,11 @@ function createSdnoServiceInstance(s1ServiceUrl, serviceInstance) { } function updateTable(serviceInstance) { + appendOenRow(); + addDeleteEventRegistration(); +} + +function appendOenRow() { var index = service_instance_insert_index; var creator = ''; $('#sai').append(''); @@ -298,3 +303,83 @@ function formatDate(date) { var ss = date.getSeconds(); return year + "-" + month + "-" + day + " " + hh + ":" + mm + ":" + ss; } + +function addDeleteEventRegistration() { + $(".data_delete_action").click(function(event) { + var trElement = $(this).parents("tr")[0]; + var tdElement = $(trElement).children("td.service_template_id")[0]; + var spanElement = $(tdElement).children("span")[0]; + var templateId = $(spanElement).text(); + var inputElement = $(tdElement).children("input")[0]; + var instanceId = $(inputElement).val(); + var result = deleteServiceInstance(templateId, instanceId); + if(result) { + trElement.remove(); + alert("Service instance deleted successfully!"); + } + }); +} + +function deleteServiceInstance(templateId, instanceId) { + var serviceTemplate = fetchServiceTemplateBy(templateId); + if(serviceTemplate === undefined) { + return; + } + var s1ServiceUrl = '/openoapi/servicegateway/v1/services'; + var result = false; + if(serviceTemplate.csarType === 'GSAR') { + result = deleteGsoServiceInstance(s1ServiceUrl, instanceId); + }else if(serviceTemplate.csarType === 'NSAR' || serviceTemplate.csarType === 'NFAR') { + result = deleteNfvoServiceInstance(s1ServiceUrl, instanceId); + }else if(serviceTemplate.csarType === 'SSAR') { + result = deleteSdnoServiceInstance(s1ServiceUrl, instanceId); + } + return result; +} + +function deleteGsoServiceInstance(s1ServiceUrl, instanceId) { + var gsoLcmUrl = '/openoapi/lifecyclemgr/v1/services/'+ instanceId; + return sendDeleteRequest(s1ServiceUrl, gsoLcmUrl); +} + +function deleteNfvoServiceInstance(s1ServiceUrl, instanceId) { + var nfvoNsUrl = '/openoapi/nslcm/v1.0/ns/' + instanceId; + var nfvoNsTerminateUrl = nfvoNsUrl +'/terminate'; + var result = sendDeleteRequest(s1ServiceUrl, nfvoNsTerminateUrl); + if(result) { + result = sendDeleteRequest(s1ServiceUrl, nfvoNsUrl); + } + return result; +} + +function deleteSdnoServiceInstance(s1ServiceUrl, instanceId) { + var sdnoNsUrl = '/openoapi/sdnonslcm/v1.0/ns/' + instanceId; + var sdnoNsTerminateUrl = sdnoNsUrl + '/terminate'; + var result = sendDeleteRequest(s1ServiceUrl, sdnoNsTerminateUrl); + if(result) { + result = sendDeleteRequest(s1ServiceUrl, sdnoNsUrl); + } + return result; +} + +function sendDeleteRequest(s1ServiceUrl, url) { + var parameter = { + URL: url + }; + var result = false; + $.ajax({ + type : "DELETE", + async: false, + url : s1ServiceUrl, + contentType : "application/json", + dataType : "json", + data : JSON.stringify(parameter), + success : function(jsonResp) { + result = true; + }, + error : function(xhr, ajaxOptions, thrownError) { + alert("Error on page : " + xhr.responseText); + } + }); + return result; +} -- cgit 1.2.3-korg