1 22 package org.jboss.test; 23 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.Hashtable ; 27 28 import javax.management.ObjectName ; 29 import javax.naming.InitialContext ; 30 31 import org.jboss.jmx.adaptor.rmi.RMIAdaptor; 32 33 41 public class JBossTestClusteredServices extends JBossTestServices 42 { 43 protected ArrayList adaptors = null; 44 protected ArrayList servers = null; 45 protected ArrayList namingURLs = null; 46 protected ArrayList namingURLsHA = null; 47 protected ArrayList httpURLs = null; 48 49 51 public JBossTestClusteredServices(Class clazz) 52 { 53 super(clazz); 54 } 55 56 57 58 @Override 59 public void setUp() throws Exception 60 { 61 super.setUp(); 62 } 63 64 @Override 65 public void tearDown() throws Exception 66 { 67 super.tearDown(); 68 } 69 70 71 72 int getServerCount() 73 { 74 return servers.size(); 75 } 76 77 RMIAdaptor[] getAdaptors() throws Exception 78 { 79 RMIAdaptor[] tmp = new RMIAdaptor[adaptors.size()]; 81 adaptors.toArray(tmp); 82 return tmp; 83 } 84 RMIAdaptor getAdaptor(int index) throws Exception 85 { 86 RMIAdaptor adaptor = (RMIAdaptor) adaptors.get(index); 88 return adaptor; 89 } 90 91 String [] getServers() throws Exception 92 { 93 String [] tmp = new String [servers.size()]; 95 servers.toArray(tmp); 96 return tmp; 97 } 98 String getServer(int index) throws Exception 99 { 100 String server = (String ) servers.get(index); 102 return server; 103 } 104 105 109 String [] getNamingURLs() throws Exception 110 { 111 String [] tmp = new String [namingURLs.size()]; 113 namingURLs.toArray(tmp); 114 return tmp; 115 } 116 String getNamingURL(int index) throws Exception 117 { 118 String server = (String ) namingURLs.get(index); 120 return server; 121 } 122 123 127 String [] getHANamingURLs() throws Exception 128 { 129 String [] tmp = new String [namingURLsHA.size()]; 131 namingURLsHA.toArray(tmp); 132 return tmp; 133 } 134 String getHANamingURL(int index) throws Exception 135 { 136 String server = (String ) namingURLsHA.get(index); 138 return server; 139 } 140 141 145 String [] getHttpURLs() throws Exception 146 { 147 String [] tmp = new String [httpURLs.size()]; 149 httpURLs.toArray(tmp); 150 return tmp; 151 } 152 String getHttpURL(int index) throws Exception 153 { 154 String server = (String ) httpURLs.get(index); 156 return server; 157 } 158 159 168 public void deploy(RMIAdaptor server, String name) throws Exception 169 { 170 if (Boolean.getBoolean("jbosstest.nodeploy") == true) 171 { 172 log.debug("Skipping deployment of: " + name); 173 return; 174 } 175 176 URL deployURL = getDeployURL(name); 177 log.debug("Deploying " + name + ", url=" + deployURL + " to " + server); 178 invoke(server, 179 getDeployerName(), 180 "deploy", 181 new Object []{deployURL}, 182 new String []{"java.net.URL"}); 183 } 184 185 public void redeploy(RMIAdaptor server, String name) throws Exception 186 { 187 if (Boolean.getBoolean("jbosstest.nodeploy") == true) 188 { 189 log.debug("Skipping redeployment of: " + name); 190 return; 191 } 192 193 URL deployURL = getDeployURL(name); 194 log.debug("Deploying " + name + ", url=" + deployURL); 195 invoke(server, 196 getDeployerName(), 197 "redeploy", 198 new Object []{deployURL}, 199 new String []{"java.net.URL"}); 200 } 201 202 211 public void undeploy(RMIAdaptor server, String name) throws Exception 212 { 213 if (Boolean.getBoolean("jbosstest.nodeploy") == true) 214 return; 215 URL deployURL = getDeployURL(name); 216 log.debug("Undeploying " + name + ", url=" + deployURL); 217 Object [] args = {deployURL}; 218 String [] sig = {"java.net.URL"}; 219 invoke(server, getDeployerName(), "undeploy", args, sig); 220 } 221 222 232 protected Object invoke(ObjectName name, String method, Object [] args, 233 String [] sig) 234 throws Exception 235 { 236 RMIAdaptor[] adaptors = getAdaptors(); 237 238 Object result = null; 239 for (int i = 0; i < adaptors.length; i++) 240 { 241 RMIAdaptor adaptor = adaptors[i]; 242 log.debug("Using RMIAdaptor: "+adaptor); 243 result = invoke(adaptor, name, method, args, sig); 244 } 245 246 return result; 247 248 } 249 250 public void init() throws Exception 251 { 252 super.init(); 253 254 if (initialContext == null) 255 { 256 initialContext = new InitialContext (); 257 } 258 if (adaptors == null) 259 { 260 adaptors = new ArrayList (); 261 servers = new ArrayList (); 262 namingURLs = new ArrayList (); 263 namingURLsHA = new ArrayList (); 264 httpURLs = new ArrayList (); 265 String adaptorName = System.getProperty("jbosstest.server.name"); 266 if (adaptorName == null) 267 adaptorName = "jmx/invoker/RMIAdaptor"; 268 269 Hashtable env = new Hashtable (); 270 env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); 271 env.put("java.naming.factory.url.pkgs", "org.jnp.interfaces"); 272 273 String node = "jbosstest.cluster.node"; 275 int count = 0; 276 while (count < 10) 277 { 278 String prop = node + count; 279 String host = System.getProperty(prop); 280 count++; 281 if (host == null) 282 break; 283 log.info(prop + " = " + host); 284 servers.add(host); 285 String urlProp = prop + ".jndi.url"; 287 String urlDefault = "jnp://" + host + ":1099"; 288 String urlValue = System.getProperty(urlProp, urlDefault); 289 log.debug("JNDI Url for node=" + count + " is:" + urlValue); 290 namingURLs.add(urlValue); 291 env.put("java.naming.provider.url", urlValue); 292 InitialContext tmpCtx = new InitialContext (env); 294 RMIAdaptor adaptor = (RMIAdaptor) tmpCtx.lookup(adaptorName); 295 adaptors.add(adaptor); 296 297 urlProp = prop + ".hajndi.url"; 299 urlDefault = "jnp://" + host + ":1100"; 300 urlValue = System.getProperty(urlProp, urlDefault); 301 log.debug("HA-JNDI Url for node=" + count + " is:" + urlValue); 302 namingURLsHA.add(urlValue); 303 304 urlProp = prop + ".http.url"; 306 urlDefault = "http://" + host + ":8080"; 307 urlValue = System.getProperty(urlProp, urlDefault); 308 log.debug("Http Url for node=" + count + " is:" + urlValue); 309 httpURLs.add(urlValue); 310 } 311 312 if (adaptors.size() == 0) 313 throw new IllegalStateException ("No jbosstest.cluster.node values found"); 314 } 315 } 316 317 320 public void setServerNames(String [] snames) 321 { 322 if (snames == null) return; 323 for (int i = 0; i < snames.length; i++) 324 { 325 servers.add(snames[i]); 326 } 327 } 328 329 } 330 | Popular Tags |