geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwo...@apache.org
Subject svn commit: r1137893 [2/2] - in /geronimo/server/trunk/framework: configs/ configs/bundle-recorder/ configs/bundle-recorder/src/ configs/bundle-recorder/src/main/ configs/bundle-recorder/src/main/history/ configs/bundle-recorder/src/main/plan/ configs/...
Date Tue, 21 Jun 2011 07:42:49 GMT
Added: geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/CSVFileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/CSVFileUtils.java?rev=1137893&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/CSVFileUtils.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/CSVFileUtils.java
Tue Jun 21 07:42:48 2011
@@ -0,0 +1,132 @@
+package org.apache.geronimo.system.bundle;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.geronimo.kernel.util.IOUtils;
+
+public class CSVFileUtils {
+    
+    public static void appendToCSVFile(File file, String[] values) throws IOException{
+               
+        BufferedWriter writer = null;
+        try {
+            writer = new BufferedWriter(new FileWriter(file,true));
+            writer.newLine();
+            String line = createCSVLine(values);
+            if (line!=null){
+                writer.append(line);
+            }
+            writer.flush();
+        } finally {
+            IOUtils.close(writer);
+        }
+    }
+    
+    public static void deleteByKeywordInCSVFile(File file, String keyword) throws IOException{
+        BufferedReader reader = null;
+        BufferedWriter writer = null;
+
+        File tmpFile = new File(file.getAbsolutePath()+".tmpfile");
+        try {
+            reader = new BufferedReader(new FileReader(file));
+            writer = new BufferedWriter(new FileWriter(tmpFile,true));
+            String line = null;
+            while (( line = reader.readLine()) != null){
+                String[] values = line.split(",");
+                boolean flag = false;
+                for (String value : values){
+                    if (value.contains(keyword)){
+                        flag = true;
+                        break;
+                    }
+                }
+                if (flag) continue;
+                
+                writer.append(line);
+                writer.newLine();
+            }
+            
+        } finally {
+            reader.close();
+            writer.close();
+        }
+        
+        if (file.delete()){
+            tmpFile.renameTo(file);
+        }else{
+            tmpFile.delete();
+            throw new RuntimeException("Can not delete a line in file: " + file.getAbsolutePath());
+        }
+
+    }
+    
+    public static List<String[]> loadCSVFile(File file) throws IOException{
+        BufferedReader reader = null;
+        List<String[]> results = new ArrayList<String[]>();
+        
+        try {
+            reader = new BufferedReader(new FileReader(file));
+            String line=null;
+            while ((line = reader.readLine())!=null){
+                if (line.trim().isEmpty()){ 
+                    continue;
+                }
+
+                results.add(line.split(","));
+            }
+        } finally {
+            IOUtils.close(reader);
+        }
+        
+        return results;
+    }
+    
+    public static void overrideCSVFile(File file, List<String[]> valuesList) throws
IOException {
+        BufferedWriter writer = null;
+
+        File tmpFile = new File(file.getAbsolutePath()+".tmpfile");
+        try {
+            writer = new BufferedWriter(new FileWriter(tmpFile,true));
+            
+            for (String[] values : valuesList){
+                String line = createCSVLine(values);
+                
+                if (line!=null){
+                    writer.append(line);
+                    writer.newLine();
+                }
+            }
+
+        } finally {
+            writer.close();
+        }
+        
+        if (file.delete()){
+            tmpFile.renameTo(file);
+        }else{
+            tmpFile.delete();
+            throw new RuntimeException("Can not delete the old record file: " + file.getAbsolutePath());
+        }
+    }
+    
+    private static String createCSVLine(String[] values){
+        String line = null;
+        if (values != null) {
+            line = "";
+            if (values.length > 0) {
+                line = values[0];
+                for (int i = 1; i < values.length; i++) {
+                    line += "," + values[i];
+                }
+            }
+        }
+        return line;
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-bundle-recorder/src/main/java/org/apache/geronimo/system/bundle/CSVFileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
Tue Jun 21 07:42:48 2011
@@ -91,6 +91,7 @@ public class DeployerCLParser extends Ba
         commandMetaData.add(InstallLibraryCommandMetaData.META_DATA);
         commandMetaData.add(EncryptCommandMetaData.META_DATA);
         commandMetaData.add(UnlockKeystoreCommandMetaData.META_DATA);
+        commandMetaData.add(InstallBundleCommandMetaData.META_DATA);
 
         addURI();
         addHost();

Added: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgs.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgs.java?rev=1137893&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgs.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgs.java
Tue Jun 21 07:42:48 2011
@@ -0,0 +1,13 @@
+package org.apache.geronimo.cli.deployer;
+
+public interface InstallBundleCommandArgs  extends CommandArgs {
+
+    boolean isInPlace(); 
+    
+    boolean isStart();
+    
+    int getStartLevel();
+    
+    
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgsImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgsImpl.java?rev=1137893&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgsImpl.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgsImpl.java
Tue Jun 21 07:42:48 2011
@@ -0,0 +1,96 @@
+package org.apache.geronimo.cli.deployer;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.geronimo.cli.CLParserException;
+
+public class InstallBundleCommandArgsImpl implements InstallBundleCommandArgs {
+
+    private final static String ARGUMENT_IN_PLACE_SHORTFORM = "i";
+    private final static String ARGUMENT_IN_PLACE = "inPlace";
+    
+    private final static String ARGUMENT_START_SHORTFORM = "s";
+    private final static String ARGUMENT_START = "start";
+        
+    private final static String ARGUMENT_START_LEVEL_SHORTFORM = "l";
+    private final static String ARGUMENT_START_LEVEL = "startLevel";
+    
+    protected final Options options;
+    protected CommandLine commandLine;
+
+    public InstallBundleCommandArgsImpl(String[] args) throws CLParserException {
+        options = new Options();
+        addInPlace();
+        addStart();
+        addStartLevel();
+        
+        CommandLineParser parser = new GnuParser();
+        try {
+            commandLine = parser.parse(options, args, true);
+        } catch (ParseException e) {
+            throw new CLParserException(e.getMessage(), e);
+        }
+        
+        if (0 == commandLine.getArgs().length) {
+            throw new CLParserException("Must specify a bundle location");
+        }
+    }
+
+    
+    protected void addInPlace() {
+        options.addOption(ARGUMENT_IN_PLACE_SHORTFORM,
+                ARGUMENT_IN_PLACE,
+                false,
+                "If inPlace is provided, the bundle is not copied to the \"repository/recorded-bundles\"
directory.");
+    }
+    
+    protected void addStart() {
+        options.addOption(ARGUMENT_START_SHORTFORM,
+                ARGUMENT_START,
+                false,
+                "If start is provided, the bundle will be automatically started after recorded
in Geronimo.");
+    }
+    
+    protected void addStartLevel() {
+        OptionBuilder optionBuilder = OptionBuilder.hasArg().withArgName("startLevel");
+        optionBuilder = optionBuilder.withLongOpt(ARGUMENT_START_LEVEL);
+        optionBuilder = optionBuilder.withDescription("If no start level are provided, will
use the framework's initial bundle start level");
+        Option option = optionBuilder.create(ARGUMENT_START_LEVEL_SHORTFORM);
+        options.addOption(option);
+        
+    }
+
+    
+    
+    @Override
+    public boolean isInPlace() {
+        return commandLine.hasOption(ARGUMENT_IN_PLACE_SHORTFORM);
+    }
+    
+    @Override
+    public boolean isStart() {
+        return commandLine.hasOption(ARGUMENT_START_SHORTFORM);
+    }
+    
+    @Override
+    public int getStartLevel(){
+        String startLevelStr = commandLine.getOptionValue(ARGUMENT_START_LEVEL_SHORTFORM);
+        if (null == startLevelStr) {
+            return -1;
+        }
+        return Integer.valueOf(startLevelStr);
+    }
+    
+    
+    
+    @Override
+    public String[] getArgs() {
+        return commandLine.getArgs();
+    }
+
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandArgsImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandMetaData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandMetaData.java?rev=1137893&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandMetaData.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandMetaData.java
Tue Jun 21 07:42:48 2011
@@ -0,0 +1,21 @@
+package org.apache.geronimo.cli.deployer;
+
+import org.apache.geronimo.cli.CLParserException;
+
+public class InstallBundleCommandMetaData extends BaseCommandMetaData {
+    public static final CommandMetaData META_DATA = new InstallBundleCommandMetaData();
+
+    private InstallBundleCommandMetaData() {
+        super("install-bundle", 
+                "2. Other Commands", 
+                "[--inPlace] [--startLevel number] [--start] bundleFile",
+                "Install and record an OSGi bundle file in Geronimo so that it can be automatically
started " + 
+                "even after you cleaned the cache directory of the OSGi framework."
+                );
+    }
+    
+    @Override
+    public CommandArgs parse(String[] newArgs) throws CLParserException {
+        return new InstallBundleCommandArgsImpl(newArgs);
+    }
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/InstallBundleCommandMetaData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/pom.xml?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/pom.xml Tue Jun 21 07:42:48
2011
@@ -67,6 +67,12 @@
             <artifactId>geronimo-crypto</artifactId>
             <version>${project.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.framework</groupId>
+            <artifactId>geronimo-bundle-recorder</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
 </project>

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/GeronimoDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/GeronimoDeploymentManager.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/GeronimoDeploymentManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/GeronimoDeploymentManager.java
Tue Jun 21 07:42:48 2011
@@ -21,6 +21,7 @@ import java.net.URL;
 import javax.enterprise.deploy.spi.DeploymentManager;
 
 import org.apache.geronimo.deployment.plugin.eba.EBADeploymentManager;
+import org.apache.geronimo.system.bundle.BundleRecorder;
 import org.apache.geronimo.system.plugin.PluginInstaller;
 import org.apache.geronimo.system.plugin.ServerArchiver;
 
@@ -29,7 +30,7 @@ import org.apache.geronimo.system.plugin
  *
  * @version $Rev$ $Date$
  */
-public interface GeronimoDeploymentManager extends DeploymentManager, PluginInstaller, ServerArchiver,
EBADeploymentManager {
+public interface GeronimoDeploymentManager extends DeploymentManager, PluginInstaller, ServerArchiver,
EBADeploymentManager, BundleRecorder {
 
     public <T> T getImplementation(Class<T> clazz);
     public URL[] getRepositories();

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/factories/BaseDeploymentFactory.java
Tue Jun 21 07:42:48 2011
@@ -53,6 +53,7 @@ public class BaseDeploymentFactory imple
     private static final Logger log = LoggerFactory.getLogger(BaseDeploymentFactory.class);
 
     public static final String URI_PREFIX = "deployer:geronimo:";
+    private static final String DEFAULT_HOST = "localhost";
     private static final int DEFAULT_PORT = 1099;
 
     public BaseDeploymentFactory() {
@@ -85,12 +86,12 @@ public class BaseDeploymentFactory imple
         if(protocol.equals("jmx") || protocol.equals("jmxs")) {
             boolean secure = protocol.equals("jmxs");
             if(!uri.startsWith("//")) {
-                return new ConnectParams(protocol, "localhost", DEFAULT_PORT, secure);
+                return new ConnectParams(protocol, DEFAULT_HOST, DEFAULT_PORT, secure);
             }
             uri = uri.substring(2);
             pos = uri.indexOf(':');
             if(pos == -1) {
-                return new ConnectParams(protocol, uri.equals("") ? "localhost" : uri, DEFAULT_PORT,
secure);
+                return new ConnectParams(protocol, uri.equals("") ? DEFAULT_HOST : uri, DEFAULT_PORT,
secure);
             }
             if(uri.indexOf('/', pos+1) > -1) {
                 return null;
@@ -101,7 +102,7 @@ public class BaseDeploymentFactory imple
             String host = uri.substring(0, pos);
             String port = uri.substring(pos+1);
             try {
-                return new ConnectParams(protocol, host.equals("") ? "localhost" : host,
Integer.parseInt(port), secure);
+                return new ConnectParams(protocol, host.equals("") ? DEFAULT_HOST : host,
Integer.parseInt(port), secure);
             } catch (NumberFormatException e) {
                 return null;
             }

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
Tue Jun 21 07:42:48 2011
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import javax.enterprise.deploy.spi.exceptions.TargetException;
 import javax.security.auth.login.FailedLoginException;
 
 import org.apache.geronimo.deployment.plugin.GeronimoDeploymentManager;
@@ -34,16 +33,15 @@ import org.apache.geronimo.deployment.sp
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.InvalidGBeanException;
 import org.apache.geronimo.kernel.NoSuchOperationException;
-import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationInfo;
 import org.apache.geronimo.kernel.config.ConfigurationModuleType;
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Dependency;
 import org.apache.geronimo.kernel.repository.MissingDependencyException;
+import org.apache.geronimo.system.bundle.BundleRecorder;
 import org.apache.geronimo.system.plugin.DownloadPoller;
 import org.apache.geronimo.system.plugin.DownloadResults;
 import org.apache.geronimo.system.plugin.PluginInstaller;
@@ -313,4 +311,23 @@ public abstract class ExtendedDeployment
         return applicationGBeanNames.iterator().next();
     }
     
+    
+    /**
+     * Get the BundleRecorderGBean
+     * @return
+     */
+    private BundleRecorder getBundleRecorder() {
+        return getImplementation(BundleRecorder.class);
+    }
+    
+    public long recordInstall(File bundleFile, boolean inplace, int startLevel) throws IOException
{
+        BundleRecorder recorder = getBundleRecorder();
+        try {
+            return recorder.recordInstall(bundleFile, inplace, startLevel);
+        } finally {
+            kernel.getProxyManager().destroyProxy(recorder);
+        }
+    }
+    
+   
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java
Tue Jun 21 07:42:48 2011
@@ -212,6 +212,15 @@ public class RemoteDeploymentManager ext
         super.updateEBAContent(applicationGBeanName, bundleId, newfile);
     }
     
+    @Override
+    public long recordInstall(File bundleFile, boolean inplace, int startLevel) throws IOException
{
+        if(!isSameMachine) {
+            throw new UnsupportedOperationException("recordBundle operation is not supportted
from a remote JMX connection.");
+        }
+        
+        return super.recordInstall(bundleFile, inplace, startLevel);
+    }
+    
     public static final GBeanInfo GBEAN_INFO;
     public static final String GBEAN_REF_MODULE_CONFIGURERS = "ModuleConfigurers";
 

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/pom.xml?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/pom.xml Tue Jun 21 07:42:48
2011
@@ -61,6 +61,11 @@
             <groupId>org.apache.karaf.shell</groupId>
             <artifactId>org.apache.karaf.shell.console</artifactId>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.aries.jmx</groupId>
+            <artifactId>org.apache.aries.jmx</artifactId>
+        </dependency>
     </dependencies>
     
 </project>

Added: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallBundle.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallBundle.java?rev=1137893&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallBundle.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallBundle.java
Tue Jun 21 07:42:48 2011
@@ -0,0 +1,91 @@
+package org.apache.geronimo.deployment.cli;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Set;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+
+import org.apache.geronimo.cli.deployer.CommandArgs;
+import org.apache.geronimo.cli.deployer.InstallBundleCommandArgs;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.plugin.GeronimoDeploymentManager;
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.osgi.jmx.framework.FrameworkMBean;
+
+public class CommandInstallBundle extends AbstractCommand {
+    public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs
commandArgs) throws DeploymentException {
+        
+        if (!isOffline(connection)) {
+            if (!(commandArgs instanceof InstallBundleCommandArgs)) {
+                throw new DeploymentSyntaxException("CommandArgs has the type [" + commandArgs.getClass()
+ "]; expected [" + InstallBundleCommandArgs.class + "]");
+            }
+            InstallBundleCommandArgs recordBundleCommandArgs = (InstallBundleCommandArgs)
commandArgs;
+            
+            File bundleFile = new File(recordBundleCommandArgs.getArgs()[0]);
+            if(!bundleFile.exists() || !bundleFile.isFile() || !bundleFile.canRead()) {
+                throw new DeploymentException("File does not exist or not a normal file or
not readable. "+bundleFile);
+            }
+            
+            DeploymentManager dmgr = connection.getDeploymentManager();
+            if(dmgr instanceof GeronimoDeploymentManager) {
+                GeronimoDeploymentManager mgr = (GeronimoDeploymentManager) dmgr;
+                boolean inPlace = recordBundleCommandArgs.isInPlace();
+                boolean start = recordBundleCommandArgs.isStart();
+                int startLevel = recordBundleCommandArgs.getStartLevel();
+                try {
+                    long bundleId = mgr.recordInstall(bundleFile, inPlace, startLevel);
+                    if ( bundleId > 0 ){
+                        consoleReader.printString(DeployUtils.reformat("Installed and recorded
bundle: " + bundleId, 4, 72));
+                        
+                        if (start){
+                            if(mgr instanceof RemoteDeploymentManager) {
+                                MBeanServerConnection mbsc = ((RemoteDeploymentManager) mgr).getJMXConnector().getMBeanServerConnection();
+                                try {
+                                    FrameworkMBean frameworkMBean = getFrameworkMBean(mbsc);
+                                    frameworkMBean.startBundle(bundleId);
+                                    consoleReader.printString(DeployUtils.reformat("Started
bundle: " + bundleId, 4, 72));
+                                } catch (Exception e) {
+                                    throw new DeploymentException("Unable to start bundle.",
e);
+                                }
+                                
+                            }else {
+                                consoleReader.printString(DeployUtils.reformat("Currently
the start option only support JMX connection.", 4, 72));
+                            }
+                        }
+                    }else {
+                        consoleReader.printString(DeployUtils.reformat("Bundle installation
failed, so did not record bundle.", 4, 72));
+                    }
+                } catch (Exception e) {
+                    throw new DeploymentException("Unable to record bundle "+recordBundleCommandArgs.getArgs()[0],
e);
+                }
+            } else {
+                throw new DeploymentException("Unable to record bundle using " + dmgr.getClass().getName()
+ " deployment manager");
+            }
+            
+        } else { //offline not supported
+            try {
+                consoleReader.printString(DeployUtils.reformat("Install bundle offline is
not supported!", 4, 72));
+            } catch (IOException e) {
+                throw new DeploymentException("Install bundle offline is not supported!");
+            }
+        }
+    }
+    
+    private FrameworkMBean getFrameworkMBean(MBeanServerConnection mbsc) throws Exception{
+        Set<ObjectName> objectNameSet = mbsc.queryNames(new ObjectName("osgi.core:type=framework,*"),
null);
+        if (objectNameSet.isEmpty()) {
+            throw new Exception("Framework mbean not found");
+            
+        } else if (objectNameSet.size() == 1) {
+            return (FrameworkMBean) MBeanServerInvocationHandler.newProxyInstance(mbsc, objectNameSet.iterator().next(),
FrameworkMBean.class, false);   
+            
+        } else {
+            throw new Exception("Found multiple framework mbeans");
+        }
+    }
+    
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandInstallBundle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java
Tue Jun 21 07:42:48 2011
@@ -34,6 +34,7 @@ import org.apache.geronimo.cli.deployer.
 import org.apache.geronimo.cli.deployer.DeployerCLParser;
 import org.apache.geronimo.cli.deployer.DistributeCommandMetaData;
 import org.apache.geronimo.cli.deployer.EncryptCommandMetaData;
+import org.apache.geronimo.cli.deployer.InstallBundleCommandMetaData;
 import org.apache.geronimo.cli.deployer.InstallLibraryCommandMetaData;
 import org.apache.geronimo.cli.deployer.InstallPluginCommandMetaData;
 import org.apache.geronimo.cli.deployer.ListModulesCommandMetaData;
@@ -88,6 +89,7 @@ public class DeployTool implements Main 
         commands.put(InstallLibraryCommandMetaData.META_DATA, new CommandInstallLibrary());
         commands.put(EncryptCommandMetaData.META_DATA, new CommandEncrypt());
         commands.put(UnlockKeystoreCommandMetaData.META_DATA, new CommandUnlockKeystore());
+        commands.put(InstallBundleCommandMetaData.META_DATA, new CommandInstallBundle());
     }
 
     private boolean failed = false;

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
Tue Jun 21 07:42:48 2011
@@ -39,6 +39,9 @@ import org.apache.geronimo.deployment.pl
  */
 public class DeployUtils extends ConfigIDExtractor {
 
+    public final static String DEFAULT_HOST = "localhost";
+    public final static Integer DEFAULT_PORT = 1099;
+    
     private final static String DEFAULT_URI = "deployer:geronimo:jmx";
     private final static String DEFAULT_SECURE_URI = "deployer:geronimo:jmxs";
     
@@ -142,10 +145,10 @@ public class DeployUtils extends ConfigI
 
     public static String getConnectionURI(String host, Integer port, boolean secure) {
         if (host == null) {
-            host = "localhost";
+            host = DEFAULT_HOST;
         }
         if (port == null) {
-            port = new Integer(1099);
+            port = DEFAULT_PORT;
         }
         String uri = (secure) ? DEFAULT_SECURE_URI : DEFAULT_URI;
         uri += "://" + host + ":" + port;

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/OnlineServerConnection.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/OnlineServerConnection.java?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/OnlineServerConnection.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/OnlineServerConnection.java
Tue Jun 21 07:42:48 2011
@@ -45,7 +45,7 @@ public class OnlineServerConnection exte
     private boolean logToSysErr;
 
     private boolean verboseMessages;
-
+    
     public OnlineServerConnection(ConnectionParams params, ConsoleReader consoleReader) throws
DeploymentException {
         this(params, new DefaultUserPasswordHandler(consoleReader));
     }
@@ -62,37 +62,39 @@ public class OnlineServerConnection exte
         logToSysErr = params.isSyserr();
         boolean secure = params.isSecure();
 
-        if ((driver != null) && uri == null) {
+        if (driver != null && uri == null) {
             throw new DeploymentSyntaxException("A custom driver requires a custom URI");
         }
         if (params.isOffline()) {
             throw new DeploymentException("Offline connection is not supported");
         }
-        if (host != null || port != null) {
-            uri = DeployUtils.getConnectionURI(host, port, secure);
-        }
-
+        
         ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
         Thread.currentThread().setContextClassLoader(DeployUtils.class.getClassLoader());
         try {
-            tryToConnect(uri, driver, user, password, secure);
+            tryToConnect(uri, driver, host, port, user, password, secure);
         } finally  {
             Thread.currentThread().setContextClassLoader(oldCL);
         }
         if (manager == null) {
             throw new DeploymentException("Unexpected error; connection failed.");
         }
+        
     }
 
-    private void tryToConnect(String argURI, String driver, String user, String password,
boolean secure) throws DeploymentException {
+    private void tryToConnect(String uri, String driver, String host, Integer port, String
user, String password, boolean secure) throws DeploymentException {
         DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
         if (driver != null) {
             loadDriver(driver, mgr);
         }
-        String useURI = argURI == null ? DeployUtils.getConnectionURI(null, null, secure)
: argURI;
+        
+        if (host != null || port != null || uri == null) {
+            uri = DeployUtils.getConnectionURI(host, port, secure);
+        }
+        
         if (user == null && password == null) {
             try {
-                SavedAuthentication savedAuthentication = DeployUtils.readSavedCredentials(useURI);
+                SavedAuthentication savedAuthentication = DeployUtils.readSavedCredentials(uri);
                 if (savedAuthentication != null) {
                     user = savedAuthentication.getUser();
                     password = new String(savedAuthentication.getPassword());
@@ -117,13 +119,13 @@ public class OnlineServerConnection exte
             }
         }
         try {
-            manager = mgr.getDeploymentManager(useURI, user, password);
-            auth = new SavedAuthentication(useURI, user, password == null ? null : password.toCharArray());
+            manager = mgr.getDeploymentManager(uri, user, password);
+            auth = new SavedAuthentication(uri, user, password == null ? null : password.toCharArray());
         } catch (AuthenticationFailedException e) {
             // server's there, you just can't talk to it
             throw new DeploymentException("Login Failed");
         } catch (DeploymentManagerCreationException e) {
-            throw new DeploymentException("Unable to connect to server at " + useURI + "
-- " + e.getMessage(), e);
+            throw new DeploymentException("Unable to connect to server at " + uri + " --
" + e.getMessage(), e);
         }
         if (manager instanceof JMXDeploymentManager) {
             JMXDeploymentManager deploymentManager = (JMXDeploymentManager) manager;
@@ -173,4 +175,5 @@ public class OnlineServerConnection exte
             return consoleReader.readLine("Username: ");
         }
     }
+    
 }

Modified: geronimo/server/trunk/framework/modules/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/pom.xml?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/pom.xml (original)
+++ geronimo/server/trunk/framework/modules/pom.xml Tue Jun 21 07:42:48 2011
@@ -62,6 +62,7 @@
         <module>geronimo-deploy-config</module>
         <module>geronimo-rmi-loader</module>
         <module>geronimo-main</module>
+        <module>geronimo-bundle-recorder</module>
     </modules>
 
     <profiles>

Modified: geronimo/server/trunk/framework/plugingroups/framework/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/plugingroups/framework/pom.xml?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/plugingroups/framework/pom.xml (original)
+++ geronimo/server/trunk/framework/plugingroups/framework/pom.xml Tue Jun 21 07:42:48 2011
@@ -111,6 +111,13 @@
             <version>${project.version}</version>
             <type>car</type>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.framework</groupId>
+            <artifactId>bundle-recorder</artifactId>
+            <version>${project.version}</version>
+            <type>car</type>
+        </dependency>
     </dependencies>
 
     <build>

Modified: geronimo/server/trunk/framework/plugingroups/framework/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/plugingroups/framework/src/main/history/dependencies.xml?rev=1137893&r1=1137892&r2=1137893&view=diff
==============================================================================
--- geronimo/server/trunk/framework/plugingroups/framework/src/main/history/dependencies.xml
(original)
+++ geronimo/server/trunk/framework/plugingroups/framework/src/main/history/dependencies.xml
Tue Jun 21 07:42:48 2011
@@ -8,6 +8,11 @@
     </module-id>
     <dependency>
         <groupId>org.apache.geronimo.framework</groupId>
+        <artifactId>bundle-recorder</artifactId>
+        <type>car</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.geronimo.framework</groupId>
         <artifactId>client-system</artifactId>
         <type>car</type>
     </dependency>



Mime
View raw message