1 17 package org.apache.geronimo.deployment.plugin.jmx; 18 19 import java.io.File ; 20 import java.io.InputStream ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import java.util.Locale ; 24 25 import javax.enterprise.deploy.model.DeployableObject ; 26 import javax.enterprise.deploy.shared.DConfigBeanVersionType ; 27 import javax.enterprise.deploy.shared.ModuleType ; 28 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 29 import javax.enterprise.deploy.spi.DeploymentManager ; 30 import javax.enterprise.deploy.spi.Target ; 31 import javax.enterprise.deploy.spi.TargetModuleID ; 32 import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException ; 33 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException ; 34 import javax.enterprise.deploy.spi.exceptions.TargetException ; 35 import javax.enterprise.deploy.spi.status.ProgressObject ; 36 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 import org.apache.geronimo.deployment.plugin.TargetImpl; 40 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; 41 import org.apache.geronimo.deployment.plugin.local.CommandSupport; 42 import org.apache.geronimo.deployment.plugin.local.DistributeCommand; 43 import org.apache.geronimo.deployment.plugin.local.RedeployCommand; 44 import org.apache.geronimo.deployment.plugin.local.StartCommand; 45 import org.apache.geronimo.deployment.plugin.local.StopCommand; 46 import org.apache.geronimo.deployment.plugin.local.UndeployCommand; 47 import org.apache.geronimo.gbean.AbstractName; 48 import org.apache.geronimo.kernel.Kernel; 49 import org.apache.geronimo.kernel.config.ConfigurationInfo; 50 import org.apache.geronimo.kernel.config.ConfigurationManager; 51 import org.apache.geronimo.kernel.config.ConfigurationModuleType; 52 import org.apache.geronimo.kernel.config.ConfigurationUtil; 53 import org.apache.geronimo.kernel.management.State; 54 55 56 59 public abstract class JMXDeploymentManager implements DeploymentManager { 60 private static final Log log = LogFactory.getLog(JMXDeploymentManager.class); 61 62 protected Kernel kernel; 63 private ConfigurationManager configurationManager; 64 private CommandContext commandContext; 65 66 protected void initialize(Kernel kernel) { 67 this.kernel = kernel; 68 configurationManager = ConfigurationUtil.getConfigurationManager(kernel); 69 commandContext = new CommandContext(true, true, null, null, false); 70 } 71 72 public void setAuthentication(String username, String password) { 73 commandContext.setUsername(username); 74 commandContext.setPassword(password); 75 } 76 77 public void release() { 78 if(kernel != null && configurationManager != null) { 79 try { 80 ConfigurationUtil.releaseConfigurationManager(kernel, configurationManager); 81 } finally { 82 configurationManager = null; 83 kernel = null; 84 } 85 } 86 } 87 88 public Target [] getTargets() { 89 if (kernel == null) { 90 throw new IllegalStateException ("Disconnected"); 91 } 92 List stores = configurationManager.listStores(); 93 if (stores.size() == 0) { 94 return null; 95 } 96 97 Target [] targets = new Target [stores.size()]; 98 for (int i = 0; i < stores.size(); i++) { 99 AbstractName storeName = (AbstractName) stores.get(i); 100 targets[i] = new TargetImpl(storeName, null); 101 } 102 return targets; 103 } 104 105 public TargetModuleID [] getAvailableModules(final ModuleType moduleType, Target [] targetList) throws TargetException { 106 ConfigFilter filter = new ConfigFilter() { 107 public boolean accept(ConfigurationInfo info) { 108 return moduleType == null || info.getType() == ConfigurationModuleType.getFromValue(moduleType.getValue()); 109 } 110 }; 111 return getModules(targetList, filter); 112 } 113 114 public TargetModuleID [] getNonRunningModules(final ModuleType moduleType, Target [] targetList) throws TargetException { 115 ConfigFilter filter = new ConfigFilter() { 116 public boolean accept(ConfigurationInfo info) { 117 return info.getState() != State.RUNNING && (moduleType == null || info.getType() == ConfigurationModuleType.getFromValue(moduleType.getValue())); 118 } 119 }; 120 return getModules(targetList, filter); 121 } 122 123 public TargetModuleID [] getRunningModules(final ModuleType moduleType, Target [] targetList) throws TargetException { 124 ConfigFilter filter = new ConfigFilter() { 125 public boolean accept(ConfigurationInfo info) { 126 return info.getState() == State.RUNNING && (moduleType == null || info.getType() == ConfigurationModuleType.getFromValue(moduleType.getValue())); 127 } 128 }; 129 return getModules(targetList, filter); 130 } 131 132 private static interface ConfigFilter { 133 boolean accept(ConfigurationInfo info); 134 } 135 136 private TargetModuleID [] getModules(Target [] targetList, ConfigFilter filter) throws TargetException { 137 if (kernel == null) { 138 throw new IllegalStateException ("Disconnected"); 139 } 140 try { 141 ArrayList result = new ArrayList (); 142 for (int i = 0; i < targetList.length; i++) { 143 TargetImpl target = (TargetImpl) targetList[i]; 144 AbstractName storeName = target.getAbstractName(); 145 List infos = configurationManager.listConfigurations(storeName); 146 for (int j = 0; j < infos.size(); j++) { 147 ConfigurationInfo info = (ConfigurationInfo) infos.get(j); 148 if (filter.accept(info)) { 149 String name = info.getConfigID().toString(); 150 List list = CommandSupport.loadChildren(kernel, name); 151 TargetModuleIDImpl moduleID = new TargetModuleIDImpl(target, name, (String []) list.toArray(new String [list.size()])); 152 moduleID.setType(CommandSupport.convertModuleType(info.getType())); 153 if(moduleID.getChildTargetModuleID() != null) { 154 for (int k = 0; k < moduleID.getChildTargetModuleID().length; k++) { 155 TargetModuleIDImpl child = (TargetModuleIDImpl) moduleID.getChildTargetModuleID()[k]; 156 if(CommandSupport.isWebApp(kernel, child.getModuleID())) { 157 child.setType(ModuleType.WAR); 158 } 159 } 160 } 161 result.add(moduleID); 162 } 163 } 164 } 165 CommandSupport.addWebURLs(kernel, result); 166 return result.size() == 0 ? null : (TargetModuleID []) result.toArray(new TargetModuleID [result.size()]); 167 } catch (Exception e) { 168 throw (TargetException ) new TargetException (e.getMessage()).initCause(e); 169 } 170 } 171 172 public ProgressObject distribute(Target [] targetList, File moduleArchive, File deploymentPlan) { 173 if (kernel == null) { 174 throw new IllegalStateException ("Disconnected"); 175 } 176 DistributeCommand command = createDistributeCommand(targetList, moduleArchive, deploymentPlan); 177 command.setCommandContext(commandContext); 178 new Thread (command).start(); 179 return command; 180 } 181 182 public ProgressObject distribute(Target [] targetList, InputStream moduleArchive, InputStream deploymentPlan) { 183 if (kernel == null) { 184 throw new IllegalStateException ("Disconnected"); 185 } 186 DistributeCommand command = createDistributeCommand(targetList, moduleArchive, deploymentPlan); 187 command.setCommandContext(commandContext); 188 new Thread (command).start(); 189 return command; 190 } 191 192 public ProgressObject start(TargetModuleID [] moduleIDList) { 193 if (kernel == null) { 194 throw new IllegalStateException ("Disconnected"); 195 } 196 StartCommand command = new StartCommand(kernel, moduleIDList); 197 command.setCommandContext(commandContext); 198 new Thread (command).start(); 199 return command; 200 } 201 202 public ProgressObject stop(TargetModuleID [] moduleIDList) { 203 if (kernel == null) { 204 throw new IllegalStateException ("Disconnected"); 205 } 206 StopCommand command = new StopCommand(kernel, moduleIDList); 207 command.setCommandContext(commandContext); 208 new Thread (command).start(); 209 return command; 210 } 211 212 public ProgressObject undeploy(TargetModuleID [] moduleIDList) { 213 if (kernel == null) { 214 throw new IllegalStateException ("Disconnected"); 215 } 216 UndeployCommand command = new UndeployCommand(kernel, moduleIDList); 217 command.setCommandContext(commandContext); 218 new Thread (command).start(); 219 return command; 220 } 221 222 public boolean isRedeploySupported() { 223 return true; 224 } 225 226 public ProgressObject redeploy(TargetModuleID [] moduleIDList, File moduleArchive, File deploymentPlan) { 227 if (kernel == null) { 228 throw new IllegalStateException ("Disconnected"); 229 } 230 RedeployCommand command = createRedeployCommand(moduleIDList, moduleArchive, deploymentPlan); 231 command.setCommandContext(commandContext); 232 new Thread (command).start(); 233 return command; 234 } 235 236 public ProgressObject redeploy(TargetModuleID [] moduleIDList, InputStream moduleArchive, InputStream deploymentPlan) { 237 if (kernel == null) { 238 throw new IllegalStateException ("Disconnected"); 239 } 240 RedeployCommand command = createRedeployCommand(moduleIDList, moduleArchive, deploymentPlan); 241 command.setCommandContext(commandContext); 242 new Thread (command).start(); 243 return command; 244 } 245 246 public Locale [] getSupportedLocales() { 247 return new Locale []{getDefaultLocale()}; 248 } 249 250 public Locale getCurrentLocale() { 251 return getDefaultLocale(); 252 } 253 254 public Locale getDefaultLocale() { 255 return Locale.getDefault(); 256 } 257 258 public boolean isLocaleSupported(Locale locale) { 259 return getDefaultLocale().equals(locale); 260 } 261 262 public void setLocale(Locale locale) { 263 throw new UnsupportedOperationException ("Cannot set Locale"); 264 } 265 266 public DConfigBeanVersionType getDConfigBeanVersion() { 267 return DConfigBeanVersionType.V1_4; 268 } 269 270 public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType version) { 271 return DConfigBeanVersionType.V1_4.equals(version); 272 } 273 274 public void setDConfigBeanVersion(DConfigBeanVersionType version) throws DConfigBeanVersionUnsupportedException { 275 if (!isDConfigBeanVersionSupported(version)) { 276 throw new DConfigBeanVersionUnsupportedException ("Version not supported " + version); 277 } 278 } 279 280 public DeploymentConfiguration createConfiguration(DeployableObject dObj) throws InvalidModuleException { 281 if(dObj.getType().equals(ModuleType.CAR)) { 282 } else if(dObj.getType().equals(ModuleType.EAR)) { 284 } else if(dObj.getType().equals(ModuleType.EJB)) { 286 try { 287 Class cls = Class.forName("org.apache.openejb.deployment.EJBConfigurer"); 288 return (DeploymentConfiguration )cls.getMethod("createConfiguration", new Class []{DeployableObject .class}).invoke(cls.newInstance(), new Object []{dObj}); 289 } catch (Exception e) { 290 log.error("Unable to invoke EJB deployer", e); 291 } 292 } else if(dObj.getType().equals(ModuleType.RAR)) { 293 } else if(dObj.getType().equals(ModuleType.WAR)) { 295 } 297 throw new InvalidModuleException ("Not supported"); 298 } 299 300 protected DistributeCommand createDistributeCommand(Target [] targetList, File moduleArchive, File deploymentPlan) { 301 return new DistributeCommand(kernel, targetList, moduleArchive, deploymentPlan); 302 } 303 304 protected DistributeCommand createDistributeCommand(Target [] targetList, InputStream moduleArchive, InputStream deploymentPlan) { 305 return new DistributeCommand(kernel, targetList, moduleArchive, deploymentPlan); 306 } 307 308 protected RedeployCommand createRedeployCommand(TargetModuleID [] moduleIDList, File moduleArchive, File deploymentPlan) { 309 return new RedeployCommand(kernel, moduleIDList, moduleArchive, deploymentPlan); 310 } 311 312 protected RedeployCommand createRedeployCommand(TargetModuleID [] moduleIDList, InputStream moduleArchive, InputStream deploymentPlan) { 313 return new RedeployCommand(kernel, moduleIDList, moduleArchive, deploymentPlan); 314 } 315 316 public void setLogConfiguration(boolean shouldLog, boolean verboseStatus) { 317 commandContext.setLogErrors(shouldLog); 318 commandContext.setVerbose(verboseStatus); 319 } 320 321 public void setInPlace(boolean inPlace) { 322 commandContext.setInPlace(inPlace); 323 } 324 } 325 | Popular Tags |