1 28 29 package org.objectweb.openccm.OpenCCM_DCI.cif; 30 31 import java.io.File ; 32 import java.io.FileDescriptor ; 33 import java.io.FileInputStream ; 34 import java.io.FileOutputStream ; 35 import java.io.FileReader ; 36 import java.io.InputStream ; 37 import java.io.InputStreamReader ; 38 import java.net.ServerSocket ; 39 import java.net.URL ; 40 import java.util.zip.ZipEntry ; 41 42 import org.objectweb.openccm.descriptor.ZipEntryRetriever; 43 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.BaseHandlerResolver; 44 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.HandlerContext; 45 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers.DefaultDeploymentLogger; 46 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers.DefaultErrorManager; 47 import org.objectweb.openccm.descriptor.deployerconfig.Deployerconfig; 48 import org.objectweb.openccm.descriptor.deployerconfig.DeployerconfigImpl; 49 import org.objectweb.openccm.descriptor.deployerconfig.beans.DeployerconfigBeanImpl; 50 import org.objectweb.openccm.descriptor.softpkg.Softpkg; 51 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBean; 52 import org.objectweb.openccm.descriptor.softpkg.beans.SoftpkgBeanImpl; 53 import org.objectweb.openccm.descriptor.softpkg.ccm.ImplementationDeployer; 54 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgDeployer; 55 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgDeployerHandler; 56 import org.objectweb.openccm.descriptor.softpkg.ccm.SoftpkgRootDeployerContext; 57 65 66 public class ExtComponentInstallationImpl 67 extends org.objectweb.openccm 68 .OpenCCM_DCI.NodeManagerSessionComposition 69 .ComponentInstallationSeg 70 { 71 72 78 81 protected org.objectweb.ccm.util.Table implementations_; 82 83 86 protected java.io.File path_; 87 88 94 100 public 101 ExtComponentInstallationImpl() 102 { implementations_ = new org.objectweb.ccm.util.Table(); 104 105 106 } 107 108 109 110 111 117 123 public void 124 setComponentInstallationDir(String path ) 125 { 126 path_ = new java.io.File (path); 127 } 128 134 148 public void 149 install(String implUUID, 150 String component_loc) 151 throws org.omg.Components.Deployment.InvalidLocation, 152 org.omg.Components.Deployment.InstallationFailure 153 { 154 156 if(implementations_.contains(implUUID)) 158 return ; 159 160 java.io.DataInputStream br= null; 161 java.io.InputStream bis = null; 162 FileOutputStream bos = null; 163 java.net.URL url = null; 164 java.io.File output; 165 166 167 String filename ; 170 try{ 172 173 filename=(new java.net.URL (component_loc)).getFile(); 174 filename=filename.substring(filename.lastIndexOf("/")); 175 176 } 177 catch(Exception e0){ 178 e0.printStackTrace(); 179 throw new org.omg.Components.Deployment.InstallationFailure(); 180 } 181 output = new java.io.File (path_, filename); 182 try 183 { 184 path_.mkdirs(); 185 bos = new java.io.FileOutputStream (output); 186 } 187 catch (java.io.FileNotFoundException e) 188 { 189 throw new org.omg.Components.Deployment.InvalidLocation(); 191 } 192 catch (java.io.IOException e1) 193 { 194 e1.printStackTrace(); 198 throw new org.omg.Components.Deployment.InstallationFailure(); 199 } 200 201 try 202 { 203 url = new java.net.URL (component_loc); 204 bis = url.openStream(); 205 206 } 207 catch (java.net.MalformedURLException e) 208 { 209 e.printStackTrace(); 210 throw new org.omg.Components.Deployment.InvalidLocation (); 211 } 212 catch (java.io.FileNotFoundException e) 213 { 214 e.printStackTrace(); 215 throw new org.omg.Components.Deployment.InvalidLocation(); 216 } 217 catch (java.io.IOException e) 218 { 219 e.printStackTrace(); 223 224 throw new org.omg.Components.Deployment.InstallationFailure(); 225 } 226 227 try 229 { 230 231 byte [] byteArray= new byte[32000]; 232 int readed=readed=bis.read(byteArray,0,32000); 233 234 while(readed>0) 235 { 236 bos.write(byteArray,0,readed); 237 readed=bis.read(byteArray,0,32000); 238 } 239 240 bis.close(); 241 bos.flush(); 242 bos.close(); 243 } 244 catch (java.io.IOException e) 245 { 246 e.printStackTrace(); 247 248 throw new org.omg.Components.Deployment.InstallationFailure(); 252 } 253 254 try{ 255 implementations_.put(implUUID,output.toURL().toString()); 256 if(component_loc.endsWith(".car")||component_loc.endsWith(".zip")) 257 { 258 processComponentArchive(output); 259 } 260 261 } 262 catch(Exception ei) 263 { 264 ei.printStackTrace(); 265 System.err.println("Problem occurs during the adding of the output URL"); 266 throw new org.omg.Components.Deployment.InstallationFailure(); 267 } 268 } 277 280 private void 281 processComponentArchive(File stream) 282 throws Exception 283 { 284 285 ZipEntryRetriever ze=new ZipEntryRetriever(stream); 286 SoftpkgRootDeployerContext sprd=new SoftpkgRootDeployerContext(); 287 ze.connectStreamManager(sprd); 288 sprd.connectZipEntryRetriever(ze); 289 DefaultDeploymentLogger ddl=new DefaultDeploymentLogger 290 (System.getProperty("WorkDir") 291 +"/ComponentInstalltionLog.log"); 292 sprd.connectDeploymentLogger(ddl); 293 sprd.connectServerSocket(new ServerSocket (0)); 294 296 FileReader fr=new FileReader (System.getProperty("DeployerConfigFile")); 297 298 Deployerconfig depl_conf=(Deployerconfig) 299 DeployerconfigBeanImpl.unmarshal(fr,false); 300 301 DefaultErrorManager erm=new DefaultErrorManager(depl_conf); 302 erm.connectDeploymentLogger(ddl); 303 sprd.connectErrorManager(erm); 304 305 String csdEntryNames[]=ze.getZipEntriesEndingBy(".csd"); 306 InputStream is=ze.getZipEntryISIgnoringDelimiterType(csdEntryNames[0]); 307 308 SoftpkgBeanImpl sbi=(SoftpkgBeanImpl) SoftpkgBeanImpl 309 .unmarshalBean(new InputStreamReader (is),true); 310 311 SoftpkgDeployerHandler softHandler= ((SoftpkgDeployerHandler) 313 sbi 314 .getExtensionManager() 315 .getExtensionByName("ccm.Deployer")); 316 317 HandlerContext dc=new HandlerContext(); 318 dc.connectHandlerResolver(new BaseHandlerResolver()); 319 softHandler.connectHandlerContext(dc); 320 321 softHandler.connectRootDeployerContext(sprd); 322 323 325 326 SoftpkgDeployer sfpkgDeployer=(SoftpkgDeployer)softHandler.getInstance(sbi); 327 328 sfpkgDeployer.processDependencies(this); 329 330 ImplementationDeployer implDeployers[]=sfpkgDeployer.getImplementationDeployers(); 331 for(int i=0;i<implDeployers.length;i++) 332 implDeployers[i].install(this); 333 334 sprd.clearAllStream(); 335 336 } 337 351 public void 352 replace(String implUUID, 353 String component_loc) 354 throws org.omg.Components.Deployment.InvalidLocation, 355 org.omg.Components.Deployment.InstallationFailure 356 { 357 install(implUUID, component_loc); 358 } 359 360 373 public void 374 remove(String implUUID) 375 throws org.omg.Components.Deployment.UnknownImplId, 376 org.omg.Components.RemoveFailure 377 { 378 Object o = implementations_.remove(implUUID); 380 381 if(o == null) 383 { 384 throw new org.omg.Components.Deployment.UnknownImplId(); 385 } 386 387 } 389 390 403 public String 404 get_implementation(String implUUID) 405 throws org.omg.Components.Deployment.UnknownImplId, 406 org.omg.Components.Deployment.InstallationFailure 407 { 408 String impl = (String )implementations_.get(implUUID); 410 411 if(impl == null) 413 { 414 throw new org.omg.Components.Deployment.UnknownImplId(); 415 } 416 417 return impl; 419 } 420 421 public String [] 422 get_all_implUUIDs() 423 { 424 String [] result= new String [implementations_.size()]; 425 int i=0; 426 427 for(java.util.Enumeration keys=implementations_.keys(); 428 keys.hasMoreElements();){ 429 result[i]=(String )keys.nextElement(); 430 i++; 431 } 432 433 return result; 434 } 435 436 public String 437 upload( String name,byte[] data){ 438 return "to implement"; 440 } 441 } 442 | Popular Tags |