1 26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.installer; 27 28 import java.io.IOException ; 29 import java.io.InputStream ; 30 import java.util.Hashtable ; 31 32 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException; 33 import org.objectweb.openccm.descriptor.softpkg.ccm.CodeInstallationFailureException; 34 import org.objectweb.openccm.descriptor.softpkg.ccm.DependencyResolutionFailureException; 35 import org.omg.Components.CCMHome; 36 import org.omg.Components.ConfigValue; 37 import org.omg.Components.Deployment.ComponentInstallation; 38 import org.omg.Components.Deployment.ComponentInstallationHelper; 39 import org.omg.Components.Deployment.ComponentServer; 40 import org.omg.Components.Deployment.Container; 41 import org.omg.Components.Deployment.InstallationFailure; 42 import org.omg.Components.Deployment.InvalidLocation; 43 import org.omg.Components.Deployment.ServerActivator; 44 import org.omg.Components.Deployment.ServerActivatorHelper; 45 46 54 public class ECMDestinationDeployer 55 extends DestinationDeployerBase 56 { 57 58 private ServerActivator sa; 64 private ComponentInstallation ci; 65 private ComponentServer cs; 66 private Hashtable containerTable; 67 private java.util.List config_values; 68 private NodeDependencyVisitorDeployer depVisitor; 69 public ECMDestinationDeployer() 75 { 76 containerTable = new Hashtable (); 77 config_values = new java.util.LinkedList (); 78 depVisitor = new NodeDependencyVisitorDeployer(); 79 } 80 90 private ServerActivator 91 getSA() 92 { 93 if (sa == null) 94 try { 95 sa = 96 ServerActivatorHelper.narrow( 97 getFindbyDeployer().resolveReference()); 98 } catch (Exception e) { 99 e.printStackTrace(); 101 } 102 return sa; 103 } 104 109 private ComponentInstallation 110 getCI() 111 { 112 if (ci == null) { 113 String ci_name ="ExtCI"+ 114 getFindbyDeployer() 115 .getFindby() 116 .getNamingservice() 117 .getName().substring(2); 118 119 120 121 try { 122 ci = ComponentInstallationHelper.narrow(getRef(ci_name)); 123 } catch (Exception e) { 124 e.printStackTrace(); 126 } 127 } 128 return ci; 129 } 130 138 private String 139 startHttpServer(InputStream input, String name) 140 throws java.io.IOException 141 { 142 (new Thread (new org 143 .objectweb 144 .openccm 145 .deploytool 146 .MicroServerHttp( 147 getRootDeployerContext().getServerSocket(), 148 input, 149 name))) 150 .start(); 151 return "http://" 152 + java.net.InetAddress.getLocalHost().getHostAddress() 153 + ':' 154 + getRootDeployerContext().getServerSocket().getLocalPort() 155 + '/' 156 + name; 157 } 158 169 private CCMHome 170 installCCMHome( 171 ConfigValue[] csConfig, 172 ConfigValue[] contConfig, 173 ConfigValue[] homeConfig, 174 String implID, 175 String entryPoint) 176 throws FatalDeploymentException { 177 CCMHome home = null; 178 try { 179 if (cs == null) 180 cs = getSA().create_component_server(csConfig); 181 Container cont = cs.create_container(contConfig); 182 home = cont.install_home(implID, entryPoint, homeConfig); 183 containerTable.put(home, cont); 184 } catch (Exception e) { 185 e.printStackTrace(); 186 throw new FatalDeploymentException(e); 187 } 188 return home; 189 } 190 191 203 public void 204 resolveDependency() 205 throws FatalDeploymentException 206 { 207 try { 208 211 getSoftpkgDeployer().visitDependencyDeployers(depVisitor); 212 216 getImplementationDeployer().visitDependencyDeployers(depVisitor); 217 getImplementationDeployer().visitCodeDeployers(depVisitor); 218 219 try { 220 String url = 221 startHttpServer( 222 getSoftpkgDeployer().getComponentArchiveStream(), 223 getSoftpkgDeployer().getSoftpkg().getName() + ".car"); 224 getComponentInstallation().install( 225 getImplementationDeployer().getImplementation().getId(), 226 url); 227 228 } catch (IOException e) { 229 e.printStackTrace(); 231 throw new FatalDeploymentException( 232 e, 233 "Cannot install implementation in target node"); 234 } catch (InvalidLocation e) { 235 e.printStackTrace(); 237 throw new FatalDeploymentException( 238 e, 239 "Cannot install implementation in target node"); 240 } catch (InstallationFailure e) { 241 e.printStackTrace(); 243 throw new FatalDeploymentException( 244 e, 245 "Cannot install implementation in target node"); 246 } 247 248 } catch (DependencyResolutionFailureException e) { 249 getErrorManager().submitException(e); 250 } catch (CodeInstallationFailureException e) { 251 e.printStackTrace(); 252 getErrorManager().submitException(e); 253 } 254 } 255 256 263 public CCMHome 264 installHome() 265 throws FatalDeploymentException 266 { 267 268 ConfigValue[] config_home = 269 271 depVisitor.getConfigValue(); 272 273 return installCCMHome( 274 new ConfigValue[0], 275 new ConfigValue[0], 276 config_home, 277 getImplementationDeployer().getImplementation().getId(), 278 depVisitor.getEntryPoint()); 279 } 280 281 288 public ComponentInstallation 289 getComponentInstallation() 290 throws FatalDeploymentException 291 { 292 return getCI(); 293 } 294 295 301 public void 302 removeHome(CCMHome home) 303 throws FatalDeploymentException 304 { 305 try { 306 Container cont = (Container) containerTable.remove(home); 307 if (cont == null) 308 return; 309 if (cont.get_homes().length == 0) 310 cont.remove(); 311 cont.remove_home(home); 312 313 } catch (Exception e) { 314 e.printStackTrace(); 315 throw new FatalDeploymentException(e); 316 } 317 } 318 319 } 320 | Popular Tags |