Bug 535737 (RHQ-2401)

Summary: add API to know how many servers are in NORMAL mode
Product: [Other] RHQ Project Reporter: John Mazzitelli <mazz>
Component: Core ServerAssignee: RHQ Project Maintainer <rhq-maint>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: cwelton, jmarques
Target Milestone: ---Keywords: CodeChange, SubBug
Target Release: ---   
Hardware: All   
OS: All   
URL: http://jira.rhq-project.org/browse/RHQ-2401
Whiteboard:
Fixed In Version: 1.4 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-10-07 03:45:59 UTC Type: ---
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: 565628    

Description John Mazzitelli 2009-09-01 17:52:00 UTC
(just adding this so I don't forget it for 1.4)

It would be nice to have an API to be able to ask "how many RHQ Servers are currently running in the cloud"?

The Server.java POJO needs this query:

    // gets all other servers running in the cloud other than the named server
    @NamedQuery(name = Server.QUERY_FIND_ALL_NORMAL_BUT_ONE, query = "" //
        + "SELECT s " //
        + "  FROM Server s " //
        + " WHERE s.name <> :name " //
        + "   AND s.operationMode = 'NORMAL'"),

CloudManagerLocal defines this:

    /**
     * Counts all of the servers currently running in the cloud, except for the given server name.
     * This lets you know, for example, if there are other servers running in the cloud, other then the server
     * making this request. Use this to ask the question, "am I the only server currently running".
     * Note this will not count servers in maintenance mode nor will it count recently installed but not yet fully started
     * servers.
     * 
     * @param serverName the server to ignore in the count
     *
     * @return the number of servers running, not including the named server
     */
    int getCountOfAllOtherNormalServers(String serverName);

CloudManagerBean has this impl:

    public int getCountOfAllOtherNormalServers(String serverName) {
        // note the use of count query to just get the number
        Query query = PersistenceUtility.createCountQuery(entityManager, Server.QUERY_FIND_ALL_NORMAL_BUT_ONE);
        query.setParameter("name", serverName);

        try {
            long serverCount = (Long) query.getSingleResult();
            return (int) serverCount;
        } catch (NoResultException nre) {
            log.debug("Could not get count of other normal instances, returning 0...");
            return 0;
        }
    }

Its kinda hokey having to pass in a server name, perhaps we use under the covers this:

org.rhq.enterprise.server.cloud.instance.ServerManagerBean.getServer()

which really just boils down to the following (if you don't want an extra DB hit to get the server name):

org.rhq.enterprise.server.cloud.instance.ServerManagerBean.getIdentity()

Comment 1 Red Hat Bugzilla 2009-11-10 21:03:43 UTC
This bug was previously known as http://jira.rhq-project.org/browse/RHQ-2401


Comment 2 wes hayutin 2010-02-16 16:53:39 UTC
Temporarily adding the keyword "SubBug" so we can be sure we have accounted for all the bugs.

keyword:
new = Tracking + FutureFeature + SubBug

Comment 3 wes hayutin 2010-02-16 16:58:54 UTC
making sure we're not missing any bugs in rhq_triage

Comment 4 Joseph Marques 2010-10-05 16:58:06 UTC
this is already implemented.  see Server.QUERY_FIND_ALL_NORMAL_CLOUD_MEMBERS.  if you want to get a count, use PersistenceUtility.createCountQuery.  in the future, we should probably write ServerCriteria so that we don't have to maintain these manual queries anymore.

Comment 5 Corey Welton 2010-10-07 03:45:59 UTC
Closing per triage