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

[V2V] Add conversion_host.id to task options #18540

Conversation

ghost
Copy link

@ghost ghost commented Mar 10, 2019

The conversion host configuration is asynchronous and we need to associate the async task with the conversion host, so that we can manipulate the tasks in the UI. For example, we only show the last configuration task for a given conversion host in the UI. This PR add the conversion host id to the enablement task options. The disable task is not required as it destroys the conversion host.

Associated RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1622728

@ghost
Copy link
Author

ghost commented Mar 10, 2019

@miq-bot add_label transformation, enhancement, hammer/yes
@miq-bot add_reviewer @djberg96
@miq-bot add_reviewer @agrare


vddk_url = params.delete(:param_v2v_vddk_package_url)

conversion_host = new(params)

unless task_id.nil?
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably change this to if task_id.present? in case it comes through as an empty param instead of nil. I've come to be paranoid about such things when dealing with http.

task.options[:conversion_host_id] = conversion_host.id
task.save!
end

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with this, but I'm thinking it should only happen if we know the conversion_host.save! was successful.

Copy link
Member

Choose a reason for hiding this comment

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

Won't .save! raise an exception and not get here if it failed?

@miq-bot
Copy link
Member

miq-bot commented Mar 11, 2019

Checked commits fabiendupont/manageiq@c12dd97~...16364c3 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

@agrare agrare self-assigned this Mar 11, 2019
params.delete(:miq_task_id) # The miq_queue.activate_miq_task will stick in a :miq_task_id
task_id = params.delete(:task_id) # In case this is being called through *_queue which will stick in a :task_id
miq_task_id = params.delete(:miq_task_id) # The miq_queue.activate_miq_task will stick in a :miq_task_id
task_id ||= miq_task_id
Copy link
Member

Choose a reason for hiding this comment

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

What? no no lets just fix enable_queue to set :miq_task_id and standardize on a single key

Copy link
Author

Choose a reason for hiding this comment

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

Yup. I didn't like it neither. How would you fix enable_queue ?

Copy link
Member

@agrare agrare Mar 11, 2019

Choose a reason for hiding this comment

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

Actually it looks like the only caller (./manageiq-api/app/controllers/api/conversion_hosts_controller.rb) just does task_id = ConversionHost.enable_queue(data.except('auth_user'), data['auth_user']) so where were you seeing a task_id parameter coming from? Because from that it looks like it gets the task_id back rather than passing one in.

Copy link
Author

Choose a reason for hiding this comment

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

I took that from existing code... @djberg96 could you shed some light here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, the enable_queue method will return the task_id on a create request, but we don't have a direct way to associate the task back to the conversion instance after that.

Copy link
Member

Choose a reason for hiding this comment

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

But enable_queue isn't passing in the task_id as a parameter right? So the only option should be miq_task_id

Copy link
Contributor

Choose a reason for hiding this comment

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

They're injected into the params via the MiqTask.generic_action_with_callback at https://github.com/ManageIQ/manageiq/blob/master/app/models/miq_task.rb#L290-L292

Copy link
Member

Choose a reason for hiding this comment

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

But those are different hashes, only task_id is passed in to the method opts


if task_id.present?
task = MiqTask.find(task_id)
task.options[:conversion_host_id] = conversion_host.id
Copy link
Member

Choose a reason for hiding this comment

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

Is options right? I thought it was context...

Copy link
Author

Choose a reason for hiding this comment

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

We've used options so much that it sounded like the logical choice.
@djberg96 would you recommend context_data over options ?

Copy link
Member

Choose a reason for hiding this comment

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

I mean is options even an attribute of an miq_task?

>> MiqTask.create!.options
NoMethodError (undefined method `options' for #<MiqTask:0x000055dc41439fe0>)

Copy link
Member

Choose a reason for hiding this comment

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

@fdupont-redhat you're probably thinking of an MiqRequestTask, that has an options column but MiqTask does not.

Copy link
Contributor

Choose a reason for hiding this comment

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

@agrare Now I'm curious what the difference between those two.

Copy link
Member

Choose a reason for hiding this comment

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

They're different models?

@djberg96
Copy link
Contributor

Yeah, I was too hasty with the approve button...

I don't think we want to use context_data because I want to use that for the params. I think we want to set the instance_id on the MiqQueue object, and that will have the relationship to the MiqTask.

@agrare
Copy link
Member

agrare commented Mar 11, 2019

I think we want to set the instance_id on the MiqQueue object, and that will have the relationship to the MiqTask.

So you'd have to create the conversion host in enable_queue so you could pass in the instance_id then, is that what you're thinking?

@djberg96
Copy link
Contributor

djberg96 commented Mar 11, 2019

@agare, I think that plan is shot because it doesn't appear that records in miq_queue are persistent. I can see the MiqQueue item created via MiqQueue.put, but it doesn't appear in database. I can see other queue items appear and disappear as well, e.g. automate tasks.

@mturley
Copy link
Contributor

mturley commented Mar 12, 2019

@djberg96 could we maybe use context_data for both? it could maybe be an object with request_params and conversion_host_id in it? Sorry if this doesn't fit the data structure, I'm thinking in JSON terms.

@djberg96
Copy link
Contributor

@mturley I guess there's no reason we couldn't do that. Working on it...

@djberg96
Copy link
Contributor

@fdupont-redhat Might be easiest if I just include this as part of #18541.

@miq-bot
Copy link
Member

miq-bot commented Mar 26, 2019

This pull request is not mergeable. Please rebase and repush.

@agrare
Copy link
Member

agrare commented Apr 1, 2019

@djberg96 can this be closed now that #18541 is merged?

@djberg96
Copy link
Contributor

djberg96 commented Apr 1, 2019

@agrare @fdupont-redhat I would say yes, close this.

@agrare agrare closed this Apr 1, 2019
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.

5 participants