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

Adding Chassis and Racks as PhysicalStorages subcollections #423

Closed

Conversation

EsdrasVP
Copy link
Member

@EsdrasVP EsdrasVP commented Jul 17, 2018

This PR is able to add:

  • GET /api/physical_storages/:c_id/physical_chassis
  • GET /api/physical_storages/:c_id/physical_chassis/:s_id
  • GET /api/physical_storages/:c_id/physical_racks
  • GET /api/physical_storages/:c_id/physical_racks/:s_id

Depends on:

@EsdrasVP EsdrasVP closed this Jul 18, 2018
@EsdrasVP EsdrasVP reopened this Jul 18, 2018
@EsdrasVP EsdrasVP changed the title Adding Chassis and Racks as PhysicalStorages subcollections [WIP] Adding Chassis and Racks as PhysicalStorages subcollections Jul 25, 2018
@EsdrasVP EsdrasVP force-pushed the add_subcollections_to_storages branch from 74fead8 to 156d65e Compare July 25, 2018 16:36
@miq-bot miq-bot added the wip label Jul 25, 2018
@EsdrasVP EsdrasVP force-pushed the add_subcollections_to_storages branch from 156d65e to 05a9252 Compare July 25, 2018 16:54
@EsdrasVP EsdrasVP changed the title [WIP] Adding Chassis and Racks as PhysicalStorages subcollections Adding Chassis and Racks as PhysicalStorages subcollections Jul 25, 2018
@miq-bot miq-bot removed the wip label Jul 25, 2018
@EsdrasVP EsdrasVP force-pushed the add_subcollections_to_storages branch from 05a9252 to 755c169 Compare July 25, 2018 17:00
@EsdrasVP
Copy link
Member Author

@abellotti Could you check this out?

@miq-bot
Copy link
Member

miq-bot commented Aug 2, 2018

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

@EsdrasVP EsdrasVP force-pushed the add_subcollections_to_storages branch from 755c169 to dac0186 Compare August 2, 2018 14:07
@miq-bot
Copy link
Member

miq-bot commented Aug 2, 2018

Checked commit EsdrasVP@dac0186 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
4 files checked, 0 offenses detected
Everything looks fine. 👍

module Subcollections
module PhysicalRacks
def physical_racks_query_resource(object)
object.respond_to?(:physical_rack) ? PhysicalRack.where(:id => object.physical_rack_id) : []
Copy link
Member

Choose a reason for hiding this comment

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

can't this be object.physical_rack instead of the PhysicalRack.where ... ?

Copy link
Member Author

@EsdrasVP EsdrasVP Aug 6, 2018

Choose a reason for hiding this comment

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

Actually no, because PhysicalRack has many PhysicalStorages and not the inverse. So if we call object.physical_rack the code will break. That's why, instead, we use the reference physical_rack_id which denotes the PhysicalRack in which the PhysicalStorage belongs to.

Copy link
Member

Choose a reason for hiding this comment

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

@EsdrasVP What will break? It looks like the relationships are defined in both directions...

app/models/physical_chassis.rb:9:  belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_chassis
app/models/physical_rack.rb:4:  belongs_to :ext_management_system, :foreign_key => :ems_id, :inverse_of => :physical_racks,
app/models/physical_rack.rb:6:  has_many :physical_chassis, :dependent => :nullify, :inverse_of => :physical_rack
app/models/physical_rack.rb:7:  has_many :physical_servers, :dependent => :nullify, :inverse_of => :physical_rack
app/models/physical_rack.rb:8:  has_many :physical_storages, :dependent => :nullify, :inverse_of => :physical_rack
app/models/physical_server.rb:22:  belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_servers
app/models/physical_storage.rb:4:  belongs_to :physical_rack, :foreign_key => :physical_rack_id, :inverse_of => :physical_storages

Copy link
Member Author

Choose a reason for hiding this comment

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

@bdunne They have, PhysicalRack and PhysicalChassis will have many PhysicalStorages, but the problem is that PhysicalStorage will only belong to one PhysicalRack/PhysicalChassis. So what happens when I use object.physical_rack is that a method all is called to return a list of PhysicalRacks/PhysicalChassis when this list doesn't exist and only a object is returned. So when I access /api/physical_storages/:id/physical_racks, for instance, the following error is presented:

{
    "error": {
        "kind": "internal_server_error",
        "message": "undefined method `all' for #<PhysicalRack:0x007f1bf0c52098>",
        "klass": "NoMethodError"
    }
}

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I must have missed the notification... It sounds like it should be /api/physical_storages/:id/physical_racks should be /api/physical_storages/:id/physical_rack. Maybe this should be a sub-resource rather than a sub-collection. Is that right @abellotti?

Copy link
Member

Choose a reason for hiding this comment

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

if there's one and only one, the subcollection does not make sense here, it can currently be accessed via GET /api/physical_storages/:id?attributes=physical_rack
as shown by the OPTIONS /api/physical_storages in the relationships section.

Copy link
Member Author

Choose a reason for hiding this comment

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

if there's one and only one, the subcollection does not make sense here, it can currently be accessed via GET /api/physical_storages/:id?attributes=physical_rack
as shown by the OPTIONS /api/physical_storages in the relationships section.

@abellotti @bdunne This makes sense, I spoke with @rodneyhbrown7 and we agreed to use the current method to access the physical storage relationships. So this PR can be closed.

module Subcollections
module PhysicalChassis
def physical_chassis_query_resource(object)
object.respond_to?(:physical_chassis) ? ManageIQ::Providers::PhysicalInfraManager::PhysicalChassis.where(:id => object.physical_chassis_id) : []
Copy link
Member

Choose a reason for hiding this comment

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

same question as below

@abellotti abellotti requested a review from bdunne August 6, 2018 17:33
@EsdrasVP
Copy link
Member Author

@abellotti Is there any other reservation regarding this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants