Repository: brooklyn-server
Updated Branches:
  refs/heads/master 27feabcc9 -> f3aa339fd


uninstall removes catalog items


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/f76118ce
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f76118ce
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f76118ce

Branch: refs/heads/master
Commit: f76118cec3d7f8a1a2788d16dc7268843cb073b7
Parents: 8a4886f
Author: Alex Heneveld <[email protected]>
Authored: Wed May 3 17:06:53 2017 +0100
Committer: Alex Heneveld <[email protected]>
Committed: Fri May 5 12:43:59 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/api/typereg/RegisteredType.java    |  1 +
 .../CatalogOsgiVersionMoreEntityRebindTest.java | 18 +++----------
 .../brooklyn/core/mgmt/ha/OsgiManager.java      | 28 +++++++++++++-------
 3 files changed, 23 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f76118ce/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java 
b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
index fad3d35..8225187 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/RegisteredType.java
@@ -37,6 +37,7 @@ public interface RegisteredType extends Identifiable {
     
     String getSymbolicName();
     String getVersion();
+    /** Bundle in symbolicname:id format where this type is defined */
     String getContainingBundle();
 
     Collection<OsgiBundleWithUrl> getLibraries();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f76118ce/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
----------------------------------------------------------------------
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
index 16814c0..e47f719 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityRebindTest.java
@@ -242,27 +242,15 @@ public class CatalogOsgiVersionMoreEntityRebindTest 
extends AbstractYamlRebindTe
             Entity app2 = createAndStartApplication(yaml);
             Asserts.shouldHaveFailedPreviously("Expected deployment to fail 
after uninstall; instead got "+app2);
         } catch (Exception e) {
-            // org.apache.brooklyn.util.exceptions.CompoundRuntimeException: 
Unable to instantiate item; 2 errors including: 
-            // Transformer for brooklyn-camp gave an error creating this plan: 
Transformer for catalog gave an error creating this plan: 
-            // Unable to instantiate 
org.apache.brooklyn.test.osgi.entities.more.MoreEntity; 
-            // 2 errors including: Error in definition of 
org.apache.brooklyn.test.osgi.entities.more.MoreEntity:0.12.0-SNAPSHOT: 
-            // Unable to create spec for type 
brooklyn:org.apache.brooklyn.test.osgi.entities.more.MoreEntity. 
-            // The reference 
brooklyn:org.apache.brooklyn.test.osgi.entities.more.MoreEntity looks like a 
URL 
-            // (running the CAMP Brooklyn assembly-template instantiator) but 
-            // the protocol brooklyn isn't white listed ([classpath, http, 
https]). 
-            // It's also neither a catalog item nor a java type.
-            // TODO different error after catalog item uninstalled
-            Asserts.expectedFailureContainsIgnoreCase(e, 
BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY, "not", "registered");
+            Asserts.expectedFailureContainsIgnoreCase(e, "unable to match", 
BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
         }
         
         try {
             StartableApplication app2 = rebind();
             Asserts.shouldHaveFailedPreviously("Expected deployment to fail 
rebind; instead got "+app2);
         } catch (Exception e) {
-            Asserts.expectedFailure(e);
-            // TODO should fail to rebind this app
-            // (currently fails to load the catalog item, since it wasn't 
removed)
-            // Asserts.expectedFailureContainsIgnoreCase(e, 
BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY, "simple-app-yaml");
+            // should fail to rebind this entity
+            Asserts.expectedFailureContainsIgnoreCase(e, more.getId(), "unable 
to load", BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
         }
     }
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f76118ce/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java 
b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
index cdb40f4..17d5645 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/ha/OsgiManager.java
@@ -38,6 +38,7 @@ import 
org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.BrooklynVersion;
@@ -74,6 +75,7 @@ import com.google.common.annotations.Beta;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
@@ -297,6 +299,8 @@ public class OsgiManager {
         }
     }
     
+    
+    
     /**
      * Removes this bundle from Brooklyn management, 
      * removes all catalog items it defined,
@@ -318,15 +322,11 @@ public class OsgiManager {
         }
         
mgmt.getRebindManager().getChangeListener().onUnmanaged(bundleMetadata);
         
-        // TODO uninstall things that come from this bundle
-//        mgmt.getTypeRegistry().getMatching(new Predicate<RegisteredType>() {
-//            @Override
-//            public boolean apply(RegisteredType input) {
-//                XXX;
-//                input.getLibraries();
-//                return false;
-//            }
-//        });
+        // uninstall things that come from this bundle
+        List<RegisteredType> thingsFromHere = 
ImmutableList.copyOf(getTypesFromBundle( bundleMetadata.getVersionedName() ));
+        for (RegisteredType t: thingsFromHere) {
+            mgmt.getCatalog().deleteCatalogItem(t.getSymbolicName(), 
t.getVersion());
+        }
         
         Bundle bundle = 
framework.getBundleContext().getBundle(bundleMetadata.getOsgiUniqueUrl());
         if (bundle==null) {
@@ -339,6 +339,16 @@ public class OsgiManager {
             throw Exceptions.propagate(e);
         }
     }
+
+    protected Iterable<RegisteredType> getTypesFromBundle(final VersionedName 
vn) {
+        final String bundleId = vn.toString();
+        return mgmt.getTypeRegistry().getMatching(new 
Predicate<RegisteredType>() {
+            @Override
+            public boolean apply(RegisteredType input) {
+                return bundleId.equals(input.getContainingBundle());
+            }
+        });
+    }
     
     // TODO DO on snapshot install, uninstall old equivalent snapshots (items 
in use might stay in use though?)
     

Reply via email to