1 23 24 29 30 package com.sun.enterprise.config.serverbeans; 31 32 import com.sun.enterprise.config.ConfigContext; 33 import com.sun.enterprise.config.ConfigException; 34 35 import com.sun.enterprise.config.serverbeans.Domain; 36 import com.sun.enterprise.config.serverbeans.Clusters; 37 import com.sun.enterprise.config.serverbeans.Cluster; 38 import com.sun.enterprise.config.serverbeans.Server; 39 import com.sun.enterprise.config.serverbeans.ServerRef; 40 import com.sun.enterprise.config.serverbeans.ApplicationRef; 41 import com.sun.enterprise.config.serverbeans.ResourceRef; 42 import com.sun.enterprise.config.serverbeans.Config; 43 44 import java.util.ArrayList ; 45 46 50 public class ClusterHelper extends ConfigAPIHelper { 51 52 55 public static String getClustersAsString(Cluster[] clusters) 56 { 57 String result = ""; 58 for (int i = 0; i < clusters.length; i++) { 59 result += clusters[i].getName(); 60 if (i < clusters.length - 1) { 61 result += ","; 62 } 63 } 64 return result; 65 } 66 67 70 public static Cluster[] getClustersInDomain(ConfigContext configContext) 71 throws ConfigException 72 { 73 final Domain domain = getDomainConfigBean(configContext); 74 final Clusters clusters = domain.getClusters(); 75 if (clusters != null) { 76 if (clusters.getCluster() != null) { 77 return clusters.getCluster(); 78 } 79 } 80 return new Cluster[0]; 81 } 82 83 86 public static boolean isACluster(ConfigContext configContext, String clusterName) 87 throws ConfigException 88 { 89 final Domain domain = getDomainConfigBean(configContext); 90 final Clusters clusters = domain.getClusters(); 91 if (clusters == null) { 92 return false; 93 } 94 final Cluster cluster = clusters.getClusterByName(clusterName); 95 return (cluster != null ? true : false); 96 } 97 98 102 public static Cluster getClusterByName(ConfigContext configContext, String clusterName) 103 throws ConfigException 104 { 105 final Domain domain = getDomainConfigBean(configContext); 106 final Cluster cluster = domain.getClusters().getClusterByName(clusterName); 107 if (cluster == null) { 108 throw new ConfigException(_strMgr.getString("noSuchCluster", 109 clusterName)); 110 } 111 return cluster; 112 } 113 114 121 public static Cluster getClusterForInstance(ConfigContext configContext, String instanceName) 122 throws ConfigException 123 { 124 Cluster[] clusters = getClustersInDomain(configContext); 125 for (int i = 0; i < clusters.length; i++) { 126 ServerRef[] servers = clusters[i].getServerRef(); 127 for (int j = 0; j < servers.length; j++) { 128 if (servers[j].getRef().equals(instanceName)) { 129 Server server = ServerHelper.getServerByName(configContext, instanceName); 132 return (clusters[i]); 133 } 134 } 135 } 136 throw new ConfigException(_strMgr.getString("noSuchClusteredInstance", 137 instanceName)); 138 } 139 140 141 145 public static Cluster[] getClustersReferencingConfig(ConfigContext configContext, String configName) 146 throws ConfigException 147 { 148 Config config = getConfigByName(configContext, configName); 150 151 Cluster[] clusters = getClustersInDomain(configContext); 153 ArrayList result = new ArrayList (); 154 for (int i = 0; i < clusters.length; i++) { 155 if (clusters[i].getConfigRef().equals(configName)) { 156 result.add(clusters[i]); 157 } 158 } 159 return (Cluster[])result.toArray(new Cluster[result.size()]); 160 } 161 162 166 public static Cluster[] getClustersForNodeAgent(ConfigContext configContext, String agentName) 167 throws ConfigException 168 { 169 Cluster[] clusters = getClustersInDomain(configContext); 170 Server[] servers = ServerHelper.getServersOfANodeAgent(configContext, agentName); 171 ArrayList result = new ArrayList (); 172 for (int i = 0; i < clusters.length; i++) { 173 ServerRef[] serverRefs = clusters[i].getServerRef(); 174 for (int j = 0; j < serverRefs.length; j++) { 175 for (int k = 0; k < servers.length; k++) { 176 if (serverRefs[j].getRef().equals(servers[k].getName())) { 177 if (!result.contains(clusters[i])) { 178 result.add(clusters[i]); 179 } 180 } 181 } 182 } 183 } 184 return (Cluster[])result.toArray(new Cluster[result.size()]); 185 } 186 187 192 public static Config getConfigForCluster(ConfigContext configContext, String clusterName) 193 throws ConfigException 194 { 195 final Cluster cluster = getClusterByName(configContext, clusterName); 196 final Domain domain = getDomainConfigBean(configContext); 197 final Config config = domain.getConfigs().getConfigByName(cluster.getConfigRef()); 198 if (config == null) { 199 throw new ConfigException(_strMgr.getString("noSuchClusterConfig", 200 cluster.getConfigRef(), clusterName)); 201 } 202 return config; 203 } 204 205 210 public static boolean isClusterStandAlone(ConfigContext configContext, String clusterName) 211 throws ConfigException 212 { 213 final Cluster cluster = getClusterByName(configContext, clusterName); 214 final String configName = cluster.getConfigRef(); 215 if (isConfigurationNameStandAlone(configName, clusterName)) { 216 if (isConfigurationReferencedByClusterOnly(configContext, configName, clusterName)) { 217 return true; 218 } 219 } 220 return false; 221 } 222 223 226 public static boolean clusterReferencesApplication(ConfigContext configContext, 227 String clusterName, String appName) throws ConfigException 228 { 229 final Cluster cluster = getClusterByName(configContext, clusterName); 230 return clusterReferencesApplication(cluster, appName); 231 } 232 233 public static boolean clusterReferencesApplication(Cluster cluster, String appName) 234 throws ConfigException 235 { 236 final ApplicationRef ref = cluster.getApplicationRefByRef(appName); 237 return (ref == null) ? false : true; 238 } 239 240 public static boolean clusterReferencesJdbcConPool(ConfigContext ctx, 241 String clusterName, String poolName) throws ConfigException 242 { 243 244 final Cluster cluster = getClusterByName(ctx, clusterName); 245 return clusterReferencesJdbcConPool(cluster, poolName); 246 } 247 248 public static boolean clusterReferencesJdbcConPool(Cluster cluster, 249 String poolName) throws ConfigException 250 { 251 final ResourceRef ref = cluster.getResourceRefByRef(poolName); 252 return (ref == null) ? false : true; 253 } 254 255 258 public static Cluster[] getClustersReferencingApplication(ConfigContext configContext, String appName) 259 throws ConfigException 260 { 261 Cluster[] clusters = getClustersInDomain(configContext); 263 ArrayList result = new ArrayList (); 264 for (int i = 0; i < clusters.length; i++) { 265 if (clusterReferencesApplication(clusters[i], appName)) { 266 result.add(clusters[i]); 267 } 268 } 269 return (Cluster[])result.toArray(new Cluster[result.size()]); 270 } 271 272 275 public static boolean clusterReferencesResource(ConfigContext configContext, 276 String clusterName, String resourceName) throws ConfigException 277 { 278 final Cluster cluster = getClusterByName(configContext, clusterName); 279 return clusterReferencesResource(cluster, resourceName); 280 } 281 282 public static boolean clusterReferencesResource(Cluster cluster, 283 String resourceName) throws ConfigException 284 { 285 final ResourceRef ref = cluster.getResourceRefByRef(resourceName); 286 return (ref == null) ? false : true; 287 } 288 289 292 public static Cluster[] getClustersReferencingResource(ConfigContext configContext, String resName) 293 throws ConfigException 294 { 295 Cluster[] clusters = getClustersInDomain(configContext); 297 ArrayList result = new ArrayList (); 298 for (int i = 0; i < clusters.length; i++) { 299 if (clusterReferencesResource(clusters[i], resName)) { 300 result.add(clusters[i]); 301 } 302 } 303 return (Cluster[])result.toArray(new Cluster[result.size()]); 304 } 305 306 307 310 public static ApplicationRef[] getApplicationReferences(ConfigContext configContext, 311 String clusterName) throws ConfigException 312 { 313 final Cluster cluster = getClusterByName(configContext, clusterName); 314 if (cluster.getApplicationRef() == null) { 315 return new ApplicationRef[0]; 316 } else { 317 return cluster.getApplicationRef(); 318 } 319 } 320 321 324 public static ResourceRef[] getResourceReferences(ConfigContext configContext, 325 String clusterName) throws ConfigException 326 { 327 final Cluster cluster = getClusterByName(configContext, clusterName); 328 if (cluster.getResourceRef() == null) { 329 return new ResourceRef[0]; 330 } else { 331 return cluster.getResourceRef(); 332 } 333 } 334 } 335 | Popular Tags |