1 22 package org.objectweb.petals.jbi.management.deployment.deploy; 23 24 import java.io.InputStream ; 25 import java.net.URI ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import javax.management.ObjectName ; 31 32 import org.objectweb.petals.jbi.component.lifecycle.ServiceAssemblyLifeCycle; 33 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants; 34 import org.objectweb.petals.jbi.management.deployment.DeploymentServiceImpl; 35 import org.objectweb.petals.jbi.management.deployment.DeploymentTaskFactory; 36 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils; 37 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService; 38 import org.objectweb.petals.jbi.management.service.ManagementException; 39 import org.objectweb.petals.jbi.management.service.util.XMLResult; 40 import org.objectweb.petals.jbi.management.systemstate.SystemState; 41 import org.objectweb.petals.processor.Task; 42 import org.objectweb.petals.processor.TaskProcessor; 43 import org.objectweb.petals.repository.RepositoryService; 44 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor; 45 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit; 46 import org.objectweb.petals.util.LoggingUtil; 47 48 56 public class AllSUDeploymentTask implements Task { 57 58 61 protected SystemState recoverySrv; 62 63 66 protected RepositoryService repositorySrv; 67 68 71 protected LifeCycleManagerService managerService; 72 73 protected DeploymentServiceImpl deploymentService; 74 75 78 protected LoggingUtil log; 79 80 public AllSUDeploymentTask(SystemState recoverySrv, 81 RepositoryService repositorySrv, 82 LifeCycleManagerService managerService, 83 DeploymentServiceImpl deploymentService, LoggingUtil log) { 84 super(); 85 this.recoverySrv = recoverySrv; 86 this.repositorySrv = repositorySrv; 87 this.managerService = managerService; 88 this.deploymentService = deploymentService; 89 this.log = log; 90 } 91 92 @SuppressWarnings ("unchecked") 93 public void execute(HashMap context) throws Exception { 94 URI installationRoot = (URI ) context 95 .get(DeploymentContextConstants.SA_INSTALL_ROOT); 96 97 JBIDescriptor descriptor = (JBIDescriptor) context 98 .get(DeploymentContextConstants.SA_DESCRIPTOR); 99 100 XMLResult xmlResult = (XMLResult) context 101 .get(DeploymentContextConstants.XML_RESULT); 102 103 Map <String , URI > suInstallRoots = (Map <String , URI >) context 104 .get(DeploymentContextConstants.SU_INSTALL_ROOTS); 105 106 List <TaskProcessor> suTaskProcessors = (List <TaskProcessor>) context 107 .get(DeploymentContextConstants.SU_TASK_PROCESSORS); 108 109 112 ServiceAssemblyLifeCycle saLifeCycle = createSALifeCycle( 113 installationRoot, descriptor); 114 115 119 deploySUS(installationRoot, saLifeCycle, descriptor, suInstallRoots, 120 xmlResult, suTaskProcessors); 121 122 125 context.put(DeploymentContextConstants.SA_LIFECYCLE, saLifeCycle); 126 } 127 128 146 protected void deploySUS(URI installationRoot, 147 ServiceAssemblyLifeCycle saLifeCycle, JBIDescriptor descriptor, 148 Map <String , URI > suInstallRoots, XMLResult xmlResult, 149 List <TaskProcessor> suTaskProcessors) throws Exception { 150 List <ServiceUnit> serviceUnits = descriptor.getServiceAssembly() 151 .getServiceUnits(); 152 if (serviceUnits != null) { 153 StringBuffer componentOutput = new StringBuffer (); 154 for (ServiceUnit serviceUnit : serviceUnits) { 155 156 159 HashMap <String , Object > suDeploymentContext = new HashMap <String , Object >(); 160 suDeploymentContext.put( 161 DeploymentContextConstants.SA_LIFECYCLE, saLifeCycle); 162 suDeploymentContext.put( 163 DeploymentContextConstants.SU_DESCRIPTOR, serviceUnit); 164 suDeploymentContext.put( 165 DeploymentContextConstants.SU_INSTALL_ROOT, 166 suInstallRoots.get(DeploymentUtils 167 .getServiceUnitName(serviceUnit))); 168 169 172 DeploymentTaskFactory deploymentTaskFactory = deploymentService 173 .getDeploymentTaskFactory(); 174 Task suToComponentDeploymentTask = deploymentTaskFactory 175 .getSuToComponentDeploymentTask(); 176 Task createAndRegisterSULifeCycleTask = deploymentTaskFactory 177 .getCreateAndRegisterSULifeCycleTask(); 178 179 182 TaskProcessor processor = new TaskProcessor( 183 suDeploymentContext, log); 184 processor.addTask(suToComponentDeploymentTask); 185 processor.addTask(createAndRegisterSULifeCycleTask); 186 if (suTaskProcessors != null) { 187 suTaskProcessors.add(processor); 188 } 189 190 193 if (!processor.process()) { 194 String msg = "Error occured during the deployment of a ServiceUnit"; 195 throw new Exception (msg); 196 } 197 String xmlReturn = (String ) suDeploymentContext 198 .get(DeploymentContextConstants.COMPONENT_XML_RESULT); 199 if (!isValidComponentTask(xmlReturn, this.getClass() 200 .getClassLoader().getResourceAsStream( 201 "schema/management-message-component.xsd"))) { 202 xmlReturn = xmlResult.wrapComponentTaskResult(serviceUnit 203 .getTargetComponentName(), "deploy", xmlReturn); 204 } 205 componentOutput.append(xmlReturn); 206 } 207 xmlResult.addComponentTaskResult(componentOutput); 208 } 209 } 210 211 223 protected ServiceAssemblyLifeCycle createSALifeCycle(URI installationRoot, 224 JBIDescriptor descriptor) throws ManagementException { 225 ObjectName objectName = managerService.getDeploymentServiceMBeanName(); 227 228 return new ServiceAssemblyLifeCycle(objectName, log, descriptor 229 .getServiceAssembly(), repositorySrv, recoverySrv, 230 installationRoot); 231 232 } 233 234 243 protected boolean isValidComponentTask(String componentTask, InputStream xsd) { 244 return XMLResult.isValidComponentTask(componentTask, xsd); 245 } 246 247 @SuppressWarnings ("unchecked") 248 public void undo(HashMap context) { 249 List <TaskProcessor> suTaskProcessors = (List <TaskProcessor>) context 250 .get(DeploymentContextConstants.SU_TASK_PROCESSORS); 251 252 if (suTaskProcessors != null) { 253 for (TaskProcessor processor : suTaskProcessors) { 254 processor.unprocess(); 255 } 256 } 257 } 258 259 } 260 | Popular Tags |