You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/04/21 22:41:26 UTC

[07/16] incubator-brooklyn git commit: support for multi-item catalog yaml

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eaaca787/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java
index 98e5a6b..a3eb161 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/CatalogResource.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Set;
 
@@ -60,6 +61,7 @@ import brooklyn.rest.filter.HaHotStateRequired;
 import brooklyn.rest.transform.CatalogTransformer;
 import brooklyn.rest.util.WebResourceUtils;
 import brooklyn.util.ResourceUtils;
+import brooklyn.util.collections.MutableMap;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.exceptions.Exceptions;
 import brooklyn.util.stream.Streams;
@@ -96,7 +98,6 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     static Set<String> missingIcons = MutableSet.of();
     
-    @SuppressWarnings("unchecked")
     @Override
     public Response create(String yaml) {
         if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.ADD_CATALOG_ITEM, yaml)) {
@@ -104,39 +105,24 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
                 Entitlements.getEntitlementContext().user());
         }
         
-        CatalogItem<?,?> item;
+        Iterable<? extends CatalogItem<?, ?>> items; 
         try {
-            item = brooklyn().getCatalog().addItem(yaml);
+            items = brooklyn().getCatalog().addItems(yaml);
         } catch (IllegalArgumentException e) {
             return Response.status(Status.BAD_REQUEST)
                     .type(MediaType.APPLICATION_JSON)
                     .entity(ApiError.of(e))
                     .build();
         }
-        String itemId = item.getId();
-        log.info("REST created catalog item: "+item);
-
-        // FIXME configurations/ not supported
-        switch (item.getCatalogItemType()) {
-        case TEMPLATE:
-            return Response.created(URI.create("applications/" + itemId + "/" + item.getVersion()))
-                    .entity(CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<? extends Entity, EntitySpec<?>>) item))
-                    .build();
-        case ENTITY:
-            return Response.created(URI.create("entities/" + itemId + "/" + item.getVersion()))
-                    .entity(CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<? extends Entity, EntitySpec<?>>) item))
-                    .build();
-        case POLICY:
-            return Response.created(URI.create("policies/" + itemId))
-                    .entity(CatalogTransformer.catalogPolicySummary(brooklyn(), (CatalogItem<? extends Policy, PolicySpec<?>>) item))
-                    .build();
-        case LOCATION:
-            return Response.created(URI.create("locations/" + itemId + "/" + item.getVersion()))
-                    .entity(CatalogTransformer.catalogLocationSummary(brooklyn(), (CatalogItem<? extends Location, LocationSpec<?>>) item))
-                    .build();
-        default:
-            throw new IllegalStateException("Unsupported catalog item type "+item.getCatalogItemType()+": "+item);
+
+        log.info("REST created catalog items: "+items);
+
+        Map<String,Object> result = MutableMap.of();
+        
+        for (CatalogItem<?,?> item: items) {
+            result.put(item.getId(), CatalogTransformer.catalogItemSummary(brooklyn(), item));
         }
+        return Response.status(Status.CREATED).entity(result).build();
     }
 
     @Override
@@ -223,17 +209,17 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     }
 
     @Override
-    public List<CatalogEntitySummary> listEntities(String regex, String fragment) {
-        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_ENTITY, regex, fragment);
-        return cast(result, CatalogEntitySummary.class);
+    public List<CatalogEntitySummary> listEntities(String regex, String fragment, boolean allVersions) {
+        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_ENTITY, regex, fragment, allVersions);
+        return castList(result, CatalogEntitySummary.class);
     }
 
     @Override
-    public List<CatalogItemSummary> listApplications(String regex, String fragment) {
+    public List<CatalogItemSummary> listApplications(String regex, String fragment, boolean allVersions) {
         Predicate<CatalogItem<Application, EntitySpec<? extends Application>>> filter =
                 Predicates.and(CatalogPredicates.<Application,EntitySpec<? extends Application>>deprecated(false),
                         CatalogPredicates.IS_TEMPLATE);
-        return getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment);
+        return getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment, allVersions);
     }
 
     @Override
@@ -286,9 +272,9 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     }
 
     @Override
-    public List<CatalogPolicySummary> listPolicies(String regex, String fragment) {
-        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_POLICY, regex, fragment);
-        return cast(result, CatalogPolicySummary.class);
+    public List<CatalogPolicySummary> listPolicies(String regex, String fragment, boolean allVersions) {
+        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_POLICY, regex, fragment, allVersions);
+        return castList(result, CatalogPolicySummary.class);
     }
 
     @Override
@@ -328,9 +314,9 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     }
 
     @Override
-    public List<CatalogLocationSummary> listLocations(String regex, String fragment) {
-        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_LOCATION, regex, fragment);
-        return cast(result, CatalogLocationSummary.class);
+    public List<CatalogLocationSummary> listLocations(String regex, String fragment, boolean allVersions) {
+        List<CatalogItemSummary> result = getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_LOCATION, regex, fragment, allVersions);
+        return castList(result, CatalogLocationSummary.class);
     }
 
     @Override
@@ -370,13 +356,15 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
-    private <T,SpecT> List<CatalogItemSummary> getCatalogItemSummariesMatchingRegexFragment(Predicate<CatalogItem<T,SpecT>> type, String regex, String fragment) {
+    private <T,SpecT> List<CatalogItemSummary> getCatalogItemSummariesMatchingRegexFragment(Predicate<CatalogItem<T,SpecT>> type, String regex, String fragment, boolean allVersions) {
         List filters = new ArrayList();
         filters.add(type);
         if (Strings.isNonEmpty(regex))
             filters.add(CatalogPredicates.xml(StringPredicates.containsRegex(regex)));
         if (Strings.isNonEmpty(fragment))
             filters.add(CatalogPredicates.xml(StringPredicates.containsLiteralIgnoreCase(fragment)));
+        if (!allVersions)
+            filters.add(CatalogPredicates.isBestVersion(mgmt()));
         
         filters.add(CatalogPredicates.entitledToSee(mgmt()));
 
@@ -464,7 +452,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements Cat
 
     // TODO Move to an appropriate utility class?
     @SuppressWarnings("unchecked")
-    private static <T> List<T> cast(List<? super T> list, Class<T> elementType) {
+    private static <T> List<T> castList(List<? super T> list, Class<T> elementType) {
         List<T> result = Lists.newArrayList();
         for (Object element : list) {
             result.add((T) element);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eaaca787/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
index 362d152..74185d7 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/LocationResource.java
@@ -29,7 +29,6 @@ import javax.ws.rs.core.Response;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.catalog.CatalogItem;
 import brooklyn.location.Location;
 import brooklyn.location.LocationDefinition;
 import brooklyn.location.basic.LocationConfigKeys;
@@ -51,6 +50,7 @@ import com.google.common.collect.FluentIterable;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Sets;
 
+@SuppressWarnings("deprecation")
 @HaHotStateRequired
 public class LocationResource extends AbstractBrooklynRestResource implements LocationApi {
 
@@ -142,7 +142,7 @@ public class LocationResource extends AbstractBrooklynRestResource implements Lo
               }
           }
 
-          CatalogItem<?, ?> item = brooklyn().getCatalog().addItem(Joiner.on("\n").join(yaml.build()));
+          brooklyn().getCatalog().addItems(Joiner.on("\n").join(yaml.build()));
           LocationDefinition l = brooklyn().getLocationRegistry().getDefinedLocationByName(name);
           return Response.created(URI.create(name))
                   .entity(LocationTransformer.newInstance(mgmt(), l, LocationDetailLevel.LOCAL_EXCLUDING_SECRET))

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eaaca787/usage/rest-server/src/main/java/brooklyn/rest/transform/CatalogTransformer.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/CatalogTransformer.java b/usage/rest-server/src/main/java/brooklyn/rest/transform/CatalogTransformer.java
index adee3e2..053a9c3 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/transform/CatalogTransformer.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/CatalogTransformer.java
@@ -49,13 +49,13 @@ import brooklyn.rest.domain.SensorSummary;
 import brooklyn.rest.domain.SummaryComparators;
 import brooklyn.rest.util.BrooklynRestResourceUtils;
 import brooklyn.util.collections.MutableMap;
+import brooklyn.util.exceptions.Exceptions;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
 
 public class CatalogTransformer {
 
-    @SuppressWarnings("unused")
     private static final org.slf4j.Logger log = LoggerFactory.getLogger(CatalogTransformer.class);
     
     public static CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Entity,EntitySpec<?>> item) {
@@ -81,10 +81,27 @@ public class CatalogTransformer {
             item.isDeprecated(), makeLinks(item));
     }
 
+    @SuppressWarnings("unchecked")
     public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, CatalogItem<?,?> item) {
+        try {
+            switch (item.getCatalogItemType()) {
+            case TEMPLATE:
+            case ENTITY:
+                return catalogEntitySummary(b, (CatalogItem<? extends Entity, EntitySpec<?>>) item);
+            case POLICY:
+                return catalogPolicySummary(b, (CatalogItem<? extends Policy, PolicySpec<?>>) item);
+            case LOCATION:
+                return catalogLocationSummary(b, (CatalogItem<? extends Location, LocationSpec<?>>) item);
+            default:
+                log.warn("Unexpected catalog item type when getting self link (supplying generic item): "+item.getCatalogItemType()+" "+item);
+            }
+        } 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.getJavaType(), item.getPlanYaml(),
-                item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), item.isDeprecated(), makeLinks(item));
+            item.getJavaType(), item.getPlanYaml(),
+            item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), item.isDeprecated(), makeLinks(item));
     }
 
     public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Policy,PolicySpec<?>> item) {
@@ -104,12 +121,29 @@ public class CatalogTransformer {
     }
 
     protected static Map<String, URI> makeLinks(CatalogItem<?,?> item) {
-        return MutableMap.<String, URI>of();
+        return MutableMap.<String, URI>of().addIfNotNull("self", URI.create(getSelfLink(item)));
+    }
+
+    protected static String getSelfLink(CatalogItem<?,?> item) {
+        String itemId = item.getId();
+        switch (item.getCatalogItemType()) {
+        case TEMPLATE:
+            return "/v1/applications/" + itemId + "/" + item.getVersion();
+        case ENTITY:
+            return "/v1/entities/" + itemId + "/" + item.getVersion();
+        case POLICY:
+            return "/v1/policies/" + itemId + "/" + item.getVersion();
+        case LOCATION:
+            return "/v1/locations/" + itemId + "/" + item.getVersion();
+        default:
+            log.warn("Unexpected catalog item type when getting self link (not supplying self link): "+item.getCatalogItemType()+" "+item);
+            return null;
+        }
     }
-    
     private static String tidyIconLink(BrooklynRestResourceUtils b, CatalogItem<?,?> item, String iconUrl) {
         if (b.isUrlServerSideAndSafe(iconUrl))
             return "/v1/catalog/icon/"+item.getSymbolicName() + "/" + item.getVersion();
         return iconUrl;
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eaaca787/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogResourceTest.java
index eb8b848..69dc58d 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/CatalogResourceTest.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import javax.ws.rs.core.MediaType;
@@ -76,7 +77,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
     @Test
     /** based on CampYamlLiteTest */
-    public void testRegisterCustomEntityWithBundleWhereEntityIsFromCoreAndIconFromBundle() {
+    public void testRegisterCustomEntityTopLevelSyntaxWithBundleWhereEntityIsFromCoreAndIconFromBundle() {
         TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
 
         String symbolicName = "my.catalog.entity.id";
@@ -127,7 +128,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     }
 
     @Test
-    public void testRegisterOSGiPolicy() {
+    public void testRegisterOsgiPolicyTopLevelSyntax() {
         TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
 
         String symbolicName = "my.catalog.policy.id";
@@ -146,8 +147,8 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
                 "brooklyn.policies:\n"+
                 "- type: " + policyType;
 
-        CatalogPolicySummary entityItem = client().resource("/v1/catalog")
-                .post(CatalogPolicySummary.class, yaml);
+        CatalogPolicySummary entityItem = Iterables.getOnlyElement( client().resource("/v1/catalog")
+                .post(new GenericType<Map<String,CatalogPolicySummary>>() {}, yaml).values() );
 
         Assert.assertNotNull(entityItem.getPlanYaml());
         Assert.assertTrue(entityItem.getPlanYaml().contains(policyType));
@@ -158,6 +159,14 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
     @Test
     public void testListAllEntities() {
+        List<CatalogEntitySummary> entities = client().resource("/v1/catalog/entities")
+                .get(new GenericType<List<CatalogEntitySummary>>() {});
+        assertTrue(entities.size() > 0);
+    }
+
+    @Test
+    public void testListAllEntitiesAsItem() {
+        // ensure things are happily downcasted and unknown properties ignored (e.g. sensors, effectors)
         List<CatalogItemSummary> entities = client().resource("/v1/catalog/entities")
                 .get(new GenericType<List<CatalogItemSummary>>() {});
         assertTrue(entities.size() > 0);
@@ -165,24 +174,24 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
     @Test
     public void testFilterListOfEntitiesByName() {
-        List<CatalogItemSummary> entities = client().resource("/v1/catalog/entities")
-                .queryParam("fragment", "reDISclusTER").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> entities = client().resource("/v1/catalog/entities")
+                .queryParam("fragment", "reDISclusTER").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(entities.size(), 1);
 
         log.info("RedisCluster-like entities are: " + entities);
 
-        List<CatalogItemSummary> entities2 = client().resource("/v1/catalog/entities")
-                .queryParam("regex", "[Rr]ed.[sulC]+ter").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> entities2 = client().resource("/v1/catalog/entities")
+                .queryParam("regex", "[Rr]ed.[sulC]+ter").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(entities2.size(), 1);
 
         assertEquals(entities, entities2);
     
-        List<CatalogItemSummary> entities3 = client().resource("/v1/catalog/entities")
-                .queryParam("fragment", "bweqQzZ").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> entities3 = client().resource("/v1/catalog/entities")
+                .queryParam("fragment", "bweqQzZ").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(entities3.size(), 0);
 
-        List<CatalogItemSummary> entities4 = client().resource("/v1/catalog/entities")
-                .queryParam("regex", "bweq+z+").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> entities4 = client().resource("/v1/catalog/entities")
+                .queryParam("regex", "bweq+z+").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(entities4.size(), 0);
     }
 
@@ -215,7 +224,7 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     @Test
     public void testGetCatalogEntityIconDetails() throws IOException {
         String catalogItemId = "testGetCatalogEntityIconDetails";
-        addTestCatalogItem(catalogItemId);
+        addTestCatalogItemRedisAsEntity(catalogItemId);
         ClientResponse response = client().resource(URI.create("/v1/catalog/icon/" + catalogItemId + "/" + TEST_VERSION))
                 .get(ClientResponse.class);
         response.bufferEntity();
@@ -225,15 +234,16 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         Assert.assertNotNull(image);
     }
 
-    private void addTestCatalogItem(String catalogItemId) {
-        addTestCatalogItem(catalogItemId, TEST_VERSION, "brooklyn.entity.nosql.redis.RedisStore");
+    private void addTestCatalogItemRedisAsEntity(String catalogItemId) {
+        addTestCatalogItem(catalogItemId, null, TEST_VERSION, "brooklyn.entity.nosql.redis.RedisStore");
     }
 
-    private void addTestCatalogItem(String catalogItemId, String version, String service) {
+    private void addTestCatalogItem(String catalogItemId, String itemType, String version, String service) {
         String yaml =
                 "brooklyn.catalog:\n"+
                 "  id: " + catalogItemId + "\n"+
                 "  name: My Catalog App\n"+
+                (itemType!=null ? "  item_type: "+itemType+"\n" : "")+
                 "  description: My description\n"+
                 "  icon_url: classpath:///redis-logo.png\n"+
                 "  version: " + version + "\n"+
@@ -248,8 +258,8 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
     @Test
     public void testListPolicies() {
-        Set<CatalogItemSummary> policies = client().resource("/v1/catalog/policies")
-                .get(new GenericType<Set<CatalogItemSummary>>() {});
+        Set<CatalogPolicySummary> policies = client().resource("/v1/catalog/policies")
+                .get(new GenericType<Set<CatalogPolicySummary>>() {});
 
         assertTrue(policies.size() > 0);
         CatalogItemSummary asp = null;
@@ -275,8 +285,9 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
                 "- type: " + locationType);
 
         // Create location item
-        CatalogLocationSummary locationItem = client().resource("/v1/catalog")
-                .post(CatalogLocationSummary.class, yaml);
+        Map<String, CatalogLocationSummary> items = client().resource("/v1/catalog")
+                .post(new GenericType<Map<String,CatalogLocationSummary>>() {}, yaml);
+        CatalogLocationSummary locationItem = Iterables.getOnlyElement(items.values());
 
         Assert.assertNotNull(locationItem.getPlanYaml());
         Assert.assertTrue(locationItem.getPlanYaml().contains(locationType));
@@ -343,10 +354,10 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     public void testSetDeprecated() {
         String itemId = "my.catalog.item.id.for.deprecation";
         String serviceType = "brooklyn.entity.basic.BasicApplication";
-        addTestCatalogItem(itemId, TEST_VERSION, serviceType);
-        addTestCatalogItem(itemId, "2.0", serviceType);
-        List<CatalogItemSummary> applications = client().resource("/v1/catalog/applications")
-                .queryParam("fragment", itemId).get(new GenericType<List<CatalogItemSummary>>() {});
+        addTestCatalogItem(itemId, "template", TEST_VERSION, serviceType);
+        addTestCatalogItem(itemId, "template", "2.0", serviceType);
+        List<CatalogEntitySummary> applications = client().resource("/v1/catalog/applications")
+                .queryParam("fragment", itemId).queryParam("allVersions", "true").get(new GenericType<List<CatalogEntitySummary>>() {});
         assertEquals(applications.size(), 2);
         CatalogItemSummary summary0 = applications.get(0);
         CatalogItemSummary summary1 = applications.get(1);
@@ -359,8 +370,8 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
         assertEquals(getDeprecationResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
 
-        List<CatalogItemSummary> applicationsAfterDeprecation = client().resource("/v1/catalog/applications")
-                .queryParam("fragment", "basicapp").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> applicationsAfterDeprecation = client().resource("/v1/catalog/applications")
+                .queryParam("fragment", "basicapp").queryParam("allVersions", "true").get(new GenericType<List<CatalogEntitySummary>>() {});
 
         assertEquals(applicationsAfterDeprecation.size(), 1);
         assertTrue(applicationsAfterDeprecation.contains(summary1));
@@ -370,8 +381,8 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
 
         assertEquals(getUnDeprecationResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
 
-        List<CatalogItemSummary> applicationsAfterUnDeprecation = client().resource("/v1/catalog/applications")
-                .queryParam("fragment", "basicapp").get(new GenericType<List<CatalogItemSummary>>() {});
+        List<CatalogEntitySummary> applicationsAfterUnDeprecation = client().resource("/v1/catalog/applications")
+                .queryParam("fragment", "basicapp").queryParam("allVersions", "true").get(new GenericType<List<CatalogEntitySummary>>() {});
 
         assertEquals(applications, applicationsAfterUnDeprecation);
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/eaaca787/utils/common/src/main/java/brooklyn/util/yaml/Yamls.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/yaml/Yamls.java b/utils/common/src/main/java/brooklyn/util/yaml/Yamls.java
index 2bcbe87..d13edcb 100644
--- a/utils/common/src/main/java/brooklyn/util/yaml/Yamls.java
+++ b/utils/common/src/main/java/brooklyn/util/yaml/Yamls.java
@@ -317,6 +317,17 @@ public class Yamls {
         }
 
         @Beta
+        public String getMatchedYamlTextOrWarn() {
+            try {
+                return getMatchedYamlText();
+            } catch (Exception e) {
+                Exceptions.propagateIfFatal(e);
+                log.warn("Unable to match yaml text in "+this+": "+e, e);
+                return null;
+            }
+        }
+        
+        @Beta
         public String getMatchedYamlText() {
             if (!found()) return null;
             
@@ -484,6 +495,7 @@ b: 1
      * where {@link YamlExtract#isMatch()} is false and {@link YamlExtract#getError()} is set. */
     public static YamlExtract getTextOfYamlAtPath(String yaml, Object ...path) {
         YamlExtract result = new YamlExtract();
+        if (yaml==null) return result;
         try {
             int pathIndex = 0;
             result.yaml = yaml;