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.descriptor.data;
00032 
00033 import org.objectweb.proactive.ProActive;
00034 import org.objectweb.proactive.core.ProActiveException;
00035 import org.objectweb.proactive.core.ProActiveRuntimeException;
00036 import org.objectweb.proactive.core.node.Node;
00037 import org.objectweb.proactive.core.node.NodeException;
00038 import org.objectweb.proactive.core.process.ExternalProcess;
00039 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl;
00040 import org.objectweb.proactive.core.util.UrlBuilder;
00041 import org.objectweb.proactive.filetransfer.FileVector;
00042 
00043 
00059 public class VirtualNodeLookup extends RuntimeDeploymentProperties
00060     implements VirtualNode {
00061     private VirtualNode virtualNode;
00062     private String name;
00063     private String urlForLookup;
00064     private String lookupProtocol;
00065     private String lookupHost;
00066     private boolean isActivated = false;
00067 
00068     
00069     private int portForLookup = 1099;
00070     private String message = "########## Calling this method on a VirtualNodeLookup has no sense, since such VirtualNode object references a remote VirtualNode ##########";
00071     private String notActivatedMessage = "This VirtualNode lookup is not yet activated. Activate it first";
00072     protected String runtimeHostForLookup = "LOOKUP_HOST";
00073     protected String runtimePortForLookup = "LOOKUP_PORT";
00074     private int fileBlockSize, overlapping;
00075     
00076     public VirtualNodeLookup(String name) {
00077         this.name = name;
00078         ProActiveRuntimeImpl proActiveRuntimeImpl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime();
00079         proActiveRuntimeImpl.registerLocalVirtualNode(this, this.name);
00080         fileBlockSize=org.objectweb.proactive.core.filetransfer.FileBlock.DEFAULT_BLOCK_SIZE;
00081         overlapping=org.objectweb.proactive.core.filetransfer.FileTransferService.DEFAULT_MAX_SIMULTANEOUS_BLOCKS;
00082         
00083     }
00084 
00088     public String getProperty() {
00089         if (!isActivated) {
00090             vnLogger.error(notActivatedMessage);
00091         }
00092         return virtualNode.getProperty();
00093     }
00094 
00098     public String getName() {
00099         return this.name;
00100     }
00101 
00105     public long getTimeout() {
00106         if (!isActivated) {
00107             vnLogger.error(notActivatedMessage);
00108         }
00109         return virtualNode.getTimeout();
00110     }
00111 
00115     public void addVirtualMachine(VirtualMachine virtualMachine) {
00116         vnLogger.warn(message);
00117     }
00118 
00122     public VirtualMachine getVirtualMachine() {
00123         if (!isActivated) {
00124             vnLogger.error(notActivatedMessage);
00125         }
00126         return virtualNode.getVirtualMachine();
00127     }
00128 
00132     public void activate() {
00133         if (!isActivated) {
00134             if (isWaitingForProperties()) {
00135                 return;
00136             }
00137             try {
00138                 this.urlForLookup = UrlBuilder.buildUrl(this.lookupHost, this.name,
00139                       this.lookupProtocol, this.portForLookup);
00140                 
00141                 
00142                 this.virtualNode = ProActive.lookupVirtualNode(urlForLookup);
00143                 isActivated = true;
00144             } catch (ProActiveException e) {
00145                 e.printStackTrace();
00146                 throw new ProActiveRuntimeException(e);
00147             }
00148         } else {
00149             vnLogger.debug("VirtualNode " + this.name +
00150                 " already activated");
00151         }
00152     }
00153 
00157     public int getNbMappedNodes() {
00158         if (!isActivated) {
00159             vnLogger.error(notActivatedMessage);
00160         }
00161         return virtualNode.getNbMappedNodes();
00162     }
00163 
00167     public int createdNodeCount() {
00168         throw new RuntimeException(
00169             "This method is deprecated, use getNumberOfCurrentlyCreatedNodes() or getNumberOfCreatedNodesAfterDeployment()");
00170     }
00171 
00175     public int getNumberOfCurrentlyCreatedNodes() {
00176         if (!isActivated) {
00177             vnLogger.error(notActivatedMessage);
00178         }
00179         return virtualNode.getNumberOfCurrentlyCreatedNodes();
00180     }
00181 
00185     public Node getNode() throws NodeException {
00186         if (!isActivated) {
00187             throw new NodeException(notActivatedMessage);
00188         }
00189         try {
00190             checkActivation();
00191         } catch (ProActiveException pae) {
00192             throw new NodeException(pae);
00193         }
00194         return virtualNode.getNode();
00195     }
00196 
00197     
00198 
00199 
00200 
00201     public int getNumberOfCreatedNodesAfterDeployment() {
00202         if (!isActivated) {
00203             vnLogger.error(notActivatedMessage);
00204         }
00205         return virtualNode.getNumberOfCreatedNodesAfterDeployment();
00206     }
00207 
00211     @Deprecated
00212     public Node getNode(int index) throws NodeException {
00213         if (!isActivated) {
00214             throw new NodeException(notActivatedMessage);
00215         }
00216         try {
00217             checkActivation();
00218         } catch (ProActiveException pae) {
00219             throw new NodeException(pae);
00220         }
00221         return virtualNode.getNode(index);
00222     }
00223 
00227     public String[] getNodesURL() throws NodeException {
00228         if (!isActivated) {
00229             throw new NodeException(notActivatedMessage);
00230         }
00231         try {
00232             checkActivation();
00233         } catch (ProActiveException pae) {
00234             throw new NodeException(pae);
00235         }
00236         return virtualNode.getNodesURL();
00237     }
00238 
00242     public Node[] getNodes() throws NodeException {
00243         if (!isActivated) {
00244             throw new NodeException(notActivatedMessage);
00245         }
00246         try {
00247             checkActivation();
00248         } catch (ProActiveException pae) {
00249             throw new NodeException(pae);
00250         }
00251         return virtualNode.getNodes();
00252     }
00253 
00257     public Node getNode(String url) throws NodeException {
00258         if (!isActivated) {
00259             throw new NodeException(notActivatedMessage);
00260         }
00261         try {
00262             checkActivation();
00263         } catch (ProActiveException pae) {
00264             throw new NodeException(pae);
00265         }
00266         return virtualNode.getNode(url);
00267     }
00268 
00269     public void killAll(boolean softly) {
00270         vnLogger.warn(message);
00271     }
00272 
00276     public void createNodeOnCurrentJvm(String protocol) {
00277         vnLogger.warn(message);
00278     }
00279 
00280     public Object getUniqueAO() throws ProActiveException {
00281         if (!isActivated) {
00282             throw new ProActiveException(notActivatedMessage);
00283         }
00284         checkActivation();
00285         return virtualNode.getUniqueAO();
00286     }
00287 
00288     public boolean isActivated() {
00289         return isActivated;
00290     }
00291 
00295     public boolean isLookup() {
00296         return true;
00297     }
00298 
00299     
00300     
00301     
00302 
00306     public String getJobID() {
00307         if (!isActivated) {
00308             vnLogger.error(notActivatedMessage);
00309         }
00310         return virtualNode.getJobID();
00311     }
00312 
00317     public void setRuntimeInformations(String information, String value)
00318         throws ProActiveException {
00319         try {
00320             checkProperty(information);
00321         } catch (ProActiveException e) {
00322             throw new ProActiveException("only " + runtimeHostForLookup +
00323                 " and" + runtimePortForLookup +
00324                 " property can be set at runtime", e);
00325         }
00326         performTask(information, value);
00327     }
00328 
00329     
00330     
00331     
00332     
00333     
00334     
00335     
00336     public void setLookupInformations(String host, String protocol, String port) {
00337         
00338         this.lookupProtocol = protocol;
00339         if (host.indexOf("*") > -1) {
00340             runtimeProperties.add(runtimeHostForLookup);
00341         } else {
00342             this.lookupHost = host;
00343         }
00344         if (port.indexOf("*") > -1) {
00345             runtimeProperties.add(runtimePortForLookup);
00346         } else {
00347             this.portForLookup = new Integer(port).intValue();
00348         }
00349     }
00350 
00354     public int getMinNumberOfNodes() {
00355         if (!isActivated) {
00356             vnLogger.error(notActivatedMessage);
00357         }
00358         return virtualNode.getMinNumberOfNodes();
00359     }
00360 
00364     public boolean isMultiple() {
00365         if (!isActivated) {
00366             vnLogger.error(notActivatedMessage);
00367         }
00368         return virtualNode.isMultiple();
00369     }
00370 
00371     
00372     
00373     
00374     private boolean isWaitingForProperties() {
00375         return (runtimeProperties.size() >= 1);
00376     }
00377 
00378     private void performTask(String information, String value) {
00379         if (information.equals(runtimeHostForLookup)) {
00380             this.lookupHost = value;
00381         } else {
00382             this.portForLookup = new Integer(value).intValue();
00383         }
00384         runtimeProperties.remove(information);
00385         if (!isWaitingForProperties()) {
00386             this.urlForLookup = UrlBuilder.buildUrl(this.lookupHost, this.name,
00387                     this.lookupProtocol, this.portForLookup);
00388             activate();
00389         }
00390     }
00391 
00392     private void checkActivation() throws ProActiveException {
00393         if (isWaitingForProperties()) {
00394             String exceptionMessage = "This VirtualNode has not yet been activated since, it is waiting for runtime properties ";
00395             for (int i = 0; i < runtimeProperties.size(); i++) {
00396                 exceptionMessage = exceptionMessage.concat(runtimeProperties.get(
00397                             i) + " ");
00398             }
00399             throw new ProActiveException(exceptionMessage);
00400         }
00401     }
00402 
00403     public int startMPI() {
00404         throw new RuntimeException(
00405             " ERROR: No MPI process attached with the virtual node !");
00406     }
00407 
00408         
00409 
00410 
00411         public FileVector fileTransferRetrieve() throws ProActiveException {
00412                 
00413                         throw new ProActiveException("No File Transfer Retrieve support from VirtualNodeLookup");
00414                 
00415         }
00416 
00417         public ExternalProcess getMPIProcess() {
00418                 
00419                 return null;
00420         }
00421 
00422         public boolean hasMPIProcess() {
00423                 
00424                 return false;
00425         }
00426         
00427         public void setFileTransferParams(int fileBlockSize, int overlapping) {
00428 
00429                 this.fileBlockSize=fileBlockSize;
00430                 this.overlapping=overlapping;
00431         }
00432         
00433 }