1 26 27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer; 28 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.util.Hashtable ; 32 import org.ist.coach.DCI.NodeManager; 33 import org.ist.coach.DCI.NodeManagerHelper; 34 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException; 35 import org.objectweb.openccm.descriptor.softpkg.ccm.CodeInstallationFailureException; 36 import org.objectweb.openccm.descriptor.softpkg.ccm.DependencyResolutionFailureException; 37 import org.omg.Components.CCMHome; 38 import org.omg.Components.ConfigValue; 39 import org.omg.Components.Deployment.ComponentInstallation; 40 import org.omg.Components.Deployment.ComponentServer; 41 import org.omg.Components.Deployment.Container; 42 import org.omg.Components.Deployment.InstallationFailure; 43 import org.omg.Components.Deployment.InvalidLocation; 44 45 53 public class NodeDestinationDeployer 54 extends DestinationDeployerBase 55 { 56 62 private NodeManager node; 63 64 private ComponentServer cs; 65 66 private Hashtable containerTable; 67 68 private java.util.List config_values; 69 70 private NodeDependencyVisitorDeployer depVisitor; 71 72 78 public 79 NodeDestinationDeployer() 80 { 81 containerTable = new Hashtable (); 82 config_values = new java.util.LinkedList (); 83 depVisitor = new NodeDependencyVisitorDeployer(); 84 } 85 86 92 95 private CCMHome 96 installCCMHome( 97 ConfigValue[] csConfig, 98 ConfigValue[] contConfig, 99 ConfigValue[] homeConfig, 100 String implID, 101 String entryPoint) 102 throws FatalDeploymentException 103 { 104 CCMHome home = null; 105 try { 106 if (cs == null) 107 cs = 108 getNode() 109 .provide_server_activator() 110 .create_component_server( 111 csConfig); 112 Container cont = cs.create_container(contConfig); 113 home = cont.install_home(implID, entryPoint, homeConfig); 114 containerTable.put(home, cont); 115 } catch (Exception e) { 116 e.printStackTrace(); 117 throw new FatalDeploymentException(this,e,"Cannot deploy the CCMHome on the required destination"); 118 } 119 return home; 120 } 121 122 127 private NodeManager 128 getNode() 129 throws Exception 130 { 131 if (node == null) 132 { 133 node = getNodeDeployer().getNodeManager(); 134 } 135 return node; 136 } 137 138 145 private String 146 startHttpServer(InputStream input, String name) 147 throws java.io.IOException 148 { 149 (new Thread (new org 150 .objectweb 151 .openccm 152 .deploytool 153 .MicroServerHttp( 154 getRootDeployerContext().getServerSocket(), 155 input, 156 name))) 157 .start(); 158 return "http://" 159 + java.net.InetAddress.getLocalHost().getHostAddress() 160 + ':' 161 + getRootDeployerContext().getServerSocket().getLocalPort() 162 + '/' 163 + name; 164 } 165 166 172 179 public void 180 resolveDependency() 181 throws FatalDeploymentException 182 { 183 try { 184 187 getSoftpkgDeployer().visitDependencyDeployers(depVisitor); 188 192 getImplementationDeployer().visitDependencyDeployers(depVisitor); 193 getImplementationDeployer().visitCodeDeployers(depVisitor); 194 195 try { 196 String url = 197 startHttpServer( 198 getSoftpkgDeployer().getComponentArchiveStream(), 199 getSoftpkgDeployer().getSoftpkg().getName() + ".car"); 200 getComponentInstallation().install( 201 getSoftpkgDeployer().getSoftpkg().getName(), 202 url); 203 204 } catch (IOException e) { 205 e.printStackTrace(); 207 throw new FatalDeploymentException( 208 e, 209 "Cannot install implementation in target node"); 210 } catch (InvalidLocation e) { 211 e.printStackTrace(); 213 throw new FatalDeploymentException( 214 e, 215 "Cannot install implementation in target node"); 216 } catch (InstallationFailure e) { 217 e.printStackTrace(); 219 throw new FatalDeploymentException( 220 e, 221 "Cannot install implementation in target node"); 222 } 223 224 } catch (DependencyResolutionFailureException e) { 225 getErrorManager().submitException(e); 226 } catch (CodeInstallationFailureException e) { 227 e.printStackTrace(); 228 getErrorManager().submitException(e); 229 } 230 } 231 232 239 public CCMHome 240 installHome() 241 throws FatalDeploymentException 242 { 243 244 ConfigValue[] config_home = 245 247 depVisitor.getConfigValue(); 248 249 return installCCMHome( 250 new ConfigValue[0], 251 new ConfigValue[0], 252 config_home, 253 getImplementationDeployer().getImplementation().getId(), 254 depVisitor.getEntryPoint()); 255 } 256 257 264 public ComponentInstallation 265 getComponentInstallation() 266 throws FatalDeploymentException 267 { 268 try { 269 270 return getNode().provide_component_installation(); 271 } catch (Exception e) { 272 getLogger().log("Exception occured during retrieving of Node"); 273 throw new FatalDeploymentException(this,e,"Cannot access to the componentinstallation on the required destination"); 274 } 275 } 276 277 283 public void 284 removeHome(CCMHome home) 285 throws FatalDeploymentException 286 { 287 try { 288 Container cont = (Container) containerTable.remove(home); 289 if(cont==null) 290 return ; 291 cont.remove_home(home); 292 293 if(cont.get_homes().length==0){ 294 if(cont.get_component_server().get_containers().length==1) 295 cont.get_component_server().remove(); 296 else 297 cont.remove(); 298 } 299 300 } catch (Exception e) { 301 e.printStackTrace(); 302 throw new FatalDeploymentException(e); 303 } 304 } 305 306 } 307 | Popular Tags |