1 7 package org.objectweb.openccm.Deployment; 8 9 import java.io.FileReader ; 10 import java.io.File ; 11 import org.objectweb.ccm.descriptor.componentassembly.beans.ComponentassemblyBean; 12 import org.objectweb.ccm.descriptor.componentassembly.beans.ComponentassemblyBeanImpl; 13 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.base.FatalDeploymentException; 14 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.base.HandlerContext; 15 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.base.InitializationError; 16 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.installer.DefaultDestinationDeployerFactory; 17 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.managers.DefaultDeploymentLogger; 18 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.managers.DefaultErrorManager; 19 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.root.ComponentassemblyDeployer; 20 import org.objectweb.ccm.descriptor.componentassembly.ccm.deployer.root.ComponentassemblyDeployerHandler; 21 import org.objectweb.ccm.descriptor.deployerconfig.DeployerconfigImpl; 22 import org.objectweb.ccm.descriptor.deployerconfig.beans.DeployerconfigBeanImpl; 23 import org.omg.Components.Deployment.AssemblyPOA; 24 30 public class AssemblyBase extends AssemblyPOA { 31 32 33 private org.objectweb.util.cmdline.api.Console console; 40 41 private ComponentassemblyBean assemblyObject; 43 44 private org.omg.Components.Deployment.AssemblyOperations etat; 46 47 private org.omg.CosNaming.NamingContextExt ns ; 49 private org.omg.CosNaming.NameComponent [] ncomp; 51 52 private java.util.zip.ZipFile zipFile; 53 54 private AssemblyConfigurator configurator; 55 56 private ComponentassemblyDeployerHandler handler; 57 58 private String registrationName; 59 60 private String assemblyWorkDirPath; 61 62 private File assemblyWorkDir; 63 64 private DefaultDeploymentLogger ddl=null; 65 71 public AssemblyBase(AssemblyConfigurator configurator){ 72 this.configurator=configurator; 73 etat=new AssemblyImplInactive(); 74 assemblyObject=configurator.getComponentassemblyTree(); 75 init(); 76 } 77 78 private void 79 init() 80 { 81 82 try{ 83 handler=((ComponentassemblyDeployerHandler) 84 assemblyObject 85 .getExtensionManager() 86 .getExtensionByName("ccm.deployer.root.Deployer")); 87 handler.connectHandlerContext(new HandlerContext()); 88 89 java.net.ServerSocket s = new java.net.ServerSocket (0); 90 91 92 93 handler.connectServerSocket(s); 94 ddl=new DefaultDeploymentLogger(); 96 handler.connectDeploymentLogger(ddl); 97 98 } 99 catch(Exception e) 100 { 101 e.printStackTrace(); 102 } 104 105 try{ 106 107 FileReader fr=new FileReader 108 (System.getProperty("DeployerConfigFile")); 109 DeployerconfigImpl depl_conf=(DeployerconfigImpl) 110 DeployerconfigBeanImpl.unmarshal(fr,true); 111 DefaultErrorManager erm=new DefaultErrorManager(depl_conf); 112 erm.connectDeploymentLogger(ddl); 113 handler.connectErrorManager(erm); 114 115 DefaultDestinationDeployerFactory dddf= 116 new DefaultDestinationDeployerFactory(depl_conf); 117 118 handler.connectDestinationDeployerFactory(dddf); 119 120 } 121 catch(Exception e){ 122 125 e.printStackTrace(); 126 System.err.println(">> Error manager : No configuration file precised"); 127 } 128 129 configurator.configure(handler); 130 131 } 132 133 137 public void 138 registerAssembly() 139 { 140 141 try{ 142 org.omg.Components.Deployment.Assembly assemblyRef= 144 configurator.getAssembly(); 145 146 ns=org.omg.CosNaming.NamingContextExtHelper 148 .narrow(org.objectweb.openccm.corba 149 .TheNameService 150 .getNamingContext() 151 .getNamingContext()); 152 153 ncomp= org.objectweb.ccm.descriptor 155 .componentassembly 156 .ccm.deployer.registrar 157 .RegisterwithnamingDeployer 158 .rebind(ns, 159 System.getProperty("Assemblies_ns_dir")+ 160 assemblyObject.getId(), 161 assemblyRef); 162 registrationName=ns.to_string(ncomp).replace('/','.'); 163 assemblyWorkDirPath=System.getProperty("WorkDir")+"/"+registrationName; 166 assemblyWorkDir=new File (assemblyWorkDirPath); 167 assemblyWorkDir.mkdirs(); 168 ddl.setLogFile(assemblyWorkDirPath+"/DeploymentLog.log"); 169 170 } 171 catch(Exception e){ 172 System.err.println("Following exception occur during assembly registration"); 173 System.err.println(e.getMessage()); 174 System.err.println("Cannot register the assembly"+ 175 System.getProperty("Assemblies_ns_dir") + 176 assemblyObject.getId()); 177 return ; 178 } 179 System.out.println("The Assembly"+ 180 System.getProperty("Assemblies_ns_dir")+ 181 assemblyObject.getId()+" is referenced"); 182 } 183 184 185 188 public void 189 unregisterAssembly() 190 { 191 try{ 192 ComponentassemblyDeployer cad=(ComponentassemblyDeployer) 193 194 handler.getInstance((ComponentassemblyBeanImpl)assemblyObject); 195 cad.clearAllStream(); 196 }catch(Exception e) 197 { 198 e.printStackTrace(); 199 System.err.println("Problem occured during stream closing"); 200 } 201 202 try{ 203 ns.unbind(ncomp); 204 ddl.removeLogFile(); 205 configurator.deleteTemporaryFile(); 206 assemblyWorkDir.delete(); 207 } 208 catch(Exception e){ 209 System.err.println("Following exception occur during assembly unregistration"); 210 System.err.println(e.getMessage()); 211 System.err.println("Cannot unregister the assembly"+ 212 System.getProperty("Assemblies_ns_dir")+ 213 assemblyObject.getId()); 214 } 215 } 216 217 225 private class AssemblyImplInactive 226 implements org.omg.Components.Deployment.AssemblyOperations 227 { 228 229 private java.io.File tmpZipFile; 230 231 232 233 234 public void 235 build() 236 throws org.omg.Components.CreateFailure 237 { 238 try{ 239 240 ComponentassemblyDeployer cad=(ComponentassemblyDeployer) 241 242 handler.getInstance((ComponentassemblyBeanImpl)assemblyObject); 243 244 cad.setWorkDir(assemblyWorkDirPath); 245 246 cad.deploy(); 247 cad.configueCompleteComponents(); 248 249 } 250 catch(InitializationError er){ 251 er.printStackTrace(); 252 254 throw new org.omg.Components.CreateFailure(); 255 } 256 catch(FatalDeploymentException fde){ 257 System.err.println(fde.getMessage()); 258 } 260 261 etat=(org.omg.Components.Deployment.AssemblyOperations) new AssemblyImplActive(); 262 } 263 264 265 269 270 271 274 public void tear_down() throws org.omg.Components.RemoveFailure 275 { 276 throw new org.omg.Components.RemoveFailure(); 277 } 278 279 282 public org.omg.Components.Deployment.AssemblyState get_state() 283 { 284 return org.omg.Components.Deployment.AssemblyState.INACTIVE; 285 286 } 287 } 288 289 293 private class AssemblyImplActive 294 implements org.omg.Components.Deployment.AssemblyOperations 295 { 296 300 public void build() throws org.omg.Components.CreateFailure 301 { 302 throw new org.omg.Components.CreateFailure(); 303 } 304 305 311 public void tear_down() throws org.omg.Components.RemoveFailure 312 { 313 try{ 314 ComponentassemblyDeployer cad= 315 ((ComponentassemblyDeployer) 316 ((ComponentassemblyDeployerHandler) 317 assemblyObject 318 .getExtensionManager().getExtensionByName("ccm.deployer.root.Deployer")) 319 .getInstance((ComponentassemblyBeanImpl)assemblyObject)); 320 321 cad.tearDown(); 322 etat=(org.omg.Components.Deployment.AssemblyOperations)new AssemblyImplInactive(); 323 configurator.removeAssembly(); 324 } 325 catch(Exception e){e.printStackTrace();} 326 327 } 328 329 332 public org.omg.Components.Deployment.AssemblyState get_state() 333 { 334 return org.omg.Components.Deployment.AssemblyState.INSERVICE; 335 } 336 } 337 338 344 345 346 347 353 354 public void 355 build() 356 throws org.omg.Components.CreateFailure 357 { 358 etat.build(); 359 } 360 361 public void 362 tear_down() 363 throws org.omg.Components.RemoveFailure 364 { 365 etat.tear_down(); 366 } 367 368 369 public org.omg.Components.Deployment.AssemblyState 370 get_state() 371 { 372 return etat.get_state(); 373 } 374 375 376 377 378 } 379 | Popular Tags |