00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.core.runtime.ibis;
00032
00033 import java.io.IOException;
00034 import java.lang.reflect.InvocationTargetException;
00035 import java.net.UnknownHostException;
00036 import java.security.PublicKey;
00037 import java.security.cert.X509Certificate;
00038 import java.util.ArrayList;
00039
00040 import org.objectweb.proactive.Body;
00041 import org.objectweb.proactive.core.ProActiveException;
00042 import org.objectweb.proactive.core.body.UniversalBody;
00043 import org.objectweb.proactive.core.body.ft.checkpointing.Checkpoint;
00044 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor;
00045 import org.objectweb.proactive.core.descriptor.data.VirtualNode;
00046 import org.objectweb.proactive.core.mop.ConstructorCall;
00047 import org.objectweb.proactive.core.mop.ConstructorCallExecutionFailedException;
00048 import org.objectweb.proactive.core.node.NodeException;
00049 import org.objectweb.proactive.core.process.ExternalProcess;
00050 import org.objectweb.proactive.core.process.UniversalProcess;
00051 import org.objectweb.proactive.core.runtime.ProActiveRuntime;
00052 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00053 import org.objectweb.proactive.core.runtime.VMInformation;
00054 import org.objectweb.proactive.core.util.UrlBuilder;
00055 import org.objectweb.proactive.ext.security.Communication;
00056 import org.objectweb.proactive.ext.security.ProActiveSecurityManager;
00057 import org.objectweb.proactive.ext.security.SecurityContext;
00058 import org.objectweb.proactive.ext.security.crypto.KeyExchangeException;
00059 import org.objectweb.proactive.ext.security.exceptions.RenegotiateSessionException;
00060 import org.objectweb.proactive.ext.security.exceptions.SecurityNotAvailableException;
00061 import org.objectweb.proactive.ext.security.securityentity.Entity;
00062
00063 import ibis.rmi.AlreadyBoundException;
00064 import ibis.rmi.Naming;
00065 import ibis.rmi.NotBoundException;
00066 import ibis.rmi.RemoteException;
00067 import ibis.rmi.server.UnicastRemoteObject;
00068
00069
00076 public class IbisProActiveRuntimeImpl extends UnicastRemoteObject
00077 implements IbisProActiveRuntime {
00078 protected transient ProActiveRuntime proActiveRuntime;
00079 protected String proActiveRuntimeURL;
00080
00081
00082 protected ArrayList<String> nodesArray;
00083
00084
00085 protected ArrayList<String> vnNodesArray;
00086
00087
00088
00089
00090 public IbisProActiveRuntimeImpl()
00091 throws RemoteException, AlreadyBoundException {
00092
00093 this.proActiveRuntime = ProActiveRuntimeImpl.getProActiveRuntime();
00094 this.nodesArray = new java.util.ArrayList<String>();
00095 this.vnNodesArray = new java.util.ArrayList<String>();
00096 this.proActiveRuntimeURL = buildRuntimeURL();
00097 register(proActiveRuntimeURL, false);
00098 }
00099
00100
00101
00102
00103 public String createLocalNode(String nodeName,
00104 boolean replacePreviousBinding,
00105 ProActiveSecurityManager securityManager, String vnname, String jobId)
00106 throws RemoteException, NodeException, java.rmi.AlreadyBoundException {
00107 String nodeURL = null;
00108
00109
00110 try {
00111
00112 nodeURL = buildNodeURL(nodeName);
00113
00114
00115 String name = UrlBuilder.getNameFromUrl(nodeURL);
00116
00117
00118 register(nodeURL, replacePreviousBinding);
00119 proActiveRuntime.createLocalNode(name, replacePreviousBinding,
00120 securityManager, vnname, jobId);
00121 } catch (java.net.UnknownHostException e) {
00122 throw new RemoteException("Host unknown in " + nodeURL, e);
00123 }
00124
00125 nodesArray.add(nodeURL);
00126
00127 return nodeURL;
00128 }
00129
00130 public void killAllNodes() throws RemoteException, ProActiveException {
00131 for (int i = 0; i < nodesArray.size(); i++) {
00132 String url = nodesArray.get(i);
00133 killNode(url);
00134 }
00135
00136 proActiveRuntime.killAllNodes();
00137 }
00138
00139 public void killNode(String nodeName)
00140 throws RemoteException, ProActiveException {
00141 String nodeUrl = null;
00142 String name = null;
00143
00144 try {
00145 nodeUrl = buildNodeURL(nodeName);
00146 name = UrlBuilder.getNameFromUrl(nodeUrl);
00147 unregister(nodeUrl);
00148 } catch (UnknownHostException e) {
00149 throw new RemoteException("Host unknown in " + nodeUrl, e);
00150 }
00151
00152 proActiveRuntime.killNode(name);
00153 }
00154
00155 public void createVM(UniversalProcess remoteProcess)
00156 throws IOException, ProActiveException {
00157 proActiveRuntime.createVM(remoteProcess);
00158 }
00159
00160 public String[] getLocalNodeNames()
00161 throws RemoteException, ProActiveException {
00162 return proActiveRuntime.getLocalNodeNames();
00163 }
00164
00165 public VMInformation getVMInformation() {
00166
00167
00168 return ((ProActiveRuntimeImpl) proActiveRuntime).getVMInformation();
00169 }
00170
00171 public void register(ProActiveRuntime proActiveRuntimeDist,
00172 String proActiveRuntimeName, String creatorID, String creationProtocol,
00173 String vmName) throws RemoteException, ProActiveException {
00174 proActiveRuntime.register(proActiveRuntimeDist, proActiveRuntimeName,
00175 creatorID, creationProtocol, vmName);
00176 }
00177
00182 public void unregister(ProActiveRuntime proActiveRuntimeDist,
00183 String proActiveRuntimeName, String creatorID, String creationProtocol,
00184 String vmName) throws RemoteException, ProActiveException {
00185 this.proActiveRuntime.unregister(proActiveRuntimeDist,
00186 proActiveRuntimeURL, creatorID, creationProtocol, vmName);
00187 }
00188
00189 public ProActiveRuntime[] getProActiveRuntimes()
00190 throws RemoteException, ProActiveException {
00191 return proActiveRuntime.getProActiveRuntimes();
00192 }
00193
00194 public ProActiveRuntime getProActiveRuntime(String proActiveRuntimeName)
00195 throws RemoteException, ProActiveException {
00196 return proActiveRuntime.getProActiveRuntime(proActiveRuntimeName);
00197 }
00198
00199 public void addAcquaintance(String proActiveRuntimeName)
00200 throws RemoteException, ProActiveException {
00201 proActiveRuntime.addAcquaintance(proActiveRuntimeName);
00202 }
00203
00204 public String[] getAcquaintances()
00205 throws RemoteException, ProActiveException {
00206 return proActiveRuntime.getAcquaintances();
00207 }
00208
00209 public void rmAcquaintance(String proActiveRuntimeName)
00210 throws RemoteException, ProActiveException {
00211 proActiveRuntime.rmAcquaintance(proActiveRuntimeName);
00212 }
00213
00214 public void killRT(boolean softly) throws Exception {
00215 killAllNodes();
00216 unregisterAllVirtualNodes();
00217 unregister(proActiveRuntimeURL);
00218 proActiveRuntime.killRT(false);
00219 }
00220
00221 public ExternalProcess getProcessToDeploy(
00222 ProActiveRuntime proActiveRuntimeDist, String creatorID, String vmName,
00223 String padURL) throws ProActiveException {
00224 return proActiveRuntime.getProcessToDeploy(proActiveRuntimeDist,
00225 creatorID, vmName, padURL);
00226 }
00227
00228 public String getURL() {
00229 return proActiveRuntimeURL;
00230 }
00231
00232 public ArrayList getActiveObjects(String nodeName)
00233 throws RemoteException, ProActiveException {
00234 return proActiveRuntime.getActiveObjects(nodeName);
00235 }
00236
00237 public ArrayList getActiveObjects(String nodeName, String objectName)
00238 throws RemoteException, ProActiveException {
00239 return proActiveRuntime.getActiveObjects(nodeName, objectName);
00240 }
00241
00242 public VirtualNode getVirtualNode(String virtualNodeName)
00243 throws RemoteException, ProActiveException {
00244 return proActiveRuntime.getVirtualNode(virtualNodeName);
00245 }
00246
00247 public void registerVirtualNode(String virtualNodeName,
00248 boolean replacePreviousBinding) throws IOException {
00249 String virtualNodeURL = null;
00250
00251 try {
00252
00253 virtualNodeURL = buildNodeURL(virtualNodeName);
00254
00255
00256 register(virtualNodeURL, replacePreviousBinding);
00257 } catch (java.net.UnknownHostException e) {
00258 throw new RemoteException("Host unknown in " + virtualNodeURL, e);
00259 }
00260
00261 vnNodesArray.add(virtualNodeURL);
00262 }
00263
00264 public void unregisterVirtualNode(String virtualnodeName)
00265 throws RemoteException, ProActiveException {
00266 String virtualNodeURL = null;
00267 proActiveRuntime.unregisterVirtualNode(UrlBuilder.removeVnSuffix(
00268 virtualnodeName));
00269
00270 try {
00271
00272 virtualNodeURL = buildNodeURL(virtualnodeName);
00273 unregister(virtualNodeURL);
00274 } catch (java.net.UnknownHostException e) {
00275 throw new RemoteException("Host unknown in " + virtualNodeURL, e);
00276 }
00277
00278 vnNodesArray.remove(virtualNodeURL);
00279 }
00280
00281 public void unregisterAllVirtualNodes()
00282 throws RemoteException, ProActiveException {
00283 for (int i = 0; i < vnNodesArray.size(); i++) {
00284 String url = vnNodesArray.get(i);
00285 unregisterVirtualNode(url);
00286 }
00287 }
00288
00289 public UniversalBody createBody(String nodeName,
00290 ConstructorCall bodyConstructorCall, boolean isNodeLocal)
00291 throws RemoteException, ConstructorCallExecutionFailedException,
00292 ProActiveException, InvocationTargetException {
00293 return proActiveRuntime.createBody(nodeName, bodyConstructorCall,
00294 isNodeLocal);
00295 }
00296
00297 public UniversalBody receiveBody(String nodeName, Body body)
00298 throws RemoteException, ProActiveException {
00299 return proActiveRuntime.receiveBody(nodeName, body);
00300 }
00301
00302 public UniversalBody receiveCheckpoint(String nodeURL, Checkpoint ckpt,
00303 int inc) throws RemoteException, ProActiveException {
00304 return proActiveRuntime.receiveCheckpoint(nodeURL, ckpt, inc);
00305 }
00306
00307 public String getVNName(String nodename)
00308 throws RemoteException, ProActiveException {
00309 return proActiveRuntime.getVNName(nodename);
00310 }
00311
00312
00313 public X509Certificate getCertificate()
00314 throws SecurityNotAvailableException, RemoteException, IOException {
00315 return proActiveRuntime.getCertificate();
00316 }
00317
00318 public long startNewSession(Communication policy)
00319 throws SecurityNotAvailableException, RenegotiateSessionException,
00320 RemoteException, IOException {
00321 return proActiveRuntime.startNewSession(policy);
00322 }
00323
00324 public PublicKey getPublicKey()
00325 throws SecurityNotAvailableException, RemoteException, IOException {
00326 return proActiveRuntime.getPublicKey();
00327 }
00328
00329 public byte[] randomValue(long sessionID, byte[] clientRandomValue)
00330 throws SecurityNotAvailableException, RemoteException, IOException,
00331 RenegotiateSessionException {
00332 return proActiveRuntime.randomValue(sessionID, clientRandomValue);
00333 }
00334
00335 public byte[][] publicKeyExchange(long sessionID, byte[] myPublicKey,
00336 byte[] myCertificate, byte[] signature)
00337 throws SecurityNotAvailableException, RenegotiateSessionException,
00338 KeyExchangeException, RemoteException, IOException {
00339 return proActiveRuntime.publicKeyExchange(sessionID, myPublicKey,
00340 myCertificate, signature);
00341 }
00342
00343 public byte[][] secretKeyExchange(long sessionID, byte[] encodedAESKey,
00344 byte[] encodedIVParameters, byte[] encodedClientMacKey,
00345 byte[] encodedLockData, byte[] parametersSignature)
00346 throws SecurityNotAvailableException, RenegotiateSessionException,
00347 RemoteException, IOException {
00348 return proActiveRuntime.secretKeyExchange(sessionID, encodedAESKey,
00349 encodedIVParameters, encodedClientMacKey, encodedLockData,
00350 parametersSignature);
00351 }
00352
00353 public SecurityContext getPolicy(SecurityContext securityContext)
00354 throws SecurityNotAvailableException, RemoteException, IOException {
00355 return proActiveRuntime.getPolicy(securityContext);
00356 }
00357
00358 public byte[] getCertificateEncoded()
00359 throws SecurityNotAvailableException, RemoteException, IOException {
00360 return proActiveRuntime.getCertificateEncoded();
00361 }
00362
00363 public ArrayList<Entity> getEntities()
00364 throws SecurityNotAvailableException, RemoteException, IOException {
00365 return proActiveRuntime.getEntities();
00366 }
00367
00368 public void terminateSession(long sessionID)
00369 throws RemoteException, SecurityNotAvailableException, IOException {
00370 proActiveRuntime.terminateSession(sessionID);
00371 }
00372
00377 public String getJobID(String nodeUrl)
00378 throws RemoteException, ProActiveException {
00379 return proActiveRuntime.getJobID(nodeUrl);
00380 }
00381
00382 public byte[] getClassDataFromParentRuntime(String className)
00383 throws IOException, ProActiveException {
00384 try {
00385 return proActiveRuntime.getClassDataFromParentRuntime(className);
00386 } catch (ProActiveException e) {
00387 throw new ProActiveException("class not found : " + className, e);
00388 }
00389 }
00390
00391 public byte[] getClassDataFromThisRuntime(String className)
00392 throws IOException, ProActiveException {
00393 return proActiveRuntime.getClassDataFromThisRuntime(className);
00394 }
00395
00399 public String getJobID() {
00400 return proActiveRuntime.getJobID();
00401 }
00402
00403 public void launchMain(String className, String[] parameters)
00404 throws IOException, ClassNotFoundException, NoSuchMethodException,
00405 ProActiveException {
00406 proActiveRuntime.launchMain(className, parameters);
00407 }
00408
00409 public void newRemote(String className)
00410 throws IOException, ClassNotFoundException, ProActiveException {
00411 proActiveRuntime.newRemote(className);
00412 }
00413
00414 public ProActiveDescriptor getDescriptor(String url,
00415 boolean isHierarchicalSearch) throws IOException, ProActiveException {
00416 return proActiveRuntime.getDescriptor(url, isHierarchicalSearch);
00417 }
00418
00419
00420
00421
00422 private void register(String url, boolean replacePreviousBinding)
00423 throws RemoteException {
00424 try {
00425 if (replacePreviousBinding) {
00426 Naming.rebind(UrlBuilder.removeProtocol(url, "ibis:"), this);
00427 } else {
00428 Naming.bind(UrlBuilder.removeProtocol(url, "ibis:"), this);
00429 }
00430
00431 if (url.indexOf("PA_JVM") < 0) {
00432 runtimeLogger.info(url + " successfully bound in registry at " +
00433 url);
00434 }
00435 } catch (AlreadyBoundException e) {
00436 runtimeLogger.warn("WARNING " + url + " already bound in registry",
00437 e);
00438 } catch (java.net.MalformedURLException e) {
00439 throw new RemoteException("cannot bind in registry at " + url, e);
00440 }
00441 }
00442
00443 private void unregister(String url) throws RemoteException {
00444 try {
00445 Naming.unbind(UrlBuilder.removeProtocol(url, "ibis:"));
00446
00447 if (url.indexOf("PA_JVM") < 0) {
00448 runtimeLogger.info(url + " unbound in registry");
00449 }
00450 } catch (java.net.MalformedURLException e) {
00451 throw new RemoteException("cannot unbind in registry at " + url, e);
00452 } catch (NotBoundException e) {
00453
00454 runtimeLogger.info("WARNING " + url +
00455 " is not bound in the registry ");
00456 }
00457 }
00458
00459 private String buildRuntimeURL() {
00460 int port = IbisRuntimeFactory.getRegistryHelper().getRegistryPortNumber();
00461 String host = UrlBuilder.getHostNameorIP(getVMInformation()
00462 .getInetAddress());
00463 String name = getVMInformation().getName();
00464
00465 return UrlBuilder.buildUrl(host, name, "ibis:", port);
00466 }
00467
00468 private String buildNodeURL(String url)
00469 throws java.net.UnknownHostException {
00470 int i = url.indexOf('/');
00471
00472 if (i == -1) {
00473
00474 String host = UrlBuilder.getHostNameorIP(getVMInformation()
00475 .getInetAddress());
00476 int port = IbisRuntimeFactory.getRegistryHelper()
00477 .getRegistryPortNumber();
00478
00479 return UrlBuilder.buildUrl(host, url, "ibis:", port);
00480 } else {
00481 return UrlBuilder.checkUrl(url);
00482 }
00483 }
00484
00488 public String getLocalNodeProperty(String nodeName, String key)
00489 throws IOException, ProActiveException {
00490 return this.proActiveRuntime.getLocalNodeProperty(nodeName, key);
00491 }
00492
00496 public Object setLocalNodeProperty(String nodeName, String key, String value)
00497 throws IOException, ProActiveException {
00498 return this.proActiveRuntime.setLocalNodeProperty(nodeName, key, value);
00499 }
00500 }