1 17 package org.apache.geronimo.deployment.plugin.local; 18 19 import java.io.File ; 20 import java.io.FileOutputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.io.OutputStream ; 24 import java.net.URL ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Set ; 28 import javax.enterprise.deploy.shared.CommandType ; 29 import javax.enterprise.deploy.shared.ModuleType ; 30 import javax.enterprise.deploy.spi.Target ; 31 32 import org.apache.geronimo.common.DeploymentException; 33 import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; 34 import org.apache.geronimo.gbean.AbstractName; 35 import org.apache.geronimo.gbean.AbstractNameQuery; 36 import org.apache.geronimo.kernel.Kernel; 37 38 41 public abstract class AbstractDeployCommand extends CommandSupport { 42 protected final Kernel kernel; 43 private static final String [] DEPLOY_SIG = {boolean.class.getName(), File .class.getName(), File .class.getName(), String .class.getName()}; 44 protected final boolean spool; 45 protected File moduleArchive; 46 protected File deploymentPlan; 47 protected InputStream moduleStream; 48 protected InputStream deploymentStream; 49 protected AbstractName deployer; 50 51 public AbstractDeployCommand(CommandType command, Kernel kernel, File moduleArchive, File deploymentPlan, InputStream moduleStream, InputStream deploymentStream, boolean spool) { 52 super(command); 53 this.kernel = kernel; 54 this.moduleArchive = moduleArchive; 55 this.deploymentPlan = deploymentPlan; 56 this.moduleStream = moduleStream; 57 this.deploymentStream = deploymentStream; 58 this.spool = spool; 59 deployer = getDeployerName(); 60 } 61 62 private AbstractName getDeployerName() { 63 Set deployers = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.Deployer")); 64 if (deployers.isEmpty()) { 65 fail("No Deployer GBean present in running Geronimo server. " + 66 "This usually indicates a serious problem with the configuration of " + 67 "your running Geronimo server. If " + 68 "the deployer is present but not started, the workaround is to run " + 69 "a deploy command like 'start geronimo/geronimo-gbean-deployer/1.0/car'. " + 70 "If the deployer service is not present at all (it was undeployed) then " + 71 "you need to either re-install Geronimo or get a deployment plan for the " + 72 "runtime deployer and distribute it while the server is not running and " + 73 "then start the server with a command like the above. For help on this, " + 74 "write to user@geronimo.apache.org and include the contents of your " + 75 "var/config/config.xml file."); 76 return null; 77 } 78 Iterator j = deployers.iterator(); 79 AbstractName deployer = (AbstractName) j.next(); 80 if (j.hasNext()) { 81 fail("More than one deployer found"); 82 return null; 83 } 84 return deployer; 85 86 } 87 88 protected static File createTempFile() throws IOException { 92 File tempFile = File.createTempFile("geronimo-deploymentUtil", ".tmpdir"); 93 tempFile.deleteOnExit(); 94 return tempFile; 95 } 96 97 protected void copyTo(File outfile, InputStream is) throws IOException { 98 byte[] buffer = new byte[4096]; 99 int count; 100 OutputStream os = new FileOutputStream (outfile); 101 try { 102 while ((count = is.read(buffer)) > 0) { 103 os.write(buffer, 0, count); 104 } 105 } finally { 106 os.close(); 107 } 108 } 109 110 protected void doDeploy(Target target, boolean finished) throws Exception { 111 File [] args = {moduleArchive, deploymentPlan}; 112 massageFileNames(args); 113 Object deployParams[] = new Object [] {Boolean.valueOf(commandContext.isInPlace()), args[0], args[1], target.getName()}; 114 List objectNames = (List ) kernel.invoke(deployer, "deploy", deployParams, DEPLOY_SIG); 115 if (objectNames == null || objectNames.isEmpty()) { 116 throw new DeploymentException("Server didn't deploy anything"); 117 } 118 String parentName = (String ) objectNames.get(0); 119 String [] childIDs = new String [objectNames.size()-1]; 120 for (int j=0; j < childIDs.length; j++) { 121 childIDs[j] = (String )objectNames.get(j+1); 122 } 123 124 TargetModuleIDImpl moduleID = new TargetModuleIDImpl(target, parentName, childIDs); 125 if(isWebApp(kernel, parentName)) { 126 moduleID.setType(ModuleType.WAR); 127 } 128 if(moduleID.getChildTargetModuleID() != null) { 129 for (int i = 0; i < moduleID.getChildTargetModuleID().length; i++) { 130 TargetModuleIDImpl id = (TargetModuleIDImpl) moduleID.getChildTargetModuleID()[i]; 131 if(isWebApp(kernel, id.getModuleID())) { 132 id.setType(ModuleType.WAR); 133 } 134 } 135 } 136 addModule(moduleID); 137 if(finished) { 138 addWebURLs(kernel); 139 complete("Completed with id " + parentName); 140 } 141 } 142 143 protected void massageFileNames(File [] inputs) { 144 } 145 146 public URL getRemoteDeployUploadURL() throws Exception { 147 return new URL ((String )kernel.getAttribute(deployer, "remoteDeployUploadURL")); 148 } 149 } 150 | Popular Tags |