Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alerts drop down to provider view #1918

Merged
merged 7 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
service_account_auth_status: '',
metrics_auth_status: '',
ssh_keypair_auth_status: '',
vmware_cloud_api_version: ''
vmware_cloud_api_version: '',
prometheus_alerts_hostname: '',
prometheus_alerts_api_port: '',
prometheus_alerts_tls_ca_certs: '',
prometheus_alerts_auth_status: '',
prometheus_alerts_security_protocol: '',
alerts_selection: '',
};
$scope.formId = emsCommonFormId;
$scope.afterGet = false;
Expand Down Expand Up @@ -140,7 +146,13 @@ 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.metrics_api_port = data.metrics_api_port !== undefined && data.metrics_api_port !== '' ? data.metrics_api_port.toString() : ''
$scope.emsCommonModel.metrics_api_port = data.metrics_api_port !== undefined && data.metrics_api_port !== '' ? data.metrics_api_port.toString() : '';
$scope.emsCommonModel.alerts_selection = data.alerts_selection;
$scope.emsCommonModel.prometheus_alerts_hostname = data.prometheus_alerts_hostname;
$scope.emsCommonModel.prometheus_alerts_api_port = data.prometheus_alerts_api_port !== undefined && data.prometheus_alerts_api_port !== '' ? data.prometheus_alerts_api_port.toString() : '443';
$scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status;
$scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol;
$scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs;

if ($scope.emsCommonModel.default_userid !== '') {
$scope.emsCommonModel.default_password = miqService.storedPasswordPlaceholder;
Expand Down Expand Up @@ -177,6 +189,11 @@ 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.alerts_selection = data.alerts_selection;
$scope.emsCommonModel.prometheus_alerts_api_port = '443';
$scope.emsCommonModel.prometheus_alerts_auth_status = data.prometheus_alerts_auth_status;
$scope.emsCommonModel.prometheus_alerts_security_protocol = data.prometheus_alerts_security_protocol;
$scope.emsCommonModel.prometheus_alerts_tls_ca_certs = data.prometheus_alerts_tls_ca_certs;
$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 = '';
Expand Down Expand Up @@ -247,10 +264,15 @@ 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.emsCommonModel.metrics_selection != "disabled" && $scope.emsCommonModel.ems_controller == "ems_container") &&
} else if(($scope.emsCommonModel.ems_controller == "ems_container") &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use === instead of ==

Also, a space is preferred after if per style guide

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AparnaKarve Thanks 👍 the if with no space, looked wrong ... but codeclimate didn't shout so I thought is was ok :-)

($scope.emsCommonModel.emstype) &&
($scope.emsCommonModel.metrics_hostname != '' && $scope.emsCommonModel.metrics_api_port) &&
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) {
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly !== instead of !=

Please apply this elsewhere too (to all your PR changes where this is applicable)

(($scope.currentTab == "metrics" &&
$scope.emsCommonModel.metrics_hostname != '' &&
$scope.emsCommonModel.metrics_api_port) ||
($scope.currentTab == "alerts" &&
$scope.emsCommonModel.prometheus_alerts_hostname != '' &&
$scope.emsCommonModel.prometheus_alerts_api_port != ''))) {
return true;
} else if($scope.emsCommonModel.emstype == "gce" && $scope.emsCommonModel.project != '' &&
($scope.currentTab == "default" ||
Expand Down Expand Up @@ -336,16 +358,24 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
}
};

$scope.metricSelectionChanged = function() {
if ($scope.emsCommonModel.metrics_selection == "disabled") {
$scope.tabSelectionChanged = function(tabSelector, selection) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice @yaacov ! 👍 🐈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you seating at a beach drinking from a coconut, and commenting on hard working peoples PR's ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, just your'e PR's! 😉

if (selection == "disabled") {
$scope.changeAuthTab('default');
angular.element('.nav-tabs a[href="#default"]').tab('show');
angular.element("#metrics_tab").hide();
angular.element(tabSelector).hide();
} else {
angular.element("#metrics_tab").show();
angular.element(tabSelector).show();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is OK for the first pass, since it has already been tested.
But I'm wondering if we should move this code in a directive later.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍 , the whole ruby = select_tag(... in the .haml file, should be in angular so will not need this hack :-(

};

$scope.metricSelectionChanged = function() {
$scope.tabSelectionChanged("#metrics_tab", $scope.emsCommonModel.metrics_selection);
};

$scope.alertsSelectionChanged = function() {
$scope.tabSelectionChanged("#alerts_tab", $scope.emsCommonModel.alerts_selection);
};

$scope.providerTypeChanged = function() {
if ($scope.emsCommonModel.ems_controller === 'ems_container') {
$scope.emsCommonModel.default_api_port = "8443"; // TODO: correct per-type port
Expand Down Expand Up @@ -429,14 +459,19 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
if ($scope.emsCommonModel.ssh_keypair_auth_status === true) {
$scope.postValidationModelRegistry("ssh_keypair");
}
if ($scope.emsCommonModel.prometheus_alerts_auth_status === true) {
$scope.postValidationModelRegistry("prometheus_alerts");
}
};

$scope.postValidationModelRegistry = function(prefix) {
if ($scope.postValidationModel === undefined) {
$scope.postValidationModel = {default: {},
amqp: {},
metrics: {},
ssh_keypair: {}
$scope.postValidationModel = {
default: {},
amqp: {},
metrics: {},
ssh_keypair: {},
prometheus_alerts: {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing comma is missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks ! how did this pass code climate ?

}
}
if (prefix === "default") {
Expand Down Expand Up @@ -503,6 +538,12 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.postValidationModel['service_account'] = {
service_account: $scope.emsCommonModel.service_account
}
} else if (prefix == "prometheus_alerts") {
$scope.postValidationModel['prometheus_alerts'] = {};
['prometheus_alerts_hostname', 'prometheus_alerts_api_port', 'prometheus_alerts_security_protocol', 'prometheus_alerts_tls_ca_certs']
.forEach( function(resource) {
$scope.postValidationModel['prometheus_alerts'][resource] = $scope.emsCommonModel[resource];
});
}
};

Expand Down
5 changes: 5 additions & 0 deletions app/controllers/ems_container_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def retrieve_metrics_selection
end
end

def retrieve_alerts_selection
return "disabled" if @ems.connection_configurations.try(:prometheus_alerts).nil?
"prometheus"
end

private

def textual_group_list
Expand Down
93 changes: 63 additions & 30 deletions app/controllers/mixins/ems_common_angular.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def ems_form_fields
metrics_security_protocol = security_protocol_default
metrics_tls_ca_certs = ""
keystone_v3_domain_id = ""
prometheus_alerts_hostname = ""
prometheus_alerts_api_port = ""
prometheus_alerts_security_protocol = security_protocol_default
prometheus_alerts_tls_ca_certs = ""

if @ems.connection_configurations.amqp.try(:endpoint)
amqp_hostname = @ems.connection_configurations.amqp.endpoint.hostname
Expand Down Expand Up @@ -190,6 +194,15 @@ def ems_form_fields
metrics_tls_ca_certs = connection_configurations_metrics_endpoint.certificate_authority
end

if @ems.connection_configurations.prometheus_alerts.try(:endpoint)
prometheus_alerts_hostname = @ems.connection_configurations.prometheus_alerts.endpoint.hostname
prometheus_alerts_api_port = @ems.connection_configurations.prometheus_alerts.endpoint.port
prometheus_alerts_auth_status = @ems.authentication_status_ok?(:alerts)
prometheus_alerts_security_protocol = @ems.connection_configurations.prometheus_alerts.endpoint.security_protocol
prometheus_alerts_security_protocol ||= security_protocol_default
prometheus_alerts_tls_ca_certs = @ems.connection_configurations.prometheus_alerts.endpoint.certificate_authority
end

if @ems.connection_configurations.default.try(:endpoint)
default_hostname = @ems.connection_configurations.default.endpoint.hostname
default_api_port = @ems.connection_configurations.default.endpoint.port
Expand Down Expand Up @@ -284,28 +297,34 @@ def ems_form_fields
} if controller_name == "ems_infra"

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,
:metrics_auth_status => metrics_auth_status.nil? ? false : metrics_auth_status}
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,
:metrics_auth_status => metrics_auth_status.nil? ? false : metrics_auth_status,
:prometheus_alerts_api_port => prometheus_alerts_api_port,
:prometheus_alerts_hostname => prometheus_alerts_hostname,
:prometheus_alerts_security_protocol => prometheus_alerts_security_protocol,
:prometheus_alerts_tls_ca_certs => prometheus_alerts_tls_ca_certs,
:prometheus_alerts_auth_status => prometheus_alerts_auth_status,
:alerts_selection => retrieve_alerts_selection}
end

if controller_name == "ems_middleware"
Expand Down Expand Up @@ -377,13 +396,18 @@ def set_ems_record_vars(ems, mode = nil)
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]
prometheus_alerts_tls_ca_certs = params[:prometheus_alerts_tls_ca_certs].strip if params[:prometheus_alerts_tls_ca_certs]
prometheus_alerts_hostname = params[:prometheus_alerts_hostname].strip if params[:prometheus_alerts_hostname]
prometheus_alerts_api_port = params[:prometheus_alerts_api_port].strip if params[:prometheus_alerts_api_port]
prometheus_alerts_security_protocol = params[:prometheus_alerts_security_protocol].strip if params[:prometheus_alerts_security_protocol]
default_endpoint = {}
amqp_endpoint = {}
ceilometer_endpoint = {}
ssh_keypair_endpoint = {}
metrics_endpoint = {}
hawkular_endpoint = {}
prometheus_endpoint = {}
prometheus_alerts_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}
Expand Down Expand Up @@ -456,6 +480,11 @@ def set_ems_record_vars(ems, mode = nil)
prometheus_endpoint = {:role => :prometheus, :hostname => metrics_hostname, :port => metrics_port}
prometheus_endpoint.merge!(endpoint_security_options(metrics_security_protocol, metrics_tls_ca_certs))
end
if params[:alerts_selection] == 'prometheus'
params[:cred_type] = "prometheus_alerts"
prometheus_alerts_endpoint = {:role => :prometheus_alerts, :hostname => prometheus_alerts_hostname, :port => prometheus_alerts_api_port}
prometheus_alerts_endpoint.merge!(endpoint_security_options(prometheus_alerts_security_protocol, prometheus_alerts_tls_ca_certs))
end
end

if ems.kind_of?(ManageIQ::Providers::MiddlewareManager)
Expand All @@ -476,13 +505,14 @@ def set_ems_record_vars(ems, mode = nil)
default_endpoint = {:role => :default, :hostname => hostname, :port => port}
end

endpoints = {:default => default_endpoint,
:ceilometer => ceilometer_endpoint,
:amqp => amqp_endpoint,
:ssh_keypair => ssh_keypair_endpoint,
:metrics => metrics_endpoint,
:hawkular => hawkular_endpoint,
:prometheus => prometheus_endpoint}
endpoints = {:default => default_endpoint,
:ceilometer => ceilometer_endpoint,
:amqp => amqp_endpoint,
:ssh_keypair => ssh_keypair_endpoint,
:metrics => metrics_endpoint,
:hawkular => hawkular_endpoint,
:prometheus => prometheus_endpoint,
:prometheus_alerts => prometheus_alerts_endpoint}

build_connection(ems, endpoints, mode)
end
Expand All @@ -499,7 +529,7 @@ def build_connection(ems, endpoints, mode)
authentications = build_credentials(ems, mode)
configurations = []

[:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular, :prometheus].each do |role|
[:default, :ceilometer, :amqp, :ssh_keypair, :metrics, :hawkular, :prometheus, :prometheus_alerts].each do |role|
configurations << build_configuration(ems, authentications, endpoints, role)
end

Expand Down Expand Up @@ -556,6 +586,9 @@ def build_credentials(ems, mode)
elsif params[:metrics_selection] == "prometheus"
creds[:prometheus] = {:auth_key => default_key, :save => (mode != :validate)}
end
if params[:alerts_selection] == 'prometheus'
creds[:prometheus_alerts] = {:auth_key => default_key, :save => (mode != :validate)}
end
creds[:bearer] = {:auth_key => default_key, :save => (mode != :validate)}
creds.delete(:default)
end
Expand Down
10 changes: 10 additions & 0 deletions app/views/ems_container/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@
"checkchange" => "",
"required" => "",
"selectpicker-for-select-tag" => "")
.form-group{"ng-class" => "{'has-error': angularForm.alerts.$invalid}"}
%label.col-md-2.control-label{"for" => "prov_alerts"}
= _("Alerts")
.col-md-8
= select_tag('alerts_selection', options_for_select([[_("Disabled"), "disabled"], [_("Prometheus"), "prometheus"]]),
"ng-model" => "emsCommonModel.alerts_selection",
"ng-change" => "alertsSelectionChanged()",
"checkchange" => "",
"required" => "",
"selectpicker-for-select-tag" => "")

.form-group{"ng-class" => "{'has-error': angularForm.metrics.$invalid}"}
%label.col-md-2.control-label{"for" => "prov_metrics"}
Expand Down
Loading