1 26 27 package org.objectweb.ccm.deploytool; 28 29 import java.io.File ; 31 import java.net.MalformedURLException ; 32 import org.objectweb.util.cmdline.api.CommandLine; 33 import org.objectweb.util.cmdline.lib.ApplicationBase; 34 import org.objectweb.util.cmdline.lib.DefaultCommandLine; 35 import org.objectweb.util.cmdline.lib.DefaultOptionArgument; 36 import org.objectweb.util.cmdline.lib.DefaultOptionFlag; 37 import org.omg.Components.CreateFailure; 38 39 46 47 public class DeploymentApplication 48 extends ApplicationBase 49 { 50 56 57 59 private String zipFile ; 60 61 private boolean distributedDeployment =false; 62 63 private String assemblyFactoryName =null; 64 65 private DefaultOptionArgument factory_info; 66 67 private DefaultOptionFlag local_flag; 68 74 77 public 78 DeploymentApplication() 79 { 80 super( 81 new DefaultCommandLine( 82 new String []{"ccm_deploy","ccm_deploy"} 83 ,"zip_file.aar" 84 ,new String []{"The component assembly archive to deploy"} 85 ,true 86 ) 87 ); 88 factory_info=new DefaultOptionArgument( 89 "-F", 90 "factory_name", 91 "The name of the factory to use, default is DefaultFactory ", 92 "DefaultFactory"); 93 local_flag=new DefaultOptionFlag("-l", 94 "This flag indicates that the deployment must be " 95 +"done locally without using an assembly factory", 96 false); 97 98 99 getCommandLine().addOption(local_flag); 100 getCommandLine().addOption(factory_info); 101 } 102 103 104 private class UnsupportedArchiveFormat extends Exception { 110 public UnsupportedArchiveFormat(String format){ 111 super("The archive format ["+format+ 112 "] is not supported by the deployment."); 113 } 114 } 115 116 private void 117 computeArgs(String args[]) 118 { 119 for(int i=0;i<args.length;i++){ 120 if(args[i].length()>3&&( 121 args[i].endsWith("aar")||args[i].endsWith("zip"))) 122 this.zipFile=args[i]; 123 130 } 131 132 if(local_flag.isSet()){ 133 distributedDeployment=false; 134 return; 135 }else distributedDeployment=true; 136 137 138 if(factory_info.isSet()){ 139 assemblyFactoryName= 140 System.getProperty("Assembly_factory_ns_dir")+factory_info.getArgument(); 141 getConsole().message("Use the specified assembly factory ["+factory_info.getArgument()+"]"); 142 } 143 } 144 145 private void 146 proceedLocalDeployment() 147 throws CreateFailure 148 { 149 getConsole().message("Local deployment processing"); 150 try{ 151 File f=new File (zipFile); 152 (new org.objectweb.openccm.Deployment.AssemblyImpl(f.toURL())).build(); 153 } 154 catch(MalformedURLException e){ 155 throw new CreateFailure(); 157 } 158 } 159 165 170 public String 171 getIdentity() 172 { 173 return "ccm_deploy" 174 + ' ' + org.objectweb.ccm.util.ReleaseInfo.VERSION_MAJOR 175 + '.' + org.objectweb.ccm.util.ReleaseInfo.VERSION_MINOR; 176 } 177 178 184 191 public void 192 runMain(String [] args) 193 { 194 try 195 { 196 args=org.objectweb.openccm.corba.TheORB.initialize(args); 199 org.objectweb.openccm.Components.Runtime.init(org.objectweb.openccm.corba.TheORB.getORB()); 200 org.objectweb.ccm.descriptor.EntityResolver.setCCMResolver(); 202 } 203 catch(org.objectweb.util.api.ExceptionWrapper exc) 206 { 207 report_exception(exc.getException()); 208 } 209 catch(Exception exc) 210 { 211 report_exception(exc); 212 } 213 214 super.runMain(args); 216 } 217 218 225 public int 226 start(String [] args) 227 { 228 229 computeArgs(args); 230 boolean result = deploy(zipFile); 231 return result?0:-1; 232 } 233 234 235 241 242 249 public boolean 250 deploy(String zip_file) 251 { 252 boolean result=true; 253 254 getConsole() 255 .message( 256 "Initiating deployment sequence of " 257 + zip_file 258 ); 259 260 org.omg.Components.Deployment.Assembly ass; 261 262 try{ 263 264 try{ 265 266 if(distributedDeployment){ 267 org.omg.Components.Deployment.AssemblyFactory af ; 268 269 if(assemblyFactoryName!=null){ 270 271 org.omg.CosNaming.NamingContextExt context= 272 org.omg.CosNaming.NamingContextExtHelper 273 .narrow(org.objectweb.openccm.corba.TheNameService 274 .getNamingContext() 275 .getNamingContext()); 276 277 278 af= org.objectweb.openccm 279 .OpenCCM_DCI.AssemblyFactoryManagerHelper 280 .narrow(context.resolve(context.to_name(assemblyFactoryName))) 281 .provide_assembly_factory(); 282 } 283 else { 284 285 org.objectweb.openccm.OpenCCM_DCI.DCIManager 286 DCI= 287 org.objectweb.openccm. 288 OpenCCM_DCI.DCIManagerHelper. 289 narrow(org.objectweb.openccm.corba 290 .TheORB.resolve_initial_reference("DCIManager")); 291 af=DCI.get_connection_assembly_factory(); 292 293 } 294 295 if(af==null) 296 throw new org.omg.CosNaming.NamingContextPackage.NotFound (); 297 298 java.net.ServerSocket s = new java.net.ServerSocket (0); 300 301 String archive_url = "http://" 302 + java.net.InetAddress.getLocalHost().getHostAddress() 303 + ':' + s.getLocalPort() + '/' +zip_file; 304 getConsole().message("Archive URL " + archive_url); 305 306 (new Thread (new MicroServerHttp(s))).start(); 308 309 org.omg.Components.Cookie cok= 310 af.create_assembly(archive_url); 311 312 ass=af.lookup(cok); 313 ass.build(); 314 } 316 else{ 317 getConsole().message("Proceed a local deployment, "); 318 proceedLocalDeployment(); 319 } 320 } 321 catch(java.io.IOException ioe) 322 { 323 getConsole().error 324 ("Cannot use assembly factory to download file, proceed a local deployment, "); 325 getConsole().error 326 ("the tear_down function will be disable from console"); 327 328 proceedLocalDeployment(); 329 330 331 } 332 344 catch( org.omg.CosNaming.NamingContextPackage.NotFound nf) 345 { 346 getConsole().error 347 ("Cannot found a valid assembly factory, proceed a local deployment,"); 348 getConsole().error 349 ("the tear_down function will be disable from console"); 350 351 proceedLocalDeployment(); 352 353 } 354 catch(org.omg.CosNaming.NamingContextPackage.CannotProceed cp) 355 { 356 getConsole().error 357 ("Cannot use name service to found a valid assembly factory, proceed a local deployment,"); 358 getConsole().error 359 ("the tear_down function will be disable from console"); 360 proceedLocalDeployment(); 361 } 362 catch(org.omg.CosNaming.NamingContextPackage.InvalidName in) 363 { 364 getConsole().error 365 ("Cannot found a valid assembly factory, proceed a local deployment,"); 366 getConsole().error 367 ("the tear_down function will be disable from console"); 368 proceedLocalDeployment(); 369 370 } 371 catch(org.omg.Components.Deployment.InvalidAssembly IA) 372 { 373 getConsole().error 374 ("Internal error occured during retrieving of assembly, cannot process deployment"); 375 return false; 376 } 377 378 380 } 381 catch(org.omg.Components.Deployment.InvalidLocation il) 382 { 383 getConsole().error 384 ("Cannot found the CAD file, check your path and restart the deployment"); 385 result=false; 386 } 387 catch(org.omg.Components.CreateFailure cf) 388 { 389 getConsole().error 390 ("Cannot achieved assembly deployment, be carefull only a partial assembly"); 391 getConsole().error 392 ("is deployed, assembly behavior may be corrupt"); 393 result=false; 394 } 395 396 if (!result) 397 { 398 getConsole() 399 .error( 400 "Sequence aborted during deployment of " 401 + zip_file 402 ); 403 return false; 404 } 405 406 getConsole() 407 .message( 408 "Successfully deployed " 409 + zip_file 410 ); 411 412 return result; 413 } 414 415 421 426 public static void 427 main(String [] args) 428 { 429 DeploymentApplication application = new DeploymentApplication(); 430 application.runMain(args); 431 } 432 } 433 | Popular Tags |