Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/799#discussion_r135829210
--- 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 --
there are a couple places this applies. how's this:
```
try {
rollbackBundle();
} catch (Throwable t) {
Exceptions.propagateIfFatal(t);
log.warn("Error rolling back
"+result.getVersionedName()+" after bundle start problem; server may be in
inconsistent state (swallowing this error and propagating installation error):
"+Exceptions.collapseText(t), t);
throw Exceptions.propagate(new
BundleException("Failure installing and rolling back; server may be in
inconsistent state regarding bundle "+result.getVersionedName()+". "
+ "Rollback failure
("+Exceptions.collapseText(t)+") detailed in log. Installation error is:
"+Exceptions.collapseText(e), e));
}
```
---
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.
---