1 22 package org.objectweb.petals.jbi.management.deployment.deploy; 23 24 import java.net.URI ; 25 import java.util.HashMap ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import org.objectweb.petals.PetalsException; 30 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants; 31 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils; 32 import org.objectweb.petals.jbi.management.service.ManagementException; 33 import org.objectweb.petals.jbi.management.service.PackageHandler; 34 import org.objectweb.petals.processor.Task; 35 import org.objectweb.petals.repository.RepositoryService; 36 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor; 37 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit; 38 import org.objectweb.petals.util.LoggingUtil; 39 40 46 public class SAAndSUExtractionTask implements Task { 47 48 51 protected PackageHandler packageHandler; 52 53 56 protected RepositoryService repositorySrv; 57 58 61 protected LoggingUtil log; 62 63 public SAAndSUExtractionTask(PackageHandler packageHandler, 64 RepositoryService repositorySrv, LoggingUtil log) { 65 super(); 66 this.packageHandler = packageHandler; 67 this.repositorySrv = repositorySrv; 68 this.log = log; 69 } 70 71 @SuppressWarnings ("unchecked") 72 public void execute(HashMap context) throws Exception { 73 JBIDescriptor descriptor = (JBIDescriptor) context 74 .get(DeploymentContextConstants.SA_DESCRIPTOR); 75 76 URI saArchiveURI = (URI ) context 77 .get(DeploymentContextConstants.ARCHIVE_URI); 78 79 82 URI saInstallRoot = explodeSA(saArchiveURI, descriptor); 83 84 87 Map <String , URI > suInstallRoots = expendSUS(saInstallRoot, descriptor); 88 89 92 context.put(DeploymentContextConstants.SA_INSTALL_ROOT, saInstallRoot); 93 context 94 .put(DeploymentContextConstants.SU_INSTALL_ROOTS, 95 suInstallRoots); 96 97 } 98 99 112 protected URI explodeSA(URI saArchiveURI, JBIDescriptor descriptor) 113 throws ManagementException { 114 115 String msg; 116 URI installationRoot = null; 117 118 try { 119 installationRoot = repositorySrv.addServiceAssemblyPackage( 120 DeploymentUtils.getServiceAssemblyName(descriptor), 121 saArchiveURI); 122 123 } catch (PetalsException pe) { 124 msg = "Unexpected error adding JBI installation " 125 + "package into repository. "; 126 log.error(msg, pe); 127 throw new ManagementException(msg, pe); 128 } 129 130 if (installationRoot == null) { 131 msg = "Unexpected Platform repository service error. The SA" 132 + "installation root must NOT be null: " 133 + DeploymentUtils.getServiceAssemblyName(descriptor); 134 log.error(msg); 135 throw new ManagementException(msg); 136 } 137 138 return installationRoot; 139 } 140 141 152 protected Map <String , URI > expendSUS(URI saInstallRoot, 153 JBIDescriptor descriptor) throws ManagementException { 154 Map <String , URI > suInstallRoots = new HashMap <String , URI >(); 155 List <ServiceUnit> sus = descriptor.getServiceAssembly() 156 .getServiceUnits(); 157 for (ServiceUnit unit : sus) { 158 URI suArchiveURI = getSUArchiveURI(unit, saInstallRoot); 159 URI suInstallRoot = expandSUIntoSA(unit.getIdentification() 160 .getName(), suArchiveURI, DeploymentUtils 161 .getServiceAssemblyName(descriptor)); 162 suInstallRoots.put(unit.getIdentification().getName(), 163 suInstallRoot); 164 } 165 return suInstallRoots; 166 } 167 168 177 protected URI getSUArchiveURI(ServiceUnit su, URI saInstallRoot) { 178 String suZipNAme = su.getTargetArtifactsZip(); 179 String suZipURL = "file://" + saInstallRoot.getPath() + suZipNAme; 180 return packageHandler.processAndGetPackageURI(suZipURL.replaceAll(" ", 181 "%20"), true); 182 } 183 184 197 protected URI expandSUIntoSA(String suId, URI suZipLocation, String saId) 198 throws ManagementException { 199 log.start(); 200 String msg; 201 URI result = null; 202 203 try { 204 result = repositorySrv.explodeSUIntoSAInstallFolder(suId, 205 suZipLocation, saId); 206 } catch (PetalsException pe) { 207 msg = "Unexpected error expending service JBI installation " 208 + "package into repository."; 209 log.error(msg, pe); 210 throw new ManagementException(msg, pe); 211 } 212 if (result == null) { 213 msg = "Unexpected platform repository service error. The " 214 + "su root must NOT be null: " + suId; 215 log.error(msg); 216 throw new ManagementException(msg); 217 } 218 log.end(); 219 return result; 220 } 221 222 public void undo(HashMap context) { 223 JBIDescriptor descriptor = (JBIDescriptor) context 224 .get(DeploymentContextConstants.SA_DESCRIPTOR); 225 226 try { 227 repositorySrv.removeServiceAssemblyPackage(DeploymentUtils 228 .getServiceAssemblyName(descriptor)); 229 } catch (PetalsException e) { 230 String msg = "Failed to revert a SAAndSUExtractionTask"; 231 log.error(msg, e); 232 } 233 234 } 235 236 } 237 | Popular Tags |