From 6a260ecd5ddc37e52555a45a38785ce5034f7301 Mon Sep 17 00:00:00 2001 From: Xinni Ge Date: Thu, 21 Jun 2018 14:23:49 +0900 Subject: [PATCH] Add support of AutoScalingGroup Change-Id: Ib0fc88eddb9bb5b02b158d199b729bf4f42f3a11 Task: #19672 Story: #2002031 --- .../components/modal-template.controller.js | 1 + .../components/template-generator.module.js | 1 + .../os__heat__autoscalinggroup-blue.svg | 4 + .../os__heat__autoscalinggroup-gray.svg | 3 + .../os__heat__autoscalinggroup-green.svg | 4 + .../os__heat__autoscalinggroup-red.svg | 4 + .../os__heat__autoscalinggroup.html | 144 +++++++++++++++++ .../os__heat__autoscalinggroup.js | 145 ++++++++++++++++++ .../os__heat__autoscalinggroup.spec.js | 128 ++++++++++++++++ .../os__heat__autoscalinggroup.svg | 4 + 10 files changed, 438 insertions(+) create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js create mode 100644 heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.svg diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js index 12e4a1d5..de5ce402 100644 --- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/modal-template.controller.js @@ -67,6 +67,7 @@ func = hotgenUtils.extract_list; break; case 'resource_def': + case 'resource': func = hotgenUtils.extract_resource_def; break; default: diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js index 365ffa9c..7e2f2c41 100644 --- a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/components/template-generator.module.js @@ -24,6 +24,7 @@ .constant('horizon.dashboard.project.heat_dashboard.template_generator.validationRules', { 'name': /^[A-Za-z0-9_.-]+$/, 'path': /^\/[a-z0-9/-]+$/, + 'integer': /^\d*$/, 'keypair': /^([A-Za-z0-9_.-]{1,255})=([A-Za-z0-9_.-]{1,255})$/, 'ip_address': /^([0-9.]{1,15})|([A-Fa-f0-9:]{1,39})$/, 'domain': /^[A-Za-z0-9_.-]+$/, diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg new file mode 100644 index 00000000..78ff04d0 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-blue.svg @@ -0,0 +1,4 @@ + +Layer 1Layer 2 + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg new file mode 100644 index 00000000..11603d0b --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-gray.svg @@ -0,0 +1,3 @@ +Layer 1Layer 2 + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg new file mode 100644 index 00000000..010baa7a --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-green.svg @@ -0,0 +1,4 @@ + +Layer 1Layer 2 + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg new file mode 100644 index 00000000..97495056 --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup-red.svg @@ -0,0 +1,4 @@ + +Layer 1Layer 2 + + diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html new file mode 100644 index 00000000..deecc4ea --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html @@ -0,0 +1,144 @@ + + + + + + + +
+
You did not enter a valid integer.
+
You did not enter a non-negative number.
+
You must supply a maximum size.
+
You must supply an integer.
+
+
+ + + + +
+
You did not enter a valid integer.
+
You did not enter a non-negative number.
+
You must supply a minimum size.
+
You must supply an integer.
+
+
+ + + + existing items + uploading a template file + +
+
You did not specify Resource Type.
+
+
+ +
+ + + + {$ resource_type $} + + + +
+ +
+
+ + + + + + + choose a file + + +
+ + + + + + + +
+ + + + + +
+
+ + + + + + + + + +
+
+ + + + +
+
You did not enter a valid integer.
+
You did not enter a non-negative number.
+
You must supply an integer.
+
+
+ + + + +
+
You did not enter a valid integer.
+
You did not enter a non-negative number.
+
You must supply an integer.
+
+
+ + + + + +
+
You did not enter a valid integer.
+
You did not enter a non-negative number.
+
You must supply an integer.
+
+
+ + + +
+
You did not enter a valid number.
+
You did not enter a non-negative number.
+
+
+ + + + +
+
You did not enter a valid integer.
+
You did not enter a positive number.
+
You must supply an integer.
+
+
+ +
+
+ + + + + + + +
diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js new file mode 100644 index 00000000..d108110e --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.js @@ -0,0 +1,145 @@ +(function() { + 'use strict'; + + /* OS::Heat::AutoScalingGroup + * + */ + + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .value('osHeatAutoScalingGroupSettings', + { + resource_key: "OS__Heat__AutoScalingGroup", + admin: false, + icon: { + class: 'fa-hdd-o', + name: 'OS::Heat::AutoScalingGroup', + code: '\uf0a0', + color: '#0bb238' + }, + label: 'name', + modal_component: '', + edge_settings: null, + necessary_properties: ['max_size', 'min_size', 'resource'] + } + ) + + // Register the resource to globals + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .run(['osHeatAutoScalingGroupSettings','hotgenGlobals', function(osHeatAutoScalingGroupSettings, hotgenGlobals){ + hotgenGlobals.update_resource_icons( + osHeatAutoScalingGroupSettings.resource_key , + osHeatAutoScalingGroupSettings.icon); + + hotgenGlobals.update_resource_components( + osHeatAutoScalingGroupSettings.resource_key, + osHeatAutoScalingGroupSettings.modal_component); + + hotgenGlobals.update_node_labels( + osHeatAutoScalingGroupSettings.resource_key, + osHeatAutoScalingGroupSettings.label); + }]); + + + // Define controller + function osHeatAutoScalingGroupController($scope, hotgenGlobals, hotgenNotify, validationRules) { + this.$onInit = function(){ + $scope.dependson = this.dependson; + if (typeof this.autoscalinggroup.resource === 'undefined'){ + this.autoscalinggroup.resource = {'type': '', 'properties': [{}]}; + } + if (typeof this.autoscalinggroup.rolling_updates === 'undefined'){ + this.autoscalinggroup.rolling_updates = {}; + } + if (this.autoscalinggroup.resource.type){ + $scope.filecontent = hotgenGlobals.get_reference_file(this.autoscalinggroup.resource.type); + } + }; + + $scope.validate_integer = validationRules['integer']; + $scope.controller = this; + $scope.resource_types = []; + var resource_types = hotgenGlobals.get_resource_types(); + resource_types.forEach(function(element){ + $scope.resource_types.push(element.replace(/_/g, ':')); + }); + $scope.options = hotgenGlobals.get_resource_options(); + $scope.update_upload = function(){ + if ($scope.controller.autoscalinggroup && $scope.controller.autoscalinggroup.resource && $scope.controller.autoscalinggroup.resource.type.indexOf('.yaml') != -1){ + return 'true'; + } + return 'false'; + } + + $scope.is_upload = $scope.update_upload(); + + $scope.$watch('is_upload', function(newValue, oldValue){ + if (oldValue === newValue){ + return; + } + if (newValue === true || newValue === 'true'){ + $scope.controller.autoscalinggroup.resource.properties = [{}]; + if (!($scope.filecontent && $scope.filecontent.length >= 0)){ + $scope.controller.autoscalinggroup.resource.type = ''; + } + } else{ + // ; + } + }); + + $scope.file_upload = function(element){ + var file = element.files[0]; + if (!file){ + return; + } + var textType = /\.yaml$/; + if (file.name.match(textType)) { + var reader = new FileReader(); + $scope.controller.autoscalinggroup.resource.type = file.name; + reader.onload = function(e) { + hotgenNotify.show_success('Read file content.'); + hotgenGlobals.set_reference_file(file.name, reader.result) + $scope.filecontent = reader.result; + } + reader.readAsText(file); + } else { + hotgenNotify.show_error('File type is not supported.'); + } + } + $scope.clickUpload = function(){ + setTimeout(function () { + angular.element('#resourcetype-file').trigger('click'); + }, 0); + }; + this.delete_property = function(index){ + this.autoscalinggroup.resource.properties.splice(index, 1); + + } + this.add_property = function(){ + this.autoscalinggroup.resource.properties.push({}); + } + } + + function osHeatAutoScalingGroupPath (basePath){ + return basePath + 'js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.html'; + } + + osHeatAutoScalingGroupController.$inject = ['$scope', 'hotgenGlobals', 'hotgenNotify', + 'horizon.dashboard.project.heat_dashboard.template_generator.validationRules', + ]; + + osHeatAutoScalingGroupPath.$inject = ['horizon.dashboard.project.heat_dashboard.template_generator.basePath']; + + angular.module('horizon.dashboard.project.heat_dashboard.template_generator') + .component('osHeatAutoscalinggroup', { + templateUrl: osHeatAutoScalingGroupPath, + controller: osHeatAutoScalingGroupController, + bindings: { + 'autoscalinggroup': '=', + 'dependson': '=', + 'connectedoptions': '<', + 'formReference': '<', + } + }); + + +})(); diff --git a/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js new file mode 100644 index 00000000..37e12d8e --- /dev/null +++ b/heat_dashboard/static/dashboard/project/heat_dashboard/template_generator/js/resources/os__heat__autoscalinggroup/os__heat__autoscalinggroup.spec.js @@ -0,0 +1,128 @@ +(function() { + 'use strict'; + + describe('component os-heat-auto-scaling-group', function(){ + + beforeEach(module('horizon.dashboard.project.heat_dashboard.template_generator')); + + beforeEach(module('appTemplates')); + + var $scope, $isolateScope, $compile; + var hotgenNotify; + var element; + + beforeEach(inject(function($injector) { + $scope = $injector.get('$rootScope').$new(); + $compile = $injector.get('$compile'); + hotgenNotify = $injector.get('hotgenNotify'); + spyOn(hotgenNotify, 'show_success'); + spyOn(hotgenNotify, 'show_error'); + + $scope.resource = {}; + $scope.dependson = []; + $scope.connectedoptions = []; + $scope.resourceForm = {}; + + // element will enable you to test your directive's element on the DOM + element = $compile(angular.element(''))($scope); + + // Digest needs to be called to set any values on the directive's scope + $scope.$digest(); + + $isolateScope = element.isolateScope(); + })); + + it('find tab title Properties', function() { + expect(element.find('span').html()).toContain("Properties"); + expect($isolateScope.is_upload).toEqual('false'); + }); + + it('find tab title with resource set', function() { + $scope.resource = {resource: {type: 'filepath.yaml'}}; + + // element will enable you to test your directive's element on the DOM + element = $compile(angular.element(' +Layer 1Layer 2 + +