brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [3/7] git commit: Catalog and Location resources return representation of newly-created entities
Date Fri, 18 Jul 2014 12:38:26 GMT
Catalog and Location resources return representation of newly-created entities


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

Branch: refs/heads/master
Commit: 016485f2b9fab2220f4227bb8d0b22beccaa2edf
Parents: af9c4c0
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Wed Jul 9 18:09:37 2014 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Wed Jul 16 19:19:50 2014 +0100

----------------------------------------------------------------------
 .../rest/resources/CatalogResource.java         | 31 +++++++++++++++-----
 .../rest/resources/LocationResource.java        |  6 ++--
 2 files changed, 26 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/016485f2/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 89efb30..007c19c 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
@@ -39,6 +39,8 @@ import brooklyn.catalog.internal.BasicBrooklynCatalog;
 import brooklyn.catalog.internal.CatalogDto;
 import brooklyn.entity.Entity;
 import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.policy.Policy;
+import brooklyn.policy.PolicySpec;
 import brooklyn.rest.api.CatalogApi;
 import brooklyn.rest.domain.ApiError;
 import brooklyn.rest.domain.CatalogEntitySummary;
@@ -89,14 +91,27 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
         }
         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)).build();
-        case ENTITY: return Response.created(URI.create("entities/" + itemId)).build();
-        case POLICY: return Response.created(URI.create("policies/" + itemId)).build();
-        case CONFIGURATION: return Response.created(URI.create("configurations/" + itemId)).build();
-        default: throw new IllegalStateException("Unsupported catalog item type "+item.getCatalogItemType()+":
"+item);
+        case TEMPLATE:
+            return Response.created(URI.create("applications/" + itemId))
+                    .entity(CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<?
extends Entity, EntitySpec<?>>) item))
+                    .build();
+        case ENTITY:
+            return Response.created(URI.create("entities/" + itemId))
+                    .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 CONFIGURATION:
+            return Response.created(URI.create("configurations/" + itemId))
+                    .entity(CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<?
extends Entity, EntitySpec<?>>) item))
+                    .build();
+        default:
+            throw new IllegalStateException("Unsupported catalog item type "+item.getCatalogItemType()+":
"+item);
         }
     }
 
@@ -133,7 +148,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
         throw WebResourceUtils.notFound("Entity with id '%s' not found", entityId);
       }
 
-      return CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<? extends
Entity,EntitySpec<?>>) result);
+      return CatalogTransformer.catalogEntitySummary(brooklyn(), (CatalogItem<? extends
Entity, EntitySpec<?>>) result);
     }
 
     @Override
@@ -153,7 +168,7 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
           throw WebResourceUtils.notFound("Policy with id '%s' not found", policyId);
         }
 
-        return CatalogTransformer.catalogItemSummary(brooklyn(), result);
+        return CatalogTransformer.catalogPolicySummary(brooklyn(), (CatalogItem<? extends
Policy, PolicySpec<?>>) result);
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/016485f2/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 6334ded..d8a4e40 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
@@ -48,8 +48,6 @@ import brooklyn.util.text.Identifiers;
 
 import com.google.common.base.Function;
 import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
 public class LocationResource extends AbstractBrooklynRestResource implements LocationApi
{
@@ -131,7 +129,9 @@ public class LocationResource extends AbstractBrooklynRestResource implements
Lo
       String id = Identifiers.makeRandomId(8);
       LocationDefinition l = new BasicLocationDefinition(id, locationSpec.getName(), locationSpec.getSpec(),
locationSpec.getConfig());
       brooklyn().getLocationRegistry().updateDefinedLocation(l);
-      return Response.created(URI.create(id)).build();
+      return Response.created(URI.create(id))
+              .entity(LocationTransformer.newInstance(mgmt(), l, LocationDetailLevel.LOCAL_EXCLUDING_SECRET))
+              .build();
   }
 
   public void delete(String locationId) {


Mime
View raw message