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   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-01 15:22:17 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Bug Depends On:    
Bug Blocks: 809626, 811507    

Description Stefan Negrea 2012-04-11 06:39:58 EDT
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"/>

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

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 name="JBossAS7 Standalone Server">

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

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 06:48:30 EDT
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 07:02:08 EDT
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.

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

Comment 4 Heiko W. Rupp 2013-09-01 15:22:17 EDT
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.