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

Generic Objects API #50

Merged
merged 7 commits into from
Sep 18, 2017
Merged

Generic Objects API #50

merged 7 commits into from
Sep 18, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Sep 11, 2017

Generic Objects API CRUD
(will make separate PRs for subcollection actions and calling generic object methods)

GET

  • Returns property_attributes by default
  • can specify associations to return
GET /api/generic_objects/:id?associations=vms,services

response:
{
  "id": "<id>",
  "name": "generic_object_name",
  "generic_object_definition_id": "id",
  "property_attributes": { "widget": "test", "is_something": true },
  "vms": [ { "id": "id" ...  } ],
  "services": [ { "id": "id" ... }]  
}

POST /api/generic_objects

Creating a new generic object

{  
   "generic_object_definition":{  
      "href":"/api/generic_object_definitions/:id"
   },
   "name":"go_name1",
   "uid":"optional_uid",
   "property_attributes":{  
      "widget":"widget value",
      "is_something":false
   },
   "associations":{  
      "vms":[  
         {  
            "href":"/api/vms/:id"
         },
         {  
            "href":"api/vms/:id"
         }
      ],
      "services":[  
         {  
            "href":"api/service/:id"
         }
      ]
   }
}

Editing a Generic Object

  • Much like create - accepts associations and property_attributes
{  
   "action":"edit",
   "resources":[  
      {  
         "href":"/api/generic_objects/:id",
         "name":"updated name",
         "property_attributes":{  
            "widget":"updated widget"
         }
      }
   ]
}

Deleting a Generic Object

{  
   "action":"delete",
   "resources":[  
      {  
         "href":"/api/generic_objects/:id"
      }
   ]
}

POST /api/generic_objects/:id

Editing a generic object

{  
   "action":"edit",
   "resource":{  
      "name":"updated object",
      "property_attributes":{  
         "widget":"updated widget val",
         "is_something":false
      },
      "associations":{  
         "vms":[  
            {  
               "href":"/api/vms/:id"
            }
         ],
         "services":[  

         ]
      }
   }
}

Deleting a generic object

{
   "action": "delete"
}

DELETE api/generic_objects/:id

@miq-bot add_label enhancement
@miq-bot assign @abellotti

def set_additional_attributes
@additional_attributes = %w(property_attributes)
return unless params[:property_associations]
params[:property_associations].split(',').each do |prop|
Copy link
Author

Choose a reason for hiding this comment

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

@abellotti wanted to get your thoughts on this approach to returning associations since it's slightly different than we talked about. With GET /generic_objects/:id?property_associations=vms,services, and by adding them to the additional attributes, they can then get returned as if they were a normal relationship, ie:

{
  "id": "<generic_object_id>",
   ...
  "vms" [ {"id": "vm_id" }, ... ]
  "services": [ ... ]
}

thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I like it, I wonder if the parameter shouldn't just be associations=vms,services,... to match the add_associations/remove_associations actions.

Copy link
Author

Choose a reason for hiding this comment

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

@abellotti yeah, I like that. will update! 👍

@jntullo jntullo changed the title [WIP] Generic Objects API Generic Objects API Sep 13, 2017
@miq-bot miq-bot removed the wip label Sep 13, 2017
@abellotti
Copy link
Member

Thanks @jntullo for the PR. this LGTM 👍

/cc @imtayadeway can I borrow your 👀 for a quick look here. Thanks!!

@@ -112,7 +112,8 @@ def normalize_select_attributes(obj, opts)
end

def normalize_array(obj)
obj.collect { |item| normalize_attr(@req.subcollection || @req.collection, item) }
type = @req.subcollection || @req.collection
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wish, you can use type = @req.subject here ☺️

Copy link
Member

Choose a reason for hiding this comment

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

👍 🎵

use subject instead of collection/subcollection
@abellotti
Copy link
Member

@imtayadeway waiting for your approval when you get a chance. Thanks !!

@miq-bot
Copy link
Member

miq-bot commented Sep 18, 2017

Checked commits jntullo/manageiq-api@5d5fbf3~...103df94 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 0 offenses detected
Everything looks fine. 🏆

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

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

This LGTM. Thank you @jntullo ! 🥇

@chriskacerguis
Copy link
Contributor

Echoing a previous question but how do you (1) get GO’s for a service and (2) how does one associate a GO with a service?

/cc @chalettu

@jntullo
Copy link
Author

jntullo commented Sep 18, 2017

@chriskacerguis @chalettu services don't have GO's so much as a GO can have a service. A service can be added to a Generic Object via association so long as that association is defined in the generic object definition of the GO (see #15 or #37). Then if that relationship exists, the services can be added as seen in the examples I have documented above (via both create and edit).

@lfu and @bzwei would be best to describe it though, and to inform if there is a straightforward way in which to grab generic objects of a service.

@chriskacerguis
Copy link
Contributor

@jntullo thanks for the clarification. So, given a service, how can I get the associated GO's?

@lfu
Copy link
Member

lfu commented Sep 18, 2017

A service can be added to a Generic Object via association so long as that association is defined in the generic object definition of the GO (see #15 or #37).

@jntullo This is correct. A service can be connected to a generic object as an association.

Generic objects can also be added to a service as resources. @chriskacerguis To get the associated GO's of a given service, just call:

service.generic_objects

(see ManageIQ/manageiq#15490)

@jntullo
Copy link
Author

jntullo commented Sep 18, 2017

@lfu thank you! I did not see that relationship.

@chriskacerguis I will create a PR for a subcollection on services. ie /services/:id/generic_objects

@chriskacerguis
Copy link
Contributor

@jntullo much appreciated!!

@lfu thank you for pointing that out.

You both are awesome.

@jntullo
Copy link
Author

jntullo commented Sep 18, 2017

@chriskacerguis @chalettu just realized, it's not even necessary for the subcollection. you'll be able to specify attributes=generic_objects since that relationship already exists.

@chriskacerguis
Copy link
Contributor

nice. Thanks @jntullo

@chriskacerguis
Copy link
Contributor

@chalettu does all that address your concerns?

@chalettu
Copy link

I believe this does address my concerns . Thank you so much @jntullo for helping to clarify

@abellotti
Copy link
Member

@jntullo agreeing with you above, simply accessing via attributes=generic_objects. Otherwise, we'd need to add the subcollection to all API CI's which map to an Miq reportable model type.

@abellotti
Copy link
Member

LGTM !!! Thanks @jntullo for this API enhancement 👍

@abellotti abellotti added this to the Sprint 69 Ending Sep 18, 2017 milestone Sep 18, 2017
@abellotti abellotti merged commit 1c1e5ef into ManageIQ:master Sep 18, 2017
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.

7 participants