From 6e4170f3f03c9db3a523d7e7d07c57bd5d4314ac Mon Sep 17 00:00:00 2001 From: Luji7 Date: Wed, 2 Nov 2016 12:15:28 +0800 Subject: Issue-Id: GSO-88 add error prompt and async receive job status for creating and deleting non GSO service. Change-Id: I9cd41ea8eeccb9d5d0eb84568ed28a1bce19fe3b Signed-off-by: Luji7 --- .../src/main/webapp/lifecyclemgr/gsolcmmain.html | 1 + .../src/main/webapp/lifecyclemgr/js/gsolcm.js | 213 +++++++++++++++++---- .../lifecyclemgr/js/jquery.bootstrap-growl.min.js | 1 + 3 files changed, 176 insertions(+), 39 deletions(-) create mode 100644 openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/jquery.bootstrap-growl.min.js diff --git a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/gsolcmmain.html b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/gsolcmmain.html index b7357c52..a2828b7d 100644 --- a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/gsolcmmain.html +++ b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/gsolcmmain.html @@ -30,6 +30,7 @@ + diff --git a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js index ceb62ad9..907f4821 100644 --- a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js +++ b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/gsolcm.js @@ -49,15 +49,40 @@ lcmHandler.prototype = { return createNetworkServiceInstance(template, serviceInstance, gatewayService); } ).then( - function(serviceInstance) { - updateTable(serviceInstance); + function(response) { $.isLoading('hide'); - $('#vmAppDialog').removeClass('in').css('display', 'none'); + if(response.status === 'success') { + updateTable(response.serviceInstance); + $('#vmAppDialog').removeClass('in').css('display', 'none'); + } else { + showErrorMessage('Create service failed', response.errorResult); + } } ); } }; +function showErrorMessage(title, result) { + var info = '
' + '
' + title + '

'; + info = info + '
Status: ' + result.status + '

'; + info = info + '

Description:
'; + if(result.statusDescription.forEach === undefined) { + info = info + '
' + result.statusDescription + '

'; + } else { + result.statusDescription.forEach(function(message) { + info = info + '

' + message + '

'; + }); + } + info = info + '

Error code: '+ result.errorCode + '
'; + $.bootstrapGrowl(info, { + type: 'danger', + align: 'center', + width: "auto", + delay: 10000, + allow_dismiss: true + }); +} + function checkLocation(parameters) { var checkPass = true; var i = 0; @@ -477,25 +502,30 @@ function createGsoServiceInstance(gatewayService, serviceInstance, serviceTempla dataType: "json", data: JSON.stringify(parameter) })).then(function(response) { - serviceInstance.serviceId = response.serviceId; - defer.resolve(serviceInstance); + if(response.result.status === 'success') { + serviceInstance.serviceId = response.serviceId; + defer.resolve({status: 'success', instance: serviceInstance}); + } else { + defer.resolve({status: 'fail', errorResult: response.result}); + } }); return defer; } function createNfvoServiceInstance(gatewayService, serviceInstance, template) { - var nfvoLcmNsUri = '/openoapi/nslcm/v1/ns'; + var nfvoLcmUri = '/openoapi/nslcm/v1'; serviceInstance.nsdId = template.id; - return createServiceInstance(gatewayService, nfvoLcmNsUri, serviceInstance); + return createServiceInstance(gatewayService, nfvoLcmUri, serviceInstance); } function createSdnoServiceInstance(gatewayService, serviceInstance) { - var sdnoLcmNsUri = '/openoapi/sdnonslcm/v1/ns'; + var sdnoLcmUri = '/openoapi/sdnonslcm/v1'; serviceInstance.nsdId = serviceInstance.serviceTemplateId; - return createServiceInstance(gatewayService, sdnoLcmNsUri, serviceInstance); + return createServiceInstance(gatewayService, sdnoLcmUri, serviceInstance); } -function createServiceInstance(gatewayService, nsUri, serviceInstance) { +function createServiceInstance(gatewayService, lcmUri, serviceInstance) { + var nsUri = lcmUri + '/ns'; var defer = $.Deferred(); var sParameter = { 'nsdId': serviceInstance.nsdId, @@ -510,23 +540,75 @@ function createServiceInstance(gatewayService, nsUri, serviceInstance) { dataType: "json", data: JSON.stringify(sParameter) })).then(function(response) { - var nsInstanceId = response.serviceId; - serviceInstance.serviceId = nsInstanceId; - var initNsUrl = nsUri + '/' + nsInstanceId + '/instantiate'; - var parameter = { - 'gatewayUri': initNsUrl, - 'nsInstanceId': nsInstanceId, - 'additionalParamForNs': serviceInstance.inputParameters - }; - return $.ajax({ - type: "POST", - url: gatewayService, - contentType: "application/json", - dataType: "json", - data: JSON.stringify(parameter) - }); - }).then(function() { - defer.resolve(serviceInstance); + if(response.result.status === 'success') { + var nsInstanceId = response.serviceId; + serviceInstance.serviceId = nsInstanceId; + var initNsUrl = nsUri + '/' + nsInstanceId + '/instantiate'; + var parameter = { + 'gatewayUri': initNsUrl, + 'nsInstanceId': nsInstanceId, + 'additionalParamForNs': serviceInstance.inputParameters + }; + return $.ajax({ + type: "POST", + url: gatewayService, + contentType: "application/json", + dataType: "json", + data: JSON.stringify(parameter) + }); + } else { + return response; + } + }).then(function(response) { + if(response.result.status === 'success') { + var jobId = response.serviceId; + var jobStatusUri = lcmUri + '/jobs/' + jobId; + var timerDefer = $.Deferred(); + var timeout = 600000; + var fun = function() { + if(timeout === 0) { + timerDefer.resolve({ + status: 'fail', + statusDescription: 'Operation is timeout!', + errorCode: '' + }); + return; + } + timeout = timeout - 1000; + $.when( + $.ajax({ + type: "GET", + url: jobStatusUri + }) + ).then( + function(jobResponse) { + var responseDesc = jobResponse.responseDescriptor; + if(responseDesc.status === 'finished' || responseDesc.status === 'error') { + timerDefer.resolve(responseDesc); + } + } + ); + }; + var timerId = setInterval(fun, 1000); + $.when(timerDefer).then( + function(responseDesc) { + clearInterval(timerId); + if(responseDesc.status === 'finished') { + defer.resolve({status: 'success', instance: serviceInstance}); + } else { + defer.resolve({ + status: 'fail', + errorResult: { + status: responseDesc.status, + statusDescription: responseDesc.statusDescription, + errorCode: responseDesc.errorCode + }}}); + } + } + ); + } else { + defer.resolve({status: 'fail', errorResult: response.result}); + } }); return defer; } @@ -568,14 +650,18 @@ function deleteNe(rowId, row) { $.isLoading( "hide" ); $('#sai').bootstrapTable('remove', {field: 'serviceId', values: [instanceId]}); }; + var failFun = function(responseDesc) { + $.isLoading( "hide" ); + showErrorMessage("Delete service failed", responseDesc); + } if(serviceType === 'GSO') { deleteGsoServiceInstance(gatewayService, instanceId, remove); } else if (serviceType === 'NFVO') { - var nfvoNsUri = '/openoapi/nslcm/v1/ns'; - deleteNonGsoServiceInstance(gatewayService, nfvoNsUri, instanceId, remove); + var nfvoLcmUri = '/openoapi/nslcm/v1'; + deleteNonGsoServiceInstance(gatewayService, nfvoLcmUri, instanceId, remove, failFun); } else if (serviceType === 'SDNO') { - var sdnoNsUri = '/openoapi/sdnonslcm/v1/ns'; - deleteNonGsoServiceInstance(gatewayService, sdnoNsUri, instanceId, remove); + var sdnoLcmUri = '/openoapi/sdnonslcm/v1'; + deleteNonGsoServiceInstance(gatewayService, sdnoLcmUri, instanceId, remove, failFun); } } }; @@ -593,18 +679,67 @@ function deleteGsoServiceInstance(gatewayService, instanceId, remove) { ); } -function deleteNonGsoServiceInstance(gatewayService, nsUri, instanceId, remove) { +function deleteNonGsoServiceInstance(gatewayService, lcmUri, instanceId, remove, failFun) { + var nsUri = lcmUri + '/ns'; $.when( terminateNetworkServiceInstance(gatewayService, nsUri, instanceId) ).then( - function() { - return deleteNetworkServiceInstance(gatewayService, nsUri, instanceId); - } - ).then( - function() { - remove(); + function(response) { + var jobId = response.jobId; + var jobStatusUri = lcmUri + '/jobs/' + jobId; + var timerDefer = $.Deferred(); + var timeout = 600000; + var fun = function() { + if(timeout === 0) { + timerDefer.resolve({ + status: 'fail', + statusDescription: 'Operation is timeout!', + errorCode: '' + }); + return; + } + timeout = timeout - 1000; + $.when( + $.ajax({ + type: "GET", + url: jobStatusUri + }) + ).then( + function(jobResponse) { + var responseDesc = jobResponse.responseDescriptor; + if(responseDesc.status === 'finished' || responseDesc.status === 'error') { + timerDefer.resolve(responseDesc); + } + } + ); + }; + var timerId = setInterval(fun, 1000); + $.when(timerDefer).then( + function(responseDesc) { + clearInterval(timerId); + if(responseDesc.status === 'finished') { + $.when( + deleteNetworkServiceInstance(gatewayService, nsUri, instanceId) + ).then( + function(nsResponse) { + if(nsResponse.status === 'success') { + remove(); + } else { + failFun(nsResponse); + } + } + ).fail(function() { + failFun({status: "fail", statusDescription: "delete service failed.", errorCode: "500"}}); + }); + } else { + failFun(responseDesc); + } + } + ); } - ); + ).fail(function() { + failFun({status: "fail", statusDescription: "delete service failed.", errorCode: "500"}}); + }); } function deleteNetworkServiceInstance(gatewayService, nsUri, instanceId) { diff --git a/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/jquery.bootstrap-growl.min.js b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/jquery.bootstrap-growl.min.js new file mode 100644 index 00000000..67837e50 --- /dev/null +++ b/openo-portal/portal-lifecyclemgr/src/main/webapp/lifecyclemgr/js/jquery.bootstrap-growl.min.js @@ -0,0 +1 @@ +(function(){var c;c=jQuery;c.bootstrapGrowl=function(f,a){var b,e,d;a=c.extend({},c.bootstrapGrowl.default_options,a);b=c("
");b.attr("class","bootstrap-growl alert");a.type&&b.addClass("alert-"+a.type);a.allow_dismiss&&(b.addClass("alert-dismissible"),b.append(''));b.append(f);a.top_offset&&(a.offset={from:"top",amount:a.top_offset});d=a.offset.amount;c(".bootstrap-growl").each(function(){return d= Math.max(d,parseInt(c(this).css(a.offset.from))+c(this).outerHeight()+a.stackup_spacing)});e={position:"body"===a.ele?"fixed":"absolute",margin:0,"z-index":"9999",display:"none"};e[a.offset.from]=d+"px";b.css(e);"auto"!==a.width&&b.css("width",a.width+"px");c(a.ele).append(b);switch(a.align){case "center":b.css({left:"50%","margin-left":"-"+b.outerWidth()/2+"px"});break;case "left":b.css("left","20px");break;default:b.css("right","20px")}b.fadeIn();0