From 39f61a073a768e012cc33af6ba79de027cfdbba7 Mon Sep 17 00:00:00 2001 From: nimrodshn Date: Wed, 7 Jun 2017 19:18:49 +0300 Subject: [PATCH 1/2] add support for monitoring selection in UI some refactoring further refactoring further changes to ui for support refactoring moved the drop down to the provider section further refactoring further refactoring further refactoring add refactoring for support further support for edit Fixing specs and some refactoring minor refactoring some refactoring minor fixes in design Refactoring and renaming . . minor refactoring changed retrieve_metrics_selection refactored code: changed variable names to 'metric_' prefix and refactored 'retrieve_metrics' method some refactoring refactored code and tests refactored code a bit some refactoring some refactoring minor refactoring refactored a bit added authentication for prometheus losed unneeded parantheses refctored metricsStatusChanged added cred type fixed tab bug moved metrics down minor refactoring using angular now minor refactoring minor refactoring to tabs move from jquery to angular moved from querySelector to id refactor code very good commit refactored get route usless assignment bad refactor --- .../ems_common/ems_common_form_controller.js | 103 ++++++++--------- app/controllers/ems_container_controller.rb | 8 +- app/controllers/mixins/ems_common_angular.rb | 106 +++++++++++------- app/views/ems_container/_form.html.haml | 13 +++ .../angular/_multi_auth_credentials.html.haml | 62 +++++----- .../controllers/ems_common_controller_spec.rb | 34 +++--- .../ems_container_controller_spec.rb | 30 ++--- 7 files changed, 189 insertions(+), 167 deletions(-) diff --git a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js index 22a5fcc2df8..5c65826b5f7 100644 --- a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js +++ b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js @@ -10,13 +10,14 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' hostname: '', default_hostname: '', amqp_hostname: '', - hawkular_hostname: '', metrics_hostname: '', + metrics_selection: '', + metrics_api_port: '', + metrics_security_protocol: '', + metrics_tls_ca_certs: '', project: '', default_api_port: '', amqp_api_port: '', - hawkular_api_port: '', - metrics_api_port: '', api_version: '', default_security_protocol: '', default_tls_verify: true, @@ -24,8 +25,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' realm: '', security_protocol: '', amqp_security_protocol: '', - hawkular_security_protocol: '', - hawkular_tls_ca_certs: '', provider_region: '', default_userid: '', default_password: '', @@ -45,7 +44,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' host_default_vnc_port_start: '', host_default_vnc_port_end: '', event_stream_selection: '', - metrics_selection: '', bearer_token_exists: false, ems_controller: '', default_auth_status: '', @@ -53,7 +51,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' service_account_auth_status: '', metrics_auth_status: '', ssh_keypair_auth_status: '', - hawkular_auth_status: '', vmware_cloud_api_version: '' }; $scope.formId = emsCommonFormId; @@ -96,7 +93,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.hostname = data.hostname; $scope.emsCommonModel.default_hostname = data.default_hostname; $scope.emsCommonModel.amqp_hostname = data.amqp_hostname; - $scope.emsCommonModel.hawkular_hostname = data.hawkular_hostname; + $scope.emsCommonModel.metrics_selection = data.metrics_selection; $scope.emsCommonModel.metrics_hostname = data.metrics_hostname; $scope.emsCommonModel.project = data.project; @@ -105,9 +102,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.provider_id = data.provider_id !== undefined ? data.provider_id.toString() : ""; $scope.emsCommonModel.default_api_port = data.default_api_port !== undefined && data.default_api_port !== '' ? data.default_api_port.toString() : $scope.getDefaultApiPort($scope.emsCommonModel.emstype); + $scope.emsCommonModel.metrics_port = data.metrics_port !== undefined && data.metrics_port !== '' ? data.metrics_port.toString() : '443'; $scope.emsCommonModel.amqp_api_port = data.amqp_api_port !== undefined && data.amqp_api_port !== '' ? data.amqp_api_port.toString() : '5672'; - $scope.emsCommonModel.hawkular_api_port = data.hawkular_api_port !== undefined && data.hawkular_api_port !== '' ? data.hawkular_api_port.toString() : '443'; - $scope.emsCommonModel.metrics_api_port = data.metrics_api_port !== undefined && data.metrics_api_port !== '' ? data.metrics_api_port.toString() : ''; $scope.emsCommonModel.metrics_database_name = data.metrics_database_name !== undefined && data.metrics_database_name !== '' ? data.metrics_database_name : data.metrics_default_database_name; $scope.emsCommonModel.api_version = data.api_version; $scope.emsCommonModel.default_security_protocol = data.default_security_protocol; @@ -116,8 +112,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.default_tls_verify = data.default_tls_verify; $scope.emsCommonModel.default_tls_ca_certs = data.default_tls_ca_certs; $scope.emsCommonModel.amqp_security_protocol = data.amqp_security_protocol !== '' ? data.amqp_security_protocol : 'non-ssl'; - $scope.emsCommonModel.hawkular_security_protocol = data.hawkular_security_protocol; - $scope.emsCommonModel.hawkular_tls_ca_certs = data.hawkular_tls_ca_certs; + $scope.emsCommonModel.metrics_security_protocol = data.metrics_security_protocol; + $scope.emsCommonModel.metrics_tls_ca_certs = data.metrics_tls_ca_certs; $scope.emsCommonModel.provider_region = data.provider_region; $scope.emsCommonModel.default_userid = data.default_userid; $scope.emsCommonModel.amqp_userid = data.amqp_userid; @@ -135,8 +131,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.host_default_vnc_port_end = data.host_default_vnc_port_end; $scope.emsCommonModel.event_stream_selection = data.event_stream_selection; - $scope.emsCommonModel.metrics_selection = data.metrics_selection; - $scope.emsCommonModel.metrics_selection_default = data.metrics_selection_default; $scope.emsCommonModel.bearer_token_exists = data.bearer_token_exists; @@ -146,7 +140,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.service_account_auth_status = data.service_account_auth_status; $scope.emsCommonModel.metrics_auth_status = data.metrics_auth_status; $scope.emsCommonModel.ssh_keypair_auth_status = data.ssh_keypair_auth_status; - $scope.emsCommonModel.hawkular_auth_status = data.hawkular_auth_status; + $scope.emsCommonModel.metrics_api_port = data.metrics_api_port !== undefined && data.metrics_api_port !== '' ? data.metrics_api_port.toString() : '' if ($scope.emsCommonModel.default_userid !== '') { $scope.emsCommonModel.default_password = miqService.storedPasswordPlaceholder; @@ -183,22 +177,22 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.openstack_infra_providers_exist = data.openstack_infra_providers_exist; $scope.emsCommonModel.default_api_port = ''; $scope.emsCommonModel.amqp_api_port = '5672'; - $scope.emsCommonModel.metrics_selection = data.metrics_selection; - $scope.emsCommonModel.hawkular_api_port = '443'; $scope.emsCommonModel.api_version = 'v2'; $scope.emsCommonModel.ems_controller = data.ems_controller; $scope.emsCommonModel.ems_controller === 'ems_container' ? $scope.emsCommonModel.default_api_port = '8443' : $scope.emsCommonModel.default_api_port = ''; + $scope.emsCommonModel.metrics_api_port = '443'; + $scope.emsCommonModel.metrics_selection = data.metrics_selection; $scope.emsCommonModel.default_security_protocol = data.default_security_protocol; - $scope.emsCommonModel.hawkular_security_protocol = data.hawkular_security_protocol; + $scope.emsCommonModel.metrics_security_protocol = data.metrics_security_protocol; $scope.emsCommonModel.default_tls_ca_certs = data.default_tls_ca_certs; - $scope.emsCommonModel.hawkular_tls_ca_certs = data.hawkular_tls_ca_certs; + $scope.emsCommonModel.metrics_tls_ca_certs = data.metrics_tls_ca_certs; $scope.emsCommonModel.default_auth_status = data.default_auth_status; $scope.emsCommonModel.amqp_auth_status = data.amqp_auth_status; $scope.emsCommonModel.service_account_auth_status = data.service_account_auth_status; - $scope.emsCommonModel.metrics_auth_status = true; $scope.emsCommonModel.ssh_keypair_auth_status = true; - $scope.emsCommonModel.hawkular_auth_status = data.hawkular_auth_status; + $scope.emsCommonModel.metrics_auth_status = data.metrics_auth_status; $scope.emsCommonModel.vmware_cloud_api_version = '9.0'; + miqService.sparkleOff(); $scope.afterGet = true; @@ -253,9 +247,9 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' ($scope.emsCommonModel.default_hostname != '' && $scope.emsCommonModel.default_api_port) && ($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) { return true; - } else if(($scope.currentTab == "hawkular" && $scope.emsCommonModel.ems_controller == "ems_container") && + } else if(($scope.emsCommonModel.metrics_selection != "disabled" && $scope.emsCommonModel.ems_controller == "ems_container") && ($scope.emsCommonModel.emstype) && - ($scope.emsCommonModel.hawkular_hostname != '' && $scope.emsCommonModel.hawkular_api_port) && + ($scope.emsCommonModel.metrics_hostname != '' && $scope.emsCommonModel.metrics_api_port) && ($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) { return true; } else if($scope.emsCommonModel.emstype == "gce" && $scope.emsCommonModel.project != '' && @@ -268,7 +262,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' }; $scope.isDetectionEnabled = function() { - return ($scope.currentTab == "hawkular" && $scope.emsCommonModel.ems_controller == "ems_container") && + return ($scope.emsCommonModel.metrics_selection == "hawkular" && $scope.emsCommonModel.ems_controller == "ems_container") && ($scope.emsCommonModel.emstype == "openshift") && ($scope.emsCommonModel.default_hostname && $scope.emsCommonModel.default_api_port) && ($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid); @@ -306,10 +300,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.$broadcast('clearErrorOnTab', {tab: "amqp"}); } - if ($scope.emsCommonModel.metrics_selection === "hawkular_disabled") { - $scope.$broadcast('clearErrorOnTab', {tab: "hawkular"}); - } - var authStatus = $scope.currentTab + "_auth_status"; if ($scope.emsCommonModel[authStatus] === true) { $scope.postValidationModelRegistry($scope.currentTab); @@ -346,11 +336,19 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' } }; + $scope.metricSelectionChanged = function() { + if ($scope.emsCommonModel.metrics_selection == "disabled") { + $scope.changeAuthTab('default'); + angular.element('.nav-tabs a[href="#default"]').tab('show'); + angular.element("#metrics_tab").hide(); + } else { + angular.element("#metrics_tab").show(); + } + }; + $scope.providerTypeChanged = function() { if ($scope.emsCommonModel.ems_controller === 'ems_container') { $scope.emsCommonModel.default_api_port = "8443"; // TODO: correct per-type port - $scope.emsCommonModel.metrics_selection = "hawkular_".concat($scope.emsCommonModel.metrics_selection_default); - // Container types are nearly identical, no point resetting most fields on type change. return; } $scope.emsCommonModel.default_api_port = ""; @@ -431,9 +429,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' if ($scope.emsCommonModel.ssh_keypair_auth_status === true) { $scope.postValidationModelRegistry("ssh_keypair"); } - if ($scope.emsCommonModel.hawkular_auth_status === true) { - $scope.postValidationModelRegistry("hawkular"); - } }; $scope.postValidationModelRegistry = function(prefix) { @@ -441,8 +436,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.postValidationModel = {default: {}, amqp: {}, metrics: {}, - ssh_keypair: {}, - hawkular: {}} + ssh_keypair: {} + } } if (prefix === "default") { if ($scope.newRecord) { @@ -477,17 +472,22 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' amqp_password: amqp_password, }; } else if (prefix === "metrics") { - if ($scope.newRecord) { - var metrics_password = $scope.emsCommonModel.metrics_password; - } else { - var metrics_password = $scope.emsCommonModel.metrics_password === "" ? "" : miqService.storedPasswordPlaceholder; - } var metricsValidationModel = { - metrics_hostname: $scope.emsCommonModel.metrics_hostname, - metrics_api_port: $scope.emsCommonModel.metrics_api_port, - metrics_userid: $scope.emsCommonModel.metrics_userid, - metrics_password: metrics_password, + metrics_hostname: $scope.emsCommonModel.metrics_hostname, + metrics_api_port: $scope.emsCommonModel.metrics_api_port, }; + if ($scope.emsCommonModel.metrics_selection == "hawkular" || $scope.emsCommonModel.metrics_selection == "prometheus") { + metricsValidationModel.metrics_security_protocol = $scope.emsCommonModel.metrics_security_protocol; + metricsValidationModel.metrics_tls_ca_certs = $scope.emsCommonModel.metrics_tls_ca_certs; + } else { + if ($scope.newRecord) { + var metrics_password = $scope.emsCommonModel.metrics_password; + } else { + var metrics_password = $scope.emsCommonModel.metrics_password === "" ? "" : miqService.storedPasswordPlaceholder; + } + metricsValidationModel.metrics_userid = $scope.emsCommonModel.metrics_userid; + metricsValidationModel.metrics_password = metrics_password; + } $scope.postValidationModel['metrics'] = metricsValidationModel; } else if (prefix === "ssh_keypair") { if ($scope.newRecord) { @@ -503,13 +503,6 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.postValidationModel['service_account'] = { service_account: $scope.emsCommonModel.service_account } - } else if (prefix === "hawkular") { - $scope.postValidationModel['hawkular'] = { - hawkular_hostname: $scope.emsCommonModel.hawkular_hostname, - hawkular_api_port: $scope.emsCommonModel.hawkular_api_port, - hawkular_security_protocol: $scope.emsCommonModel.hawkular_security_protocol, - hawkular_tls_ca_certs: $scope.emsCommonModel.hawkular_tls_ca_certs, - } } }; @@ -534,7 +527,7 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' }; $scope.updateHawkularHostname = function(value) { - $scope.emsCommonModel.hawkular_hostname = value; + $scope.emsCommonModel.metrics_hostname = value; }; $scope.radioSelectionChanged = function() { @@ -551,11 +544,5 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' } }; - $scope.containerMetricsChanged = function() { - if ($scope.emsCommonModel.metrics_selection === "hawkular_disabled") { - $scope.$broadcast('clearErrorOnTab', {tab: "hawkular"}); - } - }; - init(); }]); diff --git a/app/controllers/ems_container_controller.rb b/app/controllers/ems_container_controller.rb index 36b3d49a5c9..d63177acdab 100644 --- a/app/controllers/ems_container_controller.rb +++ b/app/controllers/ems_container_controller.rb @@ -92,7 +92,13 @@ def get_hostname_from_routes(ems) end def retrieve_metrics_selection - @ems.endpoints.count == 1 ? 'hawkular_disabled' : 'hawkular_enabled' + if @ems.connection_configurations.try(:prometheus) + "prometheus" + elsif @ems.connection_configurations.try(:hawkular) + "hawkular" + else + "disabled" + end end private diff --git a/app/controllers/mixins/ems_common_angular.rb b/app/controllers/mixins/ems_common_angular.rb index a8979de1f49..f2bbefe044f 100644 --- a/app/controllers/mixins/ems_common_angular.rb +++ b/app/controllers/mixins/ems_common_angular.rb @@ -140,11 +140,9 @@ def ems_form_fields metrics_hostname = "" metrics_port = "" metrics_database_name = "" + metrics_security_protocol = security_protocol_default + metrics_tls_ca_certs = "" keystone_v3_domain_id = "" - hawkular_hostname = "" - hawkular_api_port = "" - hawkular_security_protocol = security_protocol_default - hawkular_tls_ca_certs = "" if @ems.connection_configurations.amqp.try(:endpoint) amqp_hostname = @ems.connection_configurations.amqp.endpoint.hostname @@ -177,12 +175,21 @@ def ems_form_fields end if @ems.connection_configurations.hawkular.try(:endpoint) - hawkular_hostname = @ems.connection_configurations.hawkular.endpoint.hostname - hawkular_api_port = @ems.connection_configurations.hawkular.endpoint.port - hawkular_auth_status = @ems.authentication_status_ok?(:hawkular) - hawkular_security_protocol = @ems.connection_configurations.hawkular.endpoint.security_protocol - hawkular_security_protocol ||= security_protocol_default - hawkular_tls_ca_certs = @ems.connection_configurations.hawkular.endpoint.certificate_authority + metrics_hostname = @ems.connection_configurations.hawkular.endpoint.hostname + metrics_port = @ems.connection_configurations.hawkular.endpoint.port + metrics_auth_status = @ems.authentication_status_ok?(:hawkular) + metrics_security_protocol = @ems.connection_configurations.hawkular.endpoint.security_protocol + metrics_security_protocol ||= security_protocol_default + metrics_tls_ca_certs = @ems.connection_configurations.hawkular.endpoint.certificate_authority + end + + if @ems.connection_configurations.prometheus.try(:endpoint) + metrics_hostname = @ems.connection_configurations.prometheus.endpoint.hostname + metrics_port = @ems.connection_configurations.prometheus.endpoint.port + metrics_auth_status = @ems.authentication_status_ok?(:prometheus) + metrics_security_protocol = @ems.connection_configurations.prometheus.endpoint.security_protocol + metrics_security_protocol ||= security_protocol_default + metrics_tls_ca_certs = @ems.connection_configurations.prometheus.endpoint.certificate_authority end if @ems.connection_configurations.default.try(:endpoint) @@ -278,29 +285,29 @@ def ems_form_fields :ssh_keypair_auth_status => ssh_keypair_auth_status.nil? ? true : ssh_keypair_auth_status } if controller_name == "ems_infra" - render :json => {:name => @ems.name, - :emstype => @ems.emstype, - :zone => zone, - :hostname => @ems.hostname, - :default_hostname => @ems.connection_configurations.default.endpoint.hostname, - :metrics_selection => retrieve_metrics_selection, - :metrics_selection_default => @ems.emstype == 'kubernetes' ? 'disabled' : 'enabled', - :hawkular_hostname => hawkular_hostname, - :default_api_port => @ems.connection_configurations.default.endpoint.port, - :hawkular_api_port => hawkular_api_port, - :api_version => @ems.api_version ? @ems.api_version : "v2", - :default_security_protocol => default_security_protocol, - :hawkular_security_protocol => hawkular_security_protocol, - :default_tls_ca_certs => default_tls_ca_certs, - :hawkular_tls_ca_certs => hawkular_tls_ca_certs, - :provider_region => @ems.provider_region, - :default_userid => @ems.authentication_userid ? @ems.authentication_userid : "", - :service_account => service_account ? service_account : "", - :bearer_token_exists => @ems.authentication_token(:bearer).nil? ? false : true, - :ems_controller => controller_name, - :default_auth_status => default_auth_status, - :hawkular_auth_status => hawkular_auth_status, - } if controller_name == "ems_container" + if controller_name == "ems_container" + render :json => {:name => @ems.name, + :emstype => @ems.emstype, + :zone => zone, + :hostname => @ems.hostname, + :default_hostname => @ems.connection_configurations.default.endpoint.hostname, + :default_api_port => @ems.connection_configurations.default.endpoint.port, + :metrics_selection => retrieve_metrics_selection, + :metrics_selection_default => @ems.emstype == 'kubernetes' ? 'disabled' : 'enabled', + :metrics_hostname => metrics_hostname, + :metrics_api_port => metrics_port, + :metrics_tls_ca_certs => metrics_tls_ca_certs, + :metrics_security_protocol => metrics_security_protocol, + :api_version => @ems.api_version ? @ems.api_version : "v2", + :default_security_protocol => default_security_protocol, + :default_tls_ca_certs => default_tls_ca_certs, + :provider_region => @ems.provider_region, + :default_userid => @ems.authentication_userid ? @ems.authentication_userid : "", + :service_account => service_account ? service_account : "", + :bearer_token_exists => @ems.authentication_token(:bearer).nil? ? false : true, + :ems_controller => controller_name, + :default_auth_status => default_auth_status} + end if controller_name == "ems_middleware" render :json => {:name => @ems.name, @@ -368,17 +375,16 @@ def set_ems_record_vars(ems, mode = nil) metrics_hostname = params[:metrics_hostname].strip if params[:metrics_hostname] metrics_port = params[:metrics_api_port].strip if params[:metrics_api_port] metrics_database_name = params[:metrics_database_name].strip if params[:metrics_database_name] - hawkular_hostname = params[:hawkular_hostname].strip if params[:hawkular_hostname] - hawkular_api_port = params[:hawkular_api_port].strip if params[:hawkular_api_port] - hawkular_security_protocol = params[:hawkular_security_protocol].strip if params[:hawkular_security_protocol] + metrics_security_protocol = params[:metrics_security_protocol].strip if params[:metrics_security_protocol] + metrics_tls_ca_certs = params[:metrics_tls_ca_certs].strip if params[:metrics_tls_ca_certs] default_tls_ca_certs = params[:default_tls_ca_certs].strip if params[:default_tls_ca_certs] - hawkular_tls_ca_certs = params[:hawkular_tls_ca_certs].strip if params[:hawkular_tls_ca_certs] default_endpoint = {} amqp_endpoint = {} ceilometer_endpoint = {} ssh_keypair_endpoint = {} metrics_endpoint = {} hawkular_endpoint = {} + prometheus_endpoint = {} if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) default_endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} @@ -438,9 +444,18 @@ def set_ems_record_vars(ems, mode = nil) params[:cred_type] = ems.default_authentication_type if params[:cred_type] == "default" default_endpoint = {:role => :default, :hostname => hostname, :port => port} default_endpoint.merge!(endpoint_security_options(ems.security_protocol, default_tls_ca_certs)) - if params[:metrics_selection] == 'hawkular_enabled' - hawkular_endpoint = {:role => :hawkular, :hostname => hawkular_hostname, :port => hawkular_api_port} - hawkular_endpoint.merge!(endpoint_security_options(hawkular_security_protocol, hawkular_tls_ca_certs)) + if params[:metrics_selection] == 'hawkular' + if metrics_hostname.blank? + default_key = params[:default_password] || ems.authentication_key + metrics_hostname = get_hostname_from_routes(ems, default_endpoint, default_key) + end + params[:cred_type] = "hawkular" + hawkular_endpoint = {:role => :hawkular, :hostname => metrics_hostname, :port => metrics_port} + hawkular_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs)) + elsif params[:metrics_selection] == 'prometheus' + params[:cred_type] = "prometheus" + prometheus_endpoint = {:role => :prometheus, :hostname => metrics_hostname, :port => metrics_port} + prometheus_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs)) end end @@ -467,7 +482,8 @@ def set_ems_record_vars(ems, mode = nil) :amqp => amqp_endpoint, :ssh_keypair => ssh_keypair_endpoint, :metrics => metrics_endpoint, - :hawkular => hawkular_endpoint} + :hawkular => hawkular_endpoint, + :prometheus => prometheus_endpoint} build_connection(ems, endpoints, mode) end @@ -484,7 +500,7 @@ def build_connection(ems, endpoints, mode) authentications = build_credentials(ems, mode) configurations = [] - [:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular].each do |role| + [:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular, :prometheus].each do |role| configurations << build_configuration(ems, authentications, endpoints, role) end @@ -536,7 +552,11 @@ def build_credentials(ems, mode) end if ems.kind_of?(ManageIQ::Providers::ContainerManager) default_key = params[:default_password] ? params[:default_password] : ems.authentication_key - creds[:hawkular] = {:auth_key => default_key, :save => (mode != :validate)} + if params[:metrics_selection] == "hawkular" + creds[:hawkular] = {:auth_key => default_key, :save => (mode != :validate)} + elsif params[:metrics_selection] == "prometheus" + creds[:prometheus] = {:auth_key => default_key, :save => (mode != :validate)} + end creds[:bearer] = {:auth_key => default_key, :save => (mode != :validate)} creds.delete(:default) end diff --git a/app/views/ems_container/_form.html.haml b/app/views/ems_container/_form.html.haml index 663be8d0643..fb29b976080 100644 --- a/app/views/ems_container/_form.html.haml +++ b/app/views/ems_container/_form.html.haml @@ -63,6 +63,19 @@ "required" => "", "selectpicker-for-select-tag" => "") + .form-group{"ng-class" => "{'has-error': angularForm.metrics.$invalid}"} + %label.col-md-2.control-label{"for" => "prov_metrics"} + = _("Metrics") + .col-md-8 + = select_tag('metrics_selection', options_for_select([[_("Disabled"), "disabled"], [_("Hawkular"), "hawkular"], + [_("Prometheus"), "prometheus"]]), + "ng-model" => "emsCommonModel.metrics_selection", + "ng-change" => "metricSelectionChanged()", + "checkchange" => "", + "required" => "", + "selectpicker-for-select-tag" => "") + + %hr = render :partial => "layouts/angular/multi_auth_credentials", :locals => {:record => @ems, :ng_model => "emsCommonModel"} diff --git a/app/views/layouts/angular/_multi_auth_credentials.html.haml b/app/views/layouts/angular/_multi_auth_credentials.html.haml index a0019230b09..134c4e8911f 100644 --- a/app/views/layouts/angular/_multi_auth_credentials.html.haml +++ b/app/views/layouts/angular/_multi_auth_credentials.html.haml @@ -1,11 +1,8 @@ - validate_url ||= (record.id || @selected_hosts) ? "update" : "create" -- legendtext ||= _("Endpoints") - vm_scope ||= false - main_scope = vm_scope ? "$parent.vm" : "$parent" #auth_tabs - %h3 - = legendtext %ul.nav.nav-tabs = miq_tab_header('default', nil, {'ng-click' => "changeAuthTab('default')"}) do %i{"error-on-tab" => "default", :style => "color:#cc0000"} @@ -21,9 +18,10 @@ %i{"error-on-tab" => "ssh_keypair", :style => "color:#cc0000"} = _("RSA key pair") - elsif controller_name == "ems_container" - = miq_tab_header('hawkular', nil, {'ng-click' => "changeAuthTab('hawkular')"}) do - %i{"error-on-tab" => "hawkular", :style => "color:#cc0000"} - = _("Hawkular") + = miq_tab_header('metrics', nil, 'ng-click' => "changeAuthTab('metrics')") do + %div{"ng-if" => "emsCommonModel.metrics_selection == 'prometheus' || emsCommonModel.metrics_selection == 'hawkular'"} + %i{"error-on-tab" => "metrics", :style => "color:#cc0000"} + = _("Metrics") - elsif controller_name == "host" = miq_tab_header('remote', nil, {'ng-click' => "changeAuthTab('remote')"}) do = _("Remote Login") @@ -252,38 +250,17 @@ %span{:style => "color:black"} = _("Used for SSH connection to all %{hosts} in this provider.") % {:hosts => title_for_hosts} - elsif controller_name == "ems_container" - = miq_tab_content('hawkular', 'default') do + = miq_tab_content('metrics', 'default') do .form-group .col-md-12.col-md-12 - %label.radio-inline.control-label{"for" => "container_hawkular_disabled"} - %input{:type => "radio", - :name => "metrics_selection", - :id => "container_hawkular_disabled", - :ng_checked => "emsCommonModel.metrics_selection == hawkular_disabled", - :value => "hawkular_disabled", - :ng_model => "emsCommonModel.metrics_selection", - :ng_change => "containerMetricsChanged()", - :checkchange => ""} - = _("Disabled") - %label.radio-inline.control-label{"for" => "container_hawkular_enabled"} - %input{:type => "radio", - :name => "metrics_selection", - :id => "container_hawkular_enabled", - :ng_checked => "emsCommonModel.metrics_selection == hawkular_enabled", - :value => "hawkular_enabled", - :ng_model => "emsCommonModel.metrics_selection", - :checkchange => ""} - = _("Enabled") - %hr - %div{"ng-if" => "emsCommonModel.metrics_selection == 'hawkular_enabled'"} - + %div{"ng-if" => "emsCommonModel.metrics_selection == 'hawkular'"} = render :partial => "layouts/angular-bootstrap/endpoints_angular", :locals => {:ng_show => true, :ng_model => ng_model.to_s, :id => record.id, :ng_reqd_hostname => "true", :ng_reqd_api_port => "true", - :prefix => "hawkular", + :prefix => "metrics", :detection => true} = render :partial => "layouts/angular-bootstrap/auth_credentials_angular_bootstrap", :locals => {:ng_show => true, @@ -293,9 +270,30 @@ :ng_show_password => "false", :validate_url => validate_url, :id => record.id, - :prefix => "hawkular", + :prefix => "metrics", :verify_title_off => _("hawkular URL and API port fields are needed to perform validation."), :basic_info_needed => true} + + %div{"ng-if" => "emsCommonModel.metrics_selection == 'prometheus'"} + = render :partial => "layouts/angular-bootstrap/endpoints_angular", + :locals => {:ng_show => true, + :ng_model => ng_model.to_s, + :id => record.id, + :ng_reqd_hostname => "true", + :ng_reqd_api_port => "true", + :prefix => "metrics"} + = render :partial => "layouts/angular-bootstrap/auth_credentials_angular_bootstrap", + :locals => {:ng_show => true, + :ng_model => ng_model.to_s, + :main_scope => main_scope, + :ng_show_userid => "false", + :ng_show_password => "false", + :ng_show_verify => "false", + :validate_url => validate_url, + :id => record.id, + :prefix => "metrics", + :verify_title_off => _("prometheus URL and API port fields are needed to perform validation."), + :basic_info_needed => true} .form-group .col-md-12 %span{:style => "color:black"} @@ -388,7 +386,7 @@ $('#auth_tabs').show(); %div{"ng-if" => "#{ng_model}.ems_controller == 'ems_container'"} :javascript - miq_tabs_show_hide("#hawkular_tab", true); + miq_tabs_show_hide("#metrics_tab", true); miq_tabs_init('#auth_tabs'); $('#auth_tabs').show(); diff --git a/spec/controllers/ems_common_controller_spec.rb b/spec/controllers/ems_common_controller_spec.rb index 99ae3772b6e..863bfaf75f9 100644 --- a/spec/controllers/ems_common_controller_spec.rb +++ b/spec/controllers/ems_common_controller_spec.rb @@ -85,13 +85,11 @@ context "adding new provider without hawkular endpoint" do def test_creating(emstype) raise ArgumentError, "Unsupported type [#{emstype}]" unless %w(kubernetes openshift).include?(emstype) - metrics_selection = "hawkular_#{emstype == 'kubernetes' ? 'disabled' : 'enabled'}" @ems = ExtManagementSystem.model_from_emstype(emstype).new controller.instance_variable_set(:@_params, :name => 'NimiCule', :default_userid => '_', :default_hostname => 'mytest.com', - :metrics_selection => metrics_selection, :default_api_port => '8443', :default_password => 'valid-token', :emstype => emstype) @@ -106,7 +104,7 @@ def test_creating(emstype) it "doesn't probe openshift for kubernetes" do test_creating('openshift') - expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq(nil) + expect(@ems.connection_configurations.hawkular).to eq(nil) end end @@ -118,18 +116,18 @@ def test_creating(emstype) end def test_setting_many_fields - controller.instance_variable_set(:@_params, :name => 'EMS 2', - :default_userid => '_', - :default_hostname => '10.10.10.11', - :default_api_port => '5000', - :default_security_protocol => 'ssl-with-validation-custom-ca', - :default_tls_ca_certs => '-----BEGIN DUMMY...', - :default_password => 'valid-token', - :metrics_selection => 'hawkular_enabled', - :hawkular_hostname => '10.10.10.10', - :hawkular_api_port => '8443', - :hawkular_security_protocol => 'ssl-with-validation', - :emstype => @type) + controller.instance_variable_set(:@_params, :name => 'EMS 2', + :default_userid => '_', + :default_hostname => '10.10.10.11', + :default_api_port => '5000', + :default_security_protocol => 'ssl-with-validation-custom-ca', + :default_tls_ca_certs => '-----BEGIN DUMMY...', + :default_password => 'valid-token', + :metrics_selection => 'hawkular', + :metrics_hostname => '10.10.10.10', + :metrics_api_port => '8443', + :metrics_security_protocol => 'ssl-with-validation', + :emstype => @type) controller.send(:set_ems_record_vars, @ems) expect(@flash_array).to be_nil cc = @ems.connection_configurations @@ -150,7 +148,7 @@ def test_setting_many_fields def test_setting_few_fields controller.remove_instance_variable(:@_params) - controller.instance_variable_set(:@_params, :name => 'EMS 3', :default_userid => '_', :metrics_selection => 'hawkular_enabled') + controller.instance_variable_set(:@_params, :name => 'EMS 3', :default_userid => '_') controller.send(:set_ems_record_vars, @ems) expect(@flash_array).to be_nil expect(@ems.authentication_token("bearer")).to eq('valid-token') @@ -163,7 +161,7 @@ def test_setting_few_fields test_setting_many_fields test_setting_few_fields - expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq(nil) + expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq('10.10.10.10') end it "when editing openshift EMS" do @@ -172,7 +170,7 @@ def test_setting_few_fields test_setting_many_fields test_setting_few_fields - expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq(nil) + expect(@ems.connection_configurations.hawkular.endpoint.hostname).to eq('10.10.10.10') end end end diff --git a/spec/controllers/ems_container_controller_spec.rb b/spec/controllers/ems_container_controller_spec.rb index 2c3e26904cb..e073097965c 100644 --- a/spec/controllers/ems_container_controller_spec.rb +++ b/spec/controllers/ems_container_controller_spec.rb @@ -139,21 +139,21 @@ it "Creates a provider with two endpoints if hawkular is enabled" do post :create, :params => { - "button" => "add", - "cred_type" => "hawkular", - "name" => "openshift_no_hawkular", - "emstype" => "openshift", - "zone" => 'default', - "default_security_protocol" => "ssl-without-validation", - "default_hostname" => "default_hostname", - "default_api_port" => "5000", - "default_userid" => "", - "default_password" => "", - "provider_region" => "", - "metrics_selection" => "hawkular_enabled", - "hawkular_security_protocol" => "ssl-without-validation", - "hawkular_hostname" => "hawkular_hostname", - "hawkular_api_port" => "443", + "button" => "add", + "cred_type" => "hawkular", + "name" => "openshift_no_hawkular", + "emstype" => "openshift", + "zone" => 'default', + "default_security_protocol" => "ssl-without-validation", + "default_hostname" => "default_hostname", + "default_api_port" => "5000", + "default_userid" => "", + "default_password" => "", + "provider_region" => "", + "metrics_selection" => "hawkular", + "metrics_security_protocol" => "ssl-without-validation", + "metrics_hostname" => "hawkular_hostname", + "metrics_api_port" => "443", } expect(response.status).to eq(200) ems_openshift = ManageIQ::Providers::ContainerManager.first From 91e1e997d052ce7d4bef7befa5dcde7823e46162 Mon Sep 17 00:00:00 2001 From: yaacov Date: Wed, 30 Aug 2017 10:49:49 +0300 Subject: [PATCH 2/2] fix codeclimate dup --- app/controllers/mixins/ems_common_angular.rb | 24 +++++++++----------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/controllers/mixins/ems_common_angular.rb b/app/controllers/mixins/ems_common_angular.rb index f2bbefe044f..c505a7670b0 100644 --- a/app/controllers/mixins/ems_common_angular.rb +++ b/app/controllers/mixins/ems_common_angular.rb @@ -174,22 +174,20 @@ def ems_form_fields keystone_v3_domain_id = @ems.keystone_v3_domain_id end - if @ems.connection_configurations.hawkular.try(:endpoint) - metrics_hostname = @ems.connection_configurations.hawkular.endpoint.hostname - metrics_port = @ems.connection_configurations.hawkular.endpoint.port - metrics_auth_status = @ems.authentication_status_ok?(:hawkular) - metrics_security_protocol = @ems.connection_configurations.hawkular.endpoint.security_protocol - metrics_security_protocol ||= security_protocol_default - metrics_tls_ca_certs = @ems.connection_configurations.hawkular.endpoint.certificate_authority + if respond_to?(:retrieve_metrics_selection) + metrics_selection = retrieve_metrics_selection.to_sym + connection_configurations_metrics_endpoint = @ems.connection_configurations.try(metrics_selection).try(:endpoint) + else + connection_configurations_metrics_endpoint = nil end - if @ems.connection_configurations.prometheus.try(:endpoint) - metrics_hostname = @ems.connection_configurations.prometheus.endpoint.hostname - metrics_port = @ems.connection_configurations.prometheus.endpoint.port - metrics_auth_status = @ems.authentication_status_ok?(:prometheus) - metrics_security_protocol = @ems.connection_configurations.prometheus.endpoint.security_protocol + if connection_configurations_metrics_endpoint + metrics_hostname = connection_configurations_metrics_endpoint.hostname + metrics_port = connection_configurations_metrics_endpoint.port + metrics_auth_status = @ems.authentication_status_ok?(metrics_selection) + metrics_security_protocol = connection_configurations_metrics_endpoint.security_protocol metrics_security_protocol ||= security_protocol_default - metrics_tls_ca_certs = @ems.connection_configurations.prometheus.endpoint.certificate_authority + metrics_tls_ca_certs = connection_configurations_metrics_endpoint.certificate_authority end if @ems.connection_configurations.default.try(:endpoint)