You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2014/08/19 17:54:59 UTC
[2/4] git commit: PolicyApi returns 204 to start/stop/destroy
PolicyApi returns 204 to start/stop/destroy
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a79e21ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a79e21ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a79e21ec
Branch: refs/heads/master
Commit: a79e21ec0119d7a24ed8f6b46c6cac0116465004
Parents: 96449ef
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Aug 13 16:32:44 2014 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Aug 13 16:32:44 2014 +0100
----------------------------------------------------------------------
.../main/java/brooklyn/rest/api/PolicyApi.java | 1 +
.../brooklyn/rest/resources/PolicyResource.java | 6 +-
.../rest/resources/ApplicationResourceTest.java | 72 +++++++++-----------
3 files changed, 38 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a79e21ec/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyApi.java
----------------------------------------------------------------------
diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyApi.java
index 56a03b6..6f66965 100644
--- a/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyApi.java
+++ b/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyApi.java
@@ -136,6 +136,7 @@ public interface PolicyApi {
@PathParam("policy") String policyId
) ;
+ // TODO: Should be DELETE /policy, not POST /policy/destroy
@POST
@Path("/{policy}/destroy")
@ApiOperation(value = "Destroy a policy", notes="Removes a policy from being associated with the entity and destroys it (stopping first if running)")
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a79e21ec/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java
index 7b4317d..f91b1b2 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyResource.java
@@ -108,7 +108,7 @@ public class PolicyResource extends AbstractBrooklynRestResource implements Poli
Policy policy = brooklyn().getPolicy(application, entityToken, policyId);
policy.resume();
- return Response.status(Response.Status.OK).build();
+ return Response.status(Response.Status.NO_CONTENT).build();
}
@Override
@@ -116,7 +116,7 @@ public class PolicyResource extends AbstractBrooklynRestResource implements Poli
Policy policy = brooklyn().getPolicy(application, entityToken, policyId);
policy.suspend();
- return Response.status(Response.Status.OK).build();
+ return Response.status(Response.Status.NO_CONTENT).build();
}
@Override
@@ -126,6 +126,6 @@ public class PolicyResource extends AbstractBrooklynRestResource implements Poli
policy.suspend();
entity.removePolicy(policy);
- return Response.status(Response.Status.OK).build();
+ return Response.status(Response.Status.NO_CONTENT).build();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a79e21ec/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
index a4eed27..47e4b2c 100644
--- a/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
+++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/ApplicationResourceTest.java
@@ -89,13 +89,13 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
private static final Logger log = LoggerFactory.getLogger(ApplicationResourceTest.class);
- private final ApplicationSpec simpleSpec = ApplicationSpec.builder().name("simple-app").
- entities(ImmutableSet.of(
+ private final ApplicationSpec simpleSpec = ApplicationSpec.builder().name("simple-app")
+ .entities(ImmutableSet.of(
new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()),
new EntitySpec("simple-group", EverythingGroup.class.getName())
- )).
- locations(ImmutableSet.of("localhost")).
- build();
+ ))
+ .locations(ImmutableSet.of("localhost"))
+ .build();
// Convenience for finding an EntitySummary within a collection, based on its name
private static Predicate<EntitySummary> withName(final String name) {
@@ -249,10 +249,10 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
public void testDeployWithInvalidEntityType() {
try {
clientDeploy(
- ApplicationSpec.builder().name("invalid-app").
- entities(ImmutableSet.of(new EntitySpec("invalid-ent", "not.existing.entity"))).
- locations(ImmutableSet.of("localhost")).
- build()
+ ApplicationSpec.builder().name("invalid-app")
+ .entities(ImmutableSet.of(new EntitySpec("invalid-ent", "not.existing.entity")))
+ .locations(ImmutableSet.of("localhost"))
+ .build()
);
} catch (UniformInterfaceException e) {
@@ -265,10 +265,10 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
public void testDeployWithInvalidLocation() {
try {
clientDeploy(
- ApplicationSpec.builder().name("invalid-app").
- entities(ImmutableSet.<EntitySpec>of(new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()))).
- locations(ImmutableSet.of("3423")).
- build()
+ ApplicationSpec.builder().name("invalid-app")
+ .entities(ImmutableSet.of(new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName())))
+ .locations(ImmutableSet.of("3423"))
+ .build()
);
} catch (UniformInterfaceException e) {
@@ -333,8 +333,8 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
Assert.assertNotNull(groupSummary);
String itemIds = app.get("id")+","+entitySummary.get("id")+","+groupSummary.get("id");
- Collection entities = client().resource("/v1/applications/fetch?items="+itemIds).
- get(Collection.class);
+ Collection entities = client().resource("/v1/applications/fetch?items="+itemIds)
+ .get(Collection.class);
log.info("Applications+Entities fetched are: "+entities);
Assert.assertEquals(entities.size(), apps.size()+2);
@@ -486,9 +486,9 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
Set<PolicySummary> policies = client().resource(policiesEndpoint).get(new GenericType<Set<PolicySummary>>(){});
assertEquals(policies.size(), 0);
- ClientResponse response = client().resource(policiesEndpoint).
- queryParam("type", CapitalizePolicy.class.getCanonicalName()).
- post(ClientResponse.class, Maps.newHashMap());
+ ClientResponse response = client().resource(policiesEndpoint)
+ .queryParam("type", CapitalizePolicy.class.getCanonicalName())
+ .post(ClientResponse.class, Maps.newHashMap());
assertEquals(response.getStatus(), 200);
PolicySummary policy = response.getEntity(PolicySummary.class);
assertNotNull(policy.getId());
@@ -497,34 +497,30 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest {
policies = client().resource(policiesEndpoint).get(new GenericType<Set<PolicySummary>>(){});
assertEquals(policies.size(), 1);
- String status = client().resource(policiesEndpoint+"/"+newPolicyId).
- get(String.class);
+ String status = client().resource(policiesEndpoint+"/"+newPolicyId)
+ .get(String.class);
log.info("POLICY STATUS: "+status);
- response = client().resource(policiesEndpoint+"/"+newPolicyId+"/start").
- post(ClientResponse.class);
- assertEquals(response.getStatus(), 200);
- status = client().resource(policiesEndpoint+"/"+newPolicyId).
- get(String.class);
+ response = client().resource(policiesEndpoint+"/"+newPolicyId+"/start")
+ .post(ClientResponse.class);
+ assertEquals(response.getStatus(), 204);
+ status = client().resource(policiesEndpoint+"/"+newPolicyId).get(String.class);
assertEquals(status, Lifecycle.RUNNING.name());
- response = client().resource(policiesEndpoint+"/"+newPolicyId+"/stop").
- post(ClientResponse.class);
- assertEquals(response.getStatus(), 200);
- status = client().resource(policiesEndpoint+"/"+newPolicyId).
- get(String.class);
+ response = client().resource(policiesEndpoint+"/"+newPolicyId+"/stop")
+ .post(ClientResponse.class);
+ assertEquals(response.getStatus(), 204);
+ status = client().resource(policiesEndpoint+"/"+newPolicyId).get(String.class);
assertEquals(status, Lifecycle.STOPPED.name());
- response = client().resource(policiesEndpoint+"/"+newPolicyId+"/destroy").
- post(ClientResponse.class);
- assertTrue(response.getStatus()==200 || response.getStatus()==404);
+ response = client().resource(policiesEndpoint+"/"+newPolicyId+"/destroy")
+ .post(ClientResponse.class);
+ assertEquals(response.getStatus(), 204);
+
response = client().resource(policiesEndpoint+"/"+newPolicyId).get(ClientResponse.class);
log.info("POLICY STATUS RESPONSE AFTER DESTROY: "+response.getStatus());
- assertTrue(response.getStatus()==200 || response.getStatus()==404);
- if (response.getStatus()==200) {
- assertEquals(response.getEntity(String.class), Lifecycle.DESTROYED.name());
- }
-
+ assertEquals(response.getStatus(), 404);
+
policies = client().resource(policiesEndpoint).get(new GenericType<Set<PolicySummary>>(){});
assertEquals(0, policies.size());
}