brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From geom...@apache.org
Subject [26/39] brooklyn-server git commit: switch REST API to use TypeRegistry methods (but not yet changing API)
Date Wed, 19 Jul 2017 16:25:56 GMT
switch REST API to use TypeRegistry methods (but not yet changing API)

we could have a much nicer API around bundles and type registry --
but to keep this PR minimal we've just done backwards compatibility here.
(we have to go through type registry however as we are no longer adding
things to the "catalog"; it gets added to "type registry".)


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

Branch: refs/heads/master
Commit: d7ebb6bb8c97cd5c5024bdd22d342577ebd7e3fd
Parents: 694ac1d
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Jul 4 18:09:36 2017 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Jul 4 18:09:36 2017 +0100

----------------------------------------------------------------------
 .../core/typereg/RegisteredTypePredicates.java  |  55 +++++-
 .../brooklyn/core/typereg/RegisteredTypes.java  |  30 +++-
 .../apache/brooklyn/rest/api/CatalogApi.java    |   3 +-
 .../rest/resources/CatalogResource.java         | 116 +++++-------
 .../rest/transform/CatalogTransformer.java      | 180 ++++++++++++++++++-
 .../rest/transform/LocationTransformer.java     |   9 +-
 .../rest/util/BrooklynRestResourceUtils.java    |   5 +
 .../rest/resources/ApplicationResourceTest.java |  28 +--
 .../rest/resources/CatalogResourceTest.java     |  57 +++++-
 .../rest/resources/LocationResourceTest.java    |   6 +-
 10 files changed, 376 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/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 ce54fef..0bf3490 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
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.core.typereg;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.entity.Application;
@@ -31,18 +33,23 @@ import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.util.collections.CollectionFunctionals;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.osgi.VersionedName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
 public class RegisteredTypePredicates {
 
+    private static final Logger log = LoggerFactory.getLogger(RegisteredTypePredicates.class);
+    
     public static Predicate<RegisteredType> deprecated(final boolean deprecated) {
         return new DeprecatedEqualTo(deprecated);
     }
-
     private static class DeprecatedEqualTo implements Predicate<RegisteredType> {
         private final boolean deprecated;
         
@@ -58,7 +65,6 @@ public class RegisteredTypePredicates {
     public static Predicate<RegisteredType> disabled(boolean disabled) {
         return new DisabledEqualTo(disabled);
     }
-
     private static class DisabledEqualTo implements Predicate<RegisteredType> {
         private final boolean disabled;
         
@@ -70,6 +76,21 @@ public class RegisteredTypePredicates {
             return (item != null) && item.isDisabled() == disabled;
         }
     }
+    
+    public static Predicate<RegisteredType> template(final boolean template) {
+        return new TemplateTagPresent(template);
+    }
+    private static class TemplateTagPresent implements Predicate<RegisteredType> {
+        private final boolean present;
+        
+        public TemplateTagPresent(boolean present) {
+            this.present = present;
+        }
+        @Override
+        public boolean apply(@Nullable RegisteredType item) {
+            return (item != null) && RegisteredTypes.isTemplate(item) == present;
+        }
+    }
 
     public static final Function<RegisteredType,String> ID_OF_ITEM_TRANSFORMER = new IdOfItemTransformer();
     
@@ -279,4 +300,34 @@ public class RegisteredTypePredicates {
         }
     }
 
+    @Beta // expensive way to compare everything; API likely to change to be clearer
+    public static Predicate<RegisteredType> stringRepresentationMatches(Predicate<? super String> filter) {
+        return new StringRepresentationMatches<>(checkNotNull(filter, "filter"));
+    }
+    private static class StringRepresentationMatches<T, SpecT> implements Predicate<RegisteredType> {
+        private final Predicate<? super String> filter;
+        StringRepresentationMatches(final Predicate<? super String> filter) {
+            this.filter = filter;
+        }
+        @Override
+        public boolean apply(@Nullable RegisteredType item) {
+            try {
+                String thingToCompare = 
+                    item.getVersionedName().toString()+"\n"+
+                    item.getVersionedName().toOsgiString()+"\n"+
+                    item.getTags()+"\n"+
+                    item.getDisplayName()+"\n"+
+                    item.getAliases()+"\n"+
+                    item.getDescription()+"\n"+
+                    RegisteredTypes.getImplementationDataStringForSpec(item);
+                return filter.apply(thingToCompare);
+            } catch (Exception e) {
+                // If we propagated exceptions, then we'd risk aborting the checks for other catalog items.
+                // Play it safe, in case there's something messed up with just one catalog item.
+                Exceptions.propagateIfFatal(e);
+                log.warn("Problem producing string representation of "+item+"; assuming no match, and continuing", e);
+                return false;
+            }
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/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 d0edcb1..6519edf 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
@@ -30,6 +30,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
 import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
@@ -118,6 +119,9 @@ public class RegisteredTypes {
         if (item.getLibraries()!=null) type.bundles.addAll(item.getLibraries());
         // aliases aren't on item
         if (item.tags()!=null) type.tags.addAll(item.tags().getTags());
+        if (item.getCatalogItemType()==CatalogItemType.TEMPLATE) {
+            type.tags.add(BrooklynTags.CATALOG_TEMPLATE);
+        }
 
         // these things from item we ignore: javaType, specType, registeredTypeName ...
         return type;
@@ -456,23 +460,39 @@ public class RegisteredTypes {
 
     public static RegisteredType getBestVersion(Iterable<RegisteredType> types) {
         if (types==null || !types.iterator().hasNext()) return null;
-        return Ordering.from(RegisteredTypeComparator.INSTANCE).max(types);
+        return Ordering.from(RegisteredTypeNameThenBestFirstComparator.INSTANCE).min(types);
     }
     
-    public static class RegisteredTypeComparator implements Comparator<RegisteredType> {
-        public static Comparator<RegisteredType> INSTANCE = new RegisteredTypeComparator();
-        private RegisteredTypeComparator() {}
+    /** by name, then with disabled, deprecated first, then by increasing version */ 
+    public static class RegisteredTypeNameThenWorstFirstComparator implements Comparator<RegisteredType> {
+        public static Comparator<RegisteredType> INSTANCE = new RegisteredTypeNameThenWorstFirstComparator();
+        private RegisteredTypeNameThenWorstFirstComparator() {}
         @Override
         public int compare(RegisteredType o1, RegisteredType o2) {
             return ComparisonChain.start()
+                .compare(o1.getSymbolicName(), o2.getSymbolicName(), NaturalOrderComparator.INSTANCE)
                 .compareTrueFirst(o1.isDisabled(), o2.isDisabled())
                 .compareTrueFirst(o1.isDeprecated(), o2.isDeprecated())
-                .compare(o1.getSymbolicName(), o2.getSymbolicName(), NaturalOrderComparator.INSTANCE)
                 .compare(o1.getVersion(), o2.getVersion(), VersionComparator.INSTANCE)
                 .result();
         }
     }
 
+    /** by name, then with disabled, deprecated first, then by increasing version */ 
+    public static class RegisteredTypeNameThenBestFirstComparator implements Comparator<RegisteredType> {
+        public static Comparator<RegisteredType> INSTANCE = new RegisteredTypeNameThenBestFirstComparator();
+        private RegisteredTypeNameThenBestFirstComparator() {}
+        @Override
+        public int compare(RegisteredType o1, RegisteredType o2) {
+            return ComparisonChain.start()
+                .compare(o1.getSymbolicName(), o2.getSymbolicName(), NaturalOrderComparator.INSTANCE)
+                .compareFalseFirst(o1.isDisabled(), o2.isDisabled())
+                .compareFalseFirst(o1.isDeprecated(), o2.isDeprecated())
+                .compare(o2.getVersion(), o1.getVersion(), VersionComparator.INSTANCE)
+                .result();
+        }
+    }
+
     /** validates that the given object (required) satisfies the constraints implied by the given
      * type and context object, using {@link Maybe} as the result set absent containing the error(s)
      * if not satisfied. returns an {@link Absent} if failed with details of the error,

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
----------------------------------------------------------------------
diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
index 8e1f5d8..698f97f 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
@@ -233,9 +233,10 @@ public interface CatalogApi {
         @ApiParam(name = "allVersions", value = "Include all versions (defaults false, only returning the best version)")
         @QueryParam("allVersions") @DefaultValue("false") boolean includeAllVersions);
 
+    // bad name - it is just templates
     @GET
     @Path("/applications")
-    @ApiOperation(value = "Fetch a list of application templates optionally matching a query", 
+    @ApiOperation(value = "Fetch a list of templates (for applications) optionally matching a query", 
             response = CatalogItemSummary.class,
             responseContainer = "List")
     public List<CatalogItemSummary> listApplications(

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index 6983e5d..0133962 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -35,25 +35,15 @@ import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.Entity;
-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.sensor.Enricher;
-import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.core.catalog.CatalogPredicates;
-import org.apache.brooklyn.core.catalog.internal.CatalogItemComparator;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements;
 import org.apache.brooklyn.core.mgmt.entitlement.Entitlements.StringAndArgument;
 import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.rest.api.CatalogApi;
 import org.apache.brooklyn.rest.domain.ApiError;
 import org.apache.brooklyn.rest.domain.CatalogEnricherSummary;
@@ -94,11 +84,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     private static final Logger log = LoggerFactory.getLogger(CatalogResource.class);
     private static final String LATEST = "latest";
     
-    @SuppressWarnings("rawtypes")
-    private Function<CatalogItem, CatalogItemSummary> toCatalogItemSummary(final UriInfo ui) {
-        return new Function<CatalogItem, CatalogItemSummary>() {
+    private Function<RegisteredType, CatalogItemSummary> toCatalogItemSummary(final UriInfo ui) {
+        return new Function<RegisteredType, CatalogItemSummary>() {
             @Override
-            public CatalogItemSummary apply(@Nullable CatalogItem input) {
+            public CatalogItemSummary apply(@Nullable RegisteredType input) {
                 return CatalogTransformer.catalogItemSummary(brooklyn(), input, ui.getBaseUriBuilder());
             }
         };
@@ -138,6 +127,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         return createFromYaml(yaml, forceUpdate);
     }
     
+    @SuppressWarnings("deprecation")
     @Override
     public Response createFromYaml(String yaml, boolean forceUpdate) {
         if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.ADD_CATALOG_ITEM, yaml)) {
@@ -147,7 +137,13 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
         try {
             final Iterable<? extends CatalogItem<?, ?>> items = brooklyn().getCatalog().addItems(yaml, forceUpdate);
-            return buildCreateResponse(items);
+            List<RegisteredType> itemsRT = MutableList.of();
+            for (CatalogItem<?, ?> ci: items) {
+                RegisteredType rt = brooklyn().getTypeRegistry().get(ci.getId());
+                if (rt!=null) itemsRT.add(rt);
+                else itemsRT.add(RegisteredTypes.of(ci));
+            }
+            return buildCreateResponse(itemsRT);
         } catch (Exception e) {
             Exceptions.propagateIfFatal(e);
             return badRequest(e);
@@ -167,7 +163,6 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             return message;
         }
         
-        @SuppressWarnings("deprecation")
         public static BundleInstallationRestResult of(OsgiBundleInstallationResult in, ManagementContext mgmt, BrooklynRestResourceUtils brooklynU, UriInfo ui) {
             BundleInstallationRestResult result = new BundleInstallationRestResult();
             result.message = in.getMessage();
@@ -176,10 +171,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             if (in.getCatalogItemsInstalled()!=null) {
                 result.types = MutableMap.of();
                 for (String id: in.getCatalogItemsInstalled()) {
-                    // TODO prefer to use RegisteredType, but we need transformer for those in REST
-                    //RegisteredType ci = mgmt.getTypeRegistry().get(id);
-                    
-                    CatalogItem<?, ?> ci = CatalogUtils.getCatalogItemOptionalVersion(mgmt, id);
+                    RegisteredType ci = mgmt.getTypeRegistry().get(id);
                     CatalogItemSummary summary = CatalogTransformer.catalogItemSummary(brooklynU, ci, ui.getBaseUriBuilder());
                     result.types.put(id, summary);
                 }
@@ -217,12 +209,12 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         return Response.status(Status.CREATED).entity( detail ? resultR : resultR.types ).build();
     }
 
-    private Response buildCreateResponse(Iterable<? extends CatalogItem<?, ?>> catalogItems) {
+    private Response buildCreateResponse(Iterable<RegisteredType> catalogItems) {
         log.info("REST created catalog items: "+catalogItems);
 
         Map<String,Object> result = MutableMap.of();
 
-        for (CatalogItem<?,?> catalogItem: catalogItems) {
+        for (RegisteredType catalogItem: catalogItems) {
             try {
                 result.put(
                         catalogItem.getId(),
@@ -303,10 +295,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     @Override
     public List<CatalogEntitySummary> listEntities(String regex, String fragment, boolean allVersions) {
-        Predicate<CatalogItem<Entity, EntitySpec<?>>> filter =
+        Predicate<RegisteredType> filter =
                 Predicates.and(
-                        CatalogPredicates.IS_ENTITY,
-                        CatalogPredicates.<Entity, EntitySpec<?>>disabled(false));
+                        RegisteredTypePredicates.IS_ENTITY,
+                        RegisteredTypePredicates.disabled(false));
         List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);
         return castList(result, CatalogEntitySummary.class);
     }
@@ -314,11 +306,11 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     @Override
     public List<CatalogItemSummary> listApplications(String regex, String fragment, boolean allVersions) {
         @SuppressWarnings("unchecked")
-        Predicate<CatalogItem<Application, EntitySpec<? extends Application>>> filter =
+        Predicate<RegisteredType> filter =
                 Predicates.and(
-                        CatalogPredicates.IS_TEMPLATE,
-                        CatalogPredicates.<Application,EntitySpec<? extends Application>>deprecated(false),
-                        CatalogPredicates.<Application,EntitySpec<? extends Application>>disabled(false));
+                        RegisteredTypePredicates.template(true),
+                        RegisteredTypePredicates.deprecated(false),
+                        RegisteredTypePredicates.disabled(false));
         return getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);
     }
     
@@ -331,12 +323,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
         version = processVersion(version);
 
-        //TODO These casts are not pretty, we could just provide separate get methods for the different types?
-        //Or we could provide asEntity/asPolicy cast methods on the CataloItem doing a safety check internally
-        @SuppressWarnings("unchecked")
-        CatalogItem<Entity, EntitySpec<? extends Entity>> result =
-              (CatalogItem<Entity, EntitySpec<? extends Entity>>) brooklyn().getCatalog().getCatalogItem(symbolicName, version);
-
+        RegisteredType result = brooklyn().getTypeRegistry().get(symbolicName, version);
         if (result==null) {
             throw WebResourceUtils.notFound("Entity with id '%s:%s' not found", symbolicName, version);
         }
@@ -351,10 +338,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     @Override
     public List<CatalogPolicySummary> listPolicies(String regex, String fragment, boolean allVersions) {
-        Predicate<CatalogItem<Policy, PolicySpec<?>>> filter =
+        Predicate<RegisteredType> filter =
                 Predicates.and(
-                        CatalogPredicates.IS_POLICY,
-                        CatalogPredicates.<Policy, PolicySpec<?>>disabled(false));
+                        RegisteredTypePredicates.IS_POLICY,
+                        RegisteredTypePredicates.disabled(false));
         List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);
         return castList(result, CatalogPolicySummary.class);
     }
@@ -367,11 +354,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         }
 
         version = processVersion(version);
-
-        @SuppressWarnings("unchecked")
-        CatalogItem<? extends Policy, PolicySpec<?>> result =
-                (CatalogItem<? extends Policy, PolicySpec<?>>)brooklyn().getCatalog().getCatalogItem(policyId, version);
-
+        RegisteredType result = brooklyn().getTypeRegistry().get(policyId, version);
         if (result==null) {
           throw WebResourceUtils.notFound("Policy with id '%s:%s' not found", policyId, version);
         }
@@ -381,10 +364,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     @Override
     public List<CatalogLocationSummary> listLocations(String regex, String fragment, boolean allVersions) {
-        Predicate<CatalogItem<Location, LocationSpec<?>>> filter =
+        Predicate<RegisteredType> filter =
                 Predicates.and(
-                        CatalogPredicates.IS_LOCATION,
-                        CatalogPredicates.<Location, LocationSpec<?>>disabled(false));
+                        RegisteredTypePredicates.IS_LOCATION,
+                        RegisteredTypePredicates.disabled(false));
         List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);
         return castList(result, CatalogLocationSummary.class);
     }
@@ -397,11 +380,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
         }
 
         version = processVersion(version);
-
-        @SuppressWarnings("unchecked")
-        CatalogItem<? extends Location, LocationSpec<?>> result =
-                (CatalogItem<? extends Location, LocationSpec<?>>)brooklyn().getCatalog().getCatalogItem(locationId, version);
-
+        RegisteredType result = brooklyn().getTypeRegistry().get(locationId, version);
         if (result==null) {
           throw WebResourceUtils.notFound("Location with id '%s:%s' not found", locationId, version);
         }
@@ -410,22 +389,22 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    private <T,SpecT> List<CatalogItemSummary> getCatalogItemSummariesMatchingRegexFragment(Predicate<? super CatalogItem<T,SpecT>> type, String regex, String fragment, boolean allVersions) {
-        List filters = new ArrayList();
+    private <T,SpecT> List<CatalogItemSummary> getCatalogItemSummariesMatchingRegexFragment(
+            Predicate<RegisteredType> type, String regex, String fragment, boolean allVersions) {
+        List<Predicate<RegisteredType>> filters = new ArrayList();
         filters.add(type);
         if (Strings.isNonEmpty(regex))
-            filters.add(CatalogPredicates.stringRepresentationMatches(StringPredicates.containsRegex(regex)));
+            filters.add(RegisteredTypePredicates.stringRepresentationMatches(StringPredicates.containsRegex(regex)));
         if (Strings.isNonEmpty(fragment))
-            filters.add(CatalogPredicates.stringRepresentationMatches(StringPredicates.containsLiteralIgnoreCase(fragment)));
+            filters.add(RegisteredTypePredicates.stringRepresentationMatches(StringPredicates.containsLiteralIgnoreCase(fragment)));
         if (!allVersions)
-            filters.add(CatalogPredicates.isBestVersion(mgmt()));
+            filters.add(RegisteredTypePredicates.isBestVersion(mgmt()));
         
-        filters.add(CatalogPredicates.entitledToSee(mgmt()));
+        filters.add(RegisteredTypePredicates.entitledToSee(mgmt()));
 
-        ImmutableList<CatalogItem<Object, Object>> sortedItems =
-                FluentIterable.from(brooklyn().getCatalog().getCatalogItems())
-                    .filter(Predicates.and(filters))
-                    .toSortedList(CatalogItemComparator.getInstance());
+        ImmutableList<RegisteredType> sortedItems =
+                FluentIterable.from(brooklyn().getTypeRegistry().getMatching(Predicates.and(filters)))
+                    .toSortedList(RegisteredTypes.RegisteredTypeNameThenBestFirstComparator.INSTANCE);
         return Lists.transform(sortedItems, toCatalogItemSummary(ui));
     }
 
@@ -463,10 +442,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     @Override
     public List<CatalogEnricherSummary> listEnrichers(@ApiParam(name = "regex", value = "Regular expression to search for") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") @DefaultValue("") String fragment, @ApiParam(name = "allVersions", value = "Include all versions (defaults false, only returning the best version)") @DefaultValue("false") boolean includeAllVersions) {
-        Predicate<CatalogItem<Enricher, EnricherSpec<?>>> filter =
+        Predicate<RegisteredType> filter =
                 Predicates.and(
-                        CatalogPredicates.IS_ENRICHER,
-                        CatalogPredicates.<Enricher, EnricherSpec<?>>disabled(false));
+                        RegisteredTypePredicates.IS_ENRICHER,
+                        RegisteredTypePredicates.disabled(false));
         List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, includeAllVersions);
         return castList(result, CatalogEnricherSummary.class);
     }
@@ -477,13 +456,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to see catalog entry",
                     Entitlements.getEntitlementContext().user());
         }
-
         version = processVersion(version);
-
-        @SuppressWarnings("unchecked")
-        CatalogItem<? extends Enricher, EnricherSpec<?>> result =
-                (CatalogItem<? extends Enricher, EnricherSpec<?>>)brooklyn().getCatalog().getCatalogItem(enricherId, version);
-
+        RegisteredType result = brooklyn().getTypeRegistry().get(enricherId, version);
         if (result==null) {
             throw WebResourceUtils.notFound("Enricher with id '%s:%s' not found", enricherId, version);
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
index 4259120..b1ec6e5 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.UriBuilder;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -41,9 +42,12 @@ import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.api.sensor.Enricher;
 import org.apache.brooklyn.api.sensor.EnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.entity.EntityDynamicType;
 import org.apache.brooklyn.core.mgmt.BrooklynTags;
 import org.apache.brooklyn.core.objs.BrooklynTypes;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.rest.api.CatalogApi;
 import org.apache.brooklyn.rest.domain.CatalogEnricherSummary;
 import org.apache.brooklyn.rest.domain.CatalogEntitySummary;
@@ -67,11 +71,177 @@ import org.slf4j.LoggerFactory;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
-@SuppressWarnings("deprecation")
 public class CatalogTransformer {
 
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(CatalogTransformer.class);
+    
+    public static <T extends Entity> CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
+        Set<EntityConfigSummary> config = Sets.newLinkedHashSet();
+        Set<SensorSummary> sensors = Sets.newTreeSet(SummaryComparators.nameComparator());
+        Set<EffectorSummary> effectors = Sets.newTreeSet(SummaryComparators.nameComparator());
+
+        EntitySpec<?> spec = null;
+
+        try {
+            spec = b.getTypeRegistry().createSpec(item, null, EntitySpec.class);
+            EntityDynamicType typeMap = BrooklynTypes.getDefinedEntityType(spec.getType());
+            EntityType type = typeMap.getSnapshot();
+
+            AtomicInteger paramPriorityCnt = new AtomicInteger();
+            for (SpecParameter<?> input: spec.getParameters())
+                config.add(EntityTransformer.entityConfigSummary(input, paramPriorityCnt));
+            for (Sensor<?> x: type.getSensors())
+                sensors.add(SensorTransformer.sensorSummaryForCatalog(x));
+            for (Effector<?> x: type.getEffectors())
+                effectors.add(EffectorTransformer.effectorSummaryForCatalog(x));
+
+        } catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            
+            // templates with multiple entities can't have spec created in the manner above; just ignore
+            if (item.getSuperTypes().contains(Entity.class)) {
+                log.warn("Unable to create spec for "+item+": "+e, e);
+            }
+            if (log.isTraceEnabled()) {
+                log.trace("Unable to create spec for "+item+": "+e, e);
+            }
+        }
+        
+        return new CatalogEntitySummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
+            spec!=null ? spec.getType().getName() : item.getSuperTypes().toString(), 
+            spec!=null ? 
+                CatalogItemType.ofTargetClass(spec.getType()).name() : 
+                // RegisteredTypes.isTemplate(item) ? "template" :   // could check this, but more reliable for clients to rely on tag 
+                "unknown",
+            RegisteredTypes.getImplementationDataStringForSpec(item),
+            item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub),
+            makeTags(spec, item), config, sensors, effectors,
+            item.isDeprecated(), makeLinks(item, ub));
+    }
 
+    public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
+        try {
+            if (item.getSuperTypes().contains(Application.class) ||
+                    item.getSuperTypes().contains(Entity.class)) {
+                return catalogEntitySummary(b, item, ub);
+            } else if (item.getSuperTypes().contains(Policy.class)) {
+                return catalogPolicySummary(b, item, ub);
+            } else if (item.getSuperTypes().contains(Enricher.class)) {
+                return catalogEnricherSummary(b, item, ub);
+            } else if (item.getSuperTypes().contains(Location.class)) {
+                return catalogLocationSummary(b, item, ub);
+            } else {
+                log.debug("Misc catalog item type when getting self link (supplying generic item): "+item+" "+item.getSuperTypes());
+            }
+        } catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            log.warn("Invalid item in catalog when converting REST summaries (supplying generic item), at "+item+": "+e, e);
+        }
+        return new CatalogItemSummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
+            item.getSuperTypes().toString(), 
+            item.getKind()==RegisteredTypeKind.BEAN ? "bean" : "unknown",
+            RegisteredTypes.getImplementationDataStringForSpec(item),
+            item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), item.getTags(), item.isDeprecated(), makeLinks(item, ub));
+    }
+
+    public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
+        final Set<PolicyConfigSummary> config = Sets.newLinkedHashSet();
+        PolicySpec<?> spec = null;
+        try{
+            spec = b.getTypeRegistry().createSpec(item, null, PolicySpec.class);
+            for (final SpecParameter<?> input : spec.getParameters()){
+                config.add(EntityTransformer.policyConfigSummary(input));
+            }
+        }catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            log.trace("Unable to create policy spec for "+item+": "+e, e);
+        }
+        return new CatalogPolicySummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
+                spec!=null ? spec.getType().getName() : item.getSuperTypes().toString(), 
+                CatalogItemType.POLICY.toString(),
+                RegisteredTypes.getImplementationDataStringForSpec(item),
+                item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config,
+                item.getTags(), item.isDeprecated(), makeLinks(item, ub));
+    }
+
+    public static CatalogEnricherSummary catalogEnricherSummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
+        final Set<EnricherConfigSummary> config = Sets.newLinkedHashSet();
+        EnricherSpec<?> spec = null;
+        try{
+            spec = b.getTypeRegistry().createSpec(item, null, EnricherSpec.class);
+            for (final SpecParameter<?> input : spec.getParameters()){
+                config.add(EntityTransformer.enricherConfigSummary(input));
+            }
+        }catch (Exception e) {
+            Exceptions.propagateIfFatal(e);
+            log.trace("Unable to create policy spec for "+item+": "+e, e);
+        }
+        return new CatalogEnricherSummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
+                spec!=null ? spec.getType().getName() : item.getSuperTypes().toString(), 
+                CatalogItemType.ENRICHER.toString(),
+                RegisteredTypes.getImplementationDataStringForSpec(item),
+                item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config,
+                item.getTags(), item.isDeprecated(), makeLinks(item, ub));
+    }
+
+    public static CatalogLocationSummary catalogLocationSummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
+        Set<LocationConfigSummary> config = ImmutableSet.of();
+        return new CatalogLocationSummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
+                item.getSuperTypes().toString(), 
+                CatalogItemType.LOCATION.toString(),
+                RegisteredTypes.getImplementationDataStringForSpec(item),
+                item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config,
+                item.getTags(), item.isDeprecated(), makeLinks(item, ub));
+    }
+
+    protected static Map<String, URI> makeLinks(RegisteredType item, UriBuilder ub) {
+        return MutableMap.<String, URI>of().addIfNotNull("self", getSelfLink(item, ub));
+    }
+
+    protected static URI getSelfLink(RegisteredType item, UriBuilder ub) {
+        String itemId = item.getId();
+        if (item.getSuperTypes().contains(Application.class)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getApplication").build(itemId, item.getVersion());
+        } else if (item.getSuperTypes().contains(Entity.class)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getEntity").build(itemId, item.getVersion());
+        } else if (item.getSuperTypes().contains(Policy.class)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getPolicy").build(itemId, item.getVersion());
+        } else if (item.getSuperTypes().contains(Enricher.class)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getEnricher").build(itemId, item.getVersion());
+        } else if (item.getSuperTypes().contains(Location.class)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getLocation").build(itemId, item.getVersion());
+        } else {
+            log.warn("Unexpected catalog item type when getting self link (not supplying self link): "+item+" "+item.getSuperTypes());
+            return null;
+        }
+    }
+    private static String tidyIconLink(BrooklynRestResourceUtils b, RegisteredType item, String iconUrl, UriBuilder ub) {
+        if (b.isUrlServerSideAndSafe(iconUrl)) {
+            return serviceUriBuilder(ub, CatalogApi.class, "getIcon").build(item.getSymbolicName(), item.getVersion()).toString();
+        }
+        return iconUrl;
+    }
+
+    private static Set<Object> makeTags(EntitySpec<?> spec, RegisteredType item) {
+        // Combine tags on item with an InterfacesTag.
+        Set<Object> tags = MutableSet.copyOf(item.getTags());
+        if (spec != null) {
+            Class<?> type;
+            if (spec.getImplementation() != null) {
+                type = spec.getImplementation();
+            } else {
+                type = spec.getType();
+            }
+            if (type != null) {
+                tags.add(new BrooklynTags.TraitsTag(Reflections.getAllInterfaces(type)));
+            }
+        }
+        return tags;
+    }
+
+    
+    
+    /** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
     public static <T extends Entity> CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, CatalogItem<T,EntitySpec<? extends T>> item, UriBuilder ub) {
         Set<EntityConfigSummary> config = Sets.newLinkedHashSet();
         Set<SensorSummary> sensors = Sets.newTreeSet(SummaryComparators.nameComparator());
@@ -111,6 +281,7 @@ public class CatalogTransformer {
             item.isDeprecated(), makeLinks(item, ub));
     }
 
+    /** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
     @SuppressWarnings({ "unchecked", "rawtypes" })
     public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, CatalogItem item, UriBuilder ub) {
         try {
@@ -136,6 +307,7 @@ public class CatalogTransformer {
             item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub));
     }
 
+    /** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
     public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Policy,PolicySpec<?>> item, UriBuilder ub) {
         final Set<PolicyConfigSummary> config = Sets.newLinkedHashSet();
         try{
@@ -153,6 +325,7 @@ public class CatalogTransformer {
                 item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub));
     }
 
+    /** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
     public static CatalogEnricherSummary catalogEnricherSummary(BrooklynRestResourceUtils b, CatalogItem<? extends Enricher,EnricherSpec<?>> item, UriBuilder ub) {
         final Set<EnricherConfigSummary> config = Sets.newLinkedHashSet();
         try{
@@ -170,6 +343,7 @@ public class CatalogTransformer {
                 item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub));
     }
 
+    /** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
     public static CatalogLocationSummary catalogLocationSummary(BrooklynRestResourceUtils b, CatalogItem<? extends Location,LocationSpec<?>> item, UriBuilder ub) {
         Set<LocationConfigSummary> config = ImmutableSet.of();
         return new CatalogLocationSummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
@@ -178,11 +352,11 @@ public class CatalogTransformer {
                 item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub));
     }
 
-    protected static Map<String, URI> makeLinks(CatalogItem<?,?> item, UriBuilder ub) {
+    private static Map<String, URI> makeLinks(CatalogItem<?,?> item, UriBuilder ub) {
         return MutableMap.<String, URI>of().addIfNotNull("self", getSelfLink(item, ub));
     }
 
-    protected static URI getSelfLink(CatalogItem<?,?> item, UriBuilder ub) {
+    private static URI getSelfLink(CatalogItem<?,?> item, UriBuilder ub) {
         String itemId = item.getId();
         switch (item.getCatalogItemType()) {
         case TEMPLATE:

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java
index fa3fb2c..430cbbe 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/LocationTransformer.java
@@ -25,12 +25,11 @@ import java.util.Map;
 
 import javax.ws.rs.core.UriBuilder;
 
-import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationDefinition;
 import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.config.Sanitizer;
 import org.apache.brooklyn.core.location.BasicLocationDefinition;
 import org.apache.brooklyn.core.location.CatalogLocationResolver;
@@ -62,7 +61,6 @@ public class LocationTransformer {
         return newInstance(null, id, locationSpec, LocationDetailLevel.LOCAL_EXCLUDING_SECRET, ub);
     }
     
-    @SuppressWarnings("unchecked")
     private static LocationSummary newInstance(ManagementContext mgmt, 
             LocationSpec<? extends Location> spec, ConfigBag explicitConfig, 
             String optionalExplicitId, String name, String specString, 
@@ -91,10 +89,7 @@ public class LocationTransformer {
         
         CatalogLocationSummary catalogSummary = null;
         if (CatalogLocationResolver.isLegacyWrappedReference(specString)) {
-//            RegisteredType type = mgmt.getTypeRegistry().get(CatalogLocationResolver.unwrapLegacyWrappedReference(specString));
-            // TODO REST items should switch to using the RegisteredType
-            @SuppressWarnings({ "rawtypes", "deprecation" })
-            CatalogItem ci = CatalogUtils.getCatalogItemOptionalVersion(mgmt, CatalogLocationResolver.unwrapLegacyWrappedReference(specString));
+            RegisteredType ci = mgmt.getTypeRegistry().get(CatalogLocationResolver.unwrapLegacyWrappedReference(specString));
             if (ci!=null) {
                 BrooklynRestResourceUtils br = new BrooklynRestResourceUtils(mgmt);
                 catalogSummary = CatalogTransformer.catalogLocationSummary(br, ci, ub);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
index 66467a1..9e1ce53 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/util/BrooklynRestResourceUtils.java
@@ -39,6 +39,7 @@ import org.apache.brooklyn.api.location.LocationRegistry;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants;
 import org.apache.brooklyn.camp.brooklyn.spi.dsl.methods.DslComponent;
@@ -86,6 +87,10 @@ public class BrooklynRestResourceUtils {
         this.mgmt = mgmt;
     }
 
+    public BrooklynTypeRegistry getTypeRegistry() {
+        return mgmt.getTypeRegistry();
+    }
+    
     public BrooklynCatalog getCatalog() {
         return mgmt.getCatalog();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
index 277fd32..2a53cc9 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/ApplicationResourceTest.java
@@ -32,7 +32,11 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeoutException;
 
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
@@ -71,7 +75,7 @@ import org.apache.brooklyn.util.collections.CollectionFunctionals;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.http.HttpAsserts;
 import org.apache.brooklyn.util.text.Strings;
-import org.apache.brooklyn.util.time.Duration;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.http.HttpHeaders;
 import org.apache.http.entity.ContentType;
 import org.slf4j.Logger;
@@ -87,13 +91,6 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.MultivaluedHashMap;
-
-import org.apache.cxf.jaxrs.client.WebClient;
-
 @Test(singleThreaded = true,
         // by using a different suite name we disallow interleaving other tests between the methods of this test class, which wrecks the test fixtures
         suiteName = "ApplicationResourceTest")
@@ -608,11 +605,7 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
         String itemVersion = "1.0";
         String serviceType = "org.apache.brooklyn.entity.stock.BasicApplication";
         
-        // Deploy the catalog item
-        addTestCatalogItem(itemSymbolicName, "template", itemVersion, serviceType);
-        List<CatalogEntitySummary> itemSummaries = client().path("/catalog/applications")
-                .query("fragment", itemSymbolicName).query("allVersions", "true").get(new GenericType<List<CatalogEntitySummary>>() {});
-        CatalogItemSummary itemSummary = Iterables.getOnlyElement(itemSummaries);
+        CatalogItemSummary itemSummary = testTemplateItem(itemSymbolicName, itemVersion, serviceType);
         String itemVersionedId = String.format("%s:%s", itemSummary.getSymbolicName(), itemSummary.getVersion());
         assertEquals(itemSummary.getId(), itemVersionedId);
 
@@ -660,6 +653,15 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
         }
     }
 
+    protected CatalogEntitySummary testTemplateItem(String itemSymbolicName, String itemVersion, String serviceType) {
+        // Deploy the catalog item
+        addTestCatalogItem(itemSymbolicName, "template", itemVersion, serviceType);
+        log.info("Types after adding template: "+manager.getTypeRegistry().getAll());
+        List<CatalogEntitySummary> itemSummaries = client().path("/catalog/applications")
+                .query("fragment", itemSymbolicName).query("allVersions", "true").get(new GenericType<List<CatalogEntitySummary>>() {});
+        return Iterables.getOnlyElement(itemSummaries);
+    }
+
     private void deprecateCatalogItem(String symbolicName, String version, boolean deprecated) {
         String id = String.format("%s:%s", symbolicName, version);
         Response response = client().path(String.format("/catalog/entities/%s/deprecated", id))

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
index faec520..0a91d59 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
@@ -22,7 +22,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
-import java.awt.*;
+import java.awt.Image;
+import java.awt.Toolkit;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -47,10 +48,13 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.Configurable;
 import org.apache.brooklyn.api.objs.Identifiable;
+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.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.entity.EntityPredicates;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.enricher.stock.Aggregator;
@@ -66,6 +70,7 @@ import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.osgi.BundleMaker;
+import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.javalang.Reflections;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
@@ -93,10 +98,32 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     private static String TEST_VERSION = "0.1.2";
     private static String TEST_LASTEST_VERSION = "0.1.3";
 
+    private Collection<ManagedBundle> initialBundles;
+
     @Override
     protected boolean useLocalScannedCatalog() {
         return true;
     }
+
+    @Override
+    protected void initClass() throws Exception {
+        super.initClass();
+        // cache initially installed bundles
+        OsgiManager osgi = ((ManagementContextInternal)getManagementContext()).getOsgiManager().get();
+        initialBundles = osgi.getManagedBundles().values();
+    }
+    
+    protected void initMethod() throws Exception {
+        super.initMethod();
+        
+        // and reset OSGi container
+        OsgiManager osgi = ((ManagementContextInternal)getManagementContext()).getOsgiManager().get();
+        for (ManagedBundle b: osgi.getManagedBundles().values()) {
+            if (!initialBundles.contains(b)) {
+                osgi.uninstallUploadedBundle(b);
+            }
+        }
+    }
     
     @Test
     /** based on CampYamlLiteTest */
@@ -167,7 +194,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     public void testRegisterOsgiPolicyTopLevelSyntax() {
         TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
 
-        String symbolicName = "my.catalog.policy.id";
+        String symbolicName = "my.catalog.entity.id."+JavaClassNames.niceClassAndMethod();
         String policyType = "org.apache.brooklyn.test.osgi.entities.SimplePolicy";
         String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
 
@@ -214,7 +241,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
                 .query("fragment", "vaNIllasOFTWAREpROCESS").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(entities.size(), 1);
 
-        log.info("RedisCluster-like entities are: " + entities);
+        log.info("MAtching entities are: " + entities);
 
         List<CatalogEntitySummary> entities2 = client().path("/catalog/entities")
                 .query("regex", "[Vv]an.[alS]+oftware\\w+").get(new GenericType<List<CatalogEntitySummary>>() {});
@@ -963,8 +990,11 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
     }
 
-    @Test(dependsOnMethods = {"testGetOnlyLatestApplication"})
+    @Test
     public void testGetOnlyLatestDifferentCases() {
+        // depends on installation of this
+        testGetOnlyLatestApplication();
+        
         String symbolicName = "latest.catalog.application.id";
 
         CatalogItemSummary application = client().path("/catalog/applications/" + symbolicName + "/LaTeSt")
@@ -1018,8 +1048,11 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(application.getVersion(), TEST_LASTEST_VERSION);
     }
 
-    @Test(dependsOnMethods = {"testGetOnlyLatestApplication", "testGetOnlyLatestDifferentCases"})
+    @Test
     public void testDeleteOnlyLatestApplication() throws IOException {
+        // depends on installation of this
+        testGetOnlyLatestApplication();
+
         String symbolicName = "latest.catalog.application.id";
 
         Response deleteResponse = client().path("/catalog/applications/" + symbolicName + "/latest").delete();
@@ -1031,8 +1064,11 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test(dependsOnMethods = {"testGetOnlyLatestEntity"})
+    @Test
     public void testDeleteOnlyLatestEntity() throws IOException {
+        // depends on installation of this
+        testGetOnlyLatestEntity();
+        
         String symbolicName = "latest.catalog.entity.id";
 
         Response deleteResponse = client().path("/catalog/entities/" + symbolicName + "/latest").delete();
@@ -1044,8 +1080,11 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test(dependsOnMethods = {"testGetOnlyLatestPolicy"})
+    @Test
     public void testDeleteOnlyLatestPolicy() throws IOException {
+        // depends on installation of this
+        testGetOnlyLatestPolicy();
+        
         String symbolicName = "latest.catalog.policy.id";
 
         Response deleteResponse = client().path("/catalog/policies/" + symbolicName + "/latest").delete();
@@ -1057,8 +1096,10 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(applications.get(0).getVersion(), TEST_VERSION);
     }
 
-    @Test(dependsOnMethods = {"testGetOnlyLatestLocation"})
+    @Test
     public void testDeleteOnlyLatestLocation() throws IOException {
+        testGetOnlyLatestLocation();
+        
         String symbolicName = "latest.catalog.location.id";
 
         Response deleteResponse = client().path("/catalog/locations/" + symbolicName + "/latest").delete();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d7ebb6bb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java
index d4a484d..2c2acfd 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/LocationResourceTest.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
 import org.apache.brooklyn.core.location.LocationConfigKeys;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
@@ -58,7 +59,6 @@ public class LocationResourceTest extends BrooklynRestResourceTest {
 
     private static final Logger log = LoggerFactory.getLogger(LocationResourceTest.class);
     private String legacyLocationName = "my-jungle-legacy";
-    private String legacyLocationVersion = "0.0.0.SNAPSHOT";
     
     private String locationName = "my-jungle";
     private String locationVersion = "0.1.2";
@@ -81,7 +81,7 @@ public class LocationResourceTest extends BrooklynRestResourceTest {
         log.info("added legacy, at: " + addedLegacyLocationUri);
         LocationSummary location = client().path(response.getLocation()).get(LocationSummary.class);
         log.info(" contents: " + location);
-        assertEquals(location.getSpec(), "brooklyn.catalog:"+legacyLocationName+":"+legacyLocationVersion);
+        assertEquals(location.getSpec(), "brooklyn.catalog:"+legacyLocationName+":"+BasicBrooklynCatalog.NO_VERSION);
         assertTrue(addedLegacyLocationUri.getPath().startsWith("/locations/"));
 
         JcloudsLocation l = (JcloudsLocation) getManagementContext().getLocationRegistry().getLocationManaged(legacyLocationName);
@@ -144,7 +144,7 @@ public class LocationResourceTest extends BrooklynRestResourceTest {
         });
         LocationSummary location = Iterables.getOnlyElement(matching);
         
-        URI expectedLocationUri = URI.create(getEndpointAddress() + "/locations/"+locationName).normalize();
+        URI expectedLocationUri = URI.create(getEndpointAddress() + "/locations/"+locationName+":"+locationVersion).normalize();
         Assert.assertEquals(location.getSpec(), "brooklyn.catalog:"+locationName+":"+locationVersion);
         Assert.assertEquals(location.getLinks().get("self").toString(), expectedLocationUri.getPath());
     }


Mime
View raw message