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

API - VMs collection - replace decorators with SupportsFeatureMixin #14040

Merged
merged 3 commits into from
Mar 16, 2017
Merged

API - VMs collection - replace decorators with SupportsFeatureMixin #14040

merged 3 commits into from
Mar 16, 2017

Conversation

himdel
Copy link
Contributor

@himdel himdel commented Feb 23, 2017

This removes the only remaining use of decorators from manageiq (not ui).

Service UI is using ?decorators=vms.supports_console?,vms.supports_cockpit?, so I suppose we need to preserve that. - Implementing only those two, by calling vm.supports_*?.

Since console support is not using the SupportsFeatureMixin, added it to VmOrTemplate, using the same code that was previously in VmOrTemplateDecorator.

Cockpit support is using SupportsFeatureMixin, but uses a different name than the decorator (supports_cockpit? vs supports_launch_cockpit?).

(Related to (but not dependent upon) ManageIQ/manageiq-ui-classic#237.)

Testing: (with a valid service ID, which has multiple vms..) GET /api/services/10000000000245?expand=vms&decorators=vms.supports_console%3F%2Cvms.supports_cockpit%3F

Closes ManageIQ/manageiq-ui-classic#3

@abellotti, @jntullo WDYT? :)

if vm_decorators.include? 'supports_cockpit?'
hash['supports_cockpit?'] = vm.supports_launch_cockpit?
end
hash
Copy link
Member

Choose a reason for hiding this comment

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

may end up with lotsa churn with this in API every-time there's a new decorator. Would prefer logic to be driven by "support_" prefix and calling the appropriate method on vm. Not sure about the differently named _cockpit? vs. launch_cockpit?, maybe define an alias in the model for compatibility so this code here is generic for all. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellotti My impression was that people want decorators gone from the API .. that's why I took this path, we still need to support the ones that were used, but the idea of this PR is that those would be the only ones. (And can be replaced/deprecated in a future API version.)

Does your objection still stand given that?

Copy link
Member

Choose a reason for hiding this comment

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

Ahh ok, so keeping this for compatibility 🙇 new and future code would then leverage the attributes= instead. Does the following work today then ?

GET /api/vms?expand=resources&attributes=supports_launch_cockpit?,supports_console?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly :). The attributes version does not work today, because SupportsFeatureMixin does not create virtual attributes.

Not sure if the way forward is to make SupportFeatureMixin create virtual attributes for every feature, or to add special support for these in attributes, or to introduce a new query parameter..

Copy link
Member

Choose a reason for hiding this comment

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

we can probably extend app/controllers/api/base_controller/renderer.rb's attr_virtual?/attr_accessible? to "support" those so they come for free with attributes= without having to change the query parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@abellotti Sounds good, do you want me to do it in this PR, or would you rather have your team do it..?

Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we should have capabilities or something on the API objects...so not necessarily attributes, but implemented similarly

Copy link
Member

Choose a reason for hiding this comment

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

while we certainly can add that on the server side, I just don't know how they'd be specified in the API client. I'm hoping we can still somehow use .select(...) for those and won't need something like search_options(...) as implemented in ManageIQ/manageiq-api-client#63 for collection_class.

@miq-bot
Copy link
Member

miq-bot commented Mar 13, 2017

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

himdel added 3 commits March 14, 2017 13:16
console support for vms is not handled using the SupportsFeatureMixin - adding
this feature is relied upon by SUI, preserving compatibility
@himdel
Copy link
Contributor Author

himdel commented Mar 14, 2017

@abellotti is this blocked by anything?

@miq-bot
Copy link
Member

miq-bot commented Mar 14, 2017

Checked commits https://github.com/himdel/manageiq/compare/4dcd311c92e69946f94548c8f2813f60d464baee~...21934bfeaf5127683ecc9386c7b0331cefef9537 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 1 offense detected

app/models/mixins/supports_feature_mixin.rb

  • ❗ - Line 78, Col 5 - Style/AlignHash - Align the elements of a hash literal if they span more than one line.

@abellotti
Copy link
Member

I don't think so, just me. we can introduce the capabilities/supports in a separate PR.

Thanks @himdel for fixing this. 👍

@abellotti abellotti merged commit e646755 into ManageIQ:master Mar 16, 2017
@abellotti abellotti added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 16, 2017
@himdel himdel deleted the decorator-vms branch March 20, 2017 08:26
TomasKohoutek pushed a commit to TomasKohoutek/manageiq-ui-classic that referenced this pull request Apr 7, 2017
skateman pushed a commit to ManageIQ/manageiq-decorators that referenced this pull request Jul 17, 2018
skateman pushed a commit to ManageIQ/manageiq-decorators that referenced this pull request Jan 14, 2019
only used by the API, for the Vms collection, removed in ManageIQ/manageiq#14040


(transferred from manageiq-ui-classic@3e4f447f248ad335e9479f4aa247ebf40ea8fe63)
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.

4 participants