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

Add Alert Definition Profiles (MiqAlertSet) REST API support #14438

Merged
merged 2 commits into from
Apr 27, 2017

Conversation

dkorn
Copy link
Contributor

@dkorn dkorn commented Mar 21, 2017

Adding CRUD actions support to alert definition profile API endpoint

@dkorn
Copy link
Contributor Author

dkorn commented Mar 21, 2017

@miq-bot add_label enhancement, api, control

@dkorn
Copy link
Contributor Author

dkorn commented Mar 21, 2017

@moolitayer @zeari @simon3z @abellotti please review

@dkorn dkorn force-pushed the alert_definition_profiles branch from b367c9a to 20a08c5 Compare March 22, 2017 07:54
@simon3z
Copy link
Contributor

simon3z commented Mar 22, 2017

@moolitayer I think you should review this one given that it is directly related to your work on alerts (and what we need for dwh).

REQUIRED_FIELDS = %w(description mode).freeze

def create_resource(type, id, data = {})
assert_id_not_specified(data, type)

Choose a reason for hiding this comment

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

Safe to remove this as it is called in api::base_controller:generic (I checked :beer:)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks!

module AlertDefinitions
def alert_definitions_query_resource(object)
return {} unless object.respond_to?(:miq_alerts)
object.miq_alerts

Choose a reason for hiding this comment

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

That would give us a MiqPolicySet's MiqPolicies but will not give us a VM MiqPolicies.
Is that intentional?

If you need that you should call get_policies (see miq_policy_mixin.rb)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean MiqAlertSet and MiqAlert right?

Are you sure about it? seemed to me it returns the object's miq_alerts, regarding of the set type.

BTW, to the best of my knowledge, there is no miq_alert_mixin.rb to offer get_alerts

Choose a reason for hiding this comment

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

Sorry I was confused with policies (I keep thinking of the two together). This looks good, we only need to get the miq alerts belonging to a miq alert profile

:identifier: alert_definition_profile_delete
:delete:
- :name: delete
:identifier: alert_definition_profile_delete

Choose a reason for hiding this comment

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

we need two kinds of assign here:
Assign to object and assign a policy to this profile.
(we cannot assign to object through an object subcollection since the target entities we need have no rest endpoints for example container_node.rb)

@abellotti me and @dkorn were discussing this and weren't sure how to do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's wait for @abellotti 's suggestion :)

Copy link
Member

Choose a reason for hiding this comment

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

are we talking about assigning an MiqPolicy to a CI as well as an alert_definition_profile ?

Choose a reason for hiding this comment

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

Yes. assigning miq alert to miq alert profile seems straight forward. Assigning miq alert profile to object is more complex. You can assign a miq alert profile to a specific object, all object of a provider or all object in the system ("the Enterprise"). And the UI currently has the information of which alerts can be assigned to what (based on the target type, some can be assign only to one object others only to all the objects in the system)

I don't think this would be easy to get at one shot but what we need most urgent is to assign MA to MAP and MAP to all container nodes in the system. Of course the design should allow growing other examples next

Adding CRUD actions support to alert definition profile API endpoint
@dkorn dkorn force-pushed the alert_definition_profiles branch from 20a08c5 to 4067acb Compare March 23, 2017 13:18
@dkorn
Copy link
Contributor Author

dkorn commented Mar 26, 2017

@abellotti, @moolitayer and I tried to find an implementation for assigning policies to a policy profile (to take example from) but couldn't find it.
Can you confirm it is indeed not supported?

@abellotti
Copy link
Member

MiqPolicySet does not have the add_policy method exposed to it, so I'd say not supported today. Also, could't find functionality in the UI.

@dkorn
Copy link
Contributor Author

dkorn commented Mar 28, 2017

@abellotti If you go to Control -> Explorer -> Policy Profiles you can add policies to an existing policy profile or create a new one and select policies to it (@moolitayer keep me honest here).

@abellotti Is there a reason not to expose adding MiqAlert (alert definitions) to MiqAlertSet (alert definition profiles)?

@abellotti
Copy link
Member

@dkorn I think you're right, in my DB I only had a read-only policy profile.

looks like I can attempt POST /api/policy_profiles/:id/policies in the API, with the assign and unassign actions like the other CI's, however I'm getting undefine method 'add_policy' and 'remove_policy'. So it would be good to know what methods the UI uses for this, and why we can't expose add_policy and remove_policy so it will work like like the other CI's. Also, some of the policy_profiles cannot be edited so we need to support the same and only expose the actions when in effect (driven by validate_action options in api.yml).

@dkorn
Copy link
Contributor Author

dkorn commented Mar 30, 2017

@abellotti the UI works with the MiqSet add_member, remove_member actions.

I submitted a PR to expose these actions in case the object to assign the policies to is a policy profile: #14575
Hope this approach is acceptable.

@dkorn
Copy link
Contributor Author

dkorn commented Apr 4, 2017

@abellotti can we progress with this PR (alert profiles CRUD) without the assigning of alerts to alerts profiles? (which is also discussed regarding policies in another PR of mine #14575)

@dkorn
Copy link
Contributor Author

dkorn commented Apr 19, 2017

@abellotti bumping this one up

@Loicavenel
Copy link

@abellotti Hi Alberto, we need your help on this one..

Copy link
Member

@abellotti abellotti left a comment

Choose a reason for hiding this comment

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

Hi @dkorn, this looks good, a couple of minor changes. Thanks !!

/cc @Loicavenel

module AlertDefinitions
def alert_definitions_query_resource(object)
return {} unless object.respond_to?(:miq_alerts)
object.miq_alerts
Copy link
Member

Choose a reason for hiding this comment

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

probably should return [], above 2 lines can just be:

   object.respond_to?(:miq_alerts) ? object.miq_alerts : []

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

@@ -143,3 +144,115 @@
expect(alert_definitions.second.reload.description).to eq("Updated Test Alert 2")
end
end

describe "Alerts Definition Profiles API" do
it "reads 2 alert definition profiles as a collection" do
Copy link
Member

Choose a reason for hiding this comment

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

let's add a test for accessing without appropriate role and expect the forbidden error. 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.

Added, thanks!

api_basic_authorize action_identifier(:alert_definition_profiles, :delete, :resource_actions, :post)
alert_definition_profile = FactoryGirl.create(:miq_alert_set)
run_post(alert_definition_profiles_url(alert_definition_profile.id), gen_request(:delete))
expect(response).to have_http_status(:ok)
Copy link
Member

Choose a reason for hiding this comment

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

just esthetics/grouping, if you can add a blank line between the run_* commands and the expects, here and the tests below. 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.

Done, thanks!

@dkorn dkorn closed this Apr 25, 2017
@dkorn dkorn reopened this Apr 25, 2017
Copy link
Member

@abellotti abellotti left a comment

Choose a reason for hiding this comment

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

this is looking great, minor update to api.yml and we're good. Thanks!!

config/api.yml Outdated
:identifier: alert_definition_profile
:options:
- :collection
- :subcollection
Copy link
Member

Choose a reason for hiding this comment

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

I didn't see alert_definition_profiles declared as a subcollection of others, so probably drop line 96.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

* added tests for accessing without appropriate role
* small refactor to the subcollection controller
* esthetic changes in specs
@dkorn dkorn force-pushed the alert_definition_profiles branch from 9c76216 to f509b39 Compare April 27, 2017 09:00
@miq-bot
Copy link
Member

miq-bot commented Apr 27, 2017

Checked commits dkorn/manageiq@4067acb~...f509b39 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
3 files checked, 0 offenses detected
Everything looks fine. 🍰

@abellotti abellotti added this to the Sprint 60 Ending May 8, 2017 milestone Apr 27, 2017
@abellotti
Copy link
Member

Thanks @dkorn for the update, this looks great!! 👍

@abellotti abellotti merged commit 56040f2 into ManageIQ:master Apr 27, 2017
@dkorn dkorn deleted the alert_definition_profiles branch April 27, 2017 11:13
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.

6 participants