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

[WIP] Adding support for subcollections and related subresources #61

Closed

Conversation

abellotti
Copy link
Member

  • Dynamically driven by the "subcollections" exposed via OPTIONS /api/:collection

  • supports queries and actions

    Queries:
    miq.vms.find(166).tags.collect(&:name)
    miq.vms.find(166).tags.select(:categorization).collect(&:categorization)

    Subcollection Actions:
    miq.vms.find(166).tags.assign(:name => "/managed/location/ny")
    miq.vms.find(166).tags.assign([{:name => "/managed/location/chicago"}, {:name => "/managed/cc/001"}])

    Subcollection resource actions:
    miq.vms.find(166).tags.find(32).unassign
    miq.vms.find(166).tags.where(:name => "/managed/location/*").collect(&:unassign)

Fixes: #31
Fixes: #32

@abellotti
Copy link
Member Author

abellotti commented Jan 30, 2017

  • more testing
  • DRY
  • specs
    • collections
    • resources
    • subcollections
    • subresources

@abellotti abellotti force-pushed the adding_subcollection_support branch 4 times, most recently from 75e8f0f to 5f2ddc8 Compare February 7, 2017 16:19
@abellotti abellotti force-pushed the adding_subcollection_support branch 3 times, most recently from 7954eb1 to 8a554b9 Compare February 8, 2017 16:04
@abellotti abellotti changed the title [WIP] Adding support for subcollections and related subresources Adding support for subcollections and related subresources Feb 8, 2017
@abellotti
Copy link
Member Author

@Fryguy subcollection support + lotsa tests added

@abellotti
Copy link
Member Author

ping @Fryguy for review, will be needed shortly for Automate work. Thanks.

@abellotti
Copy link
Member Author

Ping @Fryguy we need this for Automate Workspace work by @mkanoor


ACTIONS_RETURNING_RESOURCES = %w(create query).freeze

def exec_action(name, *args, &block)
Copy link
Member

Choose a reason for hiding this comment

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

Should any of these be private?

@@ -0,0 +1,50 @@
module CollectionActionMixin
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be namespaced

@@ -0,0 +1,95 @@
module QueryableMixin
Copy link
Member

Choose a reason for hiding this comment

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

Also needs namespace

@@ -0,0 +1,24 @@
module ResourceActionMixin
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

const_get(name, false)
else
const_set(name, Class.new(self))
end
Copy link
Member

Choose a reason for hiding this comment

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

It feels like there is a lot of duplication with collection.

@abellotti abellotti force-pushed the adding_subcollection_support branch from d9d208c to b98cf9d Compare September 6, 2017 20:06
- Dynamically driven by the "subcollections" exposed via OPTIONS /api/:collection
- supports queries and actions

  Queries:
  miq.vms.find(166).tags.collect(&:name)
  miq.vms.find(166).tags.select(:categorization).collect(&:categorization)

  Subcollection Actions:
  miq.vms.find(166).tags.assign(:name => "/managed/location/ny")
  miq.vms.find(166).tags.assign([{:name => "/managed/location/chicago"}, {:name => "/managed/cc/001"}])

  Subcollection resource actions:
  miq.vms.find(166).tags.find(32).unassign
  miq.vms.find(166).tags.where(:name => "/managed/location/*").collect(&:unassign)

Fixes: ManageIQ#31
Fixes: ManageIQ#32
- Moving action specific action methods for resources and subresources to seperate mixin.
- Moving action specific action methods for collections and subcollections to seperate mixin.
- Moving common queryable methods for collections and subcollections to a common QueryableMixin
- Updated options response fixture to include subcollections
- Added collection rspecs
- Added resource rspecs
- Add tests for subcollections
- Adding resource actions_vms.json
- Adding subcollection actions_vm_tags.json
- Adding tests for subresources
@@ -1,4 +1,4 @@
module ActionMixin
module ManageIQ::API::ActionMixin
Copy link
Member

Choose a reason for hiding this comment

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

Should this be ManageIQ::API::Client::ActionMixin? Otherwise it might collide with some future mixin in ManageIQ itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point 👍 will update all.

end

def filters_from_query_relation(condition, option)
filters = []
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 sure there's a way to turn this into a simpler .collect

if option.kind_of?(Array)
option.each_with_object({}) { |name, hash| hash[name] = "asc" }
else
option.dup
Copy link
Member

Choose a reason for hiding this comment

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

What is this dup for if you're going to loop over it anyway?

@abellotti abellotti changed the title Adding support for subcollections and related subresources [WIP] Adding support for subcollections and related subresources Apr 3, 2018
option.each_with_object({}) { |name, hash| hash[name] = "asc" }
else
option
end
Copy link
Member

@Fryguy Fryguy Apr 3, 2018

Choose a reason for hiding this comment

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

I feel like you can remove this completely if you just deal with defaulting nil values below.

[1] pry(main)> option = {"a" => "asc", "b" => "desc"}
[2] pry(main)> option.each {|k, v| puts "#{k} => #{v || "asc"}"}
a => asc
b => desc

[3] pry(main)> option = ["a", "b"]
[4] pry(main)> option.each {|k, v| puts "#{k} => #{v || "asc"}"}
a => asc
b => asc

res_sort_by << sort_attr
sort_order =
case sort_order
when /^asc/i then "asc"
Copy link
Member

Choose a reason for hiding this comment

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

so this could be when /^asc/i, nil then "asc"

@Fryguy
Copy link
Member

Fryguy commented Apr 3, 2018

@abellotti This is a lot to digest +3,715 −135...might need to sit with you unless you can break it up into easily digestable PRs

@abellotti
Copy link
Member Author

Marked as WIP, I need to revisit Subresource (/api/providers/1/vms/133 vs just /api/vms/133)

@abellotti
Copy link
Member Author

Agreed, getting slowly morphed/simplified as https://github.com/abellotti/manageiq-api-client/tree/enhanced_subcollection_support. will create new PR when in good shape. By simply
using resource.rb (eliminating subresource.rb and possibly subcollection.rb), this would now allow for deeply nested resource/subcollection/action calls as we'd reset at the primary CI URL where actions are provided. So allowing for the following:

miq.providers.find_by(:name => "test-provider).vms.find_by(:name => "test-vm").snapshots.collect(&:name)

@abellotti
Copy link
Member Author

closing in preference of #80

@abellotti abellotti closed this Apr 26, 2018
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.

2 participants