1 package org.objectweb.proactive.core.runtime.rmi; 2 3 import org.objectweb.proactive.Body; 4 import org.objectweb.proactive.core.body.UniversalBody; 5 import org.objectweb.proactive.core.descriptor.data.VirtualNode; 6 import org.objectweb.proactive.core.mop.ConstructorCall; 7 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException; 8 import org.objectweb.proactive.core.node.NodeException; 9 import org.objectweb.proactive.core.process.UniversalProcess; 10 import org.objectweb.proactive.core.rmi.RegistryHelper; 11 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 12 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl; 13 import org.objectweb.proactive.core.runtime.VMInformation; 14 import org.objectweb.proactive.core.util.UrlBuilder; 15 import org.objectweb.proactive.ext.security.PolicyServer; 16 import org.objectweb.proactive.ext.security.ProActiveSecurityManager; 17 18 import java.io.IOException ; 19 20 import java.lang.reflect.InvocationTargetException ; 21 22 import java.net.UnknownHostException ; 23 24 import java.rmi.AccessException ; 25 import java.rmi.ConnectException ; 26 import java.rmi.RemoteException ; 27 import java.rmi.server.UnicastRemoteObject ; 28 29 import java.security.cert.X509Certificate ; 30 31 import java.util.ArrayList ; 32 33 34 40 public class RemoteProActiveRuntimeImpl extends UnicastRemoteObject 41 implements RemoteProActiveRuntime { 42 protected transient ProActiveRuntimeImpl proActiveRuntime; 43 protected String proActiveRuntimeURL; 44 45 protected ArrayList nodesArray; 47 48 protected ArrayList vnNodesArray; 50 protected boolean hasCreatedRegistry; 51 52 public RemoteProActiveRuntimeImpl() 56 throws java.rmi.RemoteException , java.rmi.AlreadyBoundException { 57 this.hasCreatedRegistry = RegistryHelper.getRegistryCreator(); 59 this.proActiveRuntime = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime(); 60 this.nodesArray = new java.util.ArrayList (); 61 this.vnNodesArray = new java.util.ArrayList (); 62 this.proActiveRuntimeURL = buildRuntimeURL(); 64 register(proActiveRuntimeURL, false); 66 } 68 69 public String createLocalNode(String nodeName, 73 boolean replacePreviousBinding, PolicyServer ps, String VNname, String jobId) 74 throws java.rmi.RemoteException , NodeException { 75 String nodeURL = null; 76 77 try { 79 nodeURL = buildNodeURL(nodeName); 81 String name = UrlBuilder.getNameFromUrl(nodeURL); 83 84 register(nodeURL, replacePreviousBinding); 86 87 proActiveRuntime.createLocalNode(name, replacePreviousBinding, ps, 88 VNname, jobId); 89 } catch (java.net.UnknownHostException e) { 90 throw new java.rmi.RemoteException ("Host unknown in " + nodeURL, e); 91 } 92 nodesArray.add(nodeURL); 93 return nodeURL; 94 } 95 96 public void killAllNodes() throws java.rmi.RemoteException { 97 for (int i = 0; i < nodesArray.size(); i++) { 98 String url = (String ) nodesArray.get(i); 99 killNode(url); 100 } 101 } 102 103 public void killNode(String nodeName) throws java.rmi.RemoteException { 104 String nodeUrl = null; 105 String name = null; 106 try { 107 nodeUrl = buildNodeURL(nodeName); 108 name = UrlBuilder.getNameFromUrl(nodeUrl); 109 unregister(nodeUrl); 110 } catch (UnknownHostException e) { 111 throw new java.rmi.RemoteException ("Host unknown in " + nodeUrl, e); 112 } 113 proActiveRuntime.killNode(nodeName); 114 } 115 116 public void createVM(UniversalProcess remoteProcess) 122 throws IOException { 123 proActiveRuntime.createVM(remoteProcess); 124 } 125 126 public String [] getLocalNodeNames() { 131 return proActiveRuntime.getLocalNodeNames(); 132 } 133 134 public VMInformation getVMInformation() { 148 return proActiveRuntime.getVMInformation(); 149 } 150 151 public void register(ProActiveRuntime proActiveRuntimeDist, 152 String proActiveRuntimeName, String creatorID, String creationProtocol, 153 String vmName) { 154 proActiveRuntime.register(proActiveRuntimeDist, proActiveRuntimeName, 155 creatorID, creationProtocol, vmName); 156 } 157 158 public ProActiveRuntime[] getProActiveRuntimes() { 159 return proActiveRuntime.getProActiveRuntimes(); 160 } 161 162 public ProActiveRuntime getProActiveRuntime(String proActiveRuntimeName) { 163 return proActiveRuntime.getProActiveRuntime(proActiveRuntimeName); 164 } 165 166 public void killRT(boolean softly) throws java.rmi.RemoteException { 167 killAllNodes(); 168 unregisterAllVirtualNodes(); 169 unregister(proActiveRuntimeURL); 170 if (hasCreatedRegistry) { 171 if (softly) { 172 if (RegistryHelper.getRegistry().list().length > 0) { 173 new RMIKillerThread().start(); 174 return; 175 } 176 } 177 } 178 proActiveRuntime.killRT(softly); 179 } 180 181 public String getURL() { 182 return proActiveRuntimeURL; 183 } 184 185 public ArrayList getActiveObjects(String nodeName) { 193 return proActiveRuntime.getActiveObjects(nodeName); 194 } 195 196 public ArrayList getActiveObjects(String nodeName, String objectName) { 197 return proActiveRuntime.getActiveObjects(nodeName, objectName); 198 } 199 200 public VirtualNode getVirtualNode(String virtualNodeName) { 201 return proActiveRuntime.getVirtualNode(virtualNodeName); 202 } 203 204 public void registerVirtualNode(String virtualNodeName, 205 boolean replacePreviousBinding) throws java.rmi.RemoteException { 206 String virtualNodeURL = null; 207 208 try { 209 virtualNodeURL = buildNodeURL(virtualNodeName); 211 register(virtualNodeURL, replacePreviousBinding); 213 } catch (java.net.UnknownHostException e) { 214 throw new java.rmi.RemoteException ("Host unknown in " + 215 virtualNodeURL, e); 216 } 217 vnNodesArray.add(virtualNodeURL); 218 } 219 220 public void unregisterVirtualNode(String virtualnodeName) 221 throws java.rmi.RemoteException { 222 String virtualNodeURL = null; 223 proActiveRuntime.unregisterVirtualNode(UrlBuilder.removeVnSuffix( 224 virtualnodeName)); 225 try { 226 virtualNodeURL = buildNodeURL(virtualnodeName); 228 unregister(virtualNodeURL); 229 } catch (java.net.UnknownHostException e) { 230 throw new java.rmi.RemoteException ("Host unknown in " + 231 virtualNodeURL, e); 232 } 233 vnNodesArray.remove(virtualNodeURL); 234 } 235 236 public void unregisterAllVirtualNodes() throws java.rmi.RemoteException { 237 for (int i = 0; i < vnNodesArray.size(); i++) { 238 String url = (String ) vnNodesArray.get(i); 239 unregisterVirtualNode(url); 240 } 241 } 242 243 public UniversalBody createBody(String nodeName, 244 ConstructorCall bodyConstructorCall, boolean isNodeLocal) 245 throws ConstructorCallExecutionFailedException, 246 InvocationTargetException { 247 return proActiveRuntime.createBody(nodeName, bodyConstructorCall, 248 isNodeLocal); 249 } 250 251 public UniversalBody receiveBody(String nodeName, Body body) { 252 return proActiveRuntime.receiveBody(nodeName, body); 253 } 254 255 257 260 public X509Certificate getCreatorCertificate() 261 throws java.rmi.RemoteException { 262 return proActiveRuntime.getCreatorCertificate(); 263 } 264 265 268 public PolicyServer getPolicyServer() throws java.rmi.RemoteException { 269 return proActiveRuntime.getPolicyServer(); 270 } 271 272 public String getVNName(String nodename) throws java.rmi.RemoteException { 273 return proActiveRuntime.getVNName(nodename); 274 } 275 276 public void setProActiveSecurityManager(ProActiveSecurityManager ps) 277 throws java.rmi.RemoteException { 278 proActiveRuntime.setProActiveSecurityManager(ps); 279 } 280 281 284 public void setDefaultNodeVirtualNodeNAme(String s) 285 throws RemoteException { 286 proActiveRuntime.setDefaultNodeVirtualNodeName(s); 287 } 288 289 292 public void updateLocalNodeVirtualName() throws RemoteException { 293 proActiveRuntime.listVirtualNodes(); 294 } 295 296 299 public PolicyServer getNodePolicyServer(String nodeName) 300 throws RemoteException { 301 return proActiveRuntime.getNodePolicyServer(nodeName); 302 } 303 304 307 public void enableSecurityIfNeeded() throws RemoteException { 308 proActiveRuntime.enableSecurityIfNeeded(); 309 } 310 311 314 public X509Certificate getNodeCertificate(String nodeName) 315 throws RemoteException { 316 return proActiveRuntime.getNodeCertificate(nodeName); 317 } 318 319 323 public ArrayList getEntities(String nodeName) throws RemoteException { 324 return proActiveRuntime.getEntities(nodeName); 325 } 326 327 331 public ArrayList getEntities(UniversalBody uBody) throws RemoteException { 332 return proActiveRuntime.getEntities(uBody); 333 } 334 335 338 public ArrayList getEntities() throws RemoteException { 339 return proActiveRuntime.getEntities(); 340 } 341 342 345 public String getJobID(String nodeUrl) throws RemoteException { 346 return proActiveRuntime.getJobID(nodeUrl); 347 } 348 349 private void register(String url, boolean replacePreviousBinding) 353 throws java.rmi.RemoteException { 354 try { 355 if (replacePreviousBinding) { 356 java.rmi.Naming.rebind(UrlBuilder.removeProtocol(url, "rmi:"), 357 this); 358 } else { 359 java.rmi.Naming.bind(UrlBuilder.removeProtocol(url, "rmi:"), 360 this); 361 } 362 if (url.indexOf("PA_RT") < 0) { 363 logger.info(url + " successfully bound in registry at " + url); 364 } 365 } catch (java.rmi.AlreadyBoundException e) { 366 throw new java.rmi.RemoteException (url + 367 " already bound in registry", e); 368 } catch (java.net.MalformedURLException e) { 369 throw new java.rmi.RemoteException ("cannot bind in registry at " + 370 url, e); 371 } 372 } 373 374 private void unregister(String url) throws java.rmi.RemoteException { 375 try { 376 java.rmi.Naming.unbind(UrlBuilder.removeProtocol(url, "rmi:")); 377 if (url.indexOf("PA_RT") < 0) { 378 logger.info(url + " unbound in registry"); 379 } 380 } catch (ConnectException e) { 381 if ((e.getCause().getClass().getName().equals("java.net.ConnectException") && 384 e.getCause().getMessage().equals("Connection refused"))) { 385 if (url.indexOf("PA_RT") < 0) { 386 logger.info("RMIRegistry unreachable on host " + 387 getVMInformation().getInetAddress().getCanonicalHostName() + 388 " to unregister " + url + ". Killed anyway !!!"); 389 } 390 } 391 } catch (java.net.MalformedURLException e) { 392 throw new java.rmi.RemoteException ("cannot unbind in registry at " + 393 url, e); 394 } catch (java.rmi.NotBoundException e) { 395 logger.info(url + "is not bound in the registry", e); 397 } 398 } 399 400 private String buildRuntimeURL() { 401 int port = RemoteRuntimeFactory.getRegistryHelper() 402 .getRegistryPortNumber(); 403 String host = getVMInformation().getInetAddress().getCanonicalHostName(); 404 String name = getVMInformation().getName(); 405 return UrlBuilder.buildUrl(host, name, "rmi:", port); 406 } 407 408 private String buildNodeURL(String url) 409 throws java.net.UnknownHostException { 410 int i = url.indexOf('/'); 411 if (i == -1) { 412 String host = getVMInformation().getInetAddress().getCanonicalHostName(); 414 415 int port = RemoteRuntimeFactory.getRegistryHelper() 416 .getRegistryPortNumber(); 417 return UrlBuilder.buildUrl(host, url, "rmi:", port); 418 } else { 419 return UrlBuilder.checkUrl(url); 420 } 421 } 422 423 private class RMIKillerThread extends Thread { 427 public RMIKillerThread() { 428 } 429 430 public void run() { 431 try { 432 while (RegistryHelper.getRegistry().list().length > 0) { 433 Thread.sleep(600000); 435 } 436 437 proActiveRuntime.killRT(false); 438 } catch (InterruptedException e) { 439 proActiveRuntime.killRT(false); 440 e.printStackTrace(); 441 } catch (AccessException e) { 442 logger.error(e.getMessage()); 443 proActiveRuntime.killRT(false); 444 } catch (RemoteException e) { 445 logger.error(e.getMessage()); 446 proActiveRuntime.killRT(false); 447 } 448 } 449 } 450 } 451 | Popular Tags |