Bug 811525

Summary: [as7] Plugin import of resources with parent-resource-type nested more than one level inside another entity fails
Product: [Other] RHQ Project Reporter: Stefan Negrea <snegrea>
Component: Core ServerAssignee: Stefan Negrea <snegrea>
Status: CLOSED CURRENTRELEASE QA Contact: Mike Foley <mfoley>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 4.4CC: hrupp
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-01 19:22:17 UTC 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:    
Bug Blocks: 809626, 811507    

Description Stefan Negrea 2012-04-11 10:39:58 UTC
Description of problem:
The plugin import of resources with parent-resource-type nested more than one level inside another entity from the same plugin fails.

Here shortened example of such plugin descriptor:
<server name="JBossAS7 Host Controller">
 <server name="Managed Server"/>
</server>

<service name="Transactions Subsystem (Managed)">
 <runs-inside>
  <parent-resource-type name="Managed Server" plugin="jboss-as-7"/>
 </runs-inside>
</service>

The following error is observed in the logs:
Caused by: java.lang.RuntimeException: Couldn't persist type [{jboss-as-7}Transactions Subsystem (Managed)] because parent [{jboss-as-7}Managed Server] wasn't already persisted. 

How reproducible:
Every time

Steps to Reproduce:
1. Write a plugin descriptor based on the example above
2. Compile the plugin
3. Attempt to deploy de plugin
  
Actual results:
Failure to import the plugin with the error noted above.

Expected results:
Th plugin gets imported correctly.



Additional info:

The following plugin descriptor will NOT fail to import:

<server name="JBossAS7 Host Controller">
 <server name="Managed Server"/>
</server>

<server name="JBossAS7 Standalone Server">
</server>


<service name="Transactions Subsystem (Managed)">
 <runs-inside>
  <parent-resource-type name="JBossAS7 Standalone Server" plugin="jboss-as-7"/>
  <parent-resource-type name="Managed Server" plugin="jboss-as-7"/>
 </runs-inside>
</service>


The main difference here is that the service references both a top level server and a nested server. When runs-inside references another top level resource the import will not fail.

Comment 1 Stefan Negrea 2012-04-11 10:48:30 UTC
The code causing the error is in ResourceMetadataManagerBean#updateTypes. 

Using the failing example from above, the code does not take into account such deep nesting. It attempts to find the top level platform/server/services that need to be imported first. The Transactions Subsystem does not get eliminated from the initial import list, even though it should be since it is a child of another server. The code that detects children will only look at direct children of each resource to be imported and not the entire tree.

Comment 2 Stefan Negrea 2012-04-11 11:02:08 UTC
Updated the code to parse the entire tree of each resource. This will ensure that all the resources that are children of another resource (anywhere on the resource tree, not just first level) are removed from the list of top level resources to be imported. Such resource will be imported when is a direct child of a resource.

http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=commit;h=84e0423dbb8727cf8d2a2a557f1109d9a05d0f95

Comment 3 Stefan Negrea 2012-04-11 14:35:48 UTC
Added unit tests that cover the update code for the described scenario.

http://git.fedorahosted.org/git/?p=rhq/rhq.git;a=commit;h=fe3bd7a14c83f039c84154a7b67d1f0e044bd6d8

Comment 4 Heiko W. Rupp 2013-09-01 19:22:17 UTC
Bulk closing of BZs that have no target version set, but which are ON_QA for more than a year and thus are in production for a long time.