Bug 535737 (RHQ-2401) - add API to know how many servers are in NORMAL mode
Summary: add API to know how many servers are in NORMAL mode
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: RHQ-2401
Product: RHQ Project
Classification: Other
Component: Core Server
Version: unspecified
Hardware: All
OS: All
medium
medium
Target Milestone: ---
: ---
Assignee: RHQ Project Maintainer
QA Contact:
URL: http://jira.rhq-project.org/browse/RH...
Whiteboard:
Depends On:
Blocks: rhq_triage
TreeView+ depends on / blocked
 
Reported: 2009-09-01 17:52 UTC by John Mazzitelli
Modified: 2010-10-07 03:45 UTC (History)
2 users (show)

Fixed In Version: 1.4
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2010-10-07 03:45:59 UTC
Embargoed:


Attachments (Terms of Use)

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


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