Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/799#discussion_r135778715
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiArchiveInstaller.java 
---
    @@ -379,26 +388,89 @@ private synchronized void close() {
                 // eg rebind code, brooklyn.libraries list -- deferred start 
allows caller to
                 // determine whether not to start or to start all after things 
are installed
                 Runnable startRunnable = new Runnable() {
    +                private void rollbackBundle() {
    +                    if (updating) {
    +                        if (oldZipFile==null) {
    +                            throw new IllegalStateException("Did not have 
old ZIP file to install");
    +                        }
    +                        log.debug("Rolling back bundle 
"+result.getVersionedName()+" to state from "+oldZipFile);
    +                        try {
    +                            File zipFileNow = 
osgiManager.managedBundlesRecord.rollbackManagedBundleFile(result, oldZipFile);
    +                            result.bundle.update(new 
FileInputStream(Preconditions.checkNotNull(zipFileNow, "Couldn't find contents 
of old version of bundle")));
    +                        } catch (Exception e) {
    +                            Exceptions.propagateIfFatal(e);
    +                            log.error("Error rolling back following failed 
install of updated "+result.getVersionedName()+"; "
    +                                + "installation will likely be corrupted 
and correct version should be manually installed.", e);
    +                        }
    +                        
    +                        
((BasicManagedBundle)result.getMetadata()).setPersistenceNeeded(true);
    +                        
mgmt().getRebindManager().getChangeListener().onChanged(result.getMetadata());
    +                    } else {
    +                        log.debug("Uninstalling bundle 
"+result.getVersionedName()+" (roll back of failed fresh install, no previous 
version to revert to)");
    +                        
osgiManager.uninstallUploadedBundle(result.getMetadata());
    +                        
    +                        
((BasicManagedBundle)result.getMetadata()).setPersistenceNeeded(true);
    +                        
mgmt().getRebindManager().getChangeListener().onUnmanaged(result.getMetadata());
    +                    }
    +                }
                     public void run() {
                         if (start) {
                             try {
                                 log.debug("Starting bundle 
"+result.getVersionedName());
                                 result.bundle.start();
                             } catch (BundleException e) {
    +                            log.warn("Error starting bundle 
"+result.getVersionedName()+", uninstalling, restoring any old bundle, then 
re-throwing error: "+e);
    +                            rollbackBundle();
    --- End diff --
    
    If `rollbackBundle` throws an exception (e.g. if `oldZipFile==null`) then 
we'll lose the stacktrace and "caused by" of the original `BundleException`. We 
should probably wrap the rollback in a try-catch, doing a log.warn (including 
stacktrace), then wrap the `BundleException` with a message that includes 
details of the rollback problem, and propagate that `BundleException`.
    
    Thoughts?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to