brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [8/9] incubator-brooklyn git commit: type registry code review comments
Date Mon, 02 Nov 2015 16:43:05 GMT
type registry code review comments


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

Branch: refs/heads/master
Commit: 25302969df175a92a5e02b9f709964de97809d79
Parents: 50ebfaf
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Mon Nov 2 15:43:40 2015 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Nov 2 15:47:35 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/api/catalog/CatalogItem.java       |  5 +-
 .../api/typereg/BrooklynTypeRegistry.java       |  2 +-
 .../brooklyn/api/typereg/OsgiBundleWithUrl.java |  2 +-
 .../core/catalog/internal/CatalogBundleDto.java |  4 +-
 .../internal/JavaCatalogToSpecTransformer.java  |  5 +-
 .../brooklyn/core/mgmt/ha/OsgiManager.java      |  2 +-
 .../brooklyn/core/resolve/ResolveUtils.java     | 84 --------------------
 .../core/typereg/BasicOsgiBundleWithUrl.java    |  4 +-
 .../core/typereg/RegisteredTypeConstraints.java | 12 ++-
 .../core/typereg/RegisteredTypePredicates.java  |  9 ---
 .../brooklyn/core/typereg/RegisteredTypes.java  |  9 ++-
 .../apache/brooklyn/util/core/osgi/Osgis.java   |  2 +-
 .../camp/brooklyn/spi/creation/CampUtils.java   | 55 ++++++++++++-
 .../brooklyn/catalog/CatalogYamlRebindTest.java |  6 +-
 .../rest/util/BrooklynRestResourceUtils.java    |  8 +-
 15 files changed, 89 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java b/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
index 5d9b5ee..d27436e 100644
--- a/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
+++ b/api/src/main/java/org/apache/brooklyn/api/catalog/CatalogItem.java
@@ -41,7 +41,7 @@ public interface CatalogItem<T,SpecT> extends BrooklynObject, Rebindable
{
     }
     
     public static interface CatalogBundle extends OsgiBundleWithUrl {
-        /** @deprecated since 0.9.0, use {@link #isFullDetailKnown()} */
+        /** @deprecated since 0.9.0, use {@link #isNameResolved()} */
         public boolean isNamed();
     }
 
@@ -70,7 +70,8 @@ public interface CatalogItem<T,SpecT> extends BrooklynObject, Rebindable
{
     /** @return The type of the spec e.g. EntitySpec corresponding to {@link #getCatalogItemJavaType()}
*/
     public Class<SpecT> getSpecType();
     
-    /** @return The underlying java type of the item represented, or null if not known (e.g.
if it comes from yaml) */
+    /** @return The underlying java type of the item represented, if not described via a
YAML spec.
+     * Normally null (and the type comes from yaml). */
     @Nullable public String getJavaType();
 
     /** @deprecated since 0.7.0. Use {@link #getDisplayName} */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
index e13f2e6..3ade1db 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
@@ -40,7 +40,7 @@ public interface BrooklynTypeRegistry {
     }
     
     Iterable<RegisteredType> getAll();
-    Iterable<RegisteredType> getAll(Predicate<? super RegisteredType> alwaysTrue);
+    Iterable<RegisteredType> getAll(Predicate<? super RegisteredType> filter);
     
     /** @return The item matching the given given 
      * {@link RegisteredType#getSymbolicName() symbolicName} 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java b/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
index ec3ef40..e8b278b 100644
--- a/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
+++ b/api/src/main/java/org/apache/brooklyn/api/typereg/OsgiBundleWithUrl.java
@@ -31,6 +31,6 @@ public interface OsgiBundleWithUrl {
     
     /** @return true if we have a name and version for this bundle;
      * false if not, e.g. if we only know the URL and we haven't loaded it yet */
-    public boolean isFullDetailKnown();
+    public boolean isNameResolved();
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
index 51a4757..d3ce7ac 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogBundleDto.java
@@ -44,12 +44,12 @@ public class CatalogBundleDto implements CatalogBundle {
     }
 
     @Override
-    public boolean isFullDetailKnown() {
+    public boolean isNameResolved() {
         return symbolicName != null && version != null;
     }
     
     @Override
-    public boolean isNamed() { return isFullDetailKnown(); }
+    public boolean isNamed() { return isNameResolved(); }
 
     @Override
     public String getSymbolicName() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
index 742625a..7df9adf 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
@@ -44,7 +44,6 @@ import org.slf4j.LoggerFactory;
  * with structure, only a single type.
  */
 public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
-    @SuppressWarnings("unused")
     private static final Logger log = LoggerFactory.getLogger(JavaCatalogToSpecTransformer.class);
 
     private ManagementContext mgmt;
@@ -73,8 +72,12 @@ public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer
{
     public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>>
SpecT createCatalogSpec(
             CatalogItem<T, SpecT> item, Set<String> encounteredTypes) throws
PlanNotRecognizedException {
         if (item.getJavaType() != null) {
+            log.warn("Deprecated functionality (since 0.9.0). Using old-style xml catalog
items with java type attribute for " + item);
             Class<?> type;
             try {
+                // java types were deprecated before we added osgi support so this isn't
necessary,
+                // but it doesn't hurt (and if we re-instate a class+bundle approach for
RegisteredType 
+                // we will want to do this)
                 type = CatalogUtils.newClassLoadingContext(mgmt, item).loadClass(item.getJavaType());
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/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 e906e3a..0e941bd 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
@@ -171,7 +171,7 @@ public class OsgiManager {
     }
 
     public static boolean isBundleNameEqualOrAbsent(CatalogBundle bundle, Bundle b) {
-        return !bundle.isFullDetailKnown() ||
+        return !bundle.isNameResolved() ||
                 (bundle.getSymbolicName().equals(b.getSymbolicName()) &&
                 bundle.getVersion().equals(b.getVersion().toString()));
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java b/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
deleted file mode 100644
index 6ecbe96..0000000
--- a/core/src/main/java/org/apache/brooklyn/core/resolve/ResolveUtils.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.brooklyn.core.resolve;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.policy.PolicySpec;
-import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
-import org.apache.brooklyn.util.guava.Maybe;
-
-@Deprecated /** @deprecated since 0.9.0 never belonged here, and not used much; new principled
TypeRegistry simplifies things */
-// only used for camp
-// TODO-type-registry
-public class ResolveUtils {
-
-    @SuppressWarnings("unchecked")
-    public static PolicySpec<? extends Policy> resolveSpec(
-            String versionedId,
-            BrooklynClassLoadingContext loader,
-            Set<String> encounteredCatalogTypes) {
-        
-        PolicySpec<? extends Policy> spec;
-        RegisteredType item = loader.getManagementContext().getTypeRegistry().get(versionedId);
-        if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName()))
{
-            return loader.getManagementContext().getTypeRegistry().createSpec(item, null,
PolicySpec.class);
-        } else {
-            // TODO-type-registry pass the loader in to the above, and allow it to load with
the loader
-            spec = PolicySpec.create(loader.loadClass(versionedId, Policy.class));
-        }
-        return spec;
-    }
-
-    public static LocationSpec<?> resolveLocationSpec(
-            String type,
-            Map<String, Object> brooklynConfig,
-            BrooklynClassLoadingContext loader) {
-        Maybe<Class<? extends Location>> javaClass = loader.tryLoadClass(type,
Location.class);
-        if (javaClass.isPresent()) {
-            LocationSpec<?> spec = LocationSpec.create(javaClass.get());
-            if (brooklynConfig != null) {
-                spec.configure(brooklynConfig);
-            }
-            return spec;
-        } else {
-            Maybe<Location> loc = loader.getManagementContext().getLocationRegistry().resolve(type,
false, brooklynConfig);
-            if (loc.isPresent()) {
-                // TODO extensions?
-                Map<String, Object> locConfig = ((ConfigurationSupportInternal)loc.get().config()).getBag().getAllConfig();
-                Class<? extends Location> locType = loc.get().getClass();
-                Set<Object> locTags = loc.get().tags().getTags();
-                String locDisplayName = loc.get().getDisplayName();
-                return LocationSpec.create(locType)
-                        .configure(locConfig)
-                        .displayName(locDisplayName)
-                        .tags(locTags);
-            } else {
-                throw new IllegalStateException("No class or resolver found for location
type "+type);
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
index c21ca98..1c8cc40 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicOsgiBundleWithUrl.java
@@ -47,14 +47,14 @@ public class BasicOsgiBundleWithUrl implements CatalogBundle, OsgiBundleWithUrl
     }
 
     @Override
-    public boolean isFullDetailKnown() {
+    public boolean isNameResolved() {
         return symbolicName != null && version != null;
     }
     
     @Override
     @Deprecated //see super
     public boolean isNamed() {
-        return isFullDetailKnown();
+        return isNameResolved();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
index 7f49335..9d59343 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
@@ -22,6 +22,8 @@ import groovy.xml.Entity;
 
 import java.util.Set;
 
+import javax.annotation.Nullable;
+
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.objs.BrooklynObject;
@@ -38,6 +40,7 @@ public class RegisteredTypeConstraints {
 
     private static final Logger log = LoggerFactory.getLogger(RegisteredTypeConstraints.BasicRegisteredTypeConstraint.class);
     
+    /** Immutable (from caller's perspective) record of a constraint */
     public final static class BasicRegisteredTypeConstraint implements RegisteredTypeConstraint
{
         private RegisteredTypeKind kind;
         private Class<?> javaSuperType;
@@ -45,7 +48,7 @@ public class RegisteredTypeConstraints {
         
         private BasicRegisteredTypeConstraint() {}
         
-        public BasicRegisteredTypeConstraint(RegisteredTypeConstraint source) {
+        public BasicRegisteredTypeConstraint(@Nullable RegisteredTypeConstraint source) {
             if (source==null) return;
             
             this.kind = source.getKind();
@@ -83,13 +86,14 @@ public class RegisteredTypeConstraints {
 
     public static RegisteredTypeConstraint alreadyVisited(Set<String> encounteredTypeSymbolicNames)
{
         BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
-        result.encounteredTypes = encounteredTypeSymbolicNames;
+        result.encounteredTypes = encounteredTypeSymbolicNames == null ? ImmutableSet.<String>of()
: ImmutableSet.copyOf(encounteredTypeSymbolicNames);
         return result;
     }
     public static RegisteredTypeConstraint alreadyVisited(Set<String> encounteredTypeSymbolicNames,
String anotherEncounteredType) {
         BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
-        result.encounteredTypes = MutableSet.copyOf(encounteredTypeSymbolicNames);
-        if (anotherEncounteredType!=null) result.encounteredTypes.add(anotherEncounteredType);
+        MutableSet<String> encounteredTypes = MutableSet.copyOf(encounteredTypeSymbolicNames);
+        encounteredTypes.addIfNotNull(anotherEncounteredType);
+        result.encounteredTypes = encounteredTypes.asUnmodifiable();
         return result;
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
index 271add5..3560e47 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypePredicates.java
@@ -67,15 +67,6 @@ public class RegisteredTypePredicates {
         }
     }
 
-    @SuppressWarnings("unused")
-    private static final Function<RegisteredType,String> ID_OF_ITEM_TRANSFORMER_ANONYMOUS
= new Function<RegisteredType, String>() {
-        @Override @Nullable
-        public String apply(@Nullable RegisteredType input) {
-            if (input==null) return null;
-            return input.getId();
-        }
-    };
-
     public static final Function<RegisteredType,String> ID_OF_ITEM_TRANSFORMER = new
IdOfItemTransformer();
     
     private static class IdOfItemTransformer implements Function<RegisteredType,String>
{

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
index 6013f6d..8cddde2 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
@@ -22,15 +22,15 @@ import java.util.Collection;
 import java.util.List;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
 import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
 import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
 import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
-import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
+import com.google.common.collect.ImmutableList;
 
 public class RegisteredTypes {
 
@@ -58,7 +58,7 @@ public class RegisteredTypes {
         
         RegisteredSpecType type = new RegisteredSpecType(item.getSymbolicName(), item.getVersion(),
             item.getCatalogItemJavaType(), impl);
-        type.bundles = MutableList.<OsgiBundleWithUrl>copyOf(item.getLibraries());
+        type.bundles = item.getLibraries()==null ? ImmutableList.<OsgiBundleWithUrl>of()
: ImmutableList.<OsgiBundleWithUrl>copyOf(item.getLibraries());
         type.displayName = item.getDisplayName();
         type.description = item.getDescription();
         type.iconUrl = item.getIconUrl();
@@ -76,8 +76,9 @@ public class RegisteredTypes {
         public T visit(RegisteredType type) {
             if (type==null) throw new NullPointerException("Registered type must not be null");
             if (type instanceof RegisteredSpecType) {
-                visitSpec((RegisteredSpecType)type);
+                return visitSpec((RegisteredSpecType)type);
             }
+            // others go here
             throw new IllegalStateException("Unexpected registered type: "+type.getClass());
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
index 9b94f57..6d5dc91 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/osgi/Osgis.java
@@ -133,7 +133,7 @@ public class Osgis {
         }
 
         public BundleFinder bundle(CatalogBundle bundle) {
-            if (bundle.isFullDetailKnown()) {
+            if (bundle.isNameResolved()) {
                 symbolicName(bundle.getSymbolicName());
                 version(bundle.getVersion());
             }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
index 6390425..bcb18df 100644
--- a/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
+++ b/usage/camp/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/creation/CampUtils.java
@@ -26,10 +26,12 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.policy.PolicySpec;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.CampPlatform;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
 import org.apache.brooklyn.camp.brooklyn.api.AssemblyTemplateSpecInstantiator;
@@ -39,8 +41,9 @@ import org.apache.brooklyn.camp.spi.pdp.DeploymentPlan;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.BrooklynLoaderTracker;
 import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContext;
-import org.apache.brooklyn.core.resolve.ResolveUtils;
+import org.apache.brooklyn.core.objs.BrooklynObjectInternal.ConfigurationSupportInternal;
 import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.stream.Streams;
 import org.apache.brooklyn.util.yaml.Yamls;
 
@@ -106,7 +109,7 @@ public class CampUtils {
         }
 
         String versionedId = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "policy_type",
"policyType", "type"), "policy type");
-        PolicySpec<? extends Policy> spec = ResolveUtils.resolveSpec(versionedId, loader,
encounteredCatalogTypes);
+        PolicySpec<? extends Policy> spec = resolveSpec(versionedId, loader, encounteredCatalogTypes);
         Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get("brooklyn.config");
         if (brooklynConfig != null) {
             spec.configure(brooklynConfig);
@@ -139,7 +142,7 @@ public class CampUtils {
 
         String type = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "location_type",
"locationType", "type"), "location type");
         Map<String, Object> brooklynConfig = (Map<String, Object>) itemMap.get("brooklyn.config");
-        return ResolveUtils.resolveLocationSpec(type, brooklynConfig, loader);
+        return resolveLocationSpec(type, brooklynConfig, loader);
     }
 
     public static DeploymentPlan makePlanFromYaml(ManagementContext mgmt, String yaml) {
@@ -156,4 +159,50 @@ public class CampUtils {
         }
     }
 
+    @SuppressWarnings("unchecked")
+    private static PolicySpec<? extends Policy> resolveSpec(
+            String versionedId,
+            BrooklynClassLoadingContext loader,
+            Set<String> encounteredCatalogTypes) {
+        
+        PolicySpec<? extends Policy> spec;
+        RegisteredType item = loader.getManagementContext().getTypeRegistry().get(versionedId);
+        if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName()))
{
+            return loader.getManagementContext().getTypeRegistry().createSpec(item, null,
PolicySpec.class);
+        } else {
+            // TODO-type-registry pass the loader in to the above, and allow it to load with
the loader
+            spec = PolicySpec.create(loader.loadClass(versionedId, Policy.class));
+        }
+        return spec;
+    }
+
+    private static LocationSpec<?> resolveLocationSpec(
+            String type,
+            Map<String, Object> brooklynConfig,
+            BrooklynClassLoadingContext loader) {
+        Maybe<Class<? extends Location>> javaClass = loader.tryLoadClass(type,
Location.class);
+        if (javaClass.isPresent()) {
+            LocationSpec<?> spec = LocationSpec.create(javaClass.get());
+            if (brooklynConfig != null) {
+                spec.configure(brooklynConfig);
+            }
+            return spec;
+        } else {
+            Maybe<Location> loc = loader.getManagementContext().getLocationRegistry().resolve(type,
false, brooklynConfig);
+            if (loc.isPresent()) {
+                // TODO extensions?
+                Map<String, Object> locConfig = ((ConfigurationSupportInternal)loc.get().config()).getBag().getAllConfig();
+                Class<? extends Location> locType = loc.get().getClass();
+                Set<Object> locTags = loc.get().tags().getTags();
+                String locDisplayName = loc.get().getDisplayName();
+                return LocationSpec.create(locType)
+                        .configure(locConfig)
+                        .displayName(locDisplayName)
+                        .tags(locTags);
+            } else {
+                throw new IllegalStateException("No class or resolver found for location
type "+type);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
index 2996685..989bdb3 100644
--- a/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
+++ b/usage/camp/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlRebindTest.java
@@ -191,7 +191,11 @@ public class CatalogYamlRebindTest extends AbstractYamlRebindTest {
                 addCatalogItems(String.format(locCatalogFormat, locVersion));
                 break;
             case STRIP_DEPRECATION_AND_ENABLEMENT_FROM_CATALOG_ITEM:
-                // nothing here -- but below we rebind with these fields removed to ensure
that we can rebind
+                // set everything false -- then below we rebind with these fields removed
to ensure that we can rebind
+                CatalogUtils.setDeprecated(mgmt(), appSymbolicName, appVersion, false);
+                CatalogUtils.setDeprecated(mgmt(), locSymbolicName, locVersion, false);
+                CatalogUtils.setDisabled(mgmt(), appSymbolicName, appVersion, false);
+                CatalogUtils.setDisabled(mgmt(), locSymbolicName, locVersion, false);
                 break;
             case NO_OP:
                 break; // no-op

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/25302969/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
index 2d9054a..e92c5f1 100644
--- a/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
+++ b/usage/rest-server/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
@@ -145,7 +145,7 @@ public class BrooklynRestResourceUtils {
     public Entity getEntity(String application, String entity) {
         if (entity==null) return null;
         Application app = application!=null ? getApplication(application) : null;
-        Entity e = (Entity) mgmt.getEntityManager().getEntity(entity);
+        Entity e = mgmt.getEntityManager().getEntity(entity);
         
         if (e!=null) {
             if (!Entitlements.isEntitled(mgmt.getEntitlementManager(), Entitlements.SEE_ENTITY,
e)) {
@@ -201,10 +201,10 @@ public class BrooklynRestResourceUtils {
      * an entity matching the given ID or name; returns the first such entity, or null if
none found
      **/
     public Entity searchForEntityNamed(Entity root, String entity) {
-        if (root.getId().equals(entity) || entity.equals(root.getDisplayName())) return (Entity)
root;
+        if (root.getId().equals(entity) || entity.equals(root.getDisplayName())) return root;
         for (Entity child: root.getChildren()) {
             Entity result = searchForEntityNamed(child, entity);
-            if (result!=null) return (Entity) result;
+            if (result!=null) return result;
         }
         return null;
     }
@@ -393,7 +393,7 @@ public class BrooklynRestResourceUtils {
     }
 
     public Task<?> start(Application app, List<? extends Location> locations)
{
-        return Entities.invokeEffector((Entity)app, app, Startable.START,
+        return Entities.invokeEffector(app, app, Startable.START,
                 MutableMap.of("locations", locations));
     }
 


Mime
View raw message