ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1544103 - in /ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent: InstallationFailedException.java impl/DefaultController.java
Date Thu, 21 Nov 2013 10:56:58 GMT
Author: jawi
Date: Thu Nov 21 10:56:58 2013
New Revision: 1544103

URL: http://svn.apache.org/r1544103
Log:
ACE-432 - log deployment problems more accurately:

- added some verbose logging when a deployment fails, as to better
  aid the debugging of potential problems.


Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/InstallationFailedException.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/InstallationFailedException.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/InstallationFailedException.java?rev=1544103&r1=1544102&r2=1544103&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/InstallationFailedException.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/InstallationFailedException.java
Thu Nov 21 10:56:58 2013
@@ -18,25 +18,95 @@
  */
 package org.apache.ace.agent;
 
+import org.apache.ace.agent.impl.DeploymentHandlerImpl;
+import org.osgi.service.deploymentadmin.DeploymentException;
+
 /**
  * Generic exception that is thrown when an installation of an update failed.
  * 
- * @see UpdateHandler#install(java.io.InputStream)
+ * @see DeploymentHandlerImpl#install(java.io.InputStream)
  */
 public class InstallationFailedException extends Exception {
+
+    /* DeploymentException codes duplicated for ease of use. */
+
+    public static final int CODE_CANCELLED = 401;
+    public static final int CODE_NOT_A_JAR = 404;
+    public static final int CODE_ORDER_ERROR = 450;
+    public static final int CODE_MISSING_HEADER = 451;
+    public static final int CODE_BAD_HEADER = 452;
+    public static final int CODE_MISSING_FIXPACK_TARGET = 453;
+    public static final int CODE_MISSING_BUNDLE = 454;
+    public static final int CODE_MISSING_RESOURCE = 455;
+    public static final int CODE_SIGNING_ERROR = 456;
+    public static final int CODE_BUNDLE_NAME_ERROR = 457;
+    public static final int CODE_FOREIGN_CUSTOMIZER = 458;
+    public static final int CODE_BUNDLE_SHARING_VIOLATION = 460;
+    public static final int CODE_RESOURCE_SHARING_VIOLATION = 461;
+    public static final int CODE_COMMIT_ERROR = 462;
+    public static final int CODE_OTHER_ERROR = 463;
+    public static final int CODE_PROCESSOR_NOT_FOUND = 464;
+    public static final int CODE_TIMEOUT = 465;
+
     private static final long serialVersionUID = 1L;
 
+    private final int m_code;
+
     /**
      * Creates a new {@link InstallationFailedException} instance.
      */
-    public InstallationFailedException(String msg) {
-        super(msg);
+    public InstallationFailedException(String msg, DeploymentException cause) {
+        super(msg, cause.getCause());
+        m_code = cause.getCode();
     }
 
     /**
-     * Creates a new {@link InstallationFailedException} instance.
+     * @return the code of the originating deployment exception, see the <tt>CODE_*</tt>
constants for more information.
+     */
+    public int getCode() {
+        return m_code;
+    }
+
+    /**
+     * @return a string representation as to why the installation failed, never <code>null</code>.
      */
-    public InstallationFailedException(String msg, Throwable cause) {
-        super(msg, cause);
+    public String getReason() {
+        switch (m_code) {
+            case CODE_BAD_HEADER:
+                return "Syntax error in any manifest header";
+            case CODE_BUNDLE_NAME_ERROR:
+                return "Bundle symbolic name is not the same as defined by the deployment
package manifest";
+            case CODE_BUNDLE_SHARING_VIOLATION:
+                return "Bundle with the same symbolic name already exists";
+            case CODE_CANCELLED:
+                return "Installation was cancelled";
+            case CODE_COMMIT_ERROR:
+                return "A Resource Processors involved in the deployment session threw an
exception with the CODE_PREPARE error code";
+            case CODE_FOREIGN_CUSTOMIZER:
+                return "Matched resource processor service is a customizer from another deployment
package";
+            case CODE_MISSING_BUNDLE:
+                return "A bundle in the deployment package is marked as DeploymentPackage-Missing
but there is no such bundle in the target deployment package";
+            case CODE_MISSING_FIXPACK_TARGET:
+                return "Fix pack version range doesn't fit to the version of the target deployment
package or the target deployment package of the fix pack doesn't exist";
+            case CODE_MISSING_HEADER:
+                return "Missing mandatory manifest header";
+            case CODE_MISSING_RESOURCE:
+                return "A resource in the source deployment package is marked as DeploymentPackage-Missing
but there is no such resource in the target deployment package";
+            case CODE_NOT_A_JAR:
+                return "The InputStream is not a jar";
+            case CODE_ORDER_ERROR:
+                return "Order of files in the deployment package is bad";
+            case CODE_PROCESSOR_NOT_FOUND:
+                return "The Resource Processor service with the given PID is not found";
+            case CODE_RESOURCE_SHARING_VIOLATION:
+                return "An artifact of any resource already exists";
+            case CODE_SIGNING_ERROR:
+                return "Bad deployment package signing";
+            case CODE_TIMEOUT:
+                return "Installation of deployment package timed out";
+            case CODE_OTHER_ERROR:
+            default:
+                return "Unknown/other error condition";
+        }
     }
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java?rev=1544103&r1=1544102&r2=1544103&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java Thu
Nov 21 10:56:58 2013
@@ -124,7 +124,7 @@ public class DefaultController extends C
 
                             delegate.install(downloadResult.getInputStream());
 
-                            endInstallation(updateInfo, true /* success */, null);
+                            installationSuccess(updateInfo);
 
                             clearDownloadState();
                         }
@@ -148,8 +148,11 @@ public class DefaultController extends C
                         if (cause instanceof RetryAfterException) {
                             throw (RetryAfterException) cause;
                         }
-                        else if (cause instanceof Exception) {
-                            throw (Exception) cause;
+                        else if (cause instanceof InstallationFailedException) {
+                            throw (InstallationFailedException) cause;
+                        }
+                        else if (cause instanceof IOException) {
+                            throw (IOException) cause;
                         }
                         else {
                             throw new RuntimeException("Failed to handle cause!", cause);
@@ -160,9 +163,13 @@ public class DefaultController extends C
                     // Does not cause the installation to end...
                     throw ex;
                 }
-                catch (Exception ex) {
+                catch (InstallationFailedException ex) {
+                    // All other exceptions cause the installation to end/fail...
+                    installationFailed(updateInfo, ex);
+                }
+                catch (IOException ex) {
                     // All other exceptions cause the installation to end/fail...
-                    endInstallation(updateInfo, false /* success */, ex);
+                    installationFailed(updateInfo, ex);
                 }
             }
         }
@@ -219,14 +226,17 @@ public class DefaultController extends C
 
                 delegate.install(inputStream);
 
-                endInstallation(updateInfo, true /* success */, null);
+                installationSuccess(updateInfo);
             }
             catch (RetryAfterException ex) {
                 // We aren't ready yet...
                 throw ex;
             }
-            catch (Exception ex) {
-                endInstallation(updateInfo, false /* success */, ex);
+            catch (InstallationFailedException ex) {
+                installationFailed(updateInfo, ex);
+            }
+            catch (IOException ex) {
+                installationFailed(updateInfo, ex);
             }
             finally {
                 closeSilently(inputStream);
@@ -337,21 +347,44 @@ public class DefaultController extends C
          * Should be called to notify that an installation is ended, successfully or unsuccessfully.
          * 
          * @param updateInfo
+         *            the information about the update.
+         */
+        protected final void installationSuccess(UpdateInfo updateInfo) {
+            m_lastVersionSuccessful = true;
+            m_failureCount = 0;
+            m_controller.sendDeploymentCompletedEvent(updateInfo, true /* success */);
+        }
+
+        /**
+         * Should be called to notify that an installation is ended, successfully or unsuccessfully.
+         * 
+         * @param updateInfo
          *            the information about the update;
-         * @param success
-         *            <code>true</code> if the installation was successful, <code>false</code>
otherwise;
          * @param cause
          *            the (optional) cause why the installation failed.
          */
-        protected final void endInstallation(UpdateInfo updateInfo, boolean success, Exception
cause) throws RetryAfterException {
-            m_lastVersionSuccessful = success;
-            if (cause instanceof InstallationFailedException || cause instanceof IOException)
{
-                m_failureCount++;
-            }
-            else {
-                m_failureCount = 0;
-            }
-            m_controller.sendDeploymentCompletedEvent(updateInfo, success);
+        protected final void installationFailed(UpdateInfo updateInfo, InstallationFailedException
cause) {
+            getController().logWarning("Installation of deployment package failed: %s!",
cause, cause.getReason());
+
+            m_lastVersionSuccessful = false;
+            m_failureCount++;
+            m_controller.sendDeploymentCompletedEvent(updateInfo, false /* success */);
+        }
+
+        /**
+         * Should be called to notify that an installation is ended, successfully or unsuccessfully.
+         * 
+         * @param updateInfo
+         *            the information about the update;
+         * @param cause
+         *            the (optional) cause why the installation failed.
+         */
+        protected final void installationFailed(UpdateInfo updateInfo, IOException cause)
{
+            getController().logWarning("Installation of deployment package failed: generic
I/O exception.", cause);
+
+            m_lastVersionSuccessful = false;
+            m_failureCount++;
+            m_controller.sendDeploymentCompletedEvent(updateInfo, false /* success */);
         }
 
         protected final DefaultController getController() {
@@ -477,7 +510,7 @@ public class DefaultController extends C
             }
 
             logDebug("Config changed: disabled: %s, update: %s, fixPkg: %s, syncDelay: %d,
syncInterval: %d, maxRetries: %d", m_disabled.get(), m_updateStreaming.get(), m_fixPackage.get(),
m_syncDelay.get(), m_interval.get(), m_maxRetries.get());
-            
+
             scheduleRunAfterDelay();
         }
     }
@@ -488,15 +521,15 @@ public class DefaultController extends C
         long interval = m_interval.get();
 
         if (disabled) {
-        	logDebug("Controller disabled by configuration. Skipping...");
-        	return;
+            logDebug("Controller disabled by configuration. Skipping...");
+            return;
         }
         try {
-        	logDebug("Controller syncing...");
-        	runFeedback();
-        	runAgentUpdate();
-        	runDeploymentUpdate();
-        	logDebug("Sync completed. Rescheduled in %d seconds", interval);
+            logDebug("Controller syncing...");
+            runFeedback();
+            runAgentUpdate();
+            runDeploymentUpdate();
+            logDebug("Sync completed. Rescheduled in %d seconds", interval);
         }
         catch (RetryAfterException e) {
             // any method may throw this causing the sync to abort. The server is busy so
no sense in trying
@@ -529,13 +562,13 @@ public class DefaultController extends C
 
         unscheduleRun();
     }
-    
+
     protected void scheduleRunAfterDelay() {
         long delay = m_syncDelay.get();
 
         scheduleRun(delay);
 
-        logDebug("Controller scheduled to run in %d seconds", delay);        
+        logDebug("Controller scheduled to run in %d seconds", delay);
     }
 
     protected void scheduleRun(long seconds) {
@@ -627,12 +660,12 @@ public class DefaultController extends C
         boolean fixPackage = m_fixPackage.get();
 
         UpdateInstaller updateInstaller = getUpdateInstaller();
-    	try {
-    		updateInstaller.installUpdate(getAgentUpdateHandler(), fixPackage, maxRetries);
-    	}
-    	catch (IOException e) {
+        try {
+            updateInstaller.installUpdate(getAgentUpdateHandler(), fixPackage, maxRetries);
+        }
+        catch (IOException e) {
             logError("Agent update aborted due to Exception.", e);
-    	}
+        }
     }
 
     private void runDeploymentUpdate() throws RetryAfterException {
@@ -642,12 +675,12 @@ public class DefaultController extends C
         boolean fixPackage = m_fixPackage.get();
 
         UpdateInstaller updateInstaller = getUpdateInstaller();
-    	try {
-    		updateInstaller.installUpdate(getDeploymentHandler(), fixPackage, maxRetries);
-    	}
-    	catch (IOException e) {
+        try {
+            updateInstaller.installUpdate(getDeploymentHandler(), fixPackage, maxRetries);
+        }
+        catch (IOException e) {
             logError("Deployment update aborted due to Exception.", e);
-    	}
+        }
     }
 
     private void runFeedback() throws RetryAfterException {



Mime
View raw message