Description of problem: User is unable to purge deleted plug-ins even though plug-in is marked deleted and eligible for purge. This is due to the following query PluginManagerBean.isReadyForPurge(Plugin plugin) using a LIKE query to verify all the plug-in's resource types have been deleted: DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*) FROM ResourceType resourcetype WHERE ( LOWER( resourcetype.plugin ) like :pluginName ESCAPE '\\' AND resourcetype.deleted = :deleted ) 2012-08-03 17:09:49,666 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbossas%) 2012-08-03 17:09:49,666 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false) 2012-08-03 17:09:49,667 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=49 In this case, the plug-in which was deleted is named JBossAS and all of its resource types have also been deleted. However, due to '%jbossas%' being bound to the :pluginName variable and the use of the LIKE comparison, the query returns a count of 49 rows due to the JBossAS5 plug-in also being installed. Therefore, the JBossAS plug-in could only be purged if the JBossAS5 plug-in was also deleted -- which is undesirable. Version-Release number of selected component (if applicable): 3.1.0 How reproducible: Always Steps to Reproduce: 1. Ensure JBoss AS 4 and AS 5 plug-ins are installed 2. Import JBoss EAP 4.3 (profile: all) instance into inventory 3. Delete JBossAS (4.x) and JBoss Cache (2.x) plug-ins * Message center should show: Deleted agent plugins: [JBoss Application Server, JBossCache 2.x Services] 4. Confirm plug-ins have been marked deleted * From http://localhost:7080/coregui/#Test/ServerAccess/SQL execute: SELECT id,name,display_name,description,version,amps_version,enabled,status,path,md5,ctime,mtime,deployment FROM rhq_plugin WHERE deployment='AGENT' AND status='DELETED' ORDER BY name,id ASC; The result should contain the two deleted plug-ins with the name "JBossAS" and "JBossCache". 5. Purge the plug-ins (Note: You must click Show Deleted to select the deleted plug-ins for purge) * Message center should show: Preparing to purge agent plugins [JBoss Application Server, JBossCache 2.x Services]. This may take a few minutes ... 6. Confirm the plug-ins have been purged After the purge was performed, the plug-ins should be purged within 5 minutes. Actual results: Even after 30 minutes, the JBossAS and JBossCache plug-ins have not been removed and server debug log reveals the following message each time plug-in purge job is executed: DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*) FROM ResourceType resourcetype WHERE ( LOWER( resourcetype.plugin ) like :pluginName ESCAPE '\\' AND resourcetype.deleted = :deleted ) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbossas%) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=49 DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] SELECT COUNT(*) FROM ResourceType resourcetype WHERE ( LOWER( resourcetype.plugin ) like :pluginName ESCAPE '\\' AND resourcetype.deleted = :deleted ) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (pluginName, %jbosscache%) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryGenerator] Bind: (deleted, false) DEBUG [org.rhq.enterprise.server.util.CriteriaQueryRunner] restriction=COUNT_ONLY, resultCount=9 Expected results: The JBossAS and JBossCache plug-ins should be removed from the rhq_plugin table and no longer appear on the agent plug-ins page in the UI. Additional info: Mazz tracked this down to the isReadyForPurge method itself. The method should use criteria.setStrict(true). It should also log at debug to indicate the actual count so that plug-in purge failure can be easily determined.
As per triage: retarget at 312
PluginManagerBean.isReadyForPurge(Plugin) has been refactored so that the LIKE operator is not used in the resource type criteria. I have also added a test method in PluginManagerBeanTest to cover this scenario. Lastly, a debug log statement that looks like the following has been added to isReadyForPurge, <plugin> is not ready to be purged. There are still <resource_type_count> resource types in the system for this plugin. master commit hashes: cf039adcb51 2f891cc677
Changes have been pushed to the release/jon3.1.x branch. commit hashes: a77fb7ef8c9fe 687c313ad97f
Moving this to ON_QA as available for testing in https://brewweb.devel.redhat.com//buildinfo?buildID=243389.
Verified on JON 3.1.2 ER2 build. The plugins are removed from 'rhq_plugin' table. Below query returns empty set. SELECT id,name,display_name,description,version,amps_version,enabled,status,path,md5,ctime,mtime,deployment FROM rhq_plugin WHERE deployment='AGENT' AND status='DELETED' ORDER BY name,id ASC; The plugins does not appear on the 'Agent Plug-ins' page in the UI. The server log shows below debug message: 2012-12-05 14:50:06,604 DEBUG [org.rhq.enterprise.server.resource.metadata.PluginManagerBean] AgentPlugin [id=10011, name=JBossAS, md5=5fad5b96751fa0ac672dbb587e9a0981] is not ready to be purged. It still has 27 resource types in the database.