From 30d5cfc7bd4108c23896d449206ab271d16edba2 Mon Sep 17 00:00:00 2001 From: Luji7 Date: Thu, 12 Oct 2017 18:27:16 +0800 Subject: Fix create dialog open failed. Change-Id: I85fa9396ef3ccd6b9a3e9601f188721ba39da8c8 Issue-id: USECASEUI-36 Signed-off-by: Luji7 --- .../scripts/controller/ServiceTemplateService.js | 241 ++++++++++++++++++- .../uui/fusion/scripts/controller/lcmController.js | 195 ++++++++++++++-- .../scripts/view-models/create-service-dialog.html | 127 ++++++---- .../scripts/view-models/lifecyclemanagement.html | 259 +++++---------------- .../scripts/view-models/vnf-ns-onboard-dialog.html | 48 ++++ 5 files changed, 614 insertions(+), 256 deletions(-) create mode 100644 usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/view-models/vnf-ns-onboard-dialog.html (limited to 'usecaseui-lcm') diff --git a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js index 328e1bbb..e329e947 100644 --- a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js +++ b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/ServiceTemplateService.js @@ -14,6 +14,245 @@ * limitations under the License. */ app.factory("ServiceTemplateService", function($http, $log) { + var url = ''; + return { + getAllCustomers: function (processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/customers', + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var customers = response.data; + var result = customers.map(function (customer) { + return { + name: customer['subscriber-name'], + id: customer['global-customer-id'], + }; + }); + processFun(result); + }); + }, - return {}; + getAllServiceTypes: function (customerId, processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/customers/' + customerId + '/service-subscriptions', + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var serviceSubscriptions = response.data; + var result = serviceSubscriptions.map(function (serviceSubscription) { + return { + name: serviceSubscription['service-type'], + value: serviceSubscription['service-type'] + }; + }); + processFun(result); + }); + }, + + getServiceInstances: function (customerId, serviceType, processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/service-instances?customerId='+customerId+'&&serviceType='+serviceType, + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var serviceInstances = response.data; + var result = serviceInstances.map(function (serviceInstance) { + return { + serviceInstanceId: serviceInstance['service-instance-id'], + serviceInstanceName: serviceInstance['service-instance-name'], + serviceType: serviceInstance['service-type'], + }; + }); + processFun(result); + }); + }, + + getAllServiceTemplates: function (processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/service-templates', + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var templates = response.data; + var result = templates.map(function (template) { + return { + name: template.name, + id: template.uuid, + invariantUUID: template.invariantUUID, + version: template.version, + toscaModelURL: template.toscaModelURL + }; + }); + processFun(result); + }); + }, + + getTemplateParameters: function (template, processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/service-templates/' + template.id, + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var inputRsp = response.data; + processFun(inputRsp); + }); + }, + + getAllVimInfo: function (processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/locations/', + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var vimInfos = response.data; + var result = vimInfos.map(function (vim) { + return { + name: vim['cloud-owner'] + '-' + vim['cloud-region-id'], + value: vim['cloud-owner'] + '-' + vim['cloud-region-id'] + }; + }); + processFun(result); + }); + }, + + createService: function (customer, serviceType, service, template) { + + function translateInputs(t, customer,serviceType, c) { + var reqParas = { + subscriptionServiceType: serviceType.value + }; + c[t.name].parameters.forEach(function (parameter) { + reqParas[parameter.name] = parameter.value;// todo + }); + var nestedSegments = t.nestedTemplates.map(function (nestedTemplate) { + return translateInputs(nestedTemplate,customer,serviceType, c); + }); + return { + domainHost: c[t.name].location.value,// ??? + nodeTemplateName: t.name+':'+t.version, + nodeType: 'service', + 'GLOBALSUBSCIBERID': customer.id, + 'SUBSCIBERNAME': customer.name, + requestParameters: reqParas, + segments: nestedSegments + }; + } + + var cache = {}; + cache[template.name] = { + location: service.location.value, + parameters: service.parameters + }; + service.segments.forEach(function (segment) { + cache[segment.nodeTemplateName] = { + location: segment.location.value, + parameters: segment.parameters + } + }); + console.log('cache ----'); + console.log(cache); + + var reqPara = translateInputs(template,customer, serviceType, cache); + var requestBody = { + service: { + name: service.serviceName, + description: service.serviceDescription, + serviceDefId: template.invariantUUID, + templateId: template.uuid, // uuid ?? + parameters: reqPara + } + }; + + console.log('request body: '); + console.log(requestBody); + + return $http({ + url: url+'/onapapi/uui-lcm/v1/services', + method: 'POST', + data: JSON.stringify(requestBody), + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + console.log('create response...'); + console.log(response.data); + }); + }, + + deleteService: function (serviceId) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/services/' + serviceId, + method: 'DELETE', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + console.log('delete response...'); + console.log(response.data); + }); + }, + + getPackages: function (processFun) { + return $http({ + url: url+'/onapapi/uui-lcm/v1/vf-ns-packages', + method: 'GET', + data: null, + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + var packageRsp = response.data; + var packages = []; + packageRsp.nsPackage.forEach(function (ns) { + packages.push({ + uuid: ns.uuid, + invariantUUID: ns.invariantUUID, + name: ns.name, + type: 'NS' + }) + }); + packageRsp.vnfPackages.forEach(function (vnf) { + packages.push({ + uuid: vnf.uuid, + invariantUUID: vnf.invariantUUID, + name: vnf.name, + type: 'VF' + }) + }); + processFun(packages); + }); + }, + + packageOnboard: function (onboardPackage, vims) { + console.log('onboard...'); + console.log(onboardPackage); + console.log(vims); + var requestBody = { + csarId: onboardPackage.uuid + } + if(onboardPackage.type === 'NS') { + return $http({ + url: url+'/onapapi/uui-lcm/v1/ns-packages', + method: 'POST', + data: JSON.stringify(requestBody), + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + console.log('onboard ns package response...'); + console.log(response.data); + }); + } else { + return $http({ + url: url+'/onapapi/uui-lcm/v1/vf-packages', + method: 'POST', + data: JSON.stringify(requestBody), + headers: {'Content-Type': 'application/json'} + }).then(function(response){ + console.log('onboard vf package response...'); + console.log(response.data); + }); + } + } + }; }); diff --git a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js index b09cfb07..0b2d431d 100644 --- a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js +++ b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/controller/lcmController.js @@ -13,38 +13,207 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -app.controller('lcmCtrl', ['$scope','$uibModal', '$log', '$http', '$timeout', '$interval', 'uiGridConstants', 'uiGridGroupingConstants', - function ($scope,$uibModal, $log, $http, $timeout, $interval) { - $scope.openCreateServiceDialog = function () { - console.log('start to open dialog....'); +app.controller('lcmCtrl', ['$scope', '$state', '$uibModal', '$log', '$http', '$timeout', '$interval', 'ServiceTemplateService', + function ($scope, $state, $uibModal, $log, $http, $timeout, $interval, ServiceTemplateService) { + var ctrl = this; + ctrl.openCreateServiceDialog = function () { var modalInstance = $uibModal.open({ ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', templateUrl : 'app/uui/fusion/scripts/view-models/create-service-dialog.html', - controller : 'createServiceCtrl' + controller : 'createServiceCtrl', + controllerAs : 'ctrl', + resolve: { + customer: function () { + return ctrl.customer; + }, + serviceType: function () { + return ctrl.serviceType; + } + } + }); + modalInstance.result.then( + function(result) { + console.log('receive ok button clicked!'); + console.log(result); + }, + function(reason) { + console.log('receive cancel button clicked!'); + console.log(reason); + $log.info('Modal dismissed at: ' + new Date()); + } + ); + }; + + ctrl.init = function () { + ctrl.canCreateService = "true"; + ServiceTemplateService.getAllCustomers(function (customers) { + ctrl.customers = customers; + }); + ServiceTemplateService.getPackages(function (packages) { + ctrl.packages = packages; + }); + }; + + ctrl.customerChanged = function () { + if(ctrl.customer === undefined || ctrl.customer === null) { + ctrl.serviceTypes = []; + } else { + ServiceTemplateService.getAllServiceTypes(ctrl.customer.id, function (serviceTypes) { + ctrl.serviceTypes = serviceTypes; + }); + } + ctrl.serviceType = undefined; + ctrl.canCreateService = "true"; + }; + + ctrl.serviceTypeChanged = function () { + if(ctrl.serviceType === undefined || ctrl.serviceType === null || ctrl.customer === undefined || ctrl.customer === null) { + ctrl.canCreateService = "true"; + return; + } + ctrl.canCreateService = "false"; + ServiceTemplateService.getServiceInstances(ctrl.customer.id, ctrl.serviceType.type, function (instances) { + ctrl.serviceInstances = instances; + }); + }; + + ctrl.packageOnboard = function (onboardPackage) { + var modalInstance = $uibModal.open({ + ariaLabelledBy: 'modal-title', + ariaDescribedBy: 'modal-body', + templateUrl : 'app/uui/fusion/scripts/view-models/vnf-ns-onboard-dialog.html', + controller : 'packageOnboardCtrl', + controllerAs : 'ctrl', + resolve: { + onboardPackage: function () { + return onboardPackage; + } + } }); modalInstance.result.then( - function() { + function(result) { console.log('receive ok button clicked!'); + console.log(result); }, - function() { + function(reason) { console.log('receive cancel button clicked!'); - $log.info('Modal dismissed at: ' + new Date()) + console.log(reason); + $log.info('Modal dismissed at: ' + new Date()); } ); }; } ] ) -.controller('createServiceCtrl',['ServiceTemplateService', - function($scope, $uibModalInstance, ServiceTemplateService) { +.controller('createServiceCtrl',['$scope', '$state', '$uibModalInstance', 'ServiceTemplateService', 'customer', 'serviceType', + function($scope, $state, $uibModalInstance, ServiceTemplateService, customer, serviceType) { + var ctrl = this; + + ctrl.templates = ServiceTemplateService.getAllServiceTemplates(); - $scope.ok = function() { + ctrl.changeInput = function (serviceTemplate) { + var paras = serviceTemplate.inputs.map(function (input) { + return { + name: input.name, + description: input.description, + defaultValue: input.defaultValue, + isRequired: input.isRequired, + readonly: "" + }; + }); + + var segmentsPara = serviceTemplate.nestedTemplates.map(function (nestedTemplate) { + var nestedParas = nestedTemplate.inputs.map(function (input) { + return { + name: input.name, + description: input.description, + defaultValue: input.defaultValue, + isRequired: input.isRequired, + readonly: "" + }; + }); + return { + nodeTemplateName: nestedTemplate.name, + location: { + name: nestedTemplate.name + " location",// ??? + }, + parameters: nestedParas + }; + }); + + var service = { + serviceName: ctrl.service.serviceName, + serviceDescription: ctrl.service.serviceDescription, + location: { + name: "local host" // ??? + }, + parameters: paras, + segments: segmentsPara + }; + ctrl.service = service; + }; + + ctrl.serviceTemplateChanged = function (template) { + console.log('serviceTemplateChanged invoked... ' + template); + if(template === undefined || template === null) { + ctrl.service = undefined; + ctrl.realTemplate = undefined; + } else { + ServiceTemplateService.getTemplateParameters(template, function (templateRsp) { + ctrl.realTemplate = templateRsp; + ctrl.changeInput(ctrl.realTemplate); + }); + } + }; + + ctrl.ok = function() { console.log('ok button clicked!'); + console.log('service: '); + console.log(ctrl.service); + console.log(customer); + console.log(serviceType); + console.log(ctrl.realTemplate); + ServiceTemplateService.createService(customer, serviceType, ctrl.service, ctrl.realTemplate); + var result = 'success.'; + $uibModalInstance.close(result); }; + + console.log($uibModalInstance); // cancel click - $scope.cancel = function() { + ctrl.cancel = function() { $uibModalInstance.dismiss('cancel'); - } + }; + + ServiceTemplateService.getAllVimInfo(function (vims) { + ctrl.locations = vims; + }); + }] +).controller('packageOnboardCtrl',['$scope', '$state', '$uibModalInstance', 'ServiceTemplateService','onboardPackage', + function($scope, $state, $uibModalInstance, ServiceTemplateService, onboardPackage) { + var ctrl = this; + + ServiceTemplateService.getAllVimInfo(function (vims) { + ctrl.packageLocations = vims; + }); + + ctrl.ok = function() { + var proVims = []; + ctrl.packageLocations.forEach(function (location) { + if(location.productenv) { + proVims.push(location.name); + } + }); + ServiceTemplateService.packageOnboard(onboardPackage, { + testenv: ctrl.testenv, + productenv: proVims + }); + $uibModalInstance.close('successfully'); + }; + // cancel click + ctrl.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; + }] ); diff --git a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/view-models/create-service-dialog.html b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/view-models/create-service-dialog.html index a00f54b9..760a067f 100644 --- a/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/view-models/create-service-dialog.html +++ b/usecaseui-lcm/src/main/webapp/app/uui/fusion/scripts/view-models/create-service-dialog.html @@ -16,68 +16,101 @@ -->