brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/19] git commit: add ability to rename entity via REST - WIP deep tag serialization
Date Tue, 09 Sep 2014 22:49:05 GMT
add ability to rename entity via REST - WIP deep tag serialization


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

Branch: refs/heads/master
Commit: 0eda14b89974e1b3fa6336857117b4aa9365afff
Parents: e8d8a72
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Sep 2 18:00:21 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Sep 9 11:26:23 2014 +0100

----------------------------------------------------------------------
 api/src/main/java/brooklyn/entity/Entity.java     |  2 --
 .../entity/basic/BasicApplicationImpl.java        |  7 +++++++
 .../main/java/brooklyn/rest/api/EntityApi.java    | 18 +++++++++++++++++-
 .../brooklyn/rest/resources/EntityResource.java   |  9 ++++++++-
 .../rest/transform/EntityTransformer.java         |  5 +++--
 .../rest/resources/ApiDocResourceTest.java        |  4 ++--
 .../rest/resources/EntityResourceTest.java        | 13 ++++++++++++-
 7 files changed, 49 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/api/src/main/java/brooklyn/entity/Entity.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/entity/Entity.java b/api/src/main/java/brooklyn/entity/Entity.java
index 9a09392..88a10fa 100644
--- a/api/src/main/java/brooklyn/entity/Entity.java
+++ b/api/src/main/java/brooklyn/entity/Entity.java
@@ -25,8 +25,6 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import com.google.common.annotations.Beta;
-
 import brooklyn.basic.BrooklynObject;
 import brooklyn.config.ConfigKey;
 import brooklyn.config.ConfigKey.HasConfigKey;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/core/src/main/java/brooklyn/entity/basic/BasicApplicationImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/BasicApplicationImpl.java b/core/src/main/java/brooklyn/entity/basic/BasicApplicationImpl.java
index 6915556..5cecf3f 100644
--- a/core/src/main/java/brooklyn/entity/basic/BasicApplicationImpl.java
+++ b/core/src/main/java/brooklyn/entity/basic/BasicApplicationImpl.java
@@ -19,4 +19,11 @@
 package brooklyn.entity.basic;
 
 public class BasicApplicationImpl extends AbstractApplication implements BasicApplication
{
+    
+    @Override
+    public void init() {
+        super.init();
+        setDefaultDisplayName("Application ("+getId()+")");
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/usage/rest-api/src/main/java/brooklyn/rest/api/EntityApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/EntityApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/EntityApi.java
index ea6bd5a..9b62d30 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/EntityApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/EntityApi.java
@@ -119,6 +119,19 @@ public interface EntityApi {
 
   @POST
   @ApiOperation(
+      value = "Rename an entity"
+  )
+  @ApiErrors(value = {
+      @ApiError(code = 404, reason = "Undefined application or entity")
+  })
+  @Path("/{entity}/name")
+  public Response rename(
+      @ApiParam(value = "Application ID or name", required = true) @PathParam("application")
final String applicationId, 
+      @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final
String entityId, 
+      @ApiParam(value = "New name for this entity", required = true) @QueryParam("name")
final String name);
+  
+  @POST
+  @ApiOperation(
       value = "Expunge an entity",
       responseClass = "brooklyn.rest.domain.TaskSummary"
   )
@@ -126,7 +139,10 @@ public interface EntityApi {
       @ApiError(code = 404, reason = "Undefined application or entity")
   })
   @Path("/{entity}/expunge")
-  public Response expunge(@PathParam("application") final String application, @PathParam("entity")
final String entity, @QueryParam("release") final boolean release);
+  public Response expunge(
+      @ApiParam(value = "Application ID or name", required = true) @PathParam("application")
final String applicationId, 
+      @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final
String entityId, 
+      @ApiParam(value = "Whether to gracefully release all resources", required = true) @QueryParam("release")
final boolean release);
   
   @GET
   @Path("/{entity}/descendants")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityResource.java
index d4d3962..e3b8b3e 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityResource.java
@@ -77,7 +77,7 @@ public class EntityResource extends AbstractBrooklynRestResource implements
Enti
   }
 
   @Override
-  public List<EntitySummary> getChildren( final String application, final String entity)
{
+  public List<EntitySummary> getChildren(final String application, final String entity)
{
       return FluentIterable
               .from(brooklyn().getEntity(application, entity).getChildren())
               .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY))
@@ -128,6 +128,13 @@ public class EntityResource extends AbstractBrooklynRestResource implements
Enti
   }
 
     @Override
+    public Response rename(String application, String entity, String newName) {
+        EntityLocal entityLocal = brooklyn().getEntity(application, entity);
+        entityLocal.setDisplayName(newName);
+        return status(Response.Status.OK).build();
+    }
+
+    @Override
     public Response expunge(String application, String entity, boolean release) {
         EntityLocal entityLocal = brooklyn().getEntity(application, entity);
         Task<?> task = brooklyn().expunge(entityLocal, release);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
b/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
index 23107c5..a0fc86e 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
@@ -67,8 +67,9 @@ public class EntityTransformer {
                 .put("locations", URI.create(entityUri + "/locations"))
                 .put("tags", URI.create(entityUri + "/tags"))
                 .put("catalog", URI.create("/v1/catalog/entities/" + type))
-                .put("expunge", URI.create(entityUri + "/expunge")
-            );
+                .put("expunge", URI.create(entityUri + "/expunge"))
+                .put("rename", URI.create(entityUri + "/name"))
+            ;
         if (entity.getIconUrl()!=null)
             lb.put("iconUrl", URI.create(entityUri + "/icon"));
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/usage/rest-server/src/test/java/brooklyn/rest/resources/ApiDocResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApiDocResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApiDocResourceTest.java
index a46e48c..bf086ab 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApiDocResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApiDocResourceTest.java
@@ -52,7 +52,7 @@ public class ApiDocResourceTest extends BrooklynRestResourceTest {
             addResource(o);
         }
     }
-
+    
     @Test
     public void testCountRestResources() throws Exception {
         Documentation response = client().resource("/v1/apidoc/").get(Documentation.class);
@@ -74,7 +74,7 @@ public class ApiDocResourceTest extends BrooklynRestResourceTest {
     @Test
     public void testEntityDetails() throws Exception {
         Documentation response = client().resource("/v1/apidoc/brooklyn.rest.resources.EntityResource").get(Documentation.class);
-        assertEquals(countOperations(response), 11);
+        assertEquals(countOperations(response), 12);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eda14b8/usage/rest-server/src/test/java/brooklyn/rest/resources/EntityResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/EntityResourceTest.java
b/usage/rest-server/src/test/java/brooklyn/rest/resources/EntityResourceTest.java
index bedf61b..abd8e18 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/EntityResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/EntityResourceTest.java
@@ -33,6 +33,7 @@ import brooklyn.rest.domain.ApplicationSpec;
 import brooklyn.rest.domain.EntitySpec;
 import brooklyn.rest.testing.BrooklynRestResourceTest;
 import brooklyn.rest.testing.mocks.RestMockSimpleEntity;
+import brooklyn.test.HttpTestUtils;
 import brooklyn.util.collections.MutableList;
 
 import com.google.common.base.Predicate;
@@ -85,8 +86,18 @@ public class EntityResourceTest extends BrooklynRestResourceTest {
         Assert.assertFalse(tags.contains("bar"));
     }
     
+    @Test
+    public void testRename() throws Exception {
+        ClientResponse response = client().resource(entityEndpoint + "/name")
+                .queryParam("name", "New Name")
+                .post(ClientResponse.class);
+
+        HttpTestUtils.assertHealthyStatusCode(response.getStatus());
+        Assert.assertTrue(entity.getDisplayName().equals("New Name"));
+    }
+    
     // TODO any entity or complex object should be cleaned up as part of WebResourceUtils
call
-    @Test(groups="WIP")
+    @Test(groups="WIP", dependsOnMethods={"testTagsSanity"})
     public void testTagsDoNotSerializeTooMuch() throws Exception {
         entity.getTagSupport().addTag("foo");
         entity.getTagSupport().addTag(entity.getParent());


Mime
View raw message