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 Service resource linking. #16082

Merged
merged 2 commits into from
Oct 12, 2017
Merged

Conversation

lfu
Copy link
Member

@lfu lfu commented Oct 2, 2017

Link provisioned VMs to the service.

@miq-bot assign @gmcculloug
@miq-bot add_label service, enhancement, fine/no

@miq-bot
Copy link
Member

miq-bot commented Oct 2, 2017

@lfu Cannot apply the following label because they are not recognized: service

@@ -65,6 +65,7 @@ class Service < ApplicationRecord
include TenancyMixin
include SupportsFeatureMixin
include Metric::CiMixin
include ResourceLinking
Copy link
Contributor

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?

Copy link
Member

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)
Copy link
Contributor

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",
Copy link
Contributor

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)
Copy link
Contributor

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?
Copy link
Contributor

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) }
Copy link
Member

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

@lfu
Copy link
Member Author

lfu commented Oct 5, 2017

@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
Copy link
Member

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]
Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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.

@lfu lfu force-pushed the service_resource_linking branch from 7b07d99 to d8efbb5 Compare October 5, 2017 20:27
}
end

def dispatch_start
Copy link
Contributor

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

@bzwei
Copy link
Contributor

bzwei commented Oct 5, 2017

@lfu lfu force-pushed the service_resource_linking branch from d8efbb5 to 5b04bcc Compare October 6, 2017 15:17
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
Copy link
Member

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?

Copy link

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

Copy link
Member

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
Copy link
Member

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.

Copy link
Member Author

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]
Copy link
Member

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

@lfu lfu force-pushed the service_resource_linking branch 6 times, most recently from 0f99bf4 to 03d6ca6 Compare October 10, 2017 13:43
Copy link
Member

@gmcculloug gmcculloug left a comment

Choose a reason for hiding this comment

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

One minor comment but overall this looks good.

@bzwei @mkanoor Please take another look.

extend ActiveSupport::Concern

def add_provider_vms(provider, uid_ems_array)
vm_id_array = Array(uid_ems_array).compact.uniq
Copy link
Member

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.

@lfu lfu force-pushed the service_resource_linking branch from 03d6ca6 to f8bb682 Compare October 10, 2017 18:22
:id => id, :name => name, :service_id => options[:service_id]
}
_log.error(msg)
signal(:abort, msg, 'error')
Copy link
Contributor

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.

Copy link
Contributor

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.

@lfu lfu force-pushed the service_resource_linking branch from f8bb682 to 4146352 Compare October 11, 2017 14:03
@miq-bot
Copy link
Member

miq-bot commented Oct 11, 2017

Checked commits lfu/manageiq@eac5d1f~...4146352 with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0
5 files checked, 1 offense detected

app/models/service/linking_workflow.rb

@gmcculloug gmcculloug merged commit d4da91c into ManageIQ:master Oct 12, 2017
@gmcculloug gmcculloug added this to the Sprint 71 Ending Oct 16, 2017 milestone Oct 12, 2017
:service_id => service.id
}
end
let(:job) { described_class.create_job(options) }
Copy link
Contributor

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?

@lfu lfu deleted the service_resource_linking branch October 16, 2017 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants