brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] incubator-brooklyn git commit: Allows catalog items to be deprecated
Date Thu, 05 Mar 2015 09:53:52 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 1f3bff401 -> 1b0037b60


Allows catalog items to be deprecated


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

Branch: refs/heads/master
Commit: f0fe508941d90c0a76f20542d51b9d8182b23740
Parents: d2e1487
Author: Martin Harris <github@nakomis.com>
Authored: Thu Mar 5 09:29:52 2015 +0000
Committer: Martin Harris <github@nakomis.com>
Committed: Thu Mar 5 09:29:52 2015 +0000

----------------------------------------------------------------------
 .../java/brooklyn/catalog/BrooklynCatalog.java  |  3 ++
 .../main/java/brooklyn/catalog/CatalogItem.java |  6 +++
 .../main/java/brooklyn/entity/EntityType.java   |  1 -
 .../brooklyn/mementos/CatalogItemMemento.java   |  2 +
 .../brooklyn/catalog/CatalogPredicates.java     |  9 ++++
 .../catalog/internal/BasicBrooklynCatalog.java  | 10 +++++
 .../catalog/internal/CatalogItemDo.java         | 12 ++++-
 .../internal/CatalogItemDtoAbstract.java        | 11 +++++
 .../rebind/BasicCatalogItemRebindSupport.java   |  1 +
 .../rebind/dto/BasicCatalogItemMemento.java     | 17 ++++++-
 .../entity/rebind/dto/MementosGenerators.java   |  3 +-
 .../entity/rebind/RebindCatalogItemTest.java    | 20 ++++++++-
 .../main/java/brooklyn/rest/api/CatalogApi.java |  7 +++
 .../rest/domain/CatalogEntitySummary.java       |  6 ++-
 .../rest/domain/CatalogItemSummary.java         | 12 ++++-
 .../rest/domain/CatalogPolicySummary.java       |  3 +-
 .../rest/resources/CatalogResource.java         | 21 ++++++++-
 .../rest/transform/CatalogTransformer.java      |  6 +--
 .../rest/resources/CatalogResourceTest.java     | 47 +++++++++++++++++++-
 19 files changed, 180 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/api/src/main/java/brooklyn/catalog/BrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/catalog/BrooklynCatalog.java b/api/src/main/java/brooklyn/catalog/BrooklynCatalog.java
index 42e4218..e2b39b0 100644
--- a/api/src/main/java/brooklyn/catalog/BrooklynCatalog.java
+++ b/api/src/main/java/brooklyn/catalog/BrooklynCatalog.java
@@ -65,6 +65,9 @@ public interface BrooklynCatalog {
     /** convenience for filtering items in the catalog; see CatalogPredicates for useful
filters */
     <T,SpecT> Iterable<CatalogItem<T,SpecT>> getCatalogItems(Predicate<?
super CatalogItem<T,SpecT>> filter);
 
+    /** persists the catalog item to the object store, if persistence is enabled */
+    public void persist(CatalogItem<?, ?> catalogItem);
+
     /** @return The classloader which should be used to load classes and entities;
      * this includes all the catalog's classloaders in the right order */
     public ClassLoader getRootClassLoader();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/api/src/main/java/brooklyn/catalog/CatalogItem.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/catalog/CatalogItem.java b/api/src/main/java/brooklyn/catalog/CatalogItem.java
index d3824fd..4dd63fa 100644
--- a/api/src/main/java/brooklyn/catalog/CatalogItem.java
+++ b/api/src/main/java/brooklyn/catalog/CatalogItem.java
@@ -94,4 +94,10 @@ public interface CatalogItem<T,SpecT> extends BrooklynObject, Rebindable
{
     @Override
     public String getCatalogItemId();
 
+    public void setDeprecated(boolean deprecated);
+
+    /**
+     * @return True if the item has been deprecated and should not be shown in the catalog
+     */
+    boolean isDeprecated();
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/api/src/main/java/brooklyn/entity/EntityType.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/entity/EntityType.java b/api/src/main/java/brooklyn/entity/EntityType.java
index de8bdfe..fd7ae72 100644
--- a/api/src/main/java/brooklyn/entity/EntityType.java
+++ b/api/src/main/java/brooklyn/entity/EntityType.java
@@ -22,7 +22,6 @@ import java.util.NoSuchElementException;
 import java.util.Set;
 
 import brooklyn.basic.BrooklynType;
-import brooklyn.config.ConfigKey;
 import brooklyn.event.Sensor;
 import brooklyn.util.guava.Maybe;
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/api/src/main/java/brooklyn/mementos/CatalogItemMemento.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/mementos/CatalogItemMemento.java b/api/src/main/java/brooklyn/mementos/CatalogItemMemento.java
index 36d497d..8bc1936 100644
--- a/api/src/main/java/brooklyn/mementos/CatalogItemMemento.java
+++ b/api/src/main/java/brooklyn/mementos/CatalogItemMemento.java
@@ -44,4 +44,6 @@ public interface CatalogItemMemento extends Memento {
 
     Class<?> getSpecType();
 
+    boolean isDeprecated();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/CatalogPredicates.java b/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
index c2872fe..82ab689 100644
--- a/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
+++ b/core/src/main/java/brooklyn/catalog/CatalogPredicates.java
@@ -43,6 +43,15 @@ public class CatalogPredicates {
         };
     }
 
+    public static <T,SpecT> Predicate<CatalogItem<T,SpecT>> deprecated(final
boolean deprecated) {
+        return new Predicate<CatalogItem<T,SpecT>>() {
+            @Override
+            public boolean apply(@Nullable CatalogItem<T,SpecT> item) {
+                return (item != null) && item.isDeprecated() == deprecated;
+            }
+        };
+    }
+
     public static final Predicate<CatalogItem<Application,EntitySpec<? extends Application>>>
IS_TEMPLATE = 
             CatalogPredicates.<Application,EntitySpec<? extends Application>>isCatalogItemType(CatalogItemType.TEMPLATE);
     public static final Predicate<CatalogItem<Entity,EntitySpec<?>>> IS_ENTITY
= 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
index 6b61b44..5c5e05f 100644
--- a/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
+++ b/core/src/main/java/brooklyn/catalog/internal/BasicBrooklynCatalog.java
@@ -18,6 +18,7 @@
  */
 package brooklyn.catalog.internal;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import io.brooklyn.camp.CampPlatform;
 import io.brooklyn.camp.spi.AssemblyTemplate;
@@ -272,6 +273,12 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             return (CatalogItem<T,SpecT>)result;
         return null;
     }
+
+    @Override
+    public void persist(CatalogItem<?, ?> catalogItem) {
+        checkArgument(getCatalogItem(catalogItem.getSymbolicName(), catalogItem.getVersion())
!= null, "Unknown catalog item %s", catalogItem);
+        mgmt.getRebindManager().getChangeListener().onChanged(catalogItem);
+    }
     
     @Override
     public ClassLoader getRootClassLoader() {
@@ -453,6 +460,7 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
         final String description = (String) catalog.getMaybe("description").orNull();
         final String iconUrl = (String) catalog.getMaybe("iconUrl").orNull();
         final String iconUrlUnderscore = (String) catalog.getMaybe("icon_url").orNull();
+        final String deprecated = (String) catalog.getMaybe("deprecated").orNull();
 
         if ((Strings.isNonBlank(id) || Strings.isNonBlank(symbolicName)) && 
                 Strings.isNonBlank(displayName) &&
@@ -526,6 +534,8 @@ public class BasicBrooklynCatalog implements BrooklynCatalog {
             catalogIconUrl = null;
         }
 
+        final Boolean catalogDeprecated = Boolean.valueOf(deprecated);
+
         CatalogUtils.installLibraries(mgmt, libraries);
 
         String versionedId = CatalogUtils.getVersionedId(catalogSymbolicName, catalogVersion);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
index b38d560..1fb0707 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDo.java
@@ -80,7 +80,17 @@ public class CatalogItemDo<T,SpecT> implements CatalogItem<T,SpecT>,
BrooklynObj
     public String getCatalogItemId() {
         return itemDto.getCatalogItemId();
     }
-    
+
+    @Override
+    public void setDeprecated(boolean deprecated) {
+        itemDto.setDeprecated(deprecated);
+    }
+
+    @Override
+    public boolean isDeprecated() {
+        return itemDto.isDeprecated();
+    }
+
     @Override
     public void setCatalogItemId(String id) {
         itemDto.setCatalogItemId(id);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
index 521f4d6..523cd79 100644
--- a/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
+++ b/core/src/main/java/brooklyn/catalog/internal/CatalogItemDtoAbstract.java
@@ -62,6 +62,7 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynO
 
     private @SetFromFlag Collection<CatalogBundle> libraries;
     private @SetFromFlag Set<Object> tags = Sets.newLinkedHashSet();
+    private @SetFromFlag boolean deprecated;
 
     /**
      * Config not supported for catalog item. See {@link #getPlanYaml()}.
@@ -135,6 +136,16 @@ public abstract class CatalogItemDtoAbstract<T, SpecT> extends
AbstractBrooklynO
         }
     }
 
+    @Override
+    public boolean isDeprecated() {
+        return deprecated;
+    }
+
+    @Override
+    public void setDeprecated(boolean deprecated) {
+        this.deprecated = deprecated;
+    }
+
     @Nonnull
     @Override
     public Collection<CatalogBundle> getLibraries() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/entity/rebind/BasicCatalogItemRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/BasicCatalogItemRebindSupport.java
b/core/src/main/java/brooklyn/entity/rebind/BasicCatalogItemRebindSupport.java
index 8ef2931..62528b9 100644
--- a/core/src/main/java/brooklyn/entity/rebind/BasicCatalogItemRebindSupport.java
+++ b/core/src/main/java/brooklyn/entity/rebind/BasicCatalogItemRebindSupport.java
@@ -50,6 +50,7 @@ public class BasicCatalogItemRebindSupport extends AbstractBrooklynObjectRebindS
                 .put("version", memento.getVersion())
                 .put("libraries", memento.getLibraries())
                 .put("planYaml", memento.getPlanYaml())
+                .put("deprecated", memento.isDeprecated())
                 .build(), instance);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/entity/rebind/dto/BasicCatalogItemMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/dto/BasicCatalogItemMemento.java b/core/src/main/java/brooklyn/entity/rebind/dto/BasicCatalogItemMemento.java
index 5c07c65..75610f8 100644
--- a/core/src/main/java/brooklyn/entity/rebind/dto/BasicCatalogItemMemento.java
+++ b/core/src/main/java/brooklyn/entity/rebind/dto/BasicCatalogItemMemento.java
@@ -53,6 +53,7 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
         protected CatalogItem.CatalogItemType catalogItemType;
         protected Class<?> catalogItemJavaType;
         protected Class<?> specType;
+        protected boolean deprecated;
 
         public Builder description(String description) {
             this.description = description;
@@ -104,6 +105,11 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
             return self();
         }
 
+        public Builder deprecated(boolean deprecated) {
+            this.deprecated = deprecated;
+            return self();
+        }
+
         public Builder from(CatalogItemMemento other) {
             super.from(other);
             description = other.getDescription();
@@ -116,6 +122,7 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
             catalogItemType = other.getCatalogItemType();
             catalogItemJavaType = other.getCatalogItemJavaType();
             specType = other.getSpecType();
+            deprecated = other.isDeprecated();
             return self();
         }
 
@@ -134,6 +141,7 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
     private CatalogItem.CatalogItemType catalogItemType;
     private Class<?> catalogItemJavaType;
     private Class<?> specType;
+    private boolean deprecated;
 
     @SuppressWarnings("unused") // For deserialisation
     private BasicCatalogItemMemento() {}
@@ -150,6 +158,7 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
         this.catalogItemType = builder.catalogItemType;
         this.specType = builder.specType;
         this.javaType = builder.javaType;
+        this.deprecated = builder.deprecated;
     }
 
     @Override
@@ -212,6 +221,11 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
     }
 
     @Override
+    public boolean isDeprecated() {
+        return deprecated;
+    }
+
+    @Override
     protected void setCustomFields(Map<String, Object> fields) {
         if (!fields.isEmpty()) {
             throw new UnsupportedOperationException("Cannot set custom fields on " + this
+ ". " +
@@ -236,7 +250,8 @@ public class BasicCatalogItemMemento extends AbstractMemento implements
CatalogI
                 .add("catalogItemJavaType", getCatalogItemJavaType())
                 .add("catalogItemType", getCatalogItemType())
                 .add("javaType", getJavaType())
-                .add("specType", getSpecType());
+                .add("specType", getSpecType())
+                .add("deprecated", isDeprecated());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/main/java/brooklyn/entity/rebind/dto/MementosGenerators.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/dto/MementosGenerators.java b/core/src/main/java/brooklyn/entity/rebind/dto/MementosGenerators.java
index ed2ad0f..a81edef 100644
--- a/core/src/main/java/brooklyn/entity/rebind/dto/MementosGenerators.java
+++ b/core/src/main/java/brooklyn/entity/rebind/dto/MementosGenerators.java
@@ -375,7 +375,8 @@ public class MementosGenerators {
             .symbolicName(catalogItem.getSymbolicName())
             .specType(catalogItem.getSpecType())
             .version(catalogItem.getVersion())
-            .planYaml(catalogItem.getPlanYaml());
+            .planYaml(catalogItem.getPlanYaml())
+            .deprecated(catalogItem.isDeprecated());
         return builder.build();
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/core/src/test/java/brooklyn/entity/rebind/RebindCatalogItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/rebind/RebindCatalogItemTest.java b/core/src/test/java/brooklyn/entity/rebind/RebindCatalogItemTest.java
index 29266e7..4454354 100644
--- a/core/src/test/java/brooklyn/entity/rebind/RebindCatalogItemTest.java
+++ b/core/src/test/java/brooklyn/entity/rebind/RebindCatalogItemTest.java
@@ -19,6 +19,7 @@
 package brooklyn.entity.rebind;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 import io.brooklyn.camp.BasicCampPlatform;
@@ -32,7 +33,6 @@ import org.testng.annotations.Test;
 
 import brooklyn.camp.lite.CampPlatformWithJustBrooklynMgmt;
 import brooklyn.camp.lite.TestAppAssemblyInstantiator;
-import brooklyn.catalog.BrooklynCatalog;
 import brooklyn.catalog.CatalogItem;
 import brooklyn.catalog.CatalogLoadMode;
 import brooklyn.catalog.internal.BasicBrooklynCatalog;
@@ -192,6 +192,24 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp {
         rebindAndAssertCatalogsAreEqual();
     }
 
+    @Test
+    public void testRebindAfterItemDeprecated() {
+        String yaml =
+                "name: rebind-yaml-catalog-item-test\n" +
+                "brooklyn.catalog:\n" +
+                "  version: " + TEST_VERSION + "\n" +
+                "services:\n" +
+                "- type: io.camp.mock:AppServer";
+        BasicBrooklynCatalog catalog = (BasicBrooklynCatalog) origManagementContext.getCatalog();
+        CatalogItem<?, ?> catalogItem = catalog.addItem(yaml);
+        assertNotNull(catalogItem, "catalogItem");
+        catalogItem.setDeprecated(true);
+        catalog.persist(catalogItem);
+        rebindAndAssertCatalogsAreEqual();
+        CatalogItem<?, ?> catalogItemAfterRebind = newManagementContext.getCatalog().getCatalogItem("rebind-yaml-catalog-item-test",
TEST_VERSION);
+        assertTrue(catalogItemAfterRebind.isDeprecated(), "Expected item to be deprecated");
+    }
+
     private void rebindAndAssertCatalogsAreEqual() {
         try {
             rebind();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java
index a6c5bff..1a03134 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/CatalogApi.java
@@ -228,5 +228,12 @@ public interface CatalogApi {
         @ApiParam(name = "version", value = "version identifier of catalog item (application,
entity, policy)", required=true)
         @PathParam("version") String version);
 
+    @POST
+    @Path("/entities/{itemId}/deprecated/{deprecated}")
+    public void setDeprecated(
+        @ApiParam(name = "itemId", value = "The ID of the catalog item to be deprecated",
required = true)
+        @PathParam("itemId") String itemId,
+        @ApiParam(name = "deprecated", value = "Whether or not the catalog item is deprecated",
required = true)
+        @PathParam("deprecated") boolean deprecated);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogEntitySummary.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogEntitySummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogEntitySummary.java
index 2933451..d383365 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogEntitySummary.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogEntitySummary.java
@@ -41,9 +41,10 @@ public class CatalogEntitySummary extends CatalogItemSummary {
             @JsonProperty("config") Set<EntityConfigSummary> config, 
             @JsonProperty("sensors") Set<SensorSummary> sensors, 
             @JsonProperty("effectors") Set<EffectorSummary> effectors,
+            @JsonProperty("deprecated") boolean deprecated,
             @JsonProperty("links") Map<String, URI> links
         ) {
-        super(symbolicName, version, name, javaType, planYaml, description, iconUrl, links);
+        super(symbolicName, version, name, javaType, planYaml, description, iconUrl, deprecated,
links);
         this.config = config;
         this.sensors = sensors;
         this.effectors = effectors;
@@ -66,6 +67,7 @@ public class CatalogEntitySummary extends CatalogItemSummary {
         return super.toString()+"["+
                 "config="+getConfig()+"; " +
                 "sensors="+getSensors()+"; "+
-                "effectors="+getEffectors()+"]";
+                "effectors="+getEffectors()+"; "+
+                "deprecated="+isDeprecated()+"]";
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java
index 553450c..570043a 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogItemSummary.java
@@ -49,6 +49,7 @@ public class CatalogItemSummary implements HasId, HasName {
     @JsonSerialize(include=Inclusion.NON_EMPTY)
     private final String iconUrl;
     private final String planYaml;
+    private final boolean deprecated;
     
     private final Map<String, URI> links;
 
@@ -60,8 +61,9 @@ public class CatalogItemSummary implements HasId, HasName {
             @JsonProperty("planYaml") String planYaml,
             @JsonProperty("description") String description,
             @JsonProperty("iconUrl") String iconUrl,
+            @JsonProperty("deprecated") boolean deprecated,
             @JsonProperty("links") Map<String, URI> links
-        ) {
+            ) {
         this.id = symbolicName + ":" + version;
         this.symbolicName = symbolicName;
         this.type = symbolicName;
@@ -72,6 +74,7 @@ public class CatalogItemSummary implements HasId, HasName {
         this.description = description;
         this.iconUrl = iconUrl;
         this.links = (links == null) ? ImmutableMap.<String, URI>of() : ImmutableMap.copyOf(links);
+        this.deprecated = deprecated;
     }
 
     @Override
@@ -116,17 +119,22 @@ public class CatalogItemSummary implements HasId, HasName {
         return links;
     }
 
+    public boolean isDeprecated() {
+        return deprecated;
+    }
+
     @Override
     public String toString() {
         return Objects.toStringHelper(this)
                 .add("id", symbolicName)
                 .add("version", version)
+                .add("deprecated", deprecated)
                 .toString();
     }
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(symbolicName, version, name, javaType);
+        return Objects.hashCode(symbolicName, version, name, javaType, deprecated);
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogPolicySummary.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogPolicySummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogPolicySummary.java
index 000bd85..daef120 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogPolicySummary.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/CatalogPolicySummary.java
@@ -39,9 +39,10 @@ public class CatalogPolicySummary extends CatalogItemSummary {
             @JsonProperty("description") String description,
             @JsonProperty("iconUrl") String iconUrl,
             @JsonProperty("config") Set<PolicyConfigSummary> config,
+            @JsonProperty("deprecated") boolean deprecated,
             @JsonProperty("links") Map<String, URI> links
         ) {
-        super(symbolicName, version, name, javaType, planYaml, description, iconUrl, links);
+        super(symbolicName, version, name, javaType, planYaml, description, iconUrl, deprecated,
links);
         // TODO expose config from policies
         this.config = (config == null) ? ImmutableSet.<PolicyConfigSummary>of() : config;
     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/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 535d923..baf25b7 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
@@ -40,6 +40,7 @@ import brooklyn.catalog.internal.BasicBrooklynCatalog;
 import brooklyn.catalog.internal.CatalogDto;
 import brooklyn.catalog.internal.CatalogItemComparator;
 import brooklyn.catalog.internal.CatalogUtils;
+import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
 import brooklyn.entity.proxying.EntitySpec;
 import brooklyn.management.entitlement.Entitlements;
@@ -67,6 +68,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.io.Files;
 import com.sun.jersey.core.header.FormDataContentDisposition;
+import com.wordnik.swagger.core.ApiParam;
 
 public class CatalogResource extends AbstractBrooklynRestResource implements CatalogApi {
 
@@ -176,10 +178,12 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
 
     @Override
     public List<CatalogItemSummary> listApplications(String regex, String fragment)
{
-        return getCatalogItemSummariesMatchingRegexFragment(CatalogPredicates.IS_TEMPLATE,
regex, fragment);
+        Predicate<CatalogItem<Application, EntitySpec<? extends Application>>>
filter =
+                Predicates.and(CatalogPredicates.<Application,EntitySpec<? extends
Application>>deprecated(false),
+                        CatalogPredicates.IS_TEMPLATE);
+        return getCatalogItemSummariesMatchingRegexFragment(filter, regex, fragment);
     }
 
-    
     @Override
     @Deprecated
     public CatalogEntitySummary getEntity(String entityId) {
@@ -311,6 +315,19 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
         return getCatalogItemIcon(result);
     }
 
+    @Override
+    public void setDeprecated(String itemId, boolean deprecated) {
+        if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_CATALOG_ITEM,
StringAndArgument.of(itemId, "deprecated"))) {
+            throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify catalog",
+                    Entitlements.getEntitlementContext().user());
+        }
+        CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(mgmt(),
itemId);
+        if (item==null)
+            throw WebResourceUtils.notFound("Catalog item with id '%s' not found", itemId);
+        item.setDeprecated(deprecated);
+        mgmt().getCatalog().persist(item);
+    }
+
     private Response getCatalogItemIcon(CatalogItem<?, ?> result) {
         String url = result.getIconUrl();
         if (url==null) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/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 261dfb9..7222141 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
@@ -74,13 +74,13 @@ public class CatalogTransformer {
             item.getJavaType(), item.getPlanYaml(),
             item.getDescription(), tidyIconLink(b, item, item.getIconUrl()),
             config, sensors, effectors,
-            makeLinks(item));
+            item.isDeprecated(), makeLinks(item));
     }
 
     public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, CatalogItem<?,?>
item) {
         return new CatalogItemSummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
                 item.getJavaType(), item.getPlanYaml(),
-                item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), makeLinks(item));
+                item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), item.isDeprecated(),
makeLinks(item));
     }
 
     public static CatalogPolicySummary catalogPolicySummary(BrooklynRestResourceUtils b,
CatalogItem<? extends Policy,PolicySpec<?>> item) {
@@ -88,7 +88,7 @@ public class CatalogTransformer {
         return new CatalogPolicySummary(item.getSymbolicName(), item.getVersion(), item.getDisplayName(),
                 item.getJavaType(), item.getPlanYaml(),
                 item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), config,
-                makeLinks(item));
+                item.isDeprecated(), makeLinks(item));
     }
 
     protected static Map<String, URI> makeLinks(CatalogItem<?,?> item) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f0fe5089/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 060e3c8..98b20c3 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
@@ -224,20 +224,26 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
     }
 
     private void addTestCatalogItem(String catalogItemId) {
+        addTestCatalogItem(catalogItemId, TEST_VERSION, "brooklyn.entity.nosql.redis.RedisStore");
+    }
+
+    private void addTestCatalogItem(String catalogItemId, String version, String service)
{
         String yaml =
                 "brooklyn.catalog:\n"+
                 "  id: " + catalogItemId + "\n"+
                 "  name: My Catalog App\n"+
                 "  description: My description\n"+
                 "  icon_url: classpath:///redis-logo.png\n"+
-                "  version: " + TEST_VERSION + "\n"+
+                "  version: " + version + "\n"+
                 "\n"+
                 "services:\n"+
-                "- type: brooklyn.entity.nosql.redis.RedisStore\n";
+                "- type: " + service + "\n";
 
         client().resource("/v1/catalog").post(yaml);
     }
 
+
+
     @Test
     public void testListPolicies() {
         Set<CatalogItemSummary> policies = client().resource("/v1/catalog/policies")
@@ -280,6 +286,43 @@ public class CatalogResourceTest extends BrooklynRestResourceTest {
         assertEquals(getPostDeleteResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
     }
 
+    @Test
+    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>>()
{});
+        assertEquals(applications.size(), 2);
+        CatalogItemSummary summary0 = applications.get(0);
+        CatalogItemSummary summary1 = applications.get(1);
+
+        // Ensure that the ID required by the API is in the 'usual' format of name:id
+        String id = String.format("%s:%s", summary0.getSymbolicName(), summary0.getVersion());
+        assertEquals(summary0.getId(), id);
+        ClientResponse getDeprecationResponse = client().resource(String.format("/v1/catalog/entities/%s/deprecated/true",
id))
+                .post(ClientResponse.class);
+
+        assertEquals(getDeprecationResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
+
+        List<CatalogItemSummary> applicationsAfterDeprecation = client().resource("/v1/catalog/applications")
+                .queryParam("fragment", "basicapp").get(new GenericType<List<CatalogItemSummary>>()
{});
+
+        assertEquals(applicationsAfterDeprecation.size(), 1);
+        assertTrue(applicationsAfterDeprecation.contains(summary1));
+
+        ClientResponse getUnDeprecationResponse = client().resource(String.format("/v1/catalog/entities/%s/deprecated/false",
summary0.getId()))
+                .post(ClientResponse.class);
+
+        assertEquals(getUnDeprecationResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode());
+
+        List<CatalogItemSummary> applicationsAfterUnDeprecation = client().resource("/v1/catalog/applications")
+                .queryParam("fragment", "basicapp").get(new GenericType<List<CatalogItemSummary>>()
{});
+
+        assertEquals(applications, applicationsAfterUnDeprecation);
+    }
+
     private static String ver(String id) {
         return CatalogUtils.getVersionedId(id, TEST_VERSION);
     }


Mime
View raw message