Bug 874123 - Agent plug-in purge fails due to LIKE criteria in count query against rhq_resource_type table
Agent plug-in purge fails due to LIKE criteria in count query against rhq_res...
Status: CLOSED CURRENTRELEASE
Product: RHQ Project
Classification: Other
Component: Inventory (Show other bugs)
4.5
All All
urgent Severity high (vote)
: ---
: RHQ 4.6
Assigned To: John Sanda
Mike Foley
:
Depends On: 845700
Blocks:
  Show dependency treegraph
 
Reported: 2012-11-07 09:56 EST by John Sanda
Modified: 2013-09-03 10:43 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 845700
Environment:
Last Closed: 2013-09-03 10:43:29 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 178493 None None None 2012-11-07 09:56:04 EST

  None (edit)
Description John Sanda 2012-11-07 09:56:03 EST
+++ This bug was initially created as a clone of Bug #845700 +++

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.

--- Additional comment from ccrouch@redhat.com on 2012-08-13 12:12:13 EDT ---

As per triage: retarget at 312

--- Additional comment from jsanda@redhat.com on 2012-11-07 09:39:19 EST ---

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
Comment 1 John Sanda 2012-11-07 09:56:54 EST
Moving to ON_QA since changes have been pushed to master.
Comment 2 Heiko W. Rupp 2013-09-03 10:43:29 EDT
Bulk closing of issues in old RHQ releases that are in production for a while now.

Please open a new issue when running into an issue.

Note You need to log in before you can comment on or make changes to this bug.