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.component.ServiceUnitManager; 28 import javax.jbi.management.DeploymentException; 29 import javax.jbi.management.LifeCycleMBean; 30 31 import org.objectweb.petals.jbi.component.lifecycle.ComponentLifeCycle; 32 import org.objectweb.petals.jbi.management.deployment.DeploymentContextConstants; 33 import org.objectweb.petals.jbi.management.deployment.DeploymentUtils; 34 import org.objectweb.petals.jbi.management.service.LifeCycleManagerService; 35 import org.objectweb.petals.jbi.management.service.ManagementException; 36 import org.objectweb.petals.processor.Task; 37 import org.objectweb.petals.tools.jbicommon.descriptor.ServiceUnit; 38 import org.objectweb.petals.util.LoggingUtil; 39 40 46 public class SUToComponentDeploymentTask implements Task { 47 48 51 protected LoggingUtil log; 52 53 56 protected LifeCycleManagerService managerService; 57 58 public SUToComponentDeploymentTask(LoggingUtil log, 59 LifeCycleManagerService managerService) { 60 super(); 61 this.log = log; 62 this.managerService = managerService; 63 } 64 65 @SuppressWarnings ("unchecked") 66 public void execute(HashMap context) throws Exception { 67 68 URI installationRoot = (URI ) context 69 .get(DeploymentContextConstants.SU_INSTALL_ROOT); 70 71 ServiceUnit serviceUnit = (ServiceUnit) context 72 .get(DeploymentContextConstants.SU_DESCRIPTOR); 73 74 String xmlResult = deploySUtoComponent(installationRoot, serviceUnit); 75 76 79 context.put(DeploymentContextConstants.COMPONENT_XML_RESULT, xmlResult); 80 81 } 82 83 98 protected String deploySUtoComponent(URI installationRoot, 99 ServiceUnit serviceUnit) throws ManagementException { 100 101 104 String targetedComponent = DeploymentUtils 105 .getServiceUnitTargetedComponent(serviceUnit); 106 ComponentLifeCycle clc = managerService 107 .getComponentByName(targetedComponent); 108 if (clc == null) { 109 String msg = "The service unit can not be deployed, as the component '" 110 + targetedComponent + "' is not installed."; 111 log.error(msg); 112 throw new ManagementException(msg); 113 } 114 115 119 if (!LifeCycleMBean.STARTED.equals(clc.getCurrentState())) { 120 String msg = "Component " 121 + targetedComponent 122 + " isn't started : you can't deploy service units on a not started component !"; 123 log.error(msg); 124 throw new ManagementException(msg); 125 } 126 127 131 ServiceUnitManager sum = clc.getComponent().getServiceUnitManager(); 132 if (sum == null) { 133 String msg = "Component " 134 + targetedComponent 135 + " doesn't support deployment : service unit manager is null !"; 136 log.error(msg); 137 throw new ManagementException(msg); 138 } 139 140 String xmlReturn = null; 141 try { 142 xmlReturn = sum.deploy(DeploymentUtils 143 .getServiceUnitName(serviceUnit), installationRoot.getPath()); 144 } catch (DeploymentException e) { 145 String msg = "Deployement of the service unit " 146 + DeploymentUtils.getServiceUnitName(serviceUnit) 147 + " has failed (caused by a component \"" + targetedComponent 148 + "\" su manager exception)."; 149 log.error(msg, e); 150 throw new ManagementException(msg, e); 151 } 152 return xmlReturn; 153 } 154 155 public void undo(HashMap context) { 156 URI installationRoot = (URI ) context 157 .get(DeploymentContextConstants.SU_INSTALL_ROOT); 158 159 ServiceUnit serviceUnit = (ServiceUnit) context 160 .get(DeploymentContextConstants.SU_DESCRIPTOR); 161 162 try { 163 undeploySUFromComponent(installationRoot, serviceUnit); 164 } catch (ManagementException e) { 165 String msg = "Failed to revert a SUToComponentDeploymentTask"; 166 log.error(msg, e); 167 } 168 } 169 170 186 public String undeploySUFromComponent(URI installationRoot, 187 ServiceUnit serviceUnit) throws ManagementException { 188 191 String targetedComponent = DeploymentUtils 192 .getServiceUnitTargetedComponent(serviceUnit); 193 ComponentLifeCycle clc = managerService 194 .getComponentByName(targetedComponent); 195 if (clc == null) { 196 String msg = "The component lifecycle element for service unit deployment must be non null."; 197 log.error(msg); 198 throw new ManagementException(msg); 199 } 200 201 205 if (!LifeCycleMBean.STARTED.equals(clc.getCurrentState())) { 206 String msg = "Component " 207 + targetedComponent 208 + " isn't started : you can not deploy a service unit on a component that has not been started."; 209 log.error(msg); 210 throw new ManagementException(msg); 211 } 212 213 217 ServiceUnitManager sum = clc.getComponent().getServiceUnitManager(); 218 if (sum == null) { 219 String msg = "Component " 220 + targetedComponent 221 + " doesn't support deployment : service unit manager is null !"; 222 log.error(msg); 223 throw new ManagementException(msg); 224 } 225 226 String xmlReturn = null; 227 try { 228 xmlReturn = sum.undeploy(DeploymentUtils 229 .getServiceUnitName(serviceUnit), installationRoot.getPath()); 230 } catch (DeploymentException e) { 231 String msg = "Undeployement of the service unit " 232 + DeploymentUtils.getServiceUnitName(serviceUnit) 233 + " has failed (caused by a targeted component \"" 234 + DeploymentUtils.getServiceUnitName(serviceUnit) 235 + "\" su manager exception)."; 236 log.error(msg, e); 237 throw new ManagementException(msg, e); 238 } 239 return xmlReturn; 240 } 241 } 242 | Popular Tags |