1 31 package org.objectweb.proactive.core.descriptor.data; 32 33 import java.security.cert.X509Certificate ; 34 35 import org.objectweb.proactive.ProActive; 36 import org.objectweb.proactive.core.ProActiveException; 37 import org.objectweb.proactive.core.node.Node; 38 import org.objectweb.proactive.core.node.NodeException; 39 import org.objectweb.proactive.core.runtime.ProActiveRuntime; 40 import org.objectweb.proactive.core.runtime.ProActiveRuntimeImpl; 41 import org.objectweb.proactive.core.util.UrlBuilder; 42 import org.objectweb.proactive.ext.security.PolicyServer; 43 44 45 60 public class VirtualNodeLookup extends RuntimeDeploymentProperties 61 implements VirtualNode { 62 private VirtualNode virtualNode; 63 private ProActiveRuntime remoteProActiveRuntime; 64 private String name; 65 private String urlForLookup; 66 private String lookupProtocol; 67 private boolean isActivated = false; 68 69 private int portForLookup = 1099; 71 private String message = "########## Calling this method on a VirtualNodeLookup has no sense, since such VirtualNode object references a remote VirtualNode ##########"; 72 protected String runtimeHostForLookup = "LOOKUP_HOST"; 73 74 public VirtualNodeLookup(String name) { 75 this.name = name; 76 ProActiveRuntimeImpl proActiveRuntimeImpl = (ProActiveRuntimeImpl) ProActiveRuntimeImpl.getProActiveRuntime(); 77 proActiveRuntimeImpl.registerLocalVirtualNode(this, this.name); 78 } 79 80 83 public void setProperty(String property) { 84 logger.warn(message); 85 } 86 87 90 public String getProperty() { 91 return virtualNode.getProperty(); 92 } 93 94 public void setTimeout(String timeout, boolean waitForTimeout) { 95 logger.warn(message); 96 } 97 98 101 public void setName(String s) { 102 logger.warn(message); 103 } 104 105 108 public String getName() { 109 return virtualNode.getName(); 110 } 111 112 115 public void addVirtualMachine(VirtualMachine virtualMachine) { 116 logger.warn(message); 117 } 118 119 122 public VirtualMachine getVirtualMachine() { 123 return virtualNode.getVirtualMachine(); 124 } 125 126 129 public void activate() { 130 if (!isActivated) { 131 if (isWaitingForProperties()) { 132 return; 133 } 134 try { 135 this.virtualNode = ProActive.lookupVirtualNode(urlForLookup, 138 lookupProtocol); 139 isActivated = true; 140 } catch (ProActiveException e) { 141 e.printStackTrace(); 142 } 143 } else { 144 logger.info("VirtualNode " + this.name + " already activated !!!"); 145 } 146 } 147 148 151 public int getNodeCount() { 152 return virtualNode.getNodeCount(); 153 } 154 155 158 public int createdNodeCount() { 159 return virtualNode.createdNodeCount(); 160 } 161 162 165 public Node getNode() throws NodeException { 166 try { 167 checkActivation(); 168 } catch (ProActiveException pae) { 169 throw new NodeException(pae); 170 } 171 return virtualNode.getNode(); 172 } 173 174 177 public Node getNode(int index) throws NodeException { 178 try { 179 checkActivation(); 180 } catch (ProActiveException pae) { 181 throw new NodeException(pae); 182 } 183 return virtualNode.getNode(index); 184 } 185 186 189 public String [] getNodesURL() throws NodeException { 190 try { 191 checkActivation(); 192 } catch (ProActiveException pae) { 193 throw new NodeException(pae); 194 } 195 return virtualNode.getNodesURL(); 196 } 197 198 201 public Node[] getNodes() throws NodeException { 202 try { 203 checkActivation(); 204 } catch (ProActiveException pae) { 205 throw new NodeException(pae); 206 } 207 return virtualNode.getNodes(); 208 } 209 210 213 public Node getNode(String url) throws NodeException { 214 try { 215 checkActivation(); 216 } catch (ProActiveException pae) { 217 throw new NodeException(pae); 218 } 219 return virtualNode.getNode(url); 220 } 221 222 public void killAll(boolean softly) { 223 logger.warn(message); 224 } 225 226 229 public void createNodeOnCurrentJvm(String protocol) { 230 logger.warn(message); 231 } 232 233 public Object getUniqueAO() throws ProActiveException { 234 checkActivation(); 235 return virtualNode.getUniqueAO(); 236 } 237 238 public boolean isActivated() { 239 return isActivated; 240 } 241 242 public String getJobID(){ 246 return virtualNode.getJobID(); 247 } 248 249 253 public void setRuntimeInformations(String information, String value) 254 throws ProActiveException { 255 try { 256 checkProperty(information); 257 } catch (ProActiveException e) { 258 throw new ProActiveException("only " + runtimeHostForLookup + 259 " property can be set at runtime", e); 260 } 261 performTask(information, value); 262 } 263 264 public void setLookupInformations(String url, String protocol, int port) { 272 this.urlForLookup = url; 273 274 if (urlForLookup.indexOf("*") > -1) { 275 runtimeProperties.add(runtimeHostForLookup); 276 } 277 278 this.lookupProtocol = protocol; 279 this.portForLookup = port; 280 } 281 282 private boolean isWaitingForProperties() { 283 return (runtimeProperties.size() >= 1); 284 } 285 286 private void performTask(String information, String value) { 287 if (information.equals(runtimeHostForLookup)) { 288 urlForLookup = UrlBuilder.buildUrl(value, this.name, 289 this.lookupProtocol, this.portForLookup); 290 runtimeProperties.remove(runtimeHostForLookup); 291 activate(); 292 } 293 } 294 295 private void checkActivation() throws ProActiveException { 296 if (isWaitingForProperties()) { 297 String exceptionMessage = "This VirtualNode has not yet been activated since, it is waiting for runtime properties "; 298 for (int i = 0; i < runtimeProperties.size(); i++) { 299 exceptionMessage = exceptionMessage.concat((String ) runtimeProperties.get( 300 i) + " "); 301 } 302 throw new ProActiveException(exceptionMessage); 303 } 304 } 305 306 310 public X509Certificate getCreatorCertificate() throws ProActiveException { 311 return virtualNode.getCreatorCertificate(); 312 } 313 314 317 public PolicyServer getPolicyServer() { 318 return virtualNode.getPolicyServer(); 319 } 320 321 324 public void setPolicyServer(PolicyServer ps) { 325 System.out.println(message); 326 } 328 329 330 333 public void setPolicyFile(String file) { 334 335 } 336 337 } 338 | Popular Tags |