From 90fd673d193c08c197abc87fe4149627e1e74cd3 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Tue, 7 Mar 2017 14:54:26 +0800 Subject: create NFVO scaling function commit gui code for scaling function Issue-ID: CLIENT-168 Change-Id: I1bd4609fb2ac324f497c5a044543890980f8f4a3 Signed-off-by: Luji7 --- .../src/main/webapp/lifecyclemgr/js/DataService.js | 107 ++++++++++++++++++++- .../src/main/webapp/lifecyclemgr/js/app.js | 39 +++++++- .../main/webapp/lifecyclemgr/templates/home.html | 71 +++++++++++++- 3 files changed, 214 insertions(+), 3 deletions(-) (limited to 'lifecyclemgr/src/main/webapp') diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js index 8cc47b07..8251458f 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/DataService.js @@ -124,7 +124,10 @@ app.factory("DataService", function($http, $log){ deleteService : function(serviceId) { return deleteServiceInstance(serviceId); - } + }, + scaleService: function (nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun) { + scaleServiceInstance(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun); + } } }); @@ -756,4 +759,106 @@ function queryServiceData(){ } }); return returnVal; +} + +function scaleServiceInstance(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun) { + var parameter = { + 'nsInstanceId': nsInstanceId, + 'scaleType': 'SCALE_NS', + 'scaleNsData': [ + { + 'scaleNsByStepsData': [ + { + 'scalingDirection': scaleType, + 'aspectId': aspectId, + 'numberOfSteps': numberOfSteps + } + ] + } + ] + }; + var nfvoUri = '/openoapi/nslcm/1.0/ns/' + nsInstanceId + '/scale'; + $.when( + $.ajax({ + type: "POST", + url: nfvoUri, + contentType: "application/json", + dataType: "json", + data: JSON.stringify(parameter) + }) + ).then( + function (response) { + var jobId = response.jobID; + //show the progress dialog + return queryScaleProgress(jobId); + } + ).then(function (response) { + resultHandleFun(response); + }); +} + +function queryScaleProgress(jobId) { + //show the progress dialog + var operation = 'scale network service'; + $("#idScaleProgressTitle").text(operation); + $("#scaleProgressContent").text('status:'); + $("#scaleProgressbar").attr("style", "width: 0%"); + $("#scaleProgressDialog").modal({backdrop: 'static', keyboard: false}); + //set a timer for query operation + var defer = $.Deferred(); + var queryProgressUri = jobStatusUri(jobId); + var timerDefer = $.Deferred(); + var timeout = 3600000; + var fun = function () { + if (timeout === 0) { + timerDefer.resolve({ + status: 'error', + reason: operation + ' timeout!', + }); + return; + } + timeout = timeout - 1000; + $.when($.ajax({ + type: "GET", + url: queryProgressUri + })) + .then(function (response) { + //update progress + $("#scaleProgressbar").attr("style", "width: " + response.responseDescriptor.progress.toString() + "%"); + $("#scaleProgressValue").text(response.responseDescriptor.progress.toString() + '%'); + $("#scaleProgressContent").text('status: ' + response.responseDescriptor.statusDescription); + if (response.responseDescriptor.status == 'finished' || response.responseDescriptor.status == 'error') { + timerDefer.resolve({ + status: response.responseDescriptor.status, + reason: response.responseDescriptor.errorCode + }); + } + }); + }; + var timerId = setInterval(fun, 1000); + $.when(timerDefer) + .then(function (responseDesc) { + clearInterval(timerId); + $('#scaleProgressDialog').modal('hide'); + defer.resolve({ + status: responseDesc.status, + reason: responseDesc.reason + }); + + }); + return defer; +} + +/** + * generate url for querying operation status + * @param jobId + * @param responseId + * @returns + */ +function jobStatusUri(jobId, responseId) { + var responsePara = ''; + if (undefined !== responseId) { + responsePara = '&responseId=' + responseId; + } + return '/openoapi/nslcm/v1/jobs/' + jobId + responsePara; } \ No newline at end of file diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js index 75541d06..3fceb57a 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/js/app.js @@ -139,6 +139,20 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' }, function (reason) { $scope.error = "Error ! " + reason; }); + $('#scalingTypeIn').on("change", function (e) { + var value = $(e.target).val(); + if ('on' === value) { + $('#scalingTypeIn').attr("checked", "checked"); + $('#scalingTypeOut').removeAttr("checked"); + } + }); + $('#scalingTypeOut').on("change", function (e) { + var value = $(e.target).val(); + if ('on' === value) { + $('#scalingTypeOut').attr("checked", "checked"); + $('#scalingTypeIn').removeAttr("checked"); + } + }); }; //loadTableData(); @@ -449,7 +463,30 @@ var app = angular.module("lcApp", ["ui.router", "ngTable"])/*, 'ui.bootstrap', ' } }; bootbox.confirm("Do you confirm to delete service?", deleteHandle); - } + }; + + $scope.scaleData = function (id) { + var nsInstanceId = id; + $('#scaleNS').click( + function() { + var scaleIn = $('#scalingTypeIn').attr('checked'); + var scaleType = scaleIn === undefined ? 'SCALE_OUT' : 'SCALE_IN'; + var aspectId = $('#scalingAspect').val(); + var numberOfSteps = $('#numberOfSteps').val(); + var resultHandleFun = function(response) { + if (response.status === 'finished') { + console.log('scale successfully!'); + } else { + console.log('Scaling service failed! ' + response); + //showErrorMessage('Scaling service failed',response); + } + }; + DataService.scaleService(nsInstanceId, scaleType, aspectId, numberOfSteps, resultHandleFun); + $('#scaleNS').unbind('click'); + } + ); + $('#scaleOptionDialog').modal(); + }; }) diff --git a/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html b/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html index cac3f80d..b5bcdd7d 100644 --- a/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html +++ b/lifecyclemgr/src/main/webapp/lifecyclemgr/templates/home.html @@ -44,6 +44,7 @@ + @@ -131,7 +132,7 @@ + + + + + -- cgit 1.2.3-korg