Bug 970756

Summary: Creation of alert definition condition on operation result needs to check for valid operations
Product: [Other] RHQ Project Reporter: Heiko W. Rupp <hrupp>
Component: RESTAssignee: Heiko W. Rupp <hrupp>
Status: NEW --- QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.8CC: theute
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 967488 Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 967488    
Bug Blocks:    

Description Heiko W. Rupp 2013-06-04 19:15:48 UTC
The code in org.rhq.enterprise.server.rest.AlertDefinitionHandlerBean#conditionRestToCondition needs to validate the passed name for a CONTROL alert category.


+++ This bug was initially created as a clone of Bug #967488 +++

Description of problem: Creating alert definitions via REST API is very unclear to me. I am trying to POST a definition that would trigger an alert when given operation on given resource fails. I am not able to submit correct body to REST API to create such alert def.


Version-Release number of selected component (if applicable):
RHQ 4.8-master

How reproducible: always


Steps to Reproduce:

I've been trying to send this body:

{'name':'restAlertDef',
'enabled':True,
'dampeningCategory':'NONE',
'conditionMode':'ANY',
'conditions':[{'name':'EQUALS','option':'discovery','category':'CONTROL'}]}


Actual results: see shot1.png attachment about how that condition looks in UI


According to shot1.png .. I tried to send this: 
{'name':'restAlertDef',
'enabled':True,
'dampeningCategory':'NONE',
'conditionMode':'ANY',
'conditions':[{'name':'discovery','option':'SUCCESS','category':'CONTROL'}]}

Actual results: 
REST API returns: Can not construct instance of org.rhq.core.domain.alert.AlertConditionOperator from String value 'EQUAL': value not one of declared Enum instance names\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2bd7b0c6; line: 1, column: 68] (through reference chain: org.rhq.enterprise.server.rest.domain.AlertDefinitionRest[\"conditions\"]->org.rhq.enterprise.server.rest.domain.AlertConditionRest[\"name

Additional info:
The key issue is in "name" property of of condition, because it can be an operation name in when "category" equals "CONTROL", for this case we should also check, if operation by given name exists (if not just list all possible operations), same could apply to "option" value which is valid only if it can be parsed to OperationResult enum.

--- Additional comment from Heiko W. Rupp on 2013-06-04 15:13:50 EDT ---

master e718326

checking for valid operation names still needs to be implemented. I'll clone this BZ for that purpose.