FileDocCategorySizeDatePackage
ClusterHelper.javaAPI DocGlassfish v2 API13007Sat Dec 24 18:47:58 GMT 2005com.sun.enterprise.config.serverbeans

ClusterHelper

public class ClusterHelper extends ConfigAPIHelper
author
kebbs

Fields Summary
Constructors Summary
Methods Summary
public static booleanclusterReferencesApplication(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName, java.lang.String appName)
Return true if the given server instance references the stated application.

        final Cluster cluster = getClusterByName(configContext, clusterName);         
        return clusterReferencesApplication(cluster, appName);
    
public static booleanclusterReferencesApplication(com.sun.enterprise.config.serverbeans.Cluster cluster, java.lang.String appName)

        final ApplicationRef ref = cluster.getApplicationRefByRef(appName);
        return (ref == null) ? false : true;
    
public static booleanclusterReferencesJdbcConPool(com.sun.enterprise.config.ConfigContext ctx, java.lang.String clusterName, java.lang.String poolName)


        final Cluster cluster = getClusterByName(ctx, clusterName);
        return clusterReferencesJdbcConPool(cluster, poolName);
    
public static booleanclusterReferencesJdbcConPool(com.sun.enterprise.config.serverbeans.Cluster cluster, java.lang.String poolName)

        final ResourceRef ref = cluster.getResourceRefByRef(poolName);
        return (ref == null) ? false : true;
    
public static booleanclusterReferencesResource(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName, java.lang.String resourceName)
Return true if the given server instance references the stated resource.

        final Cluster cluster = getClusterByName(configContext, clusterName);         
        return clusterReferencesResource(cluster, resourceName);
    
public static booleanclusterReferencesResource(com.sun.enterprise.config.serverbeans.Cluster cluster, java.lang.String resourceName)

        final ResourceRef ref = cluster.getResourceRefByRef(resourceName);
        return (ref == null) ? false : true;
    
public static com.sun.enterprise.config.serverbeans.ApplicationRef[]getApplicationReferences(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return all the application refs of the server

        final Cluster cluster = getClusterByName(configContext, clusterName);
        if (cluster.getApplicationRef() == null) {
            return new ApplicationRef[0];
        } else {
            return cluster.getApplicationRef();
        }
    
public static com.sun.enterprise.config.serverbeans.ClustergetClusterByName(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return the named cluster. If the cluster does not exist, an exception will be thrown.

        final Domain domain = getDomainConfigBean(configContext);          
        final Cluster cluster = domain.getClusters().getClusterByName(clusterName);
        if (cluster == null) {
            throw new ConfigException(_strMgr.getString("noSuchCluster", 
                clusterName));
        }
        return cluster;
    
public static com.sun.enterprise.config.serverbeans.ClustergetClusterForInstance(com.sun.enterprise.config.ConfigContext configContext, java.lang.String instanceName)
Return the cluster associated with the given instanceName. An exception is thrown if the givne instanceName does not exist or is not a clustered server instance. FIXTHIS: We really need to give the server a reference to its cluster; rather than the other way around. This will make this operation much faster and management easier in general.

        Cluster[] clusters = getClustersInDomain(configContext);
        for (int i = 0; i < clusters.length; i++) {
            ServerRef[] servers = clusters[i].getServerRef();
            for (int j = 0; j < servers.length; j++) {
                if (servers[j].getRef().equals(instanceName)) {
                    // check to see if the server exists as a sanity check. 
                    // NOTE: we are not checking for duplicate server instances here.
                    Server server = ServerHelper.getServerByName(configContext, instanceName);
                    return (clusters[i]);
                }
            }
        }
        throw new ConfigException(_strMgr.getString("noSuchClusteredInstance", 
            instanceName));
    
public static java.lang.StringgetClustersAsString(com.sun.enterprise.config.serverbeans.Cluster[] clusters)
Return the given cluster array as a comma separated string

        String result = "";
        for (int i = 0; i < clusters.length; i++) {
            result += clusters[i].getName();
            if (i < clusters.length - 1) {
                result += ",";
            }
        }
        return result;
    
public static com.sun.enterprise.config.serverbeans.Cluster[]getClustersForNodeAgent(com.sun.enterprise.config.ConfigContext configContext, java.lang.String agentName)
Return all the clusters associasted with a node agent. In other words return all the clusters for the instances managed by the given agentName.

        Cluster[] clusters = getClustersInDomain(configContext);
        Server[] servers = ServerHelper.getServersOfANodeAgent(configContext, agentName);
        ArrayList result = new ArrayList();
        for (int i = 0; i < clusters.length; i++) {
            ServerRef[] serverRefs = clusters[i].getServerRef();
            for (int j = 0; j < serverRefs.length; j++) {                
                for (int k = 0; k < servers.length; k++) {
                    if (serverRefs[j].getRef().equals(servers[k].getName())) {
                        if (!result.contains(clusters[i])) {
                            result.add(clusters[i]);
                        }
                    }
                }
            }
        }
        return (Cluster[])result.toArray(new Cluster[result.size()]);
    
public static com.sun.enterprise.config.serverbeans.Cluster[]getClustersInDomain(com.sun.enterprise.config.ConfigContext configContext)
Return all the clusters in the domain or a zero length list.

        final Domain domain = getDomainConfigBean(configContext);  
        final Clusters clusters = domain.getClusters();
        if (clusters != null) {
            if (clusters.getCluster() != null) {
                return clusters.getCluster();
            }
        }            
        return new Cluster[0];
    
public static com.sun.enterprise.config.serverbeans.Cluster[]getClustersReferencingApplication(com.sun.enterprise.config.ConfigContext configContext, java.lang.String appName)
Return the server instances referencing the given configName or a zero length list.

                
        //Now find all server instances that reference the application
        Cluster[] clusters = getClustersInDomain(configContext);
        ArrayList result = new ArrayList();
        for (int i = 0; i < clusters.length; i++) {
            if (clusterReferencesApplication(clusters[i], appName)) {
                result.add(clusters[i]);
            }            
        }
        return (Cluster[])result.toArray(new Cluster[result.size()]);
    
public static com.sun.enterprise.config.serverbeans.Cluster[]getClustersReferencingConfig(com.sun.enterprise.config.ConfigContext configContext, java.lang.String configName)
Return all the clusters referencing the given configuration or a zero length list if there are none.

        
        //First ensure that the config exists
        Config config = getConfigByName(configContext, configName);
        
        //Now find all server instances that reference that config.
        Cluster[] clusters = getClustersInDomain(configContext);
        ArrayList result = new ArrayList();
        for (int i = 0; i < clusters.length; i++) {
            if (clusters[i].getConfigRef().equals(configName)) {
                result.add(clusters[i]);
            }            
        }
        return (Cluster[])result.toArray(new Cluster[result.size()]);
    
public static com.sun.enterprise.config.serverbeans.Cluster[]getClustersReferencingResource(com.sun.enterprise.config.ConfigContext configContext, java.lang.String resName)
Return the server instances referencing the given configName or a zero length list.

                
        //Now find all server instances that reference the application
        Cluster[] clusters = getClustersInDomain(configContext);
        ArrayList result = new ArrayList();
        for (int i = 0; i < clusters.length; i++) {
            if (clusterReferencesResource(clusters[i], resName)) {
                result.add(clusters[i]);
            }            
        }
        return (Cluster[])result.toArray(new Cluster[result.size()]);
    
public static com.sun.enterprise.config.serverbeans.ConfiggetConfigForCluster(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return the configuration associated with the given clusterName. An exception is thrown if the clusters configuration does not exist (which should never happen).

        final Cluster cluster = getClusterByName(configContext, clusterName);                
        final Domain domain = getDomainConfigBean(configContext);                  
        final Config config = domain.getConfigs().getConfigByName(cluster.getConfigRef());
        if (config == null) {
            throw new ConfigException(_strMgr.getString("noSuchClusterConfig", 
                cluster.getConfigRef(), clusterName));
        }
        return config;
    
public static com.sun.enterprise.config.serverbeans.ResourceRef[]getResourceReferences(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return all the resource refs of the server

        final Cluster cluster = getClusterByName(configContext, clusterName);
        if (cluster.getResourceRef() == null) {
            return new ResourceRef[0];
        } else {
            return cluster.getResourceRef();
        }
    
public static booleanisACluster(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return true if the given clusterName corresponds to the name of a cluster.

        
        final Domain domain = getDomainConfigBean(configContext);        
        final Clusters clusters = domain.getClusters();
        if (clusters == null) {
            return false;
        }
        final Cluster cluster = clusters.getClusterByName(clusterName);
        return (cluster != null ? true : false);
    
public static booleanisClusterStandAlone(com.sun.enterprise.config.ConfigContext configContext, java.lang.String clusterName)
Return true if the cluster is standalone. A standalone cluster has a configuration named -config and it configuration is referenced by the cluster (and its instances) only. No other clusters or servers may refer to its configuration.

        final Cluster cluster = getClusterByName(configContext, clusterName);
        final String configName = cluster.getConfigRef();
        if (isConfigurationNameStandAlone(configName, clusterName)) {            
            if (isConfigurationReferencedByClusterOnly(configContext, configName, clusterName)) {
                return true;
            }
        }       
       return false;