-
Notifications
You must be signed in to change notification settings - Fork 900
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
Changes to catch the retirement requester in automate. #17033
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,10 @@ def retire(ids, options = {}) | |
object = find_by(:id => id) | ||
object.retire(options) if object.respond_to?(:retire) | ||
end | ||
MiqQueue.put(:class_name => 'RetirementManager', :method_name => 'check') | ||
q_options = {:class_name => 'RetirementManager', :method_name => 'check'} | ||
user = User.current_user | ||
q_options.merge!(:user_id => user.id, :group_id => user.current_group.id, :tenant_id => user.current_tenant.id) if user | ||
MiqQueue.put(q_options) | ||
end | ||
end | ||
|
||
|
@@ -136,10 +139,11 @@ def retire_now(requester = nil) | |
def finish_retirement | ||
raise _("%{name} already retired") % {:name => name} if retired? | ||
$log.info("Finishing Retirement for [#{name}]") | ||
requester = retirement_requester | ||
update_attributes(:retires_on => Time.zone.now, :retired => true, :retirement_state => "retired") | ||
message = "#{self.class.base_model.name}: [#{name}], Retires On: [#{retires_on.strftime("%x %R %Z")}], has been retired" | ||
$log.info("Calling audit event for: #{message} ") | ||
raise_audit_event(retired_event_name, message) | ||
raise_audit_event(retired_event_name, message, requester) | ||
$log.info("Called audit event for: #{message} ") | ||
end | ||
|
||
|
@@ -178,18 +182,21 @@ def retired_event_name | |
end | ||
|
||
def raise_retirement_event(event_name, requester = nil) | ||
requester ||= User.current_user.try(:userid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The The Moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When |
||
q_options = retire_queue_options | ||
$log.info("Raising Retirement Event for [#{name}] with queue options: #{q_options.inspect}") | ||
MiqEvent.raise_evm_event(self, event_name, setup_event_hash(requester), q_options) | ||
end | ||
|
||
def raise_audit_event(event_name, message) | ||
def raise_audit_event(event_name, message, requester = nil) | ||
requester ||= User.current_user.try(:userid) | ||
event_hash = { | ||
:target_class => retirement_base_model_name, | ||
:target_id => id.to_s, | ||
:event => event_name, | ||
:message => message | ||
} | ||
event_hash[:userid] = requester if requester.present? | ||
AuditEvent.success(event_hash) | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lfu How do we ensure that the User.current_user is set? Should we be raising an error if its not set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkanoor We only take and store the user info into the queue only when the user is set. The retirement requester would default to
system
if no user is specified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
system
account would be used when retirement is initiated from the scheduler.