1 17 18 package org.apache.geronimo.deployment.cli; 19 20 import org.apache.geronimo.common.DeploymentException; 21 22 import javax.enterprise.deploy.spi.DeploymentManager ; 23 import javax.enterprise.deploy.spi.Target ; 24 import javax.enterprise.deploy.spi.TargetModuleID ; 25 import javax.enterprise.deploy.spi.exceptions.TargetException ; 26 import javax.enterprise.deploy.spi.status.ProgressObject ; 27 import java.io.PrintWriter ; 28 import java.util.ArrayList ; 29 import java.util.List ; 30 31 36 public class CommandStart extends AbstractCommand { 37 public CommandStart() { 38 super("start", "1. Common Commands", "[ModuleID|TargetModuleID]+", 39 "Accepts the configId of a module, or the fully-qualified " + 40 "TargetModuleID identifying both the module and the server or cluster it's " + 41 "on, and starts that module. The module should be available to the server " + 42 "but not currently running. If multiple modules are specified, they will " + 43 "all be started.\n" + 44 "If the server is not running, the module will be marked to start " + 45 "next time the server is started."); 46 } 47 48 public CommandStart(String command, String group, String helpArgumentList, String helpText) { 49 super(command, group, helpArgumentList, helpText); 50 } 51 52 public void execute(PrintWriter out, ServerConnection connection, String [] args) throws DeploymentException { 53 if(args.length == 0) { 54 throw new DeploymentSyntaxException("Must specify at least one module name or TargetModuleID"); 55 } 56 DeploymentManager mgr = connection.getDeploymentManager(); 57 Target [] allTargets = mgr.getTargets(); 58 TargetModuleID [] allModules; 59 try { 60 allModules = mgr.getAvailableModules(null, allTargets); 61 } catch(TargetException e) { 62 throw new DeploymentException("Unable to load module list from server", e); 63 } 64 List modules = new ArrayList (); 65 for(int i=0; i<args.length; i++) { 66 modules.addAll(DeployUtils.identifyTargetModuleIDs(allModules, args[i], false)); 67 } 68 TargetModuleID [] ids = (TargetModuleID []) modules.toArray(new TargetModuleID [modules.size()]); 69 boolean multiple = isMultipleTargets(ids); 70 ProgressObject po = runCommand(out, mgr, ids); 71 TargetModuleID [] done = po.getResultTargetModuleIDs(); 72 out.println(); 73 for(int i = 0; i < done.length; i++) { 74 TargetModuleID id = done[i]; 75 out.print(DeployUtils.reformat(getAction()+" "+id.getModuleID()+(multiple ? " on "+id.getTarget().getName() : "")+(id.getWebURL() == null || !getAction().equals("Started") ? "" : " @ "+id.getWebURL()),4, 72)); 76 if(id.getChildTargetModuleID() != null) { 77 for (int j = 0; j < id.getChildTargetModuleID().length; j++) { 78 TargetModuleID child = id.getChildTargetModuleID()[j]; 79 out.print(DeployUtils.reformat(" `-> "+child.getModuleID()+(child.getWebURL() == null || !getAction().equals("Started") ? "" : " @ "+child.getWebURL()),4, 72)); 80 } 81 } 82 out.println(); 83 } 84 if(po.getDeploymentStatus().isFailed()) { 85 throw new DeploymentException("Operation failed: "+po.getDeploymentStatus().getMessage()); 86 } 87 } 88 89 protected ProgressObject runCommand(PrintWriter out, DeploymentManager mgr, TargetModuleID [] ids) { 90 ProgressObject po = mgr.start(ids); 91 waitForProgress(out, po); 92 return po; 93 } 94 95 protected String getAction() { 96 return "Started"; 97 } 98 99 } 100 | Popular Tags |