1 22 package org.objectweb.petals.jbi.management.deployment.deploy; 23 24 import java.net.URI ; 25 import java.util.HashMap ; 26 27 import javax.jbi.JBIException; 28 29 import org.objectweb.petals.jbi.component.lifecycle.ServiceAssemblyLifeCycle; 30 import org.objectweb.petals.jbi.component.lifecycle.ServiceUnitLifeCycle; 31 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants; 32 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils; 33 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService; 34 import org.objectweb.petals.jbi.management.service.ManagementException; 35 import org.objectweb.petals.processor.Task; 36 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit; 37 import org.objectweb.petals.util.LoggingUtil; 38 39 46 public class CreateAndRegisterSULifeCycleTask implements Task { 47 48 51 protected LoggingUtil log; 52 53 56 protected LifeCycleManagerService managerService; 57 58 public CreateAndRegisterSULifeCycleTask(LoggingUtil log, 59 LifeCycleManagerService managerService) { 60 super(); 61 this.log = log; 62 this.managerService = managerService; 63 } 64 65 public void execute(HashMap context) throws Exception { 66 URI installationRoot = (URI ) context 67 .get(DeploymentContextConstants.SU_INSTALL_ROOT); 68 69 ServiceUnit serviceUnit = (ServiceUnit) context 70 .get(DeploymentContextConstants.SU_DESCRIPTOR); 71 72 ServiceAssemblyLifeCycle saLifeCycle = (ServiceAssemblyLifeCycle) context 73 .get(DeploymentContextConstants.SA_LIFECYCLE); 74 75 78 ServiceUnitLifeCycle suLifeCycle = createNewServiceUnitLifeCycle( 79 installationRoot.getPath(), serviceUnit); 80 81 84 registerSULifeCycle(suLifeCycle, saLifeCycle, serviceUnit); 85 86 } 87 88 97 protected ServiceUnitLifeCycle createNewServiceUnitLifeCycle( 98 String rootPath, ServiceUnit serviceUnit) { 99 return new ServiceUnitLifeCycle(serviceUnit, managerService, rootPath, 100 log); 101 } 102 103 118 protected void registerSULifeCycle(ServiceUnitLifeCycle suLifeCycle, 119 ServiceAssemblyLifeCycle saLifeCycle, ServiceUnit serviceUnit) 120 throws ManagementException { 121 try { 122 saLifeCycle.registerSUIntoSA(DeploymentUtils 123 .getServiceUnitName(serviceUnit), suLifeCycle); 124 } catch (JBIException e) { 125 String msg = "Error while registering the service unit " 126 + DeploymentUtils.getServiceUnitName(serviceUnit) 127 + " life cycle into the service assembly life cycle" 128 + saLifeCycle.getServiceAssembly().getIdentification() 129 .getName() + "."; 130 log.error(msg, e); 131 throw new ManagementException(msg, e); 132 } 133 } 134 135 public void undo(HashMap context) { 136 137 ServiceUnit serviceUnit = (ServiceUnit) context 138 .get(DeploymentContextConstants.SU_DESCRIPTOR); 139 140 ServiceAssemblyLifeCycle saLifeCycle = (ServiceAssemblyLifeCycle) context 141 .get(DeploymentContextConstants.SA_LIFECYCLE); 142 143 try { 144 unregisterSULifeCycle(saLifeCycle, serviceUnit); 145 } catch (ManagementException e) { 146 String msg = "Failed to revert a CreateAndRegisterSULifeCycleTask"; 147 log.error(msg, e); 148 } 149 150 } 151 152 165 protected void unregisterSULifeCycle(ServiceAssemblyLifeCycle saLifeCycle, 166 ServiceUnit serviceUnit) throws ManagementException { 167 saLifeCycle.unregisterSUFromSA(DeploymentUtils 168 .getServiceUnitName(serviceUnit)); 169 170 } 171 172 } 173 | Popular Tags |