Author: gnodet
Date: Tue Oct 10 08:08:40 2006
New Revision: 454773

URL: http://svn.apache.org/viewvc?view=rev&rev=454773
Log:
SM-701: Standardized the return of exceptions from the AdminCommandsService, 
also extended the ANT tasks to provide a deferExceptions settings which if set 
to true allows you to use the same semantics as the deploy/install directories.

Modified:
    
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsServiceMBean.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
    
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java?view=diff&rev=454773&r1=454772&r2=454773
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsService.java
 Tue Oct 10 08:08:40 2006
@@ -52,8 +52,9 @@
         * @param file
         * @return
         */
-       public String installComponent(String file) throws Exception {
-               return installComponent(file, null);
+       public String installComponent(String file, boolean deferExceptions)
+                       throws Exception {
+               return installComponent(file, null, deferExceptions);
        }
 
        /**
@@ -65,10 +66,14 @@
         *            installation properties
         * @return
         */
-       public String installComponent(String file, Properties props)
-                       throws Exception {
+       public String installComponent(String file, Properties props,
+                       boolean deferException) throws Exception {
                try {
-                       container.getInstallationService().install(file, props, 
false);
+                       if (deferException) {
+                               container.updateExternalArchive(file);
+                       } else {
+                               
container.getInstallationService().install(file, props, false);
+                       }
                        return 
ManagementSupport.createSuccessMessage("installComponent",
                                        file);
                } catch (Exception e) {
@@ -96,9 +101,10 @@
                boolean success = 
container.getInstallationService().unloadInstaller(
                                name, true);
                if (success) {
-                       return success("uninstallComponent", name);
+                       return 
ManagementSupport.createSuccessMessage("uninstallComponent",
+                                       name);
                } else {
-                       return failure("uninstallComponent", name, null);
+                       throw ManagementSupport.failure("uninstallComponent", 
name);
                }
        }
 
@@ -108,8 +114,16 @@
         * @param file
         * @return
         */
-       public String installSharedLibrary(String file) throws Exception {
-               return 
container.getInstallationService().installSharedLibrary(file);
+       public String installSharedLibrary(String file, boolean deferException)
+                       throws Exception {
+               if (deferException) {
+                       container.updateExternalArchive(file);
+                       return ManagementSupport.createSuccessMessage(
+                                       "installSharedLibrary", file);
+               } else {
+                       return container.getInstallationService()
+                                       .installSharedLibrary(file);
+               }
        }
 
        /**
@@ -147,9 +161,10 @@
                boolean success = container.getInstallationService()
                                .uninstallSharedLibrary(name);
                if (success) {
-                       return success("uninstallSharedLibrary", name);
+                       return ManagementSupport.createSuccessMessage(
+                                       "uninstallSharedLibrary", name);
                } else {
-                       return failure("uninstallSharedLibrary", name, null);
+                       throw 
ManagementSupport.failure("uninstallSharedLibrary", name);
                }
        }
 
@@ -166,9 +181,10 @@
                                throw new JBIException("Component " + name + " 
not found");
                        }
                        lcc.start();
-                       return success("startComponent", name);
+                       return 
ManagementSupport.createSuccessMessage("startComponent",
+                                       name);
                } catch (JBIException e) {
-                       throw new RuntimeException(failure("startComponent", 
name, e));
+                       throw ManagementSupport.failure("startComponent", name, 
e);
                }
        }
 
@@ -185,9 +201,10 @@
                                throw new JBIException("Component " + name + " 
not found");
                        }
                        lcc.stop();
-                       return success("stopComponent", name);
+                       return ManagementSupport
+                                       .createSuccessMessage("stopComponent", 
name);
                } catch (JBIException e) {
-                       throw new RuntimeException(failure("stopComponent", 
name, e));
+                       throw ManagementSupport.failure("stopComponent", name, 
e);
                }
        }
 
@@ -204,9 +221,10 @@
                                throw new JBIException("Component " + name + " 
not found");
                        }
                        lcc.shutDown();
-                       return success("shutdownComponent", name);
+                       return 
ManagementSupport.createSuccessMessage("shutdownComponent",
+                                       name);
                } catch (JBIException e) {
-                       throw new RuntimeException(failure("shutdownComponent", 
name, e));
+                       throw ManagementSupport.failure("shutdownComponent", 
name, e);
                }
        }
 
@@ -216,8 +234,15 @@
         * @param file
         * @return
         */
-       public String deployServiceAssembly(String file) throws Exception {
-               return container.getDeploymentService().deploy(file);
+       public String deployServiceAssembly(String file, boolean deferException)
+                       throws Exception {
+               if (deferException) {
+                       container.updateExternalArchive(file);
+                       return ManagementSupport.createSuccessMessage(
+                                       "deployServiceAssembly", file);
+               } else {
+                       return container.getDeploymentService().deploy(file);
+               }
        }
 
        /**
@@ -273,11 +298,10 @@
        public String installArchive(String location) throws Exception {
                try {
                        container.updateExternalArchive(location);
-                       return success("installArchive", location);
-
+                       return 
ManagementSupport.createSuccessMessage("installComponent",
+                                       location);
                } catch (Exception e) {
-                       throw new 
RuntimeException(failure("shutdownServiceAssembly",
-                                       location, e));
+                       throw ManagementSupport.failure("installComponent", 
location, e);
                }
        }
 
@@ -493,24 +517,6 @@
                buffer.append("</service-assembly-info-list>");
 
                return buffer.toString();
-       }
-
-       public String failure(String task, String location, Exception e) {
-               ManagementSupport.Message msg = new ManagementSupport.Message();
-               msg.setTask(task);
-               msg.setResult("FAILED");
-               msg.setType("ERROR");
-               msg.setException(e);
-               msg.setMessage(location);
-               return ManagementSupport.createFrameworkMessage(msg, (List) 
null);
-       }
-
-       public String success(String task, String location) {
-               ManagementSupport.Message msg = new ManagementSupport.Message();
-               msg.setTask(task);
-               msg.setMessage(location);
-               msg.setResult("SUCCESS");
-               return ManagementSupport.createFrameworkMessage(msg, (List) 
null);
        }
 
        public MBeanOperationInfo[] getOperationInfos() throws JMException {

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsServiceMBean.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsServiceMBean.java?view=diff&rev=454773&r1=454772&r2=454773
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsServiceMBean.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/framework/AdminCommandsServiceMBean.java
 Tue Oct 10 08:08:40 2006
@@ -26,13 +26,13 @@
  */
 public interface AdminCommandsServiceMBean extends LifeCycleMBean {
     
-    String installComponent(String file) throws Exception;
+    String installComponent(String file, boolean deferException) throws 
Exception;
 
-    String installComponent(String file,Properties properties) throws 
Exception;
+    String installComponent(String file,Properties properties, boolean 
deferException) throws Exception;
 
     String uninstallComponent(String name) throws Exception;
 
-    String installSharedLibrary(String file) throws Exception;
+    String installSharedLibrary(String file, boolean deferException) throws 
Exception;
 
     String uninstallSharedLibrary(String name) throws Exception;
 
@@ -42,7 +42,7 @@
 
     String shutdownComponent(String name) throws Exception;
 
-    String deployServiceAssembly(String file) throws Exception;
+    String deployServiceAssembly(String file, boolean deferException) throws 
Exception;
 
     String undeployServiceAssembly(String name) throws Exception;
 

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java?view=diff&rev=454773&r1=454772&r2=454773
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/DeployServiceAssemblyTask.java
 Tue Oct 10 08:08:40 2006
@@ -27,40 +27,53 @@
  * @version $Revision$
  */
 public class DeployServiceAssemblyTask extends JbiTask {
-    
-    private String file; //archivePath to install
-    
-    /**
-     * @return Returns the archivePath.
-     */
-    public String getFile() {
-        return file;
-    }
-    /**
-     * @param file The archivePath to set.
-     */
-    public void setFile(String file) {
-        this.file = file;
-    }
-    
-    /**
-     * execute the task
-     * @throws BuildException
-     */
-    public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
-        if (file == null){
-            throw new BuildException("null file - file should be an archive");
-        }
-        if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
-            throw new BuildException("file: " + file + " is not an archive");
-        }
-        File archive = new File(file);
-        String location = archive.getAbsolutePath();
-        if (!archive.isFile()) {
-            // if it's not a file, assume it's a url and pass it along
-            location = file;
-        }
-        acs.deployServiceAssembly(location);
-    }
-    
+
+       private String file; // archivePath to install
+
+       private boolean deferExceptions = false;
+
+       public boolean isDeferExceptions() {
+               return deferExceptions;
+       }
+
+       public void setDeferExceptions(boolean deferExceptions) {
+               this.deferExceptions = deferExceptions;
+       }
+
+       /**
+        * @return Returns the archivePath.
+        */
+       public String getFile() {
+               return file;
+       }
+
+       /**
+        * @param file
+        *            The archivePath to set.
+        */
+       public void setFile(String file) {
+               this.file = file;
+       }
+
+       /**
+        * execute the task
+        * 
+        * @throws BuildException
+        */
+       public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
+               if (file == null) {
+                       throw new BuildException("null file - file should be an 
archive");
+               }
+               if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
+                       throw new BuildException("file: " + file + " is not an 
archive");
+               }
+               File archive = new File(file);
+               String location = archive.getAbsolutePath();
+               if (!archive.isFile()) {
+                       // if it's not a file, assume it's a url and pass it 
along
+                       location = file;
+               }
+               acs.deployServiceAssembly(location, deferExceptions);
+       }
+
 }

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java?view=diff&rev=454773&r1=454772&r2=454773
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallComponentTask.java
 Tue Oct 10 08:08:40 2006
@@ -33,90 +33,111 @@
  * @version $Revision$
  */
 public class InstallComponentTask extends JbiTask {
-    
-    private String file; //file to install
-    private String paramsFile;
-    private List nestedParams;
-    
-    /**
-     * @return Returns the file.
-     */
-    public String getFile() {
-        return file;
-    }
-    /**
-     * @param file The file to set.
-     */
-    public void setFile(String file) {
-        this.file = file;
-    }
-    
-    public String getParams() {
-        return paramsFile;
-    }
-    public void setParams(String paramsFile) {
-        this.paramsFile = paramsFile;
-    }
-    
-    public Param createParam() {
-        Param p = new Param();
-        if (nestedParams == null) {
-            nestedParams = new ArrayList();
-        }
-        nestedParams.add(p);
-        return p;
-    }
-    
-    /**
-     * execute the task
-     * @throws BuildException
-     */
-    public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
-        if (file == null){
-            throw new BuildException("null file - file should be an archive");
-        }
-        if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
-            throw new BuildException("file: " + file + " is not an archive");
-        }
-        File archive = new File(file);
-        String location = archive.getAbsolutePath();
-        if (!archive.isFile()) {
-            // if it's not a file, assume it's a url and pass it along
-            location = file;
-        }
-        Properties props = getProperties();
-        acs.installComponent(location, props);
-    }
-    
-    private Properties getProperties() throws IOException {
-        Properties props = new Properties();
-        if (paramsFile != null) {
-            props.load(new FileInputStream(paramsFile));
-        }
-        if (nestedParams != null) {
-            for (Iterator iter = nestedParams.iterator(); iter.hasNext();) {
-                Param p = (Param) iter.next();
-                props.setProperty(p.getName(), p.getValue());
-            }
-        }
-        return props;
-    }
-    
-    public static class Param {
-        private String name;
-        private String value;
-        public String getName() {
-            return name;
-        }
-        public void setName(String name) {
-            this.name = name;
-        }
-        public String getValue() {
-            return value;
-        }
-        public void setValue(String value) {
-            this.value = value;
-        }
-    }
-    
+
+       private String file; // file to install
+
+       private String paramsFile;
+
+       private List nestedParams;
+
+       private boolean deferExceptions = false;
+
+       public boolean isDeferExceptions() {
+               return deferExceptions;
+       }
+
+       public void setDeferExceptions(boolean deferExceptions) {
+               this.deferExceptions = deferExceptions;
+       }
+
+       /**
+        * @return Returns the file.
+        */
+       public String getFile() {
+               return file;
+       }
+
+       /**
+        * @param file
+        *            The file to set.
+        */
+       public void setFile(String file) {
+               this.file = file;
+       }
+
+       public String getParams() {
+               return paramsFile;
+       }
+
+       public void setParams(String paramsFile) {
+               this.paramsFile = paramsFile;
+       }
+
+       public Param createParam() {
+               Param p = new Param();
+               if (nestedParams == null) {
+                       nestedParams = new ArrayList();
+               }
+               nestedParams.add(p);
+               return p;
+       }
+
+       /**
+        * execute the task
+        * 
+        * @throws BuildException
+        */
+       public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
+               if (file == null) {
+                       throw new BuildException("null file - file should be an 
archive");
+               }
+               if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
+                       throw new BuildException("file: " + file + " is not an 
archive");
+               }
+               File archive = new File(file);
+               String location = archive.getAbsolutePath();
+               if (!archive.isFile()) {
+                       // if it's not a file, assume it's a url and pass it 
along
+                       location = file;
+               }
+               Properties props = getProperties();
+               acs.installComponent(location, props, deferExceptions);
+       }
+
+       private Properties getProperties() throws IOException {
+               Properties props = new Properties();
+               if (paramsFile != null) {
+                       props.load(new FileInputStream(paramsFile));
+               }
+               if (nestedParams != null) {
+                       for (Iterator iter = nestedParams.iterator(); 
iter.hasNext();) {
+                               Param p = (Param) iter.next();
+                               props.setProperty(p.getName(), p.getValue());
+                       }
+               }
+               return props;
+       }
+
+       public static class Param {
+               private String name;
+
+               private String value;
+
+               public String getName() {
+                       return name;
+               }
+
+               public void setName(String name) {
+                       this.name = name;
+               }
+
+               public String getValue() {
+                       return value;
+               }
+
+               public void setValue(String value) {
+                       this.value = value;
+               }
+       }
+
 }

Modified: 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java?view=diff&rev=454773&r1=454772&r2=454773
==============================================================================
--- 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java
 (original)
+++ 
incubator/servicemix/branches/servicemix-3.0/servicemix-core/src/main/java/org/apache/servicemix/jbi/management/task/InstallSharedLibraryTask.java
 Tue Oct 10 08:08:40 2006
@@ -23,43 +23,57 @@
 
 /**
  * Install a shared library
+ * 
  * @version $Revision: 359151 $
  */
 public class InstallSharedLibraryTask extends JbiTask {
-    
-    private String file; //shared library URI to install
-    
-    /**
-     * @return Returns the file.
-     */
-    public String getFile() {
-        return file;
-    }
-    /**
-     * @param file The shared library URI to set.
-     */
-    public void setFile(String file) {
-        this.file = file;
-    }
-    
-    /**
-     * execute the task
-     * @throws BuildException
-     */
-    public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
-        if (file == null){
-            throw new BuildException("null file - file should be an archive");
-        }
-        if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
-            throw new BuildException("file: " + file + " is not an archive");
-        }
-        File archive = new File(file);
-        String location = archive.getAbsolutePath();
-        if (!archive.isFile()) {
-            // if it's not a file, assume it's a url and pass it along
-            location = file;
-        }
-        acs.installSharedLibrary(location);
-    }
-    
+
+       private String file; // shared library URI to install
+
+       private boolean deferExceptions = false;
+
+       public boolean isDeferExceptions() {
+               return deferExceptions;
+       }
+
+       public void setDeferExceptions(boolean deferExceptions) {
+               this.deferExceptions = deferExceptions;
+       }
+
+       /**
+        * @return Returns the file.
+        */
+       public String getFile() {
+               return file;
+       }
+
+       /**
+        * @param file
+        *            The shared library URI to set.
+        */
+       public void setFile(String file) {
+               this.file = file;
+       }
+
+       /**
+        * execute the task
+        * 
+        * @throws BuildException
+        */
+       public void doExecute(AdminCommandsServiceMBean acs) throws Exception {
+               if (file == null) {
+                       throw new BuildException("null file - file should be an 
archive");
+               }
+               if (!file.endsWith(".zip") && !file.endsWith(".jar")) {
+                       throw new BuildException("file: " + file + " is not an 
archive");
+               }
+               File archive = new File(file);
+               String location = archive.getAbsolutePath();
+               if (!archive.isFile()) {
+                       // if it's not a file, assume it's a url and pass it 
along
+                       location = file;
+               }
+               acs.installSharedLibrary(location, deferExceptions);
+       }
+
 }


Reply via email to