brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/10] brooklyn-server git commit: store catalog upgrades, and use when resolving persistence records
Date Tue, 07 Nov 2017 12:09:11 GMT
store catalog upgrades, and use when resolving persistence records

catalog upgrades now stored in TypeRegistry, with conveniences for finding upgrades

markers and comments for shifting to a "load registered type" semantics instead of "load java
type"

still todo is use this when we come to deploy - as per other tests


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

Branch: refs/heads/master
Commit: 8b470ae58e27d49d228b54613f8d8faca5d5d729
Parents: a3673e4
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Wed Nov 1 11:31:42 2017 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Nov 1 11:31:42 2017 +0000

----------------------------------------------------------------------
 .../brooklyn/core/mgmt/ha/OsgiManager.java      |  2 +
 .../rebind/BasicCatalogItemRebindSupport.java   | 10 +-
 .../core/mgmt/rebind/RebindIteration.java       | 44 ++++++++-
 .../core/typereg/BasicBrooklynTypeRegistry.java | 14 ++-
 .../core/typereg/BundleUpgradeParser.java       | 96 ++++++++++++++++++--
 .../core/typereg/BundleUpgradeParserTest.java   | 12 +++
 .../BrooklynLauncherRebindCatalogOsgiTest.java  | 39 +++++---
 7 files changed, 194 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/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 af23f1d..34b974a 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
@@ -49,6 +49,7 @@ import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult.ResultCode;
 import org.apache.brooklyn.core.server.BrooklynServerConfig;
 import org.apache.brooklyn.core.server.BrooklynServerPaths;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
@@ -453,6 +454,7 @@ public class OsgiManager {
                 log.warn("Error uninstalling catalog items of "+bundleMetadata+": "+e);
                 errors.add(e);
             }
+            CatalogUpgrades.clearBundleInStoredUpgrades(mgmt, bundleMetadata.getVersionedName());
             
             if (!managedBundlesRecord.remove(bundleMetadata)) {
                 Exception e = new IllegalStateException("No such bundle registered with Brooklyn
when uninstalling: "+bundleMetadata);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicCatalogItemRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicCatalogItemRebindSupport.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicCatalogItemRebindSupport.java
index 8cea7b2..aa76d26 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicCatalogItemRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicCatalogItemRebindSupport.java
@@ -18,11 +18,15 @@
  */
 package org.apache.brooklyn.core.mgmt.rebind;
 
+import java.util.Set;
+
 import org.apache.brooklyn.api.mgmt.rebind.RebindContext;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
 import org.apache.brooklyn.core.catalog.internal.CatalogItemDtoAbstract;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.flags.FlagUtils;
+import org.apache.brooklyn.util.osgi.VersionedName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +47,7 @@ public class BasicCatalogItemRebindSupport extends AbstractBrooklynObjectRebindS
         super.reconstruct(rebindContext, memento);
         FlagUtils.setFieldsFromFlags(MutableMap.builder()
                 .put("symbolicName", memento.getSymbolicName())
-                .put("containingBundle", memento.getContainingBundle())
+                .put("containingBundle", possiblyUpgradedBundle(memento.getContainingBundle()))
                 .put("javaType", memento.getJavaType())
                 .put("displayName", memento.getDisplayName())
                 .put("description", memento.getDescription())
@@ -57,6 +61,10 @@ public class BasicCatalogItemRebindSupport extends AbstractBrooklynObjectRebindS
                 .build(), instance);
     }
 
+    protected String possiblyUpgradedBundle(String bundle) {
+        return CatalogUpgrades.getBundleUpgradedIfNecessary(instance.getManagementContext(),
bundle);
+    }
+
     @Override
     protected void addConfig(RebindContext rebindContext, CatalogItemMemento memento) {
         // no-op

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 4751341..fa2b60a 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -101,6 +101,7 @@ import org.apache.brooklyn.core.objs.proxy.InternalLocationFactory;
 import org.apache.brooklyn.core.objs.proxy.InternalPolicyFactory;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
 import org.apache.brooklyn.core.typereg.BasicManagedBundle;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
 import org.apache.brooklyn.core.typereg.RegisteredTypeNaming;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
@@ -131,7 +132,7 @@ Multi-phase deserialization:
 <li> 1. load the manifest files and populate the summaries (ID+type) in {@link BrooklynMementoManifest}
 <li> 2. install bundles, instantiate and reconstruct catalog items
 <li> 3. instantiate entities+locations -- so that inter-entity references can subsequently

-       be set during deserialize (and entity config/state is set).
+           be set during deserialize (and entity config/state is set).
 <li> 4. deserialize the manifests to instantiate the mementos
 <li> 5. instantiate policies+enrichers+feeds 
         (could probably merge this with (3), depending how they are implemented)
@@ -978,16 +979,33 @@ public abstract class RebindIteration {
                 String catalogItemId, List<String> searchPath, String contextSuchAsId)
{
             checkNotNull(jType, "Type of %s (%s) must not be null", contextSuchAsId, bType.getSimpleName());
 
+            CatalogUpgrades.markerForCodeThatLoadsJavaTypesButShouldLoadRegisteredType();
+            
             List<String> warnings = MutableList.of();
             List<String> reboundSearchPath = MutableList.of();
             if (searchPath != null && !searchPath.isEmpty()) {
                 for (String searchItemId : searchPath) {
                     String fixedSearchItemId = null;
                     RegisteredType t1 = managementContext.getTypeRegistry().get(searchItemId);
+                    if (t1==null) {
+                        String newSearchItemId = CatalogUpgrades.getTypeUpgradedIfNecessary(managementContext,
searchItemId);
+                        if (!newSearchItemId.equals(searchItemId)) {
+                            // TODO make debug
+                            logRebindingInfo("Upgrading search path entry of "+bType.getSimpleName().toLowerCase()+"
"+contextSuchAsId+" from "+searchItemId+" to "+newSearchItemId);
+                            searchItemId = newSearchItemId;
+                            t1 = managementContext.getTypeRegistry().get(newSearchItemId);
+                        }
+                    }
                     if (t1!=null) fixedSearchItemId = t1.getId();
                     if (fixedSearchItemId==null) {
                         CatalogItem<?, ?> ci = findCatalogItemInReboundCatalog(bType,
searchItemId, contextSuchAsId);
-                        if (ci!=null) fixedSearchItemId = ci.getCatalogItemId();
+                        if (ci!=null) {
+                            fixedSearchItemId = ci.getCatalogItemId();
+                            logRebindingWarn("Needed rebind catalog to resolve search path
entry "+searchItemId+" (now "+fixedSearchItemId+") for "+bType.getSimpleName().toLowerCase()+"
"+contextSuchAsId+
+                                ", persistence should remove this in future but future versions
will not support this and definitions should be fixed");
+                        } else {
+                            logRebindingWarn("Could not find search path entry "+searchItemId+"
for "+bType.getSimpleName().toLowerCase()+" "+contextSuchAsId+", ignoring");
+                        }
                     }
                     if (fixedSearchItemId != null) {
                         reboundSearchPath.add(fixedSearchItemId);
@@ -1003,6 +1021,19 @@ public abstract class RebindIteration {
                 Maybe<RegisteredType> registeredType = managementContext.getTypeRegistry().getMaybe(catalogItemId,
                     // ignore bType; catalog item ID gives us the search path, but doesn't
need to be of the requested type
                     null );
+                if (registeredType.isAbsent()) {
+                    transformedCatalogItemId = CatalogUpgrades.getTypeUpgradedIfNecessary(managementContext,
catalogItemId);
+                    if (!transformedCatalogItemId.equals(catalogItemId)) {
+                        logRebindingInfo("Upgrading catalog item ID of "+bType.getSimpleName().toLowerCase()+"
"+contextSuchAsId+" from "+catalogItemId+" to "+transformedCatalogItemId);
+                        
+                        // as above
+                        registeredType = managementContext.getTypeRegistry().getMaybe(transformedCatalogItemId,
null);
+                        
+                    } else {
+                        transformedCatalogItemId = null;
+                    }
+                }
+                
                 if (registeredType.isPresent()) {
                     transformedCatalogItemId = registeredType.get().getId();
                 } else {
@@ -1308,6 +1339,15 @@ public abstract class RebindIteration {
         }
     }
     
+    /** logs at warn, except during subsequent read-only rebinds, in which it logs trace
*/
+    protected void logRebindingWarn(String message, Object... args) {
+        if (shouldLogRebinding()) {
+            LOG.warn(message, args);
+        } else {
+            LOG.trace(message, args);
+        }
+    }
+    
     protected boolean shouldLogRebinding() {
         return (readOnlyRebindCount.get() < 5) || (readOnlyRebindCount.get()%1000==0);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index dba91fc..c3f2824 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -582,7 +582,13 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
     @Beta // API stabilising
     public void delete(VersionedName type) {
         boolean changedLocally = Locks.withLock(localRegistryLock.writeLock(),
-            () -> (localRegisteredTypesAndContainingBundles.remove(type.toString()) !=
null));
+            () -> {
+                boolean changed = (localRegisteredTypesAndContainingBundles.remove(type.toString())
!= null);
+                if (changed) {
+                    CatalogUpgrades.clearTypeInStoredUpgrades(mgmt, type);
+                }
+                return changed;
+            });
         if (changedLocally) {
             return;
         }
@@ -612,6 +618,7 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
                 RegisteredType removedItem = m.remove(type.getContainingBundle());
                 if (m.isEmpty()) {
                     localRegisteredTypesAndContainingBundles.remove(type.getId());
+                    CatalogUpgrades.clearTypeInStoredUpgrades(mgmt, type.getVersionedName());
                 }
                 if (removedItem==null) {
                     throw new NoSuchElementException("Requested to delete "+type+" from "+type.getContainingBundle()+",
"
@@ -634,7 +641,10 @@ public class BasicBrooklynTypeRegistry implements BrooklynTypeRegistry
{
 
     /** Deletes all items, for use when resetting management context */
     public void clear() {
-        Locks.withLock(localRegistryLock.writeLock(), () -> localRegisteredTypesAndContainingBundles.clear());
+        Locks.withLock(localRegistryLock.writeLock(), () -> {
+            localRegisteredTypesAndContainingBundles.clear();
+            catalogUpgrades = null;
+        });
     }
 
     

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index a88ab1f..58d1dec 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 import javax.annotation.Nonnull;
@@ -34,15 +35,20 @@ import javax.annotation.Nonnull;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.osgi.VersionedName;
+import org.apache.brooklyn.util.osgi.VersionedName.VersionedNameComparator;
 import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.apache.brooklyn.util.text.QuotedStringTokenizer;
 import org.apache.brooklyn.util.text.Strings;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.VersionRange;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
@@ -60,6 +66,8 @@ import com.google.common.collect.Multimap;
  */
 public class BundleUpgradeParser {
 
+    private static final Logger log = LoggerFactory.getLogger(BundleUpgradeParser.class);
+    
     /**
      * A header in a bundle's manifest, indicating that this bundle will force the removal
of the 
      * given legacy catalog items. Here "legacy" means those in the `/catalog` persisted
state, 
@@ -183,8 +191,11 @@ public class BundleUpgradeParser {
      * It is an error to omit a version/range if that header is not present or does not declare
versions
      * of the same bundle being upgraded.  
      * 
-     * If this key is omitted, then the default is {@code *} if a {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES}
header
-     * is present and empty if that header is not present.
+     * If this key is omitted but a {@link #MANIFEST_HEADER_UPGRADE_FOR_BUNDLES} header is
present defining 
+     * versions of the containing bundle that are upgraded, then the default is {@code *}
to give the common semantics
+     * when a bundle is upgrading previous versions that types similarly upgrade.  If that
header is absent or
+     * this bundle is an upgrade for other bundles but not this bundle, then this key must
be specified if
+     * any types are intended to be upgraded.
      * 
      * What this is saying in most cases is that if a bundle {@code foo:1} contains {@code
foo-node:1}, and 
      * bundle {@code foo:2} contains {@code foo-node:2}, then:
@@ -238,6 +249,15 @@ public class BundleUpgradeParser {
             public CatalogUpgrades build() {
                 return new CatalogUpgrades(this);
             }
+            
+            public Builder clearUpgradesProvidedByType(VersionedName versionedName) {
+                upgradesProvidedByTypes.removeAll(versionedName);
+                return this;
+            }
+            public Builder clearUpgradesProvidedByBundle(VersionedName versionedName) {
+                upgradesProvidedByBundles.removeAll(versionedName);
+                return this;
+            }
         }
         
         public static Builder builder() {
@@ -291,10 +311,10 @@ public class BundleUpgradeParser {
         public Set<VersionedName> getUpgradesForType(VersionedName type) {
             return findUpgradesIn(type, upgradesProvidedByTypes);
         }
-        private static Set<VersionedName> findUpgradesIn(VersionedName bundle, Multimap<VersionedName,VersionRangedName>
upgradesMap) {
-            Set<VersionedName> result = MutableSet.of();
+        private static Set<VersionedName> findUpgradesIn(VersionedName item, Multimap<VersionedName,VersionRangedName>
upgradesMap) {
+            Set<VersionedName> result = new TreeSet<>(VersionedNameComparator.INSTANCE);
             for (Map.Entry<VersionedName,VersionRangedName> n: upgradesMap.entries())
{
-                if (contains(n.getValue(), bundle)) {
+                if (contains(n.getValue(), item)) {
                     result.add(n.getKey());
                 }
             }
@@ -329,6 +349,67 @@ public class BundleUpgradeParser {
             }
             return builder().build();
         }
+
+        @Beta
+        public static String getBundleUpgradedIfNecessary(ManagementContext mgmt, String
vName) {
+            if (vName==null) return null;
+            Maybe<OsgiManager> osgi = ((ManagementContextInternal)mgmt).getOsgiManager();
+            if (osgi.isAbsent()) {
+                // ignore upgrades if not osgi
+                return vName;
+            }
+            if (osgi.get().getManagedBundle(VersionedName.fromString(vName))!=null) {
+                // bundle installed, prefer that to upgrade 
+                return vName;
+            }
+            return getItemUpgradedIfNecessary(mgmt, vName, (cu,vn) -> cu.getUpgradesForBundle(vn));
+        }
+        @Beta
+        public static String getTypeUpgradedIfNecessary(ManagementContext mgmt, String vName)
{
+            if (vName==null || mgmt.getTypeRegistry().get(vName)!=null) {
+                // item found (or n/a), prefer that to upgrade
+                return vName;
+            }
+            return getItemUpgradedIfNecessary(mgmt, vName, (cu,vn) -> cu.getUpgradesForType(vn));
+        }
+        
+        private interface LookupFunction {
+            public Set<VersionedName> lookup(CatalogUpgrades cu, VersionedName vn);
+        }
+        private static String getItemUpgradedIfNecessary(ManagementContext mgmt, String vName,
LookupFunction lookupF) {
+            Set<VersionedName> r = lookupF.lookup(getFromManagementContext(mgmt), VersionedName.fromString(vName));
+            if (!r.isEmpty()) return r.iterator().next().toString();
+            
+            log.warn("Could not find '"+vName+"' and no upgrades specified; subsequent failure
or warning likely");
+            return vName;
+        }
+        
+        /** This method is used internally to mark places we need to update when we switch
to persisting and loading
+         *  registered type IDs instead of java types, as noted on RebindIteration.load */
+        @Beta
+        public static void markerForCodeThatLoadsJavaTypesButShouldLoadRegisteredType() {}
+        
+        @Beta
+        CatalogUpgrades withTypeCleared(VersionedName versionedName) {
+            return builder().addAll(this).clearUpgradesProvidedByType(versionedName).build();
+        }
+        @Beta
+        CatalogUpgrades withBundleCleared(VersionedName versionedName) {
+            return builder().addAll(this).clearUpgradesProvidedByType(versionedName).build();
+        }
+
+        @Beta
+        public static void clearTypeInStoredUpgrades(ManagementContext mgmt, VersionedName
versionedName) {
+            synchronized (mgmt.getTypeRegistry()) {
+                storeInManagementContext(getFromManagementContext(mgmt).withTypeCleared(versionedName),
mgmt);
+            }
+        }
+        @Beta
+        public static void clearBundleInStoredUpgrades(ManagementContext mgmt, VersionedName
versionedName) {
+            synchronized (mgmt.getTypeRegistry()) {
+                storeInManagementContext(getFromManagementContext(mgmt).withBundleCleared(versionedName),
mgmt);
+            }
+        }
     }
     
     /**
@@ -469,6 +550,9 @@ public class BundleUpgradeParser {
         }
         Set<VersionedName> typeSupplierNames = MutableList.copyOf(typeSupplier.get()).stream().map(
             (t) -> VersionedName.toOsgiVersionedName(t.getVersionedName())).collect(Collectors.toSet());
+        if (input==null && sourceVersions!=null && !sourceVersions.isEmpty())
{
+            input = "*";
+        }
         return parseVersionRangedNameEqualsVersionedNameList(input, false,
             // wildcard means all types, all versions of this bundle this bundle replaces
             getTypeNamesInBundle(typeSupplier), sourceVersions,

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 16f87b7..8803294 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -321,6 +321,18 @@ public class BundleUpgradeParserTest {
     }
     
     @Test
+    public void testParseBundleManifestUpgradesInfersTypes() throws Exception {
+        Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of(
+            new BasicRegisteredType(null, "foo", "2.0", null) ));
+        Bundle bundle = newMockBundle(new VersionedName("bundle", "2.0"), 
+            ImmutableMap.of(BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "*"));
+        CatalogUpgrades ups = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle,
typeSupplier);
+        assertTypeUpgrade(ups, "foo", "1", "foo", "2.0.0");
+        assertTypeUpgrade(ups, "foo", "2", null, null);
+        assertTypeUpgrade(ups, "far", "1", null, null);
+    }
+    
+    @Test
     public void testParseBundleManifestUpgradesValidatesIfNoBundleUpgradeVersion() throws
Exception {
         Supplier<Iterable<RegisteredType>> typeSupplier = Suppliers.ofInstance(ImmutableList.of(
             new BasicRegisteredType(null, "foo", "1.0", null) ));

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/8b470ae5/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
----------------------------------------------------------------------
diff --git a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
index 5809d06..cc089cc 100644
--- a/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
+++ b/launcher/src/test/java/org/apache/brooklyn/launcher/BrooklynLauncherRebindCatalogOsgiTest.java
@@ -703,7 +703,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
             "        type: "+BasicEntity.class.getName());
         VersionedName bundleNameV2 = new VersionedName("org.example.testRebindGetsInitialOsgiCatalog",
"2.0.0");
         Map<String,String> headers = MutableMap.of(
-            BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"
+                BundleUpgradeParser.MANIFEST_HEADER_FORCE_REMOVE_BUNDLES, "*"
                 + (removeSourceJavaBundle ? ","+"'"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL+":"+OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_VERSION+"'"
                     : ""));
         if (upgradeEntity) {
@@ -729,7 +729,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
     }
     
     @Test
-    public void testRebindUpgradeEntity() throws Exception {
+    public void testRebindUpgradeDeployedEntity() throws Exception {
         File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false, true);
         createAndStartApplication(launcherLast.getManagementContext(), 
             "services: [ { type: 'simple-entity:1' } ]");
@@ -740,10 +740,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren()
);
         
         // assert it was updated
-        
-        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
-        // TODO when upgrades work at level of catalog item ID and bundle ID, do below instead
of above
-//        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
+        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
         
         Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), "com.example.brooklyn.test.osgi.entities.SimpleEntityImpl");
         // TODO when registered types are used to create, instead of java type,
@@ -751,8 +748,29 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
 //        Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), BasicEntityImpl.class.getName());
     }
     
+//    @Test
+//    // TODO add to catalog a 'references-simple-entity' which references simple-entity:1
+//    public void testRebindUpgradeReferencedEntityFromCatalogAndDeployment() throws Exception
{
+//        File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(false, true);
+//        createAndStartApplication(launcherLast.getManagementContext(), 
+//            "services: [ { type: references-simple-entity } ]");
+//        
+//        startT2(newLauncherForTests(initialBomFileV2.getAbsolutePath()));
+//        promoteT2IfStandby();
+//        
+//        Entity entity = Iterables.getOnlyElement( Iterables.getOnlyElement(launcherLast.getManagementContext().getApplications()).getChildren()
);
+//        
+//        // assert it was updated
+//        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
+//        
+//        Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), "com.example.brooklyn.test.osgi.entities.SimpleEntityImpl");
+//        // TODO when registered types are used to create, instead of java type,
+//        // upgrade should cause the line below instead of the line above (see RebindIteration.load)
+////        Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), BasicEntityImpl.class.getName());
+//    }
+    
     @Test(groups="WIP")
-    public void testRebindUpgradeSpec() throws Exception {
+    public void testRebindUpgradeSpecInDeployedApp() throws Exception {
         File initialBomFileV2 = prepForRebindRemovedItemTestReturningBomV2(true, true);
         Application app = createAndStartApplication(launcherLast.getManagementContext(),

             Joiner.on("\n").join(
@@ -775,10 +793,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         Entity entity = Iterables.getOnlyElement( ((DynamicCluster)cluster).getMembers()
);
         
         // assert it uses the new spec
-        
-        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:1.0.0");
-        // TODO when upgrades work at level of catalog item ID and bundle ID, do below instead
of above
-//        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
+        Assert.assertEquals(entity.getCatalogItemId(), "simple-entity:2.0.0");
         
         Assert.assertEquals(Entities.deproxy(entity).getClass().getName(), "com.example.brooklyn.test.osgi.entities.SimpleEntityImpl");
         // TODO when registered types are used to create, instead of java type,
@@ -887,7 +902,7 @@ public abstract class BrooklynLauncherRebindCatalogOsgiTest extends AbstractBroo
         try {
             BrooklynLauncherRebindCatalogOsgiTest fixture = new LauncherRebindSubTests();
             fixture.setUp();
-            fixture.testRebindUpgradeEntity();
+            fixture.testRebindUpgradeDeployedEntity();
             fixture.tearDown();
         } catch (Throwable e) {
             e.printStackTrace();


Mime
View raw message