brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Versioning catalog items (take 2)
Date Thu, 13 Nov 2014 12:40:25 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/312#discussion_r20288055
  
    --- Diff: core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java ---
    @@ -948,17 +954,54 @@ protected BrooklynMementoRawData loadMementoRawData(final RebindExceptionHandler
                 RebindTracker.reset();
             }
         }
    -    
    +
    +    private boolean forceCatalogItem(EntityMementoManifest entityManifest) {
    +        return entityManifest.getCatalogItemId() == null && 
    +                BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_INFER_CATALOG_ITEM_ON_REBIND);
    +    }
    +
         private String findCatalogItemId(Map<String, EntityMementoManifest> entityIdToManifest,
EntityMementoManifest entityManifest) {
    -        EntityMementoManifest ptr = entityManifest;
    -        while (ptr != null) {
    -            if (ptr.getCatalogItemId() != null) {
    -                return ptr.getCatalogItemId();
    +        if (entityManifest.getCatalogItemId() != null) {
    +            return entityManifest.getCatalogItemId();
    +        }
    +
    +        if (BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_INFER_CATALOG_ITEM_ON_REBIND))
{
    +            //First check if any of the parent entities has a catalogItemId set.
    +            EntityMementoManifest ptr = entityManifest;
    +            while (ptr != null) {
    +                if (ptr.getCatalogItemId() != null) {
    +                    CatalogItem<?, ?> catalogItem = CatalogUtils.getCatalogItemOptionalVersion(managementContext,
ptr.getCatalogItemId());
    +                    if (catalogItem != null) {
    +                        return catalogItem.getId();
    +                    } else {
    +                        //Couldn't find a catalog item with this id, but return it anyway
and
    +                        //let the caller deal with the error.
    +                        return ptr.getCatalogItemId();
    +                    }
    +                }
    +                if (ptr.getParent() != null) {
    +                    ptr = entityIdToManifest.get(ptr.getParent());
    +                } else {
    +                    ptr = null;
    +                }
                 }
    -            if (ptr.getParent() != null) {
    -                ptr = entityIdToManifest.get(ptr.getParent());
    -            } else {
    -                ptr = null;
    +
    +            //If no parent entity has the catalogItemId set try to match them by the
type we are trying to load.
    +            //The current convention is to set catalog item IDs to the java type (for
both plain java or CAMP plan) they represent.
    +            //This will be applicable only the first time the store is rebinded, while
the catalog items don't have the default
    +            //version appended to their IDs, but then we will have catalogItemId set
on entities so not neede further anyways.
    +            BrooklynCatalog catalog = managementContext.getCatalog();
    +            ptr = entityManifest;
    +            while (ptr != null) {
    +                CatalogItem<?, ?> catalogItem = catalog.getCatalogItem(ptr.getType(),
BrooklynCatalog.DEFAULT_VERSION);
    --- End diff --
    
    this feels fragile, assuming version-less and java type matching catalog symbolic name,
rather than looking at catalog item's java type -- but maybe good enough to test with


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message