1 /** 2 * 3 * Copyright 2003-2004 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 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 /** 32 * The CLI deployer logic to start. 33 * 34 * @version $Rev: 405229 $ $Date: 2006-05-08 16:44:03 -0700 (Mon, 08 May 2006) $ 35 */ 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 }