brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject incubator-brooklyn git commit: fix rest catalog lookup from rest
Date Tue, 18 Nov 2014 23:51:40 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 4ced56e12 -> fbfd78fe5


fix rest catalog lookup from rest


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

Branch: refs/heads/master
Commit: fbfd78fe54434fe7cad89d44a2564e8e5da23b06
Parents: 4ced56e
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Nov 18 18:23:34 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Nov 18 18:24:07 2014 +0000

----------------------------------------------------------------------
 .../brooklyn/rest/resources/CatalogResource.java  | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fbfd78fe/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 ad1324d..6e317be 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
@@ -34,7 +34,6 @@ import javax.ws.rs.core.Response.Status;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.catalog.BrooklynCatalog;
 import brooklyn.catalog.CatalogItem;
 import brooklyn.catalog.CatalogPredicates;
 import brooklyn.catalog.internal.BasicBrooklynCatalog;
@@ -131,7 +130,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
     @Deprecated
     public void deleteEntity(String entityId) throws Exception {
         try {
-            brooklyn().getCatalog().deleteCatalogItem(entityId);
+            CatalogItem<?, ?> item = CatalogUtils.getCatalogItemOptionalVersion(mgmt(),
entityId);
+            if (item==null)
+                throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);
+            brooklyn().getCatalog().deleteCatalogItem(item.getSymbolicName(), item.getVersion());
         } catch (NoSuchElementException e) {
             throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);
         }
@@ -160,11 +162,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
     @Override
     @Deprecated
     public CatalogEntitySummary getEntity(String entityId) {
-        //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<? extends Entity,EntitySpec<?>> result =
-                (CatalogItem<? extends Entity,EntitySpec<?>>) brooklyn().getCatalog().getCatalogItem(entityId,
BrooklynCatalog.DEFAULT_VERSION);
+                CatalogUtils.getCatalogItemOptionalVersion(mgmt(), Entity.class, entityId);
 
         if (result==null) {
             throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);
@@ -175,6 +174,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
     
     @Override
     public CatalogEntitySummary getEntity(String entityId, String 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<? extends Entity, EntitySpec<?>> result =
               (CatalogItem<? extends Entity, EntitySpec<?>>) brooklyn().getCatalog().getCatalogItem(entityId,
version);
@@ -205,9 +206,8 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
     @Override
     @Deprecated
     public CatalogItemSummary getPolicy(String policyId) {
-        @SuppressWarnings("unchecked")
         CatalogItem<? extends Policy, PolicySpec<?>> result =
-                (CatalogItem<? extends Policy, PolicySpec<?>>) brooklyn().getCatalog().getCatalogItem(policyId,
BrooklynCatalog.DEFAULT_VERSION);
+            CatalogUtils.getCatalogItemOptionalVersion(mgmt(), Policy.class, policyId);
 
         if (result==null) {
             throw WebResourceUtils.notFound("Policy with id '%s' not found", policyId);
@@ -248,7 +248,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
     @Override
     @Deprecated
     public Response getIcon(String itemId) {
-        CatalogItem<?,?> result = brooklyn().getCatalog().getCatalogItem(itemId, BrooklynCatalog.DEFAULT_VERSION);
+        CatalogItem<?,?> result = CatalogUtils.getCatalogItemOptionalVersion(mgmt(),
itemId);
         return getCatalogItemIcon(result);
     }
 


Mime
View raw message