Skip to content

Commit

Permalink
Hawkular hostname detection changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooli Tayer committed May 7, 2017
1 parent a26db2c commit b66619d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
}
};

$scope.isDetectionEnabled = function() {
return ($scope.currentTab == "hawkular" && $scope.emsCommonModel.ems_controller == "ems_container") &&
($scope.emsCommonModel.emstype) &&
($scope.emsCommonModel.default_hostname && $scope.emsCommonModel.default_api_port) &&
($scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid) &&
($scope.emsCommonModel.default_verify != '' && $scope.angularForm.default_verify.$valid);
};

var emsCommonEditButtonClicked = function(buttonName, _serializeFields, $event) {
miqService.sparkleOn();
var url = $scope.updateUrl + '?button=' + buttonName;
Expand Down Expand Up @@ -309,6 +317,18 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
}
};

$scope.detectClicked = function($event, authType) {
miqService.sparkleOn();
miqService.detectWithRest($event, $scope.actionUrl)
.then(function success(data) {
$scope.$apply(function() {
$scope.updateHawkularHostname(data.hostname);
miqService.miqFlash(data.level, data.message);
miqSparkleOff();
});
});
};

$scope.saveClicked = function($event, formSubmit) {
if (formSubmit) {
angular.element('#button_name').val('save');
Expand Down Expand Up @@ -522,6 +542,10 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', '
$scope.angularForm[$scope.authType + '_auth_status'].$setViewValue(updatedValue);
};

$scope.updateHawkularHostname = function(value) {
$('#hawkular_hostname').val(value);
};

$scope.radioSelectionChanged = function() {
if ($scope.emsCommonModel.event_stream_selection === "ceilometer" ||
$scope.emsCommonModel.event_stream_selection === "none") {
Expand Down
6 changes: 6 additions & 0 deletions app/assets/javascripts/services/miq_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ ManageIQ.angular.app.service('miqService', ['$timeout', '$document', '$q', funct
}, 200);
};

this.detectWithRest = function($event, url) {
angular.element('#button_name').val('detect');
miqSparkleOn();
return miqRESTAjaxButton(url, $event.target, 'json');
};

this.validateWithAjax = function (url) {
miqSparkleOn();
miqAjaxButton(url, true);
Expand Down
51 changes: 40 additions & 11 deletions app/controllers/mixins/ems_common_angular.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def update
when "cancel" then update_ems_button_cancel
when "save" then update_ems_button_save
when "validate" then update_ems_button_validate
when "detect" then update_ems_button_detect
end
end

Expand Down Expand Up @@ -75,6 +76,7 @@ def create
when "add" then create_ems_button_add
when "validate" then create_ems_button_validate
when "cancel" then create_ems_button_cancel
when "detect" then create_ems_button_detect
end
end

Expand Down Expand Up @@ -113,6 +115,31 @@ def create_ems_button_cancel
{:model => ui_lookup(:model => model_name)}
end

def create_ems_button_detect
ems = model.model_from_emstype(params[:emstype]).new
update_ems_button_detect(ems)

end

def update_ems_button_detect(verify_ems = nil)
verify_ems ||= find_record_with_rbac(model, params[:id])
set_ems_record_vars(verify_ems, :validate)
@in_a_form = true

result, details = get_hostname_from_routes(verify_ems)
if result
add_flash(_("Hawkular route detection: success"))
else
add_flash(_("Hawkular route detection: failure %{details}") % {:details => details}, :error)
end

render :json => {
:message => @flash_array.last(1)[0][:message],
:level => @flash_array.last(1)[0][:level],
:hostname => result
}
end

def ems_form_fields
assert_privileges("#{permission_prefix}_edit")
@ems = model.new if params[:id] == 'new'
Expand Down Expand Up @@ -429,10 +456,6 @@ def set_ems_record_vars(ems, mode = nil)
default_endpoint = {:role => :default, :hostname => hostname, :port => port}
default_endpoint.merge!(endpoint_security_options(ems.security_protocol, default_tls_ca_certs))

if hawkular_hostname.blank?
default_key = params[:default_password] || ems.authentication_key
hawkular_hostname = get_hostname_from_routes(ems, default_endpoint, default_key)
end
hawkular_endpoint = {:role => :hawkular, :hostname => hawkular_hostname, :port => hawkular_api_port}
hawkular_endpoint.merge!(endpoint_security_options(hawkular_security_protocol, hawkular_tls_ca_certs))
end
Expand Down Expand Up @@ -465,19 +488,25 @@ def set_ems_record_vars(ems, mode = nil)
build_connection(ems, endpoints, mode)
end

def get_hostname_from_routes(ems, endpoint_hash, token)
return nil unless ems.class.respond_to?(:openshift_connect)
endpoint = Endpoint.new(endpoint_hash)
# TODO: move to backend
def get_hostname_from_routes(ems)
return nil, "Route detection not applicable for provider type" unless ems.class.respond_to?(:openshift_connect)

endpoint = ems.default_endpoint
ssl_options = {
:verify_ssl => ems.verify_ssl_mode(endpoint),
:cert_store => ems.ssl_cert_store(endpoint)
}
client = ems.class.raw_connect(endpoint.hostname, endpoint.port,
:service => :openshift, :bearer => token, :ssl_options => ssl_options)
client.get_route('hawkular-metrics', 'openshift-infra').try(:spec).try(:host)
client = ems.class.raw_connect(
endpoint.hostname, endpoint.port,
:service => :openshift,
:bearer => ems.authentication_key,
:ssl_options => ssl_options
)
[client.get_route('hawkular-metrics', 'openshift-infra').try(:spec).try(:host), "Success"]
rescue StandardError => e
$log.warn("MIQ(#{controller_name}_controller-#{action_name}): get_hostname_from_routes error: #{e}")
nil
[nil, e]
end

def endpoint_security_options(security_protocol, certificate_authority)
Expand Down
11 changes: 11 additions & 0 deletions app/views/layouts/angular-bootstrap/_endpoints_angular.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@
"checkchange" => "",
"prefix" => prefix.to_s,
"reset-validation-status" => "#{prefix}_auth_status"}
- detect = "detectClicked({target: '.detect_button'}, true)"
%span
%miq-button{:ng_if => defined?(detection) ? true : false,
:class => 'detect_button',
:name => _("Detect"),
:enabled_title => _("Detect endpoint hostname"),
:on_click => detect,
:enabled => "isDetectionEnabled()",
:xs => 'true',
:primary => 'true'}

%span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.required"}
= _("Required")
%span.help-block{"ng-show" => "angularForm.#{prefix}_hostname.$error.detectedSpaces"}
Expand Down
3 changes: 2 additions & 1 deletion app/views/layouts/angular/_multi_auth_credentials.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@
:id => record.id,
:ng_reqd_hostname => "true",
:ng_reqd_api_port => "true",
:prefix => "hawkular"}
:prefix => "hawkular",
:detection => true}
= render :partial => "layouts/angular-bootstrap/auth_credentials_angular_bootstrap",
:locals => {:ng_show => true,
:ng_model => "#{ng_model}",
Expand Down

0 comments on commit b66619d

Please sign in to comment.