Github user mikezaccardo commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/683#discussion_r31923691
--- Diff: core/src/main/java/brooklyn/entity/rebind/RebindIteration.java ---
@@ -902,45 +902,53 @@ protected void setCatalogItemId(BrooklynObject item,
String catalogItemId) {
protected <T extends BrooklynObject> Class<? extends T>
load(Class<T> bType, Memento memento) {
return load(bType, memento.getType(),
memento.getCatalogItemId(), memento.getId());
}
+
@SuppressWarnings("unchecked")
protected <T extends BrooklynObject> Class<? extends T>
load(Class<T> bType, String jType, String catalogItemId, String
contextSuchAsId) {
checkNotNull(jType, "Type of %s (%s) must not be null",
contextSuchAsId, bType.getSimpleName());
+
if (catalogItemId != null) {
- BrooklynClassLoadingContext loader =
getLoadingContextFromCatalogItemId(catalogItemId, classLoader, rebindContext);
- return loader.loadClass(jType, bType);
- } else {
- // we have previously used reflections; not sure if that's
needed?
- try {
- return (Class<T>)reflections.loadClass(jType);
- } catch (Exception e) {
- LOG.warn("Unable to load "+jType+" using reflections;
will try standard context");
- }
-
- if
(BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_INFER_CATALOG_ITEM_ON_REBIND))
{
- //Try loading from whichever catalog bundle succeeds.
- BrooklynCatalog catalog =
managementContext.getCatalog();
- for (CatalogItem<?, ?> item :
catalog.getCatalogItems()) {
- BrooklynClassLoadingContext catalogLoader =
CatalogUtils.newClassLoadingContext(managementContext, item);
- Maybe<Class<?>> catalogClass =
catalogLoader.tryLoadClass(jType);
- if (catalogClass.isPresent()) {
- return (Class<? extends T>) catalogClass.get();
- }
+ CatalogItem<?, ?> catalogItem =
rebindContext.lookup().lookupCatalogItem(catalogItemId);
+ if (catalogItem == null &&
BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_INFER_CATALOG_ITEM_ON_REBIND))
{
--- End diff --
Perhaps change this `if` condition to simply the `null` check and then have
another `if` that switches on whether `FEATURE_INFER_CATALOG_ITEM_ON_REBIND` is
true. It's easier to follow the logic this way.
---
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.
---