Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/799#discussion_r135829424
--- Diff:
core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java ---
@@ -135,14 +141,76 @@ synchronized void setManagedBundleUrl(String url,
String id) {
managedBundlesUidByUrl.put(url, id);
}
- synchronized void addManagedBundle(OsgiBundleInstallationResult
result) {
+ synchronized void addManagedBundle(OsgiBundleInstallationResult
result, File f) {
+ updateManagedBundleFile(result, f);
managedBundlesByUid.put(result.getMetadata().getId(),
result.getMetadata());
managedBundlesUidByVersionedName.put(VersionedName.toOsgiVersionedName(result.getMetadata().getVersionedName()),
result.getMetadata().getId());
if (Strings.isNonBlank(result.getMetadata().getUrl())) {
managedBundlesUidByUrl.put(result.getMetadata().getUrl(),
result.getMetadata().getId());
}
}
+
+ private File fileFor(ManagedBundle managedBundle) {
+ return new File(brooklynBundlesCacheDir,
managedBundle.getId()+"-"+managedBundle.getVersionedName().toOsgiString()+".jar");
+ }
+
+ synchronized void addInstalledWrapperBundle(ManagedBundle mb) {
+ wrapperBundles.put(mb.getVersionedName(), mb);
+ }
+ private synchronized void
removeInstalledWrapperBundle(ManagedBundle mb) {
+ wrapperBundles.remove(mb.getVersionedName());
+ }
+
+ synchronized boolean remove(ManagedBundle bundleMetadata) {
+ ManagedBundle metadata =
managedBundlesRecord.managedBundlesByUid.remove(bundleMetadata.getId());
+ if (metadata==null) {
+ return false;
+ }
+
managedBundlesRecord.managedBundlesUidByVersionedName.remove(bundleMetadata.getVersionedName());
+
managedBundlesRecord.managedBundlesUidByUrl.remove(bundleMetadata.getUrl());
+ removeInstalledWrapperBundle(bundleMetadata);
+ fileFor(bundleMetadata).delete();
+ return true;
+ }
+
+ /** Updates the bundle file associated with the given record,
creating and returning a backup if there was already such a file */
+ synchronized File
updateManagedBundleFile(OsgiBundleInstallationResult result, File fNew) {
+ File fCached = fileFor(result.getMetadata());
+ File fBak = new File(fCached.getAbsolutePath()+".bak");
+ if (fBak.equals(fNew)) {
+ // rolling back
+ throw new IllegalStateException("Cannot update to a backup
copy; use rollback instead");
+ }
+ if (fCached.exists()) {
+ log.debug("Replacing and backing up old Brooklyn local
copy of bundle file "+fCached);
+ fCached.renameTo(fBak);
+ } else {
+ log.debug("Creating Brooklyn local copy of bundle file
"+fCached);
+ }
+ try (FileInputStream fin = new FileInputStream(fNew);
FileOutputStream fout = new FileOutputStream(fCached)) {
+ Streams.copy(fin, fout);
--- End diff --
it is a different cache dir so should be fine to do it like this?
---
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.
---