-
Notifications
You must be signed in to change notification settings - Fork 897
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 Service resource linking. #16082
Conversation
@lfu Cannot apply the following label because they are not recognized: service |
ad3eb90
to
7847796
Compare
app/models/service.rb
Outdated
@@ -65,6 +65,7 @@ class Service < ApplicationRecord | |||
include TenancyMixin | |||
include SupportsFeatureMixin | |||
include Metric::CiMixin | |||
include ResourceLinking |
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.
Shall we name it ResourceLinkingMixin
similar to lines above?
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.
I was suggesting we use include_concern
here.
module Service::ResourceLinking | ||
extend ActiveSupport::Concern | ||
|
||
def add_provider_vms_queue(provider, array_of_uid_ems) |
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.
So this implementation intents to add resources by type? Next time if we want to link networks, we need to introduce new method add_provider_networks_queue
and copy the same logic?
:userid => evm_owner.userid | ||
} | ||
queue_opts = { | ||
:class_name => "Service", |
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.
You can still use self.class.name
to avoid hard coding.
array_of_uid_ems = array_of_uid_ems.kind_of?(Array) ? array_of_uid_ems.compact.uniq : [array_of_uid_ems] | ||
|
||
if Vm.where(:uid_ems => array_of_uid_ems).length != array_of_uid_ems.length | ||
task_ids = EmsRefresh.queue_refresh(provider, nil, :create_task => true) |
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.
May need to consult with the provider team whether we can avoid a full refresh.
found_vms.each { |vm| add_resource!(vm) } | ||
|
||
not_found_vms = array_of_uid_ems - found_vms.pluck(:uid_ems) | ||
_log.info("VMs not found to link to service ID [#{id}], name [#{name}]: #{not_found_vms.join("\n")}") unless not_found_vms.blank? |
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.
Consider increase the log level to warn
or error
task_ids = EmsRefresh.queue_refresh(provider, nil, :create_task => true) | ||
|
||
# Wait for the tasks to finish | ||
task_ids.each { |tid| MiqTask.wait_for_taskid(tid) } |
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.
We should not be waiting for the provider refresh synchronously, instead it should be re-queueing the work and checking. Some providers could take more then 10 mins to complete a refresh. This also means we cannot use MiqTask.generic_action_with_callback
.
cc @mkanoor
7847796
to
7b07d99
Compare
@gmcculloug @mkanoor @bzwei Please review the new logic. I will work on the specs. |
_log.info("NAME [#{options[:name]}] for user #{evm_owner.userid}") | ||
|
||
job = Service::LinkingWorkflow.create_job(options) | ||
return job |
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.
No need for the return job
line, the result of Service::LinkingWorkflow.create_job
will be returned from the method unless it is raising an error.
The previous line should just be: Service::LinkingWorkflow.create_job(options)
raise _("no target_id defined for linking targets to service") unless options[:target_id] | ||
|
||
array_of_uid_ems = options[:array_of_uid_ems] | ||
options[:array_of_uid_ems] = array_of_uid_ems.kind_of?(Array) ? array_of_uid_ems.compact.uniq : [array_of_uid_ems] |
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.
These two lines can be simplified:
options[:array_of_uid_ems] = Array(options[:array_of_uid_ems]).compact.uniq
def add_provider_vms(options) | ||
# required keys in options hash: | ||
# :target_id, the id of the provider to refresh | ||
# :array_of_uid_ems, an array of VMs' uid_ems |
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.
Does the external caller to the API need to know this name? Suggest using uid_ems_array
.
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.
Whoever calls this method needs to pass in the two parameters: target_id
and uid_ems_array
.
7b07d99
to
d8efbb5
Compare
} | ||
end | ||
|
||
def dispatch_start |
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.
I would rather not override this method. We can explicitly call start
before return the job
@lfu you can do a target refresh based on ems_ref, see example https://github.com/ManageIQ/manageiq/blob/master/app/models/manageiq/providers/cloud_manager/provision/state_machine.rb#L57 |
d8efbb5
to
5b04bcc
Compare
def add_provider_vms(options) | ||
# required keys in options hash: | ||
# :target_id, the id of the provider to refresh | ||
# :uid_ems_array, an array of VMs' uid_ems |
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.
Why are we taking these as a hash and not just normal parameters? Seems we are doing the raise
in normalize_inputs!
for target_id
when it should just be a normal argument (or keyword args). I realize you are merging the options but the existing normalize_inputs!
method could return the hash that gets merged.
Maybe something like: add_provider(target_id:, uid_ems_array:)
but depends on what the API is passing.
@jntullo Are you passing the provider object or just the ID from the API?
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.
@gmcculloug I was passing in the actual provider object with the :uid_ems_array
but see that it has changed
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.
If we need the zone
from the provider we'll need to load the object. Let's understand that first before we change what you are passing.
:userid => evm_owner.userid, | ||
:sync_key => guid, | ||
:service_id => id, | ||
:zone => my_zone |
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.
Is zone
needed for the provider refresh? If so this should be the providers zone not the service. Otherwise it would be good to eliminate all together.
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.
This zone
is for the new job, not for refresh.
raise _("no target_id defined for linking to service") unless options[:target_id] | ||
|
||
uid_ems_array = options[:uid_ems_array] || [] | ||
options[:uid_ems_array] = uid_ems_array.kind_of?(Array) ? uid_ems_array.compact.uniq : [uid_ems_array] |
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.
Not sure if the suggestion to reduce this to these two lines to the follow was lost in the comments or if you are preferring the current approach.
Suggested change: options[: uid_ems_array] = Array(options[: uid_ems_array]).compact.uniq
0f99bf4
to
03d6ca6
Compare
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.
extend ActiveSupport::Concern | ||
|
||
def add_provider_vms(provider, uid_ems_array) | ||
vm_id_array = Array(uid_ems_array).compact.uniq |
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.
Minor, but the name vm_id_array
is misleading as it is the uid
that is expected here.
03d6ca6
to
f8bb682
Compare
:id => id, :name => name, :service_id => options[:service_id] | ||
} | ||
_log.error(msg) | ||
signal(:abort, msg, 'error') |
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.
I don't see :abort
, but only :abort_job
or :error
.
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.
Never mind. I saw it in the state_machine mixin.
f8bb682
to
4146352
Compare
Checked commits lfu/manageiq@eac5d1f~...4146352 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 app/models/service/linking_workflow.rb
|
:service_id => service.id | ||
} | ||
end | ||
let(:job) { described_class.create_job(options) } |
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.
Will the job be automatically deleted after test?
Link provisioned VMs to the service.
@miq-bot assign @gmcculloug
@miq-bot add_label service, enhancement, fine/no