From f7aa7627c982601302d241049b787f29872abff5 Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Fri, 9 Jan 2015 00:02:25 +0000 Subject: [PATCH 1/2] Fix indents in rest-api --- .../java/brooklyn/rest/api/ActivityApi.java | 54 ++- .../brooklyn/rest/api/ApplicationApi.java | 316 +++++++------- .../java/brooklyn/rest/api/CatalogApi.java | 37 +- .../java/brooklyn/rest/api/EffectorApi.java | 89 ++-- .../java/brooklyn/rest/api/EntityApi.java | 392 +++++++++--------- .../brooklyn/rest/api/EntityConfigApi.java | 187 ++++----- .../java/brooklyn/rest/api/LocationApi.java | 66 ++- .../java/brooklyn/rest/api/PolicyApi.java | 226 +++++----- .../brooklyn/rest/api/PolicyConfigApi.java | 159 ++++--- .../java/brooklyn/rest/api/ScriptApi.java | 6 +- .../java/brooklyn/rest/api/SensorApi.java | 198 +++++---- .../java/brooklyn/rest/api/ServerApi.java | 37 +- .../java/brooklyn/rest/api/VersionApi.java | 6 +- .../brooklyn/rest/domain/ApplicationSpec.java | 243 +++++------ .../brooklyn/rest/domain/ConfigSummary.java | 257 ++++++------ .../brooklyn/rest/domain/EffectorSummary.java | 252 ++++++----- .../rest/domain/EntityConfigSummary.java | 62 ++- .../java/brooklyn/rest/domain/EntitySpec.java | 135 +++--- .../brooklyn/rest/domain/EntitySummary.java | 111 +++-- .../rest/domain/HighAvailabilitySummary.java | 134 +++--- .../brooklyn/rest/domain/LocationSpec.java | 113 +++-- .../brooklyn/rest/domain/LocationSummary.java | 101 +++-- .../rest/domain/PolicyConfigSummary.java | 49 ++- .../brooklyn/rest/domain/PolicySummary.java | 152 ++++--- .../rest/domain/ScriptExecutionSummary.java | 13 +- .../brooklyn/rest/domain/SensorSummary.java | 146 ++++--- .../brooklyn/rest/domain/TaskSummary.java | 339 ++++++++------- .../brooklyn/rest/domain/UsageStatistic.java | 12 +- .../brooklyn/rest/domain/UsageStatistics.java | 31 +- .../rest/domain/ApplicationSpecTest.java | 39 +- .../rest/domain/EffectorSummaryTest.java | 36 +- .../brooklyn/rest/domain/EntitySpecTest.java | 36 +- .../rest/domain/EntitySummaryTest.java | 48 +-- .../rest/domain/LocationSpecTest.java | 36 +- .../brooklyn/rest/util/RestApiTestUtils.java | 1 - 35 files changed, 2021 insertions(+), 2098 deletions(-) diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ActivityApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ActivityApi.java index 379187bdb6..603b9407e2 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/ActivityApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ActivityApi.java @@ -37,35 +37,33 @@ @Consumes(MediaType.APPLICATION_JSON) public interface ActivityApi { - @GET - @Path("/{task}") - @ApiOperation(value = "Fetch task details", responseClass = "brooklyn.rest.domain.TaskSummary") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find task") - }) + @GET + @Path("/{task}") + @ApiOperation(value = "Fetch task details", responseClass = "brooklyn.rest.domain.TaskSummary") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find task") + }) // @Produces("text/json") - public TaskSummary get( - @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId - ); - - @GET - @Path("/{task}/children") - @ApiOperation(value = "Fetch list of children tasks of this task") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find task") - }) - public List children( - @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId); - - @GET - @Path("/{task}/stream/{streamId}") - @ApiOperation(value = "Return the contents of the given stream") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find task or stream") - }) - public String stream( - @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId, - @ApiParam(value = "Stream ID", required = true) @PathParam("streamId") String streamId); + public TaskSummary get( + @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId + ); + @GET + @Path("/{task}/children") + @ApiOperation(value = "Fetch list of children tasks of this task") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find task") + }) + public List children( + @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId); + @GET + @Path("/{task}/stream/{streamId}") + @ApiOperation(value = "Return the contents of the given stream") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find task or stream") + }) + public String stream( + @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId, + @ApiParam(value = "Stream ID", required = true) @PathParam("streamId") String streamId); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ApplicationApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ApplicationApi.java index 6b67240695..929219709a 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/ApplicationApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ApplicationApi.java @@ -52,164 +52,162 @@ @Consumes(MediaType.APPLICATION_JSON) public interface ApplicationApi { - @GET - @Path("/tree") - @ApiOperation( - value = "Fetch applications and entities tree hierarchy" - ) - /** @deprecated since 0.6.0 use {@link #fetch(String)} (with slightly different, but better semantics) */ - @Deprecated - public JsonNode applicationTree(); - - @GET - @Path("/fetch") - @ApiOperation( - value = "Fetch display details for all applications and optionally selected additional entities" - ) - public JsonNode fetch( - @ApiParam(value="Selected additional entity ID's to include, comma-separated", required=false) - @DefaultValue("") - @QueryParam("items") String items); - - @GET - @ApiOperation( - value = "Fetch list of applications, as ApplicationSummary objects", - responseClass = "brooklyn.rest.domain.ApplicationSummary" - ) - public List list() ; - - @GET - @Path("/{application}") - @ApiOperation( - value = "Fetch a specific application", - responseClass = "brooklyn.rest.domain.ApplicationSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application not found") - }) - public ApplicationSummary get( - @ApiParam( - value = "ID or name of application whose details will be returned", - required = true) - @PathParam("application") String application) ; - - @POST - @Consumes({"application/x-yaml", - // see http://stackoverflow.com/questions/332129/yaml-mime-type - "text/yaml", "text/x-yaml", "application/yaml"}) - @ApiOperation( - value = "Create and start a new application from YAML", - responseClass = "brooklyn.rest.domain.TaskSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Undefined entity or location"), - @ApiError(code = 412, reason = "Application already registered") - }) - public Response createFromYaml( - @ApiParam( - name = "applicationSpec", - value = "App spec in CAMP YAML format", - required = true) - String yaml); - - // TODO archives -// @Consumes({"application/x-tar", "application/x-tgz", "application/x-zip"}) - - @POST - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN}) - @ApiOperation( - value = "Create and start a new application from miscellaneous types, including JSON either new CAMP format or legacy AppSpec format", - responseClass = "brooklyn.rest.domain.TaskSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Undefined entity or location"), - @ApiError(code = 412, reason = "Application already registered") - }) - public Response createPoly( - @ApiParam( - name = "applicationSpec", - value = "App spec in JSON, YAML, or other (auto-detected) format", - required = true) - byte[] autodetectedInput); - - @POST - @Consumes({MediaType.APPLICATION_FORM_URLENCODED}) - @ApiOperation( - value = "Create and start a new application from form URL-encoded contents (underlying type autodetected)", - responseClass = "brooklyn.rest.domain.TaskSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Undefined entity or location"), - @ApiError(code = 412, reason = "Application already registered") - }) - public Response createFromForm( - @ApiParam( - name = "applicationSpec", - value = "App spec in form-encoded YAML, JSON, or other (auto-detected) format", - required = true) - @Valid String contents); - - @DELETE - @Path("/{application}") - @ApiOperation( - value = "Delete a specified application", - responseClass = "brooklyn.rest.domain.TaskSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application not found") - }) - public Response delete( - @ApiParam( - name = "application", - value = "Application name", - required = true - ) - @PathParam("application") String application) ; - - /** @deprecated since 0.7.0 the {@link ApplicationSpec} is being retired in favour of CAMP YAML/ZIP - * (however in 0.7.0 you can still pass this object as JSON and it will be autodetected) */ - @POST - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN}) - @ApiOperation( - value = "Create and start a new application from miscellaneous types, including JSON either new CAMP format or legacy AppSpec format", - responseClass = "brooklyn.rest.domain.TaskSummary" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Undefined entity or location"), - @ApiError(code = 412, reason = "Application already registered") - }) - @Path("/createLegacy") - @Deprecated - public Response create(ApplicationSpec applicationSpec); - - @GET - @Path("/{application}/descendants") - @ApiOperation(value = "Fetch entity info for all (or filtered) descendants", - responseClass = "brooklyn.rest.domain.EntitySummary") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public List getDescendants( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value="Regular expression for an entity type which must be matched", required=false) - @DefaultValue(".*") - @QueryParam("typeRegex") String typeRegex); - - @GET - @Path("/{application}/descendants/sensor/{sensor}") - @ApiOperation(value = "Fetch values of a given sensor for all (or filtered) descendants") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public Map getDescendantsSensor( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensor, - @ApiParam(value="Regular expression for an entity type which must be matched", required=false) - @DefaultValue(".*") - @QueryParam("typeRegex") String typeRegex - ); + @GET + @Path("/tree") + @ApiOperation( + value = "Fetch applications and entities tree hierarchy" + ) + /** @deprecated since 0.6.0 use {@link #fetch(String)} (with slightly different, but better semantics) */ + @Deprecated + public JsonNode applicationTree(); + + @GET + @Path("/fetch") + @ApiOperation( + value = "Fetch display details for all applications and optionally selected additional entities" + ) + public JsonNode fetch( + @ApiParam(value="Selected additional entity ID's to include, comma-separated", required=false) + @DefaultValue("") + @QueryParam("items") String items); + + @GET + @ApiOperation( + value = "Fetch list of applications, as ApplicationSummary objects", + responseClass = "brooklyn.rest.domain.ApplicationSummary" + ) + public List list(); + + @GET + @Path("/{application}") + @ApiOperation( + value = "Fetch a specific application", + responseClass = "brooklyn.rest.domain.ApplicationSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application not found") + }) + public ApplicationSummary get( + @ApiParam( + value = "ID or name of application whose details will be returned", + required = true) + @PathParam("application") String application); + + @POST + @Consumes({"application/x-yaml", + // see http://stackoverflow.com/questions/332129/yaml-mime-type + "text/yaml", "text/x-yaml", "application/yaml"}) + @ApiOperation( + value = "Create and start a new application from YAML", + responseClass = "brooklyn.rest.domain.TaskSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Undefined entity or location"), + @ApiError(code = 412, reason = "Application already registered") + }) + public Response createFromYaml( + @ApiParam( + name = "applicationSpec", + value = "App spec in CAMP YAML format", + required = true) + String yaml); + + // TODO archives +// @Consumes({"application/x-tar", "application/x-tgz", "application/x-zip"}) + + @POST + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN}) + @ApiOperation( + value = "Create and start a new application from miscellaneous types, including JSON either new CAMP format or legacy AppSpec format", + responseClass = "brooklyn.rest.domain.TaskSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Undefined entity or location"), + @ApiError(code = 412, reason = "Application already registered") + }) + public Response createPoly( + @ApiParam( + name = "applicationSpec", + value = "App spec in JSON, YAML, or other (auto-detected) format", + required = true) + byte[] autodetectedInput); + + @POST + @Consumes({MediaType.APPLICATION_FORM_URLENCODED}) + @ApiOperation( + value = "Create and start a new application from form URL-encoded contents (underlying type autodetected)", + responseClass = "brooklyn.rest.domain.TaskSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Undefined entity or location"), + @ApiError(code = 412, reason = "Application already registered") + }) + public Response createFromForm( + @ApiParam( + name = "applicationSpec", + value = "App spec in form-encoded YAML, JSON, or other (auto-detected) format", + required = true) + @Valid String contents); + + @DELETE + @Path("/{application}") + @ApiOperation( + value = "Delete a specified application", + responseClass = "brooklyn.rest.domain.TaskSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application not found") + }) + public Response delete( + @ApiParam( + name = "application", + value = "Application name", + required = true) + @PathParam("application") String application); + + /** @deprecated since 0.7.0 the {@link ApplicationSpec} is being retired in favour of CAMP YAML/ZIP + * (however in 0.7.0 you can still pass this object as JSON and it will be autodetected) */ + @POST + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM, MediaType.TEXT_PLAIN}) + @ApiOperation( + value = "Create and start a new application from miscellaneous types, including JSON either new CAMP format or legacy AppSpec format", + responseClass = "brooklyn.rest.domain.TaskSummary" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Undefined entity or location"), + @ApiError(code = 412, reason = "Application already registered") + }) + @Path("/createLegacy") + @Deprecated + public Response create(ApplicationSpec applicationSpec); + + @GET + @Path("/{application}/descendants") + @ApiOperation(value = "Fetch entity info for all (or filtered) descendants", + responseClass = "brooklyn.rest.domain.EntitySummary") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public List getDescendants( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value="Regular expression for an entity type which must be matched", required=false) + @DefaultValue(".*") + @QueryParam("typeRegex") String typeRegex); + + @GET + @Path("/{application}/descendants/sensor/{sensor}") + @ApiOperation(value = "Fetch values of a given sensor for all (or filtered) descendants") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public Map getDescendantsSensor( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensor, + @ApiParam(value="Regular expression for an entity type which must be matched", required=false) + @DefaultValue(".*") + @QueryParam("typeRegex") String typeRegex); } 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 f527d60206..bbf9d2ffe1 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 @@ -63,8 +63,7 @@ public Response createFromMultipart( @ApiOperation(value = "Add a catalog item (e.g. new entity or policy type) by uploading YAML descriptor", responseClass = "String") public Response create( @ApiParam(name = "yaml", value = "YAML descriptor of catalog item", required = true) - @Valid String yaml - ) ; + @Valid String yaml); @POST @Consumes(MediaType.APPLICATION_XML) @@ -72,8 +71,7 @@ public Response create( @ApiOperation(value = "Resets the catalog to the given (XML) format") public Response resetXml( @ApiParam(name = "xml", value = "XML descriptor of the entire catalog to install", required = true) - @Valid String xml - ) ; + @Valid String xml); /** @deprecated since 0.7.0 use {@link #getEntity(String, String)} */ @Deprecated @@ -85,7 +83,7 @@ public Response resetXml( }) public void deleteEntity( @ApiParam(name = "entityId", value = "The ID of the entity or template to delete", required = true) - @PathParam("entityId") String entityId) throws Exception ; + @PathParam("entityId") String entityId) throws Exception; @DELETE @Path("/entities/{entityId}/{version}") @@ -98,7 +96,7 @@ public void deleteEntity( @PathParam("entityId") String entityId, @ApiParam(name = "version", value = "The version identifier of the entity or template to delete", required = true) - @PathParam("version") String version) throws Exception ; + @PathParam("version") String version) throws Exception; @GET @Path("/entities") @@ -107,8 +105,7 @@ public List listEntities( @ApiParam(name = "regex", value = "Regular expression to search for") @QueryParam("regex") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") - @QueryParam("fragment") @DefaultValue("") String fragment - ) ; + @QueryParam("fragment") @DefaultValue("") String fragment); @GET @Path("/applications") @@ -117,8 +114,7 @@ public List listApplications( @ApiParam(name = "regex", value = "Regular expression to search for") @QueryParam("regex") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") - @QueryParam("fragment") @DefaultValue("") String fragment - ) ; + @QueryParam("fragment") @DefaultValue("") String fragment); /** @deprecated since 0.7.0 use {@link #getEntity(String, String)} */ @Deprecated @@ -130,7 +126,7 @@ public List listApplications( }) public CatalogEntitySummary getEntity( @ApiParam(name = "entityId", value = "The ID of the entity or template to retrieve", required = true) - @PathParam("entityId") String entityId) throws Exception ; + @PathParam("entityId") String entityId) throws Exception; @GET @Path("/entities/{entityId}/{version}") @@ -143,7 +139,7 @@ public CatalogEntitySummary getEntity( @PathParam("entityId") String entityId, @ApiParam(name = "version", value = "The version identifier of the entity or template to retrieve", required = true) - @PathParam("version") String version) throws Exception ; + @PathParam("version") String version) throws Exception; /** @deprecated since 0.7.0 use {@link #getEntity(String, String)} */ @Deprecated @@ -155,7 +151,7 @@ public CatalogEntitySummary getEntity( }) public CatalogEntitySummary getApplication( @ApiParam(name = "applicationId", value = "The ID of the application to retrieve", required = true) - @PathParam("applicationId") String entityId) throws Exception ; + @PathParam("applicationId") String entityId) throws Exception; @GET @Path("/applications/{applicationId}/{version}") @@ -168,7 +164,7 @@ public CatalogEntitySummary getApplication( @PathParam("applicationId") String entityId, @ApiParam(name = "version", value = "The version identifier of the application to retrieve", required = true) - @PathParam("version") String version) throws Exception ; + @PathParam("version") String version) throws Exception; @GET @Path("/policies") @@ -177,8 +173,7 @@ public List listPolicies( @ApiParam(name = "regex", value = "Regular expression to search for") @QueryParam("regex") @DefaultValue("") String regex, @ApiParam(name = "fragment", value = "Substring case-insensitive to search for") - @QueryParam("fragment") @DefaultValue("") String fragment - ) ; + @QueryParam("fragment") @DefaultValue("") String fragment); /** @deprecated since 0.7.0 use {@link #getEntity(String, String)} */ @Deprecated @@ -190,7 +185,7 @@ public List listPolicies( }) public CatalogItemSummary getPolicy( @ApiParam(name = "policyId", value = "The ID of the policy to retrieve", required = true) - @PathParam("policyId") String policyId) throws Exception ; + @PathParam("policyId") String policyId) throws Exception; @GET @Path("/policies/{policyId}/{version}") @@ -202,7 +197,7 @@ public CatalogItemSummary getPolicy( @ApiParam(name = "policyId", value = "The ID of the policy to retrieve", required = true) @PathParam("policyId") String policyId, @ApiParam(name = "version", value = "The version identifier of the application to retrieve", required = true) - @PathParam("version") String version) throws Exception ; + @PathParam("version") String version) throws Exception; /** @deprecated since 0.7.0 use {@link #getIcon(String, String)} */ @Deprecated @@ -215,8 +210,7 @@ public CatalogItemSummary getPolicy( @Produces("application/image") public Response getIcon( @ApiParam(name = "itemId", value = "ID of catalog item (application, entity, policy)") - @PathParam("itemId") @DefaultValue("") String itemId - ) ; + @PathParam("itemId") @DefaultValue("") String itemId); @GET @Path("/icon/{itemId}/{version}") @@ -230,8 +224,7 @@ public Response getIcon( @PathParam("itemId") String itemId, @ApiParam(name = "version", value = "version identifier of catalog item (application, entity, policy)", required=true) - @PathParam("version") String version - ) ; + @PathParam("version") String version); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/EffectorApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/EffectorApi.java index 59726fd160..fe1f29e573 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/EffectorApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/EffectorApi.java @@ -38,51 +38,48 @@ @Consumes(MediaType.APPLICATION_JSON) public interface EffectorApi { - @GET - @ApiOperation(value = "Fetch the list of effectors", - responseClass = "brooklyn.rest.domain.EffectorSummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List list( - @ApiParam(name = "application", value = "Application name", required = true) - @PathParam("application") final String application, - @ApiParam(name = "entity", value = "Entity name", required = true) - @PathParam("entity") final String entityToken - ) ; - - @POST - @Path("/{effector}") - @ApiOperation(value = "Trigger an effector", - notes="Returns the return value (status 200) if it completes, or an activity task ID (status 202) if it times out") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or effector") - }) - @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED}) - public Response invoke( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "effector", value = "Name of the effector to trigger", required = true) - @PathParam("effector") String effectorName, - - // TODO test timeout; and should it be header, form, or what? - @ApiParam(name = "timeout", value = "Delay before server should respond with activity task ID rather than result (in millis if no unit specified): " + - "'never' (blocking) is default; " + - "'0' means 'always' return task activity ID; " + - "and e.g. '1000' or '1s' will return a result if available within one second otherwise status 202 and the activity task ID", - required = false, defaultValue = "never") - @QueryParam("timeout") - String timeout, - - @ApiParam(/* FIXME: giving a `name` in swagger @ApiParam seems wrong as this object is the body, not a named argument */ name = "parameters", - value = "Effector parameters (as key value pairs)", required = false) - @Valid - Map parameters - ) ; + @GET + @ApiOperation(value = "Fetch the list of effectors", + responseClass = "brooklyn.rest.domain.EffectorSummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List list( + @ApiParam(name = "application", value = "Application name", required = true) + @PathParam("application") final String application, + @ApiParam(name = "entity", value = "Entity name", required = true) + @PathParam("entity") final String entityToken); + @POST + @Path("/{effector}") + @ApiOperation(value = "Trigger an effector", + notes="Returns the return value (status 200) if it completes, or an activity task ID (status 202) if it times out") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or effector") + }) + @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_FORM_URLENCODED}) + public Response invoke( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "effector", value = "Name of the effector to trigger", required = true) + @PathParam("effector") String effectorName, + + // TODO test timeout; and should it be header, form, or what? + @ApiParam(name = "timeout", value = "Delay before server should respond with activity task ID rather than result (in millis if no unit specified): " + + "'never' (blocking) is default; " + + "'0' means 'always' return task activity ID; " + + "and e.g. '1000' or '1s' will return a result if available within one second otherwise status 202 and the activity task ID", + required = false, defaultValue = "never") + @QueryParam("timeout") + String timeout, + + @ApiParam(/* FIXME: giving a `name` in swagger @ApiParam seems wrong as this object is the body, not a named argument */ name = "parameters", + value = "Effector parameters (as key value pairs)", required = false) + @Valid + Map parameters); } 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 f99ef187d1..feab918da2 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 @@ -41,205 +41,195 @@ @Consumes(MediaType.APPLICATION_JSON) public interface EntityApi { - @GET - @ApiOperation(value = "Fetch the list of entities for a given application", - responseClass = "brooklyn.rest.domain.EntitySummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application not found") - }) - public List list( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application) ; - - @GET - @Path("/{entity}") - @ApiOperation(value = "Fetch details about a specific application entity", - responseClass = "brooklyn.rest.domain.EntitySummary") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public EntitySummary get( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entity - ) ; - - // TODO rename as "/children" ? - @GET - @ApiOperation(value = "Fetch details about a specific application entity's children", - responseClass = "brooklyn.rest.domain.EntitySummary") - @Path("/{entity}/children") - public List getChildren( - @PathParam("application") final String application, - @PathParam("entity") final String entity - ); - - /** @deprecated since 0.7.0 use /children */ - @Deprecated - @Path("/{entity}/entities") - public List getChildrenOld( - @PathParam("application") final String application, - @PathParam("entity") final String entity - ); - - @POST - @ApiOperation(value = "Add a child or children to this entity given a YAML spec", - responseClass = "brooklyn.rest.domain.TaskSummary") - @Consumes({"application/x-yaml", - // see http://stackoverflow.com/questions/332129/yaml-mime-type - "text/yaml", "text/x-yaml", "application/yaml", MediaType.APPLICATION_JSON}) - @Path("/{entity}/children") - public Response addChildren( - @PathParam("application") final String application, - @PathParam("entity") final String entity, - - @ApiParam( - name = "start", - value = "Whether to automatically start this child; if omitted, true for Startable entities") - @QueryParam("start") final Boolean start, - - @ApiParam(name = "timeout", value = "Delay before server should respond with incomplete activity task, rather than completed task: " + - "'never' means block until complete; " + - "'0' means return task immediately; " + - "and e.g. '20ms' (the default) will wait 20ms for completed task information to be available", - required = false, defaultValue = "20ms") - @QueryParam("timeout") final String timeout, - - @ApiParam( - name = "childrenSpec", - value = "Entity spec in CAMP YAML format (including 'services' root element)", - required = true) - String yaml - ); - - @GET - @Path("/{entity}/activities") - @ApiOperation(value = "Fetch list of tasks for this entity") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List listTasks( - @ApiParam(value = "Entity ID or name", required = true) @PathParam("application") String applicationId, - @ApiParam(value = "Application ID or name", required = true) @PathParam("entity") String entityId); - - @GET - @Path("/{entity}/activities/{task}") - @ApiOperation(value = "Fetch task details", responseClass = "brooklyn.rest.domain.TaskSummary") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or task") - }) - @Produces("text/json") - public TaskSummary getTask( - @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken, - @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId - ); - - @GET - @ApiOperation(value = "Returns an icon for the entity, if defined") - @Path("/{entity}/icon") - public Response getIcon( - @PathParam("application") final String application, - @PathParam("entity") final String entity - ); - - @GET - @Path("/{entity}/tags") - @ApiOperation(value = "Fetch list of tags on this entity") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List listTags( - @ApiParam(value = "Entity ID or name", required = true) @PathParam("application") String applicationId, - @ApiParam(value = "Application ID or name", required = true) @PathParam("entity") String entityId); - - @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" - ) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Undefined application or entity") - }) - @Path("/{entity}/expunge") - 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") - @ApiOperation(value = "Fetch entity info for all (or filtered) descendants", - responseClass = "brooklyn.rest.domain.EntitySummary") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public List getDescendants( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entity, - @ApiParam(value="Regular expression for an entity type which must be matched", required=false) - @DefaultValue(".*") - @QueryParam("typeRegex") String typeRegex - ); - - @GET - @Path("/{entity}/descendants/sensor/{sensor}") - @ApiOperation(value = "Fetch values of a given sensor for all (or filtered) descendants") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public Map getDescendantsSensor( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entity, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensor, - @ApiParam(value="Regular expression applied to filter descendant entities based on their type", required=false) - @DefaultValue(".*") - @QueryParam("typeRegex") String typeRegex - ); - - @GET - @Path("/{entity}/locations") - @ApiOperation(value = "List the locations set on the entity") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public List getLocations( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entity); - - @GET - @Path("/{entity}/spec") - @ApiOperation(value = "Get the YAML spec used to create the entity, if available") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Application or entity missing") - }) - public String getSpec( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entity - ) ; - + @GET + @ApiOperation(value = "Fetch the list of entities for a given application", + responseClass = "brooklyn.rest.domain.EntitySummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application not found") + }) + public List list( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application) ; + + @GET + @Path("/{entity}") + @ApiOperation(value = "Fetch details about a specific application entity", + responseClass = "brooklyn.rest.domain.EntitySummary") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public EntitySummary get( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entity); + + // TODO rename as "/children" ? + @GET + @ApiOperation(value = "Fetch details about a specific application entity's children", + responseClass = "brooklyn.rest.domain.EntitySummary") + @Path("/{entity}/children") + public List getChildren( + @PathParam("application") final String application, + @PathParam("entity") final String entity); + + /** @deprecated since 0.7.0 use /children */ + @Deprecated + @Path("/{entity}/entities") + public List getChildrenOld( + @PathParam("application") final String application, + @PathParam("entity") final String entity); + + @POST + @ApiOperation(value = "Add a child or children to this entity given a YAML spec", + responseClass = "brooklyn.rest.domain.TaskSummary") + @Consumes({"application/x-yaml", + // see http://stackoverflow.com/questions/332129/yaml-mime-type + "text/yaml", "text/x-yaml", "application/yaml", MediaType.APPLICATION_JSON}) + @Path("/{entity}/children") + public Response addChildren( + @PathParam("application") final String application, + @PathParam("entity") final String entity, + + @ApiParam( + name = "start", + value = "Whether to automatically start this child; if omitted, true for Startable entities") + @QueryParam("start") final Boolean start, + + @ApiParam(name = "timeout", value = "Delay before server should respond with incomplete activity task, rather than completed task: " + + "'never' means block until complete; " + + "'0' means return task immediately; " + + "and e.g. '20ms' (the default) will wait 20ms for completed task information to be available", + required = false, defaultValue = "20ms") + @QueryParam("timeout") final String timeout, + + @ApiParam( + name = "childrenSpec", + value = "Entity spec in CAMP YAML format (including 'services' root element)", + required = true) + String yaml); + + @GET + @Path("/{entity}/activities") + @ApiOperation(value = "Fetch list of tasks for this entity") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List listTasks( + @ApiParam(value = "Entity ID or name", required = true) @PathParam("application") String applicationId, + @ApiParam(value = "Application ID or name", required = true) @PathParam("entity") String entityId); + + @GET + @Path("/{entity}/activities/{task}") + @ApiOperation(value = "Fetch task details", responseClass = "brooklyn.rest.domain.TaskSummary") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or task") + }) + @Produces("text/json") + public TaskSummary getTask( + @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken, + @ApiParam(value = "Task ID", required = true) @PathParam("task") String taskId); + + @GET + @ApiOperation(value = "Returns an icon for the entity, if defined") + @Path("/{entity}/icon") + public Response getIcon( + @PathParam("application") final String application, + @PathParam("entity") final String entity); + + @GET + @Path("/{entity}/tags") + @ApiOperation(value = "Fetch list of tags on this entity") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List listTags( + @ApiParam(value = "Entity ID or name", required = true) @PathParam("application") String applicationId, + @ApiParam(value = "Application ID or name", required = true) @PathParam("entity") String entityId); + + @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" + ) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Undefined application or entity") + }) + @Path("/{entity}/expunge") + 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") + @ApiOperation(value = "Fetch entity info for all (or filtered) descendants", + responseClass = "brooklyn.rest.domain.EntitySummary") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public List getDescendants( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entity, + @ApiParam(value="Regular expression for an entity type which must be matched", required=false) + @DefaultValue(".*") + @QueryParam("typeRegex") String typeRegex); + + @GET + @Path("/{entity}/descendants/sensor/{sensor}") + @ApiOperation(value = "Fetch values of a given sensor for all (or filtered) descendants") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public Map getDescendantsSensor( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entity, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensor, + @ApiParam(value="Regular expression applied to filter descendant entities based on their type", required=false) + @DefaultValue(".*") + @QueryParam("typeRegex") String typeRegex); + + @GET + @Path("/{entity}/locations") + @ApiOperation(value = "List the locations set on the entity") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public List getLocations( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entity); + + @GET + @Path("/{entity}/spec") + @ApiOperation(value = "Get the YAML spec used to create the entity, if available") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Application or entity missing") + }) + public String getSpec( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entity); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/EntityConfigApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/EntityConfigApi.java index 75f39b3e3d..b8b75b49d0 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/EntityConfigApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/EntityConfigApi.java @@ -38,107 +38,100 @@ @Consumes(MediaType.APPLICATION_JSON) public interface EntityConfigApi { - @GET - @ApiOperation(value = "Fetch the config keys for a specific application entity", - responseClass = "brooklyn.rest.domain.ConfigSummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List list( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken - ) ; + @GET + @ApiOperation(value = "Fetch the config keys for a specific application entity", + responseClass = "brooklyn.rest.domain.ConfigSummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List list( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken); - // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} - // (and in sensors class) - @GET - @Path("/current-state") - @ApiOperation(value = "Fetch config key values in batch", notes="Returns a map of config name to value") - public Map batchConfigRead( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Return raw config data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ) ; - - @GET - @Path("/{config}") - @ApiOperation(value = "Fetch config value (json)", responseClass = "Object") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or config key") - }) - @Produces(MediaType.APPLICATION_JSON) - public Object get( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Config key ID", required = true) - @PathParam("config") String configKeyName, - @ApiParam(value = "Return raw config data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ); + // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} + // (and in sensors class) + @GET + @Path("/current-state") + @ApiOperation(value = "Fetch config key values in batch", notes="Returns a map of config name to value") + public Map batchConfigRead( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Return raw config data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - // if user requests plain value we skip some json post-processing - @GET - @Path("/{config}") - @ApiOperation(value = "Fetch config value (text/plain)", responseClass = "Object") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or config key") - }) - @Produces(MediaType.TEXT_PLAIN) - public String getPlain( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Config key ID", required = true) - @PathParam("config") String configKeyName, - @ApiParam(value = "Return raw config data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ); + @GET + @Path("/{config}") + @ApiOperation(value = "Fetch config value (json)", responseClass = "Object") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or config key") + }) + @Produces(MediaType.APPLICATION_JSON) + public Object get( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Config key ID", required = true) + @PathParam("config") String configKeyName, + @ApiParam(value = "Return raw config data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - @POST - @ApiOperation(value = "Manually set multiple config values") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - @SuppressWarnings("rawtypes") - public void setFromMap( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Apply the config to all pre-existing descendants", required = false) - @QueryParam("recurse") @DefaultValue("false") final Boolean recurse, - @ApiParam(value = "Map of config key names to values", required = true) - Map newValues - ) ; + // if user requests plain value we skip some json post-processing + @GET + @Path("/{config}") + @ApiOperation(value = "Fetch config value (text/plain)", responseClass = "Object") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or config key") + }) + @Produces(MediaType.TEXT_PLAIN) + public String getPlain( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Config key ID", required = true) + @PathParam("config") String configKeyName, + @ApiParam(value = "Return raw config data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - @POST - @Path("/{config}") - @ApiOperation(value = "Manually set a config value") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or config key") - }) - public void set( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Config key name", required = true) - @PathParam("config") String configName, - @ApiParam(value = "Apply the config to all pre-existing descendants", required = false) - @QueryParam("recurse") @DefaultValue("false") final Boolean recurse, - @ApiParam(value = "Value to set") - Object newValue - ) ; + @POST + @ApiOperation(value = "Manually set multiple config values") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + @SuppressWarnings("rawtypes") + public void setFromMap( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Apply the config to all pre-existing descendants", required = false) + @QueryParam("recurse") @DefaultValue("false") final Boolean recurse, + @ApiParam(value = "Map of config key names to values", required = true) + Map newValues); - // deletion of config is not supported; you can set it null + @POST + @Path("/{config}") + @ApiOperation(value = "Manually set a config value") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or config key") + }) + public void set( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Config key name", required = true) + @PathParam("config") String configName, + @ApiParam(value = "Apply the config to all pre-existing descendants", required = false) + @QueryParam("recurse") @DefaultValue("false") final Boolean recurse, + @ApiParam(value = "Value to set") + Object newValue); + // deletion of config is not supported; you can set it null } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/LocationApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/LocationApi.java index 11342029ef..4b6e32f2de 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/LocationApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/LocationApi.java @@ -47,42 +47,40 @@ @Consumes(MediaType.APPLICATION_JSON) public interface LocationApi { - @GET - @ApiOperation(value = "Fetch the list of locations", - responseClass = "brooklyn.rest.domain.LocationSummary", - multiValueResponse = true) - public List list() ; + @GET + @ApiOperation(value = "Fetch the list of locations", + responseClass = "brooklyn.rest.domain.LocationSummary", + multiValueResponse = true) + public List list(); + // this is here to support the web GUI's circles + @GET + @Path("/usage/LocatedLocations") + @ApiOperation(value = "Return a summary of all usage", notes="interim API, expected to change") + public Map> getLocatedLocations(); - // this is here to support the web GUI's circles - @GET - @Path("/usage/LocatedLocations") - @ApiOperation(value = "Return a summary of all usage", notes="interim API, expected to change") - public Map> getLocatedLocations() ; + @GET + @Path("/{locationId}") + @ApiOperation(value = "Fetch details about a location", + responseClass = "brooklyn.rest.domain.LocationSummary", + multiValueResponse = true) + public LocationSummary get( + @ApiParam(value = "Location id to fetch", required = true) + @PathParam("locationId") String locationId, + @ApiParam(value = "Whether full (inherited) config should be compiled", required = false) + @DefaultValue("false") + @QueryParam("full") String fullConfig); - @GET - @Path("/{locationId}") - @ApiOperation(value = "Fetch details about a location", - responseClass = "brooklyn.rest.domain.LocationSummary", - multiValueResponse = true) - public LocationSummary get( - @ApiParam(value = "Location id to fetch", required = true) - @PathParam("locationId") String locationId, - @ApiParam(value = "Whether full (inherited) config should be compiled", required = false) - @DefaultValue("false") - @QueryParam("full") String fullConfig) ; - - @POST - @ApiOperation(value = "Create a new location", responseClass = "String") - public Response create( - @ApiParam(name = "locationSpec", value = "Location specification object", required = true) - @Valid LocationSpec locationSpec) ; - - @DELETE - @Path("/{locationId}") - @ApiOperation(value = "Delete a location object by id") - public void delete( - @ApiParam(value = "Location id to delete", required = true) - @PathParam("locationId") String locationId) ; + @POST + @ApiOperation(value = "Create a new location", responseClass = "String") + public Response create( + @ApiParam(name = "locationSpec", value = "Location specification object", required = true) + @Valid LocationSpec locationSpec); + @DELETE + @Path("/{locationId}") + @ApiOperation(value = "Delete a location object by id") + public void delete( + @ApiParam(value = "Location id to delete", required = true) + @PathParam("locationId") String locationId); } 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 7154ca51b7..72a91f5968 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 @@ -38,120 +38,114 @@ @Consumes(MediaType.APPLICATION_JSON) public interface PolicyApi { - @GET - @ApiOperation(value = "Fetch the policies attached to a specific application entity", - responseClass = "brooklyn.rest.domain.PolicySummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List list( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken - ) ; - - // TODO support parameters ?show=value,summary&name=xxx - // (and in sensors class) - @GET - @Path("/current-state") - @ApiOperation(value = "Fetch policy states in batch", notes="Returns a map of policy ID to whether it is active") - // FIXME method name -- this is nothing to do with config! - public Map batchConfigRead( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken) ; - - @POST - @ApiOperation(value = "Add a policy", notes = "Returns a summary of the new policy") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity"), - @ApiError(code = 400, reason = "Type is not a class implementing Policy") - }) - public PolicySummary addPolicy( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "policyType", value = "Class of policy to add", required = true) - @QueryParam("type") - String policyTypeName, - - // TODO would like to make this optional but jersey complains if we do - @ApiParam(name = "config", value = "Configuration for the policy (as key value pairs)", required = true) - Map config - ) ; - - @GET - @Path("/{policy}") - @ApiOperation(value = "Gets status of a policy (RUNNING / SUSPENDED)") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or policy") - }) - public Status getStatus( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "policy", value = "Policy ID or name", required = true) - @PathParam("policy") String policyId - ) ; - - @POST - @Path("/{policy}/start") - @ApiOperation(value = "Start or resume a policy") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or policy") - }) - public Response start( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "policy", value = "Policy ID or name", required = true) - @PathParam("policy") String policyId - ) ; - - @POST - @Path("/{policy}/stop") - @ApiOperation(value = "Suspends a policy") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or policy") - }) - public Response stop( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "policy", value = "Policy ID or name", required = true) - @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)") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or policy") - }) - public Response destroy( - @ApiParam(name = "application", value = "Application ID or name", required = true) - @PathParam("application") String application, - - @ApiParam(name = "entity", value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - - @ApiParam(name = "policy", value = "Policy ID or name", required = true) - @PathParam("policy") String policyToken - ) ; + @GET + @ApiOperation(value = "Fetch the policies attached to a specific application entity", + responseClass = "brooklyn.rest.domain.PolicySummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List list( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken); + + // TODO support parameters ?show=value,summary&name=xxx + // (and in sensors class) + @GET + @Path("/current-state") + @ApiOperation(value = "Fetch policy states in batch", notes="Returns a map of policy ID to whether it is active") + // FIXME method name -- this is nothing to do with config! + public Map batchConfigRead( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken) ; + + @POST + @ApiOperation(value = "Add a policy", notes = "Returns a summary of the new policy") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity"), + @ApiError(code = 400, reason = "Type is not a class implementing Policy") + }) + public PolicySummary addPolicy( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "policyType", value = "Class of policy to add", required = true) + @QueryParam("type") + String policyTypeName, + + // TODO would like to make this optional but jersey complains if we do + @ApiParam(name = "config", value = "Configuration for the policy (as key value pairs)", required = true) + Map config); + + @GET + @Path("/{policy}") + @ApiOperation(value = "Gets status of a policy (RUNNING / SUSPENDED)") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or policy") + }) + public Status getStatus( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "policy", value = "Policy ID or name", required = true) + @PathParam("policy") String policyId); + + @POST + @Path("/{policy}/start") + @ApiOperation(value = "Start or resume a policy") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or policy") + }) + public Response start( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "policy", value = "Policy ID or name", required = true) + @PathParam("policy") String policyId); + + @POST + @Path("/{policy}/stop") + @ApiOperation(value = "Suspends a policy") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or policy") + }) + public Response stop( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "policy", value = "Policy ID or name", required = true) + @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)") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or policy") + }) + public Response destroy( + @ApiParam(name = "application", value = "Application ID or name", required = true) + @PathParam("application") String application, + + @ApiParam(name = "entity", value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + + @ApiParam(name = "policy", value = "Policy ID or name", required = true) + @PathParam("policy") String policyToken); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyConfigApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyConfigApi.java index 235a777cda..79e1614518 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyConfigApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/PolicyConfigApi.java @@ -37,89 +37,84 @@ @Consumes(MediaType.APPLICATION_JSON) public interface PolicyConfigApi { - @GET - @ApiOperation(value = "Fetch the config keys for a specific policy", - responseClass = "brooklyn.rest.domain.ConfigSummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity or policy") - }) - public List list( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Policy ID or name", required = true) - @PathParam("policy") final String policyToken - ) ; + @GET + @ApiOperation(value = "Fetch the config keys for a specific policy", + responseClass = "brooklyn.rest.domain.ConfigSummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity or policy") + }) + public List list( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Policy ID or name", required = true) + @PathParam("policy") final String policyToken); - // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} - // (and in sensors class) - @GET - @Path("/current-state") - @ApiOperation(value = "Fetch config key values in batch", notes="Returns a map of config name to value") - public Map batchConfigRead( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Policy ID or name", required = true) - @PathParam("policy") String policyToken) ; + // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} + // (and in sensors class) + @GET + @Path("/current-state") + @ApiOperation(value = "Fetch config key values in batch", notes="Returns a map of config name to value") + public Map batchConfigRead( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Policy ID or name", required = true) + @PathParam("policy") String policyToken) ; - @GET - @Path("/{config}") - @ApiOperation(value = "Fetch config value", responseClass = "Object") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") - }) - public String get( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Policy ID or name", required = true) - @PathParam("policy") String policyToken, - @ApiParam(value = "Config key ID", required = true) - @PathParam("config") String configKeyName - ) ; - - /** @deprecated since 0.7.0 use set with object*/ @Deprecated - @POST - @Path("/{config}/set") - @ApiOperation(value = "Sets the given config on this policy") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") - }) - public Response set( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Policy ID or name", required = true) - @PathParam("policy") String policyToken, - @ApiParam(value = "Config key ID", required = true) - @PathParam("config") String configKeyName, - @ApiParam(name = "value", value = "New value for the configuration", required = true) - @QueryParam("value") String value - ) ; - - @POST - @Path("/{config}") - @ApiOperation(value = "Sets the given config on this policy") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") - }) - public Response set( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") String entityToken, - @ApiParam(value = "Policy ID or name", required = true) - @PathParam("policy") String policyToken, - @ApiParam(value = "Config key ID", required = true) - @PathParam("config") String configKeyName, - @ApiParam(name = "value", value = "New value for the configuration", required = true) - Object value - ) ; + @GET + @Path("/{config}") + @ApiOperation(value = "Fetch config value", responseClass = "Object") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") + }) + public String get( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Policy ID or name", required = true) + @PathParam("policy") String policyToken, + @ApiParam(value = "Config key ID", required = true) + @PathParam("config") String configKeyName); + /** @deprecated since 0.7.0 use set with object*/ @Deprecated + @POST + @Path("/{config}/set") + @ApiOperation(value = "Sets the given config on this policy") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") + }) + public Response set( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Policy ID or name", required = true) + @PathParam("policy") String policyToken, + @ApiParam(value = "Config key ID", required = true) + @PathParam("config") String configKeyName, + @ApiParam(name = "value", value = "New value for the configuration", required = true) + @QueryParam("value") String value); + + @POST + @Path("/{config}") + @ApiOperation(value = "Sets the given config on this policy") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") + }) + public Response set( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") String entityToken, + @ApiParam(value = "Policy ID or name", required = true) + @PathParam("policy") String policyToken, + @ApiParam(value = "Config key ID", required = true) + @PathParam("config") String configKeyName, + @ApiParam(name = "value", value = "New value for the configuration", required = true) + Object value); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ScriptApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ScriptApi.java index db56a1744e..23e172ffb7 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/ScriptApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ScriptApi.java @@ -44,11 +44,9 @@ public interface ScriptApi { @Path("/groovy") @Consumes("application/text") @ApiOperation(value = "Execute a groovy script", - responseClass = "brooklyn.rest.domain.SensorSummary") + responseClass = "brooklyn.rest.domain.SensorSummary") public ScriptExecutionSummary groovy( @Context HttpServletRequest request, @ApiParam(name = "script", value = "Groovy script to execute", required = true) - String script - ) ; - + String script); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/SensorApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/SensorApi.java index 9f05f526ba..916786ca99 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/SensorApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/SensorApi.java @@ -46,113 +46,105 @@ @Consumes(MediaType.APPLICATION_JSON) public interface SensorApi { - @GET - @ApiOperation(value = "Fetch the sensor list for a specific application entity", - responseClass = "brooklyn.rest.domain.SensorSummary", - multiValueResponse = true) - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - public List list( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken - ) ; + @GET + @ApiOperation(value = "Fetch the sensor list for a specific application entity", + responseClass = "brooklyn.rest.domain.SensorSummary", + multiValueResponse = true) + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + public List list( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken); - @GET - @Path("/current-state") - @ApiOperation(value = "Fetch sensor values in batch", notes="Returns a map of sensor name to value") - public Map batchSensorRead( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Return raw sensor data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ) ; + @GET + @Path("/current-state") + @ApiOperation(value = "Fetch sensor values in batch", notes="Returns a map of sensor name to value") + public Map batchSensorRead( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Return raw sensor data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - @GET - @Path("/{sensor}") - @ApiOperation(value = "Fetch sensor value (json)", responseClass = "Object") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or sensor") - }) - public Object get( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensorName, - @ApiParam(value = "Return raw sensor data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ) ; + @GET + @Path("/{sensor}") + @ApiOperation(value = "Fetch sensor value (json)", responseClass = "Object") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or sensor") + }) + public Object get( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensorName, + @ApiParam(value = "Return raw sensor data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - // this method is used if user has requested plain (ie not converting to json) - @GET - @Path("/{sensor}") - @ApiOperation(value = "Fetch sensor value (text/plain)", responseClass = "String") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or sensor") - }) - @Produces(MediaType.TEXT_PLAIN) - public String getPlain( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensorName, - @ApiParam(value = "Return raw sensor data instead of display values", required = false) - @QueryParam("raw") @DefaultValue("false") final Boolean raw - ) ; + // this method is used if user has requested plain (ie not converting to json) + @GET + @Path("/{sensor}") + @ApiOperation(value = "Fetch sensor value (text/plain)", responseClass = "String") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or sensor") + }) + @Produces(MediaType.TEXT_PLAIN) + public String getPlain( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensorName, + @ApiParam(value = "Return raw sensor data instead of display values", required = false) + @QueryParam("raw") @DefaultValue("false") final Boolean raw); - @POST - @ApiOperation(value = "Manually set multiple sensor values") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application or entity") - }) - @SuppressWarnings("rawtypes") - public void setFromMap( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Map of sensor names to values", required = true) - Map newValues - ) ; + @POST + @ApiOperation(value = "Manually set multiple sensor values") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application or entity") + }) + @SuppressWarnings("rawtypes") + public void setFromMap( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Map of sensor names to values", required = true) + Map newValues); - @POST - @Path("/{sensor}") - @ApiOperation(value = "Manually set a sensor value") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or sensor") - }) - public void set( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensorName, - @ApiParam(value = "Value to set") - Object newValue - ) ; - - @DELETE - @Path("/{sensor}") - @ApiOperation(value = "Manually clear a sensor value") - @ApiErrors(value = { - @ApiError(code = 404, reason = "Could not find application, entity or sensor") - }) - public void delete( - @ApiParam(value = "Application ID or name", required = true) - @PathParam("application") final String application, - @ApiParam(value = "Entity ID or name", required = true) - @PathParam("entity") final String entityToken, - @ApiParam(value = "Sensor name", required = true) - @PathParam("sensor") String sensorName - ) ; + @POST + @Path("/{sensor}") + @ApiOperation(value = "Manually set a sensor value") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or sensor") + }) + public void set( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensorName, + @ApiParam(value = "Value to set") + Object newValue); + @DELETE + @Path("/{sensor}") + @ApiOperation(value = "Manually clear a sensor value") + @ApiErrors(value = { + @ApiError(code = 404, reason = "Could not find application, entity or sensor") + }) + public void delete( + @ApiParam(value = "Application ID or name", required = true) + @PathParam("application") final String application, + @ApiParam(value = "Entity ID or name", required = true) + @PathParam("entity") final String entityToken, + @ApiParam(value = "Sensor name", required = true) + @PathParam("sensor") String sensorName); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java index 246e31a436..add51c4d1c 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/ServerApi.java @@ -61,18 +61,18 @@ public interface ServerApi { @ApiOperation(value = "Terminate this Brooklyn server instance") @Consumes({MediaType.APPLICATION_FORM_URLENCODED}) public void shutdown( - @ApiParam(name = "stopAppsFirst", value = "Whether to stop running applications before shutting down") - @FormParam("stopAppsFirst") @DefaultValue("false") boolean stopAppsFirst, - @ApiParam(name = "forceShutdownOnError", value ="Force shutdown if apps fail to stop or timeout") - @FormParam("forceShutdownOnError") @DefaultValue("false") boolean forceShutdownOnError, - @ApiParam(name = "shutdownTimeout", value = "A maximum delay to wait for apps to gracefully stop before giving up or forcibly exiting, 0 to wait infinitely") - @FormParam("shutdownTimeout") @DefaultValue("20s") String shutdownTimeout, - @ApiParam(name = "requestTimeout", value = "Maximum time to block the request for the shutdown to finish, 0 to wait infinitely") - @FormParam("requestTimeout") @DefaultValue("20s") String requestTimeout, - @ApiParam(name = "delayForHttpReturn", value = "The delay before exiting the process, to permit the REST response to be returned") - @FormParam("delayForHttpReturn") @DefaultValue("5s") String delayForHttpReturn, - @ApiParam(name = "delayMillis", value = "Deprecated, analogous to delayForHttpReturn") - @FormParam("delayMillis") Long delayMillis); + @ApiParam(name = "stopAppsFirst", value = "Whether to stop running applications before shutting down") + @FormParam("stopAppsFirst") @DefaultValue("false") boolean stopAppsFirst, + @ApiParam(name = "forceShutdownOnError", value ="Force shutdown if apps fail to stop or timeout") + @FormParam("forceShutdownOnError") @DefaultValue("false") boolean forceShutdownOnError, + @ApiParam(name = "shutdownTimeout", value = "A maximum delay to wait for apps to gracefully stop before giving up or forcibly exiting, 0 to wait infinitely") + @FormParam("shutdownTimeout") @DefaultValue("20s") String shutdownTimeout, + @ApiParam(name = "requestTimeout", value = "Maximum time to block the request for the shutdown to finish, 0 to wait infinitely") + @FormParam("requestTimeout") @DefaultValue("20s") String requestTimeout, + @ApiParam(name = "delayForHttpReturn", value = "The delay before exiting the process, to permit the REST response to be returned") + @FormParam("delayForHttpReturn") @DefaultValue("5s") String delayForHttpReturn, + @ApiParam(name = "delayMillis", value = "Deprecated, analogous to delayForHttpReturn") + @FormParam("delayMillis") Long delayMillis); @GET @Path("/version") @@ -83,15 +83,15 @@ public void shutdown( @GET @Path("/status") @ApiOperation(value = "Returns the status of this Brooklyn instance [DEPRECATED; see ../ha/state]", - responseClass = "String", - multiValueResponse = false) + responseClass = "String", + multiValueResponse = false) public String getStatus(); @Deprecated /** @deprecated since 0.7.0 use /ha/states */ @GET @Path("/highAvailability") @ApiOperation(value = "Returns the status of all Brooklyn instances in the management plane [DEPRECATED; see ../ha/states]", - responseClass = "brooklyn.rest.domain.HighAvailabilitySummary") + responseClass = "brooklyn.rest.domain.HighAvailabilitySummary") public HighAvailabilitySummary getHighAvailability(); @GET @@ -114,7 +114,7 @@ public ManagementNodeState setHighAvailabilityNodeState( @GET @Path("/ha/states") @ApiOperation(value = "Returns the HA states and detail for all nodes in this management plane", - responseClass = "brooklyn.rest.domain.HighAvailabilitySummary") + responseClass = "brooklyn.rest.domain.HighAvailabilitySummary") public HighAvailabilitySummary getHighAvailabilityPlaneStates(); @GET @@ -135,7 +135,7 @@ public long setHighAvailabilityPriority( @ApiOperation(value = "Retrieves the persistence store data, as an archive") public Response exportPersistenceData( @ApiParam(name = "origin", value = "Whether to take from LOCAL or REMOTE state; default to AUTO detect, " - + "using LOCAL as master and REMOTE for other notes") + + "using LOCAL as master and REMOTE for other notes") @QueryParam("origin") @DefaultValue("AUTO") String origin); // TODO would be nice to allow setting, as a means to recover / control more easily than messing with persistent stores @@ -156,7 +156,8 @@ public Response exportPersistenceData( @GET @Path("/user") - @ApiOperation(value = "Return user information for this Brooklyn instance", responseClass = "String", multiValueResponse = false) + @ApiOperation(value = "Return user information for this Brooklyn instance", + responseClass = "String", multiValueResponse = false) public String getUser(); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/api/VersionApi.java b/usage/rest-api/src/main/java/brooklyn/rest/api/VersionApi.java index bee083b6a0..905e0fc46f 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/api/VersionApi.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/api/VersionApi.java @@ -36,7 +36,7 @@ public interface VersionApi { @GET - @ApiOperation(value = "Return version identifier information for this Brooklyn instance; deprecated, use /server/version", responseClass = "String", multiValueResponse = false) - public String getVersion() ; - + @ApiOperation(value = "Return version identifier information for this Brooklyn instance; deprecated, use /server/version", + responseClass = "String", multiValueResponse = false) + public String getVersion(); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSpec.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSpec.java index 2675880137..f85468fc2d 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSpec.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/ApplicationSpec.java @@ -34,142 +34,145 @@ public class ApplicationSpec implements HasName { - public static Builder builder() { - return new Builder(); - } - - public static class Builder { - private String name; - private String type; - private Set entities; - private Set locations; - private Map config; - - public Builder from(ApplicationSpec spec) { - this.name = spec.name; - this.entities = spec.entities; - this.locations = spec.locations; - return this; + public static Builder builder() { + return new Builder(); } - public Builder name(String name) { - this.name = name; - return this; + public static class Builder { + private String name; + private String type; + private Set entities; + private Set locations; + private Map config; + + public Builder from(ApplicationSpec spec) { + this.name = spec.name; + this.entities = spec.entities; + this.locations = spec.locations; + return this; + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder type(String type) { + this.type = type; + return this; + } + + public Builder entities(Set entities) { + this.entities = entities; + return this; + } + + public Builder locations(Set locations) { + this.locations = locations; + return this; + } + + public Builder config(Map config) { + this.config = config; + return this; + } + + public ApplicationSpec build() { + return new ApplicationSpec(name, type, entities, locations, config); + } } - public Builder type(String type) { - this.type = type; - return this; - } + private final String name; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String type; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Set entities; + private final Set locations; + @JsonSerialize(include = Inclusion.NON_EMPTY) + private final Map config; - public Builder entities(Set entities) { - this.entities = entities; - return this; + public ApplicationSpec( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("entities") Set entities, + @JsonProperty("locations") Collection locations, + @JsonProperty("config") Map config) { + this.name = name; + this.type = type; + if (entities==null) { + this.entities = null; + } else { + this.entities = (entities.isEmpty() && type!=null) ? null : ImmutableSet.copyOf(entities); } + this.locations = ImmutableSet.copyOf(checkNotNull(locations, "locations must be provided for an application spec")); + this.config = config == null ? Collections.emptyMap() : ImmutableMap.copyOf(config); + if (this.entities!=null && this.type!=null) throw new IllegalStateException("cannot supply both type and entities for an application spec"); + // valid for both to be null, e.g. for an anonymous type +// if (this.entities==null && this.type==null) throw new IllegalStateException("must supply either type or entities for an application spec"); + } - public Builder locations(Set locations) { - this.locations = locations; - return this; + @Override + public String getName() { + return name; } - public Builder config(Map config) { - this.config = config; - return this; + public String getType() { + return type; } - public ApplicationSpec build() { - return new ApplicationSpec(name, type, entities, locations, config); + public Set getEntities() { + return entities; } - } - - private final String name; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String type; - @JsonSerialize(include=Inclusion.NON_NULL) - private final Set entities; - private final Set locations; - @JsonSerialize(include=Inclusion.NON_EMPTY) - private final Map config; - - public ApplicationSpec( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("entities") Set entities, - @JsonProperty("locations") Collection locations, - @JsonProperty("config") Map config - ) { - this.name = name; - this.type = type; - if (entities==null) this.entities = null; - else this.entities = (entities.isEmpty() && type!=null) ? null : ImmutableSet.copyOf(entities); - this.locations = ImmutableSet.copyOf(checkNotNull(locations, "locations must be provided for an application spec")); - this.config = config == null ? Collections.emptyMap() : ImmutableMap.copyOf(config); - if (this.entities!=null && this.type!=null) throw new IllegalStateException("cannot supply both type and entities for an application spec"); - // valid for both to be null, e.g. for an anonymous type -// if (this.entities==null && this.type==null) throw new IllegalStateException("must supply either type or entities for an application spec"); - } - @Override - public String getName() { - return name; - } - - public String getType() { - return type; -} - - public Set getEntities() { - return entities; - } + public Set getLocations() { + return locations; + } - public Set getLocations() { - return locations; - } + public Map getConfig() { + return config; + } - public Map getConfig() { - return config; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ApplicationSpec that = (ApplicationSpec) o; - - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - if (type != null ? !type.equals(that.type) : that.type != null) - return false; - if (entities != null ? !entities.equals(that.entities) : that.entities != null) - return false; - if (locations != null ? !locations.equals(that.locations) : that.locations != null) - return false; - if (config != null ? !config.equals(that.config) : that.config != null) - return false; - - return true; - } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + ApplicationSpec that = (ApplicationSpec) o; + + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + if (type != null ? !type.equals(that.type) : that.type != null) + return false; + if (entities != null ? !entities.equals(that.entities) : that.entities != null) + return false; + if (locations != null ? !locations.equals(that.locations) : that.locations != null) + return false; + if (config != null ? !config.equals(that.config) : that.config != null) + return false; + + return true; + } - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (entities != null ? entities.hashCode() : 0); - result = 31 * result + (locations != null ? locations.hashCode() : 0); - result = 31 * result + (config != null ? config.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (entities != null ? entities.hashCode() : 0); + result = 31 * result + (locations != null ? locations.hashCode() : 0); + result = 31 * result + (config != null ? config.hashCode() : 0); + return result; + } - @Override - public String toString() { - return "ApplicationSpec{" + - "name='" + name + '\'' + - ", type=" + type + - ", entitySpecs=" + entities + - ", locations=" + locations + - ", config=" + config + - '}'; + @Override + public String toString() { + return "ApplicationSpec{" + + "name='" + name + '\'' + + ", type=" + type + + ", entitySpecs=" + entities + + ", locations=" + locations + + ", config=" + config + + '}'; } - } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/ConfigSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/ConfigSummary.java index c523b7dd26..2c02c70a84 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/ConfigSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/ConfigSummary.java @@ -38,135 +38,132 @@ public abstract class ConfigSummary implements HasName { - private final String name; - private final String type; - @JsonSerialize(include=Inclusion.NON_NULL) - private final Object defaultValue; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String description; - @JsonSerialize - private final boolean reconfigurable; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String label; - @JsonSerialize(include=Inclusion.NON_NULL) - private final Double priority; - @JsonSerialize(include=Inclusion.NON_NULL) - private final List> possibleValues; - - protected ConfigSummary( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("description") String description, - @JsonProperty("defaultValue") Object defaultValue, - @JsonProperty("reconfigurable") boolean reconfigurable, - @JsonProperty("label") String label, - @JsonProperty("priority") Double priority, - @JsonProperty("possibleValues") List> possibleValues - ) { - this.name = name; - this.type = type; - this.description = description; - this.defaultValue = defaultValue; - this.reconfigurable = reconfigurable; - this.label = label; - this.priority = priority; - this.possibleValues = possibleValues; - } - - protected ConfigSummary(ConfigKey config) { - this(config, null, null); - } - - @SuppressWarnings("rawtypes") - protected ConfigSummary(ConfigKey config, String label, Double priority) { - this.name = config.getName(); - this.description = config.getDescription(); - this.reconfigurable = config.isReconfigurable(); - - /* Use String, to guarantee it is serializable; otherwise get: - * No serializer found for class brooklyn.policy.autoscaling.AutoScalerPolicy$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[9]->brooklyn.rest.domain.PolicyConfigSummary["defaultValue"]) - * at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52) - */ - this.label = label; - this.priority = priority; - if (config.getType().isEnum()) { - this.type = Enum.class.getName(); - this.defaultValue = (config.getDefaultValue() == null) ? null : ((Enum)config.getDefaultValue()).name(); - this.possibleValues = FluentIterable - .from(Arrays.asList((Enum[])(config.getType().getEnumConstants()))) - .transform(new Function>() { - @Nullable - @Override - public Map apply(@Nullable Enum input) { - return ImmutableMap.of( - "value", input != null ? input.name() : null, - "description", input != null ? input.toString() : null - ); - } - }) - .toList(); - } else { - this.type = config.getTypeName(); - this.defaultValue = Jsonya.convertToJsonPrimitive(config.getDefaultValue()); - this.possibleValues = null; + private final String name; + private final String type; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Object defaultValue; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String description; + @JsonSerialize + private final boolean reconfigurable; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String label; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Double priority; + @JsonSerialize(include = Inclusion.NON_NULL) + private final List> possibleValues; + + protected ConfigSummary( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("description") String description, + @JsonProperty("defaultValue") Object defaultValue, + @JsonProperty("reconfigurable") boolean reconfigurable, + @JsonProperty("label") String label, + @JsonProperty("priority") Double priority, + @JsonProperty("possibleValues") List> possibleValues) { + this.name = name; + this.type = type; + this.description = description; + this.defaultValue = defaultValue; + this.reconfigurable = reconfigurable; + this.label = label; + this.priority = priority; + this.possibleValues = possibleValues; } - } - - @Override - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getDescription() { - return description; - } - - public boolean isReconfigurable() { - return reconfigurable; - } - - public Object getDefaultValue() { - // note constructor has converted to string, so this is safe for clients to use - return defaultValue; - } - - public String getLabel() { - return label; - } - - public Double getPriority() { - return priority; - } - - public List> getPossibleValues() { - return possibleValues; - } - - public abstract Map getLinks(); - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ConfigSummary that = (ConfigSummary) o; - - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - return result; - } - - @Override - public abstract String toString(); + + protected ConfigSummary(ConfigKey config) { + this(config, null, null); + } + + @SuppressWarnings("rawtypes") + protected ConfigSummary(ConfigKey config, String label, Double priority) { + this.name = config.getName(); + this.description = config.getDescription(); + this.reconfigurable = config.isReconfigurable(); + + /* Use String, to guarantee it is serializable; otherwise get: + * No serializer found for class brooklyn.policy.autoscaling.AutoScalerPolicy$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[9]->brooklyn.rest.domain.PolicyConfigSummary["defaultValue"]) + * at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52) + */ + this.label = label; + this.priority = priority; + if (config.getType().isEnum()) { + this.type = Enum.class.getName(); + this.defaultValue = (config.getDefaultValue() == null) ? null : ((Enum) config.getDefaultValue()).name(); + this.possibleValues = FluentIterable + .from(Arrays.asList((Enum[])(config.getType().getEnumConstants()))) + .transform(new Function>() { + @Nullable + @Override + public Map apply(@Nullable Enum input) { + return ImmutableMap.of( + "value", input != null ? input.name() : null, + "description", input != null ? input.toString() : null); + }}) + .toList(); + } else { + this.type = config.getTypeName(); + this.defaultValue = Jsonya.convertToJsonPrimitive(config.getDefaultValue()); + this.possibleValues = null; + } + } + + @Override + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getDescription() { + return description; + } + + public boolean isReconfigurable() { + return reconfigurable; + } + + public Object getDefaultValue() { + // note constructor has converted to string, so this is safe for clients to use + return defaultValue; + } + + public String getLabel() { + return label; + } + + public Double getPriority() { + return priority; + } + + public List> getPossibleValues() { + return possibleValues; + } + + public abstract Map getLinks(); + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConfigSummary that = (ConfigSummary) o; + + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + return result; + } + + @Override + public abstract String toString(); } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/EffectorSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/EffectorSummary.java index 6adebd8113..fcc1d399fa 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/EffectorSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/EffectorSummary.java @@ -31,156 +31,152 @@ public class EffectorSummary implements HasName { - public static class ParameterSummary implements HasName { + public static class ParameterSummary implements HasName { + private final String name; + private final String type; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String description; + private final T defaultValue; + + public ParameterSummary ( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("description") String description, + @JsonProperty("defaultValue") T defaultValue) { + this.name = name; + this.type = type; + this.description = description; + this.defaultValue = defaultValue; + } + + @Override + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getDescription() { + return description; + } + + public T getDefaultValue() { + return defaultValue; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ParameterSummary that = (ParameterSummary) o; + + return Objects.equal(this.name, that.name) + && Objects.equal(this.type, that.type) + && Objects.equal(this.description, that.description) + && Objects.equal(this.defaultValue, that.defaultValue); + } + + @Override + public int hashCode() { + return Objects.hashCode(name, type, description, defaultValue); + } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .omitNullValues() + .add("name", name) + .add("type", type) + .add("description", description) + .add("defaultValue", defaultValue) + .toString(); + } + } + private final String name; - private final String type; - @JsonSerialize(include=Inclusion.NON_NULL) + private final String returnType; + private final Set> parameters; + @JsonSerialize(include = Inclusion.NON_NULL) private final String description; - private final T defaultValue; - - public ParameterSummary ( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("description") String description, - @JsonProperty("defaultValue") T defaultValue - ) { - this.name = name; - this.type = type; - this.description = description; - this.defaultValue = defaultValue; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Map links; + + public EffectorSummary( + @JsonProperty("name") String name, + @JsonProperty("returnType") String returnType, + @JsonProperty("parameters") Set> parameters, + @JsonProperty("description") String description, + @JsonProperty("links") Map links) { + this.name = name; + this.description = description; + this.returnType = returnType; + this.parameters = parameters; + this.links = links != null ? ImmutableMap.copyOf(links) : null; } @Override public String getName() { - return name; + return name; } - public String getType() { - return type; + public String getDescription() { + return description; } - public String getDescription() { - return description; + public String getReturnType() { + return returnType; } - - public T getDefaultValue() { - return defaultValue; + + public Set> getParameters() { + return parameters; + } + + public Map getLinks() { + return links; } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ParameterSummary that = (ParameterSummary) o; - - return Objects.equal(this.name, that.name) && - Objects.equal(this.type, that.type) && - Objects.equal(this.description, that.description) && - Objects.equal(this.defaultValue, that.defaultValue); - + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EffectorSummary that = (EffectorSummary) o; + + if (description != null ? !description.equals(that.description) : that.description != null) + return false; + if (links != null ? !links.equals(that.links) : that.links != null) + return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) + return false; + if (returnType != null ? !returnType.equals(that.returnType) : that.returnType != null) + return false; + + return true; } @Override public int hashCode() { - return Objects.hashCode(name, type, description, defaultValue); + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + (returnType != null ? returnType.hashCode() : 0); + result = 31 * result + (parameters != null ? parameters.hashCode() : 0); + result = 31 * result + (links != null ? links.hashCode() : 0); + return result; } @Override public String toString() { - return Objects.toStringHelper(this) - .omitNullValues() - .add("name", name) - .add("type", type) - .add("description", description) - .add("defaultValue", defaultValue) - .toString(); + return "EffectorSummary{" + + "name='" + name + '\'' + + ", description='" + description + '\'' + + ", returnType='" + returnType + '\'' + + ", parameters=" + parameters + + ", links=" + links + + '}'; } - - } - - private final String name; - private final String returnType; - private final Set> parameters; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String description; - @JsonSerialize(include=Inclusion.NON_NULL) - private final Map links; - - public EffectorSummary( - @JsonProperty("name") String name, - @JsonProperty("returnType") String returnType, - @JsonProperty("parameters") Set> parameters, - @JsonProperty("description") String description, - @JsonProperty("links") Map links - ) { - this.name = name; - this.description = description; - this.returnType = returnType; - this.parameters = parameters; - this.links = links != null ? ImmutableMap.copyOf(links) : null; - } - - @Override - public String getName() { - return name; - } - - public String getDescription() { - return description; - } - - public String getReturnType() { - return returnType; - } - - public Set> getParameters() { - return parameters; - } - - public Map getLinks() { - return links; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - EffectorSummary that = (EffectorSummary) o; - - if (description != null ? !description.equals(that.description) : that.description != null) - return false; - if (links != null ? !links.equals(that.links) : that.links != null) - return false; - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) - return false; - if (returnType != null ? !returnType.equals(that.returnType) : that.returnType != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (description != null ? description.hashCode() : 0); - result = 31 * result + (returnType != null ? returnType.hashCode() : 0); - result = 31 * result + (parameters != null ? parameters.hashCode() : 0); - result = 31 * result + (links != null ? links.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "EffectorSummary{" + - "name='" + name + '\'' + - ", description='" + description + '\'' + - ", returnType='" + returnType + '\'' + - ", parameters=" + parameters + - ", links=" + links + - '}'; - } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntityConfigSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntityConfigSummary.java index 4911d9ac48..367ff5d4f7 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntityConfigSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntityConfigSummary.java @@ -30,40 +30,38 @@ public class EntityConfigSummary extends ConfigSummary { - @JsonSerialize(include=Inclusion.NON_NULL) - private final Map links; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Map links; - public EntityConfigSummary( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("description") String description, - @JsonProperty("defaultValue") Object defaultValue, - @JsonProperty("reconfigurable") boolean reconfigurable, - @JsonProperty("label") String label, - @JsonProperty("priority") Double priority, - @JsonProperty("possibleValues") List> possibleValues, - @JsonProperty("links") Map links - ) { - super(name, type, description, defaultValue, reconfigurable, label, priority, possibleValues); - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } + public EntityConfigSummary( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("description") String description, + @JsonProperty("defaultValue") Object defaultValue, + @JsonProperty("reconfigurable") boolean reconfigurable, + @JsonProperty("label") String label, + @JsonProperty("priority") Double priority, + @JsonProperty("possibleValues") List> possibleValues, + @JsonProperty("links") Map links) { + super(name, type, description, defaultValue, reconfigurable, label, priority, possibleValues); + this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); + } - public EntityConfigSummary(ConfigKey config, String label, Double priority, Map links) { - super(config, label, priority); - this.links = links!=null ? ImmutableMap.copyOf(links) : null; - } + public EntityConfigSummary(ConfigKey config, String label, Double priority, Map links) { + super(config, label, priority); + this.links = links != null ? ImmutableMap.copyOf(links) : null; + } - @Override - public Map getLinks() { - return links; - } - - @Override - public String toString() { - return "EntityConfigSummary{" + - "name='" + getName() + '\'' + - ", type='" + getType() + '\'' + - '}'; - } + @Override + public Map getLinks() { + return links; + } + @Override + public String toString() { + return "EntityConfigSummary{" + + "name='" + getName() + '\'' + + ", type='" + getType() + '\'' + + '}'; + } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySpec.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySpec.java index 9264329df6..f90d896bf1 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySpec.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySpec.java @@ -27,72 +27,71 @@ public class EntitySpec implements HasName { - private final String name; - private final String type; - private final Map config; - - public EntitySpec(String type) { - this(null, type); - } - - public EntitySpec(String name, String type) { - this(name, type, Collections.emptyMap()); - } - - public EntitySpec( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("config") Map config - ) { - this.type = checkNotNull(type, "type"); - this.name = (name == null) ? type : name; - this.config = (config != null) ? ImmutableMap.copyOf(config) : ImmutableMap.of(); - } - - @Override - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public Map getConfig() { - return config; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - EntitySpec entitySpec = (EntitySpec) o; - - if (config != null ? !config.equals(entitySpec.config) : entitySpec.config != null) - return false; - if (name != null ? !name.equals(entitySpec.name) : entitySpec.name != null) - return false; - if (type != null ? !type.equals(entitySpec.type) : entitySpec.type != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (config != null ? config.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "EntitySpec{" + - "name='" + name + '\'' + - ", type='" + type + '\'' + - ", config=" + config + - '}'; - } + private final String name; + private final String type; + private final Map config; + + public EntitySpec(String type) { + this(null, type); + } + + public EntitySpec(String name, String type) { + this(name, type, Collections. emptyMap()); + } + + public EntitySpec( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("config") Map config) { + this.type = checkNotNull(type, "type"); + this.name = (name == null) ? type : name; + this.config = (config != null) ? ImmutableMap.copyOf(config) : ImmutableMap. of(); + } + + @Override + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public Map getConfig() { + return config; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + EntitySpec entitySpec = (EntitySpec) o; + + if (config != null ? !config.equals(entitySpec.config) : entitySpec.config != null) + return false; + if (name != null ? !name.equals(entitySpec.name) : entitySpec.name != null) + return false; + if (type != null ? !type.equals(entitySpec.type) : entitySpec.type != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (config != null ? config.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "EntitySpec{" + + "name='" + name + '\'' + + ", type='" + type + '\'' + + ", config=" + config + + '}'; + } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySummary.java index 3118986379..e3e67d4da8 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/EntitySummary.java @@ -29,67 +29,66 @@ public class EntitySummary implements HasId, HasName { - private final String id; - private final String name; - private final String type; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String catalogItemId; - private final Map links; + private final String id; + private final String name; + private final String type; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String catalogItemId; + private final Map links; - public EntitySummary( - @JsonProperty("id") String id, - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("catalogItemId") String catalogItemId, - @JsonProperty("links") Map links - ) { - this.type = type; - this.id = id; - this.name = name; - this.catalogItemId = catalogItemId; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } + public EntitySummary( + @JsonProperty("id") String id, + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("catalogItemId") String catalogItemId, + @JsonProperty("links") Map links) { + this.type = type; + this.id = id; + this.name = name; + this.catalogItemId = catalogItemId; + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } - public String getType() { - return type; - } + public String getType() { + return type; + } - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - public String getCatalogItemId() { - return catalogItemId; -} - - public Map getLinks() { - return links; - } + @Override + public String getId() { + return id; + } - @Override - public boolean equals(Object o) { - return (o instanceof EntitySummary) && id.equals(((EntitySummary)o).getId()); - } + @Override + public String getName() { + return name; + } - @Override - public int hashCode() { - return id != null ? id.hashCode() : 0; - } + public String getCatalogItemId() { + return catalogItemId; + } + + public Map getLinks() { + return links; + } + + @Override + public boolean equals(Object o) { + return (o instanceof EntitySummary) && id.equals(((EntitySummary) o).getId()); + } + + @Override + public int hashCode() { + return id != null ? id.hashCode() : 0; + } - @Override - public String toString() { - return "EntitySummary{" + - "id='" + id + '\'' + - ", name=" + name + - ", type=" + type + - ", catalogItemId=" + catalogItemId + - ", links=" + links + - '}'; + @Override + public String toString() { + return "EntitySummary{" + + "id='" + id + '\'' + + ", name=" + name + + ", type=" + type + + ", catalogItemId=" + catalogItemId + + ", links=" + links + + '}'; } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/HighAvailabilitySummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/HighAvailabilitySummary.java index 33c6f3ee22..915f80e5b6 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/HighAvailabilitySummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/HighAvailabilitySummary.java @@ -40,102 +40,100 @@ public HaNodeSummary( @JsonProperty("nodeUri") URI nodeUri, @JsonProperty("status") String status, @JsonProperty("localTimestamp") Long localTimestamp, - @JsonProperty("remoteTimestamp") Long remoteTimestamp - ) { - this.nodeId = nodeId; - this.nodeUri = nodeUri; - this.status = status; - this.localTimestamp = localTimestamp; - this.remoteTimestamp = remoteTimestamp; - } - - public String getNodeId() { - return nodeId; - } - - public URI getNodeUri() { - return nodeUri; - } - - public String getStatus() { - return status; - } - - public Long getLocalTimestamp() { - return localTimestamp; - } - - public Long getRemoteTimestamp() { - return remoteTimestamp; - } - - @Override - public boolean equals(Object o) { - return (o instanceof HaNodeSummary) && Objects.equal(nodeId, ((HaNodeSummary)o).getNodeId()); - } - - @Override - public int hashCode() { - return Objects.hashCode(nodeId); - } - - @Override - public String toString() { - return "HighAvailabilitySummary{" + - "nodeId='" + nodeId + '\'' + - ", status='" + status + '\'' + - '}'; - } + @JsonProperty("remoteTimestamp") Long remoteTimestamp) { + this.nodeId = nodeId; + this.nodeUri = nodeUri; + this.status = status; + this.localTimestamp = localTimestamp; + this.remoteTimestamp = remoteTimestamp; + } + + public String getNodeId() { + return nodeId; + } + + public URI getNodeUri() { + return nodeUri; + } + + public String getStatus() { + return status; + } + + public Long getLocalTimestamp() { + return localTimestamp; + } + + public Long getRemoteTimestamp() { + return remoteTimestamp; + } + + @Override + public boolean equals(Object o) { + return (o instanceof HaNodeSummary) && Objects.equal(nodeId, ((HaNodeSummary) o).getNodeId()); + } + + @Override + public int hashCode() { + return Objects.hashCode(nodeId); + } + + @Override + public String toString() { + return "HighAvailabilitySummary{" + + "nodeId='" + nodeId + '\'' + + ", status='" + status + '\'' + + '}'; + } } - + private final String ownId; private final String masterId; private final Map nodes; private final Map links; public HighAvailabilitySummary( - @JsonProperty("ownId") String ownId, - @JsonProperty("masterId") String masterId, - @JsonProperty("nodes") Map nodes, - @JsonProperty("links") Map links - ) { - this.ownId = ownId; - this.masterId = masterId; - this.nodes = (nodes == null) ? ImmutableMap.of() : nodes; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); + @JsonProperty("ownId") String ownId, + @JsonProperty("masterId") String masterId, + @JsonProperty("nodes") Map nodes, + @JsonProperty("links") Map links) { + this.ownId = ownId; + this.masterId = masterId; + this.nodes = (nodes == null) ? ImmutableMap.of() : nodes; + this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); } public String getOwnId() { - return ownId; + return ownId; } public String getMasterId() { - return masterId; + return masterId; } - + public Map getNodes() { - return nodes; + return nodes; } - + public Map getLinks() { - return links; + return links; } @Override public boolean equals(Object o) { - return (o instanceof HighAvailabilitySummary) && ownId.equals(((HighAvailabilitySummary)o).getOwnId()); + return (o instanceof HighAvailabilitySummary) && ownId.equals(((HighAvailabilitySummary) o).getOwnId()); } @Override public int hashCode() { - return ownId != null ? ownId.hashCode() : 0; + return ownId != null ? ownId.hashCode() : 0; } @Override public String toString() { - return "HighAvailabilitySummary{" + - "ownId='" + ownId + '\'' + - ", links=" + links + - '}'; + return "HighAvailabilitySummary{" + + "ownId='" + ownId + '\'' + + ", links=" + links + + '}'; } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java index c9bbe25a2d..d4a9c1a5fa 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSpec.java @@ -34,61 +34,60 @@ /** @deprecated since 0.7.0 location spec objects will not be used from the client, instead pass yaml location spec strings */ public class LocationSpec implements HasName, HasConfig { - @JsonSerialize(include=Inclusion.NON_NULL) - private final String name; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String spec; - - @JsonSerialize(include=Inclusion.NON_EMPTY) - private final Map config; - - public static LocationSpec localhost() { - return new LocationSpec("localhost", "localhost", null); - } - - public LocationSpec( - @JsonProperty("name") String name, - @JsonProperty("spec") String spec, - @JsonProperty("config") @Nullable Map config - ) { - this.name = name; - this.spec = spec; - this.config = (config == null) ? Collections.emptyMap() : ImmutableMap.copyOf(config); - } - - @Override - public String getName() { - return name; -} - - public String getSpec() { - return spec; - } - - public Map getConfig() { - return config; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LocationSpec that = (LocationSpec) o; - return Objects.equal(name, that.name) && Objects.equal(spec, that.spec) && Objects.equal(config, that.config); - } - - @Override - public int hashCode() { - return Objects.hashCode(spec, name, config); - } - - @Override - public String toString() { - return "LocationSpec{" + - "name='" + name + '\'' + - "spec='" + spec + '\'' + - ", config=" + config + - '}'; - } + @JsonSerialize(include = Inclusion.NON_NULL) + private final String name; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String spec; + + @JsonSerialize(include = Inclusion.NON_EMPTY) + private final Map config; + + public static LocationSpec localhost() { + return new LocationSpec("localhost", "localhost", null); + } + + public LocationSpec( + @JsonProperty("name") String name, + @JsonProperty("spec") String spec, + @JsonProperty("config") @Nullable Map config) { + this.name = name; + this.spec = spec; + this.config = (config == null) ? Collections. emptyMap() : ImmutableMap.copyOf(config); + } + + @Override + public String getName() { + return name; + } + + public String getSpec() { + return spec; + } + + public Map getConfig() { + return config; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + LocationSpec that = (LocationSpec) o; + return Objects.equal(name, that.name) && Objects.equal(spec, that.spec) && Objects.equal(config, that.config); + } + + @Override + public int hashCode() { + return Objects.hashCode(spec, name, config); + } + + @Override + public String toString() { + return "LocationSpec{" + + "name='" + name + '\'' + + "spec='" + spec + '\'' + + ", config=" + config + + '}'; + } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSummary.java index 935ad01fea..64300b33c2 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/LocationSummary.java @@ -34,62 +34,61 @@ public class LocationSummary extends LocationSpec implements HasName, HasId { - private final String id; - - /** only intended for instantiated Locations, not definitions */ - @JsonSerialize(include=Inclusion.NON_NULL) - private final String type; - private final Map links; - - public LocationSummary( - @JsonProperty("id") String id, - @JsonProperty("name") String name, - @JsonProperty("spec") String spec, - @JsonProperty("type") String type, - @JsonProperty("config") @Nullable Map config, - @JsonProperty("links") Map links - ) { - super(name, spec, config); - this.id = checkNotNull(id); - this.type = type; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } + private final String id; - @Override - public String getId() { - return id; - } + /** only intended for instantiated Locations, not definitions */ + @JsonSerialize(include = Inclusion.NON_NULL) + private final String type; + private final Map links; - public String getType() { - return type; - } - - public Map getLinks() { - return links; - } + public LocationSummary( + @JsonProperty("id") String id, + @JsonProperty("name") String name, + @JsonProperty("spec") String spec, + @JsonProperty("type") String type, + @JsonProperty("config") @Nullable Map config, + @JsonProperty("links") Map links) { + super(name, spec, config); + this.id = checkNotNull(id); + this.type = type; + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } - @Override - public boolean equals(Object o) { - if (!super.equals(o)) return false; - LocationSummary that = (LocationSummary) o; - return Objects.equal(id, that.id); - } + @Override + public String getId() { + return id; + } - @Override - public int hashCode() { - return Objects.hashCode(id, links); - } + public String getType() { + return type; + } + + public Map getLinks() { + return links; + } + + @Override + public boolean equals(Object o) { + if (!super.equals(o)) return false; + LocationSummary that = (LocationSummary) o; + return Objects.equal(id, that.id); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, links); + } - @Override - public String toString() { - return "LocationSummary{" + - "id='" + getId() + '\'' + - "name='" + getName() + '\'' + - "spec='" + getSpec() + '\'' + - "type='" + getType() + '\'' + - ", config=" + getConfig() + - ", links=" + links + - '}'; + @Override + public String toString() { + return "LocationSummary{" + + "id='" + getId() + '\'' + + "name='" + getName() + '\'' + + "spec='" + getSpec() + '\'' + + "type='" + getType() + '\'' + + ", config=" + getConfig() + + ", links=" + links + + '}'; } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicyConfigSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicyConfigSummary.java index 0088d9f30c..fe70a61a6d 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicyConfigSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicyConfigSummary.java @@ -29,31 +29,30 @@ public class PolicyConfigSummary extends ConfigSummary { - @JsonSerialize(include=Inclusion.NON_NULL) - private final Map links; - - public PolicyConfigSummary( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("description") String description, - @JsonProperty("defaultValue") Object defaultValue, - @JsonProperty("reconfigurable") boolean reconfigurable, - @JsonProperty("links") Map links - ) { - super(name, type, description, defaultValue, reconfigurable, null, null, null); - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } - - @Override - public Map getLinks() { - return links; - } + @JsonSerialize(include = Inclusion.NON_NULL) + private final Map links; + + public PolicyConfigSummary( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("description") String description, + @JsonProperty("defaultValue") Object defaultValue, + @JsonProperty("reconfigurable") boolean reconfigurable, + @JsonProperty("links") Map links) { + super(name, type, description, defaultValue, reconfigurable, null, null, null); + this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); + } + + @Override + public Map getLinks() { + return links; + } - @Override - public String toString() { - return "PolicyConfigSummary{" + - "name='" + getName() + '\'' + - ", type='" + getType() + '\'' + - '}'; + @Override + public String toString() { + return "PolicyConfigSummary{" + + "name='" + getName() + '\'' + + ", type='" + getType() + '\'' + + '}'; } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicySummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicySummary.java index cf7df6b096..97fa7ff29f 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicySummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/PolicySummary.java @@ -18,90 +18,88 @@ */ package brooklyn.rest.domain; -import com.google.common.collect.ImmutableMap; +import java.net.URI; +import java.util.Map; import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.map.annotate.JsonSerialize; import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion; -import java.net.URI; -import java.util.Map; +import com.google.common.collect.ImmutableMap; public class PolicySummary implements HasName, HasId { - private final String id; - private final String name; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String catalogItemId; - private final Status state; - private final Map links; - - public PolicySummary( - @JsonProperty("id") String id, - @JsonProperty("name") String name, - @JsonProperty("catalogItemId") String catalogItemId, - @JsonProperty("state") Status state, - @JsonProperty("links") Map links - ) { - this.id = id; - this.name = name; - this.catalogItemId = catalogItemId; - this.state = state; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } - - @Override - public String getId() { - return id; - } - - @Override - public String getName() { - return name; - } - - public String getCatalogItemId() { - return catalogItemId; - } - - public Status getState() { - return state; - } - - public Map getLinks() { - return links; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - PolicySummary that = (PolicySummary) o; - - if (id != null ? !id.equals(that.id) : that.id != null) - return false; - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (id != null ? id.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "ConfigSummary{" + - "name='" + name + '\'' + - ", id='" + id + '\'' + - ", catalogItemId='" + catalogItemId + '\'' + - ", links=" + links + - '}'; - } + private final String id; + private final String name; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String catalogItemId; + private final Status state; + private final Map links; + + public PolicySummary( + @JsonProperty("id") String id, + @JsonProperty("name") String name, + @JsonProperty("catalogItemId") String catalogItemId, + @JsonProperty("state") Status state, + @JsonProperty("links") Map links) { + this.id = id; + this.name = name; + this.catalogItemId = catalogItemId; + this.state = state; + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } + + @Override + public String getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + public String getCatalogItemId() { + return catalogItemId; + } + + public Status getState() { + return state; + } + + public Map getLinks() { + return links; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + PolicySummary that = (PolicySummary) o; + + if (id != null ? !id.equals(that.id) : that.id != null) + return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } + @Override + public String toString() { + return "ConfigSummary{" + + "name='" + name + '\'' + + ", id='" + id + '\'' + + ", catalogItemId='" + catalogItemId + '\'' + + ", links=" + links + + '}'; + } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/ScriptExecutionSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/ScriptExecutionSummary.java index fe3c27ae0f..01d7c09adc 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/ScriptExecutionSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/ScriptExecutionSummary.java @@ -24,15 +24,15 @@ public class ScriptExecutionSummary { - @JsonSerialize(include=Inclusion.NON_NULL) + @JsonSerialize(include = Inclusion.NON_NULL) private final Object result; - @JsonSerialize(include=Inclusion.NON_EMPTY) + @JsonSerialize(include = Inclusion.NON_EMPTY) private final String problem; - @JsonSerialize(include=Inclusion.NON_EMPTY) + @JsonSerialize(include = Inclusion.NON_EMPTY) private final String stdout; - @JsonSerialize(include=Inclusion.NON_EMPTY) + @JsonSerialize(include = Inclusion.NON_EMPTY) private final String stderr; - + public ScriptExecutionSummary( @JsonProperty("result") Object result, @JsonProperty("problem") String problem, @@ -56,9 +56,8 @@ public String getProblem() { public String getStderr() { return stderr; } - + public String getStdout() { return stdout; } - } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/SensorSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/SensorSummary.java index a6cdb4d779..7af9e0b1d3 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/SensorSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/SensorSummary.java @@ -29,78 +29,76 @@ public class SensorSummary implements HasName { - private final String name; - private final String type; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String description; - @JsonSerialize(include=Inclusion.NON_NULL) - private final Map links; - - public SensorSummary( - @JsonProperty("name") String name, - @JsonProperty("type") String type, - @JsonProperty("description") String description, - @JsonProperty("links") Map links - ) { - this.name = name; - this.type = type; - this.description = description; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } - - @Override - public String getName() { - return name; - } - - public String getType() { - return type; - } - - public String getDescription() { - return description; - } - - public Map getLinks() { - return links; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - SensorSummary that = (SensorSummary) o; - - if (description != null ? !description.equals(that.description) : that.description != null) - return false; - if (links != null ? !links.equals(that.links) : that.links != null) - return false; - if (name != null ? !name.equals(that.name) : that.name != null) - return false; - if (type != null ? !type.equals(that.type) : that.type != null) - return false; - - return true; - } - - @Override - public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (type != null ? type.hashCode() : 0); - result = 31 * result + (description != null ? description.hashCode() : 0); - result = 31 * result + (links != null ? links.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "SensorSummary{" + - "name='" + name + '\'' + - ", type='" + type + '\'' + - ", description='" + description + '\'' + - ", links=" + links + - '}'; - } - + private final String name; + private final String type; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String description; + @JsonSerialize(include = Inclusion.NON_NULL) + private final Map links; + + public SensorSummary( + @JsonProperty("name") String name, + @JsonProperty("type") String type, + @JsonProperty("description") String description, + @JsonProperty("links") Map links) { + this.name = name; + this.type = type; + this.description = description; + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } + + @Override + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getDescription() { + return description; + } + + public Map getLinks() { + return links; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + SensorSummary that = (SensorSummary) o; + + if (description != null ? !description.equals(that.description) : that.description != null) + return false; + if (links != null ? !links.equals(that.links) : that.links != null) + return false; + if (name != null ? !name.equals(that.name) : that.name != null) + return false; + if (type != null ? !type.equals(that.type) : that.type != null) + return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (type != null ? type.hashCode() : 0); + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + (links != null ? links.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "SensorSummary{" + + "name='" + name + '\'' + + ", type='" + type + '\'' + + ", description='" + description + '\'' + + ", links=" + links + + '}'; + } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/TaskSummary.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/TaskSummary.java index 5fa0765a6f..b83140aaa7 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/TaskSummary.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/TaskSummary.java @@ -37,194 +37,193 @@ public class TaskSummary implements HasId { - private final String id; - private final String displayName; - private final String entityId; - private final String entityDisplayName; - private final String description; - private final Collection tags; - - private final Long submitTimeUtc; - private final Long startTimeUtc; - private final Long endTimeUtc; - - private final String currentStatus; - private final Object result; - private final boolean isError; - private final boolean isCancelled; - - private final List children; - private final LinkWithMetadata submittedByTask; - - @JsonSerialize(include=Inclusion.NON_NULL) - private final LinkWithMetadata blockingTask; - @JsonSerialize(include=Inclusion.NON_NULL) - private final String blockingDetails; - - private final String detailedStatus; - - @JsonSerialize(include=Inclusion.NON_NULL) - private final Map streams; - - private final Map links; - - public TaskSummary( - @JsonProperty("id") String id, - @JsonProperty("displayName") String displayName, - @JsonProperty("description") String description, - @JsonProperty("entityId") String entityId, - @JsonProperty("entityDisplayName") String entityDisplayName, - @JsonProperty("tags") Set tags, - @JsonProperty("submitTimeUtc") Long submitTimeUtc, - @JsonProperty("startTimeUtc") Long startTimeUtc, - @JsonProperty("endTimeUtc") Long endTimeUtc, - @JsonProperty("currentStatus") String currentStatus, - @JsonProperty("result") Object result, - @JsonProperty("isError") boolean isError, - @JsonProperty("isCancelled") boolean isCancelled, - @JsonProperty("children") List children, - @JsonProperty("submittedByTask") LinkWithMetadata submittedByTask, - @JsonProperty("blockingTask") LinkWithMetadata blockingTask, - @JsonProperty("blockingDetails") String blockingDetails, - @JsonProperty("detailedStatus") String detailedStatus, - @JsonProperty("streams") Map streams, - @JsonProperty("links") Map links) { - this.id = id; - this.displayName = displayName; - this.description = description; - this.entityId = entityId; - this.entityDisplayName = entityDisplayName; - this.tags = (tags == null) ? ImmutableList.of() : ImmutableList.copyOf(tags); - this.submitTimeUtc = submitTimeUtc; - this.startTimeUtc = startTimeUtc; - this.endTimeUtc = endTimeUtc; - this.currentStatus = currentStatus; - this.result = result; - this.isError = isError; - this.isCancelled = isCancelled; - this.children = children; - this.blockingDetails = blockingDetails; - this.blockingTask = blockingTask; - this.submittedByTask = submittedByTask; - this.detailedStatus = detailedStatus; - this.streams = streams; - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); -} + private final String id; + private final String displayName; + private final String entityId; + private final String entityDisplayName; + private final String description; + private final Collection tags; + + private final Long submitTimeUtc; + private final Long startTimeUtc; + private final Long endTimeUtc; + + private final String currentStatus; + private final Object result; + private final boolean isError; + private final boolean isCancelled; + + private final List children; + private final LinkWithMetadata submittedByTask; + + @JsonSerialize(include = Inclusion.NON_NULL) + private final LinkWithMetadata blockingTask; + @JsonSerialize(include = Inclusion.NON_NULL) + private final String blockingDetails; + + private final String detailedStatus; + + @JsonSerialize(include = Inclusion.NON_NULL) + private final Map streams; + + private final Map links; + + public TaskSummary( + @JsonProperty("id") String id, + @JsonProperty("displayName") String displayName, + @JsonProperty("description") String description, + @JsonProperty("entityId") String entityId, + @JsonProperty("entityDisplayName") String entityDisplayName, + @JsonProperty("tags") Set tags, + @JsonProperty("submitTimeUtc") Long submitTimeUtc, + @JsonProperty("startTimeUtc") Long startTimeUtc, + @JsonProperty("endTimeUtc") Long endTimeUtc, + @JsonProperty("currentStatus") String currentStatus, + @JsonProperty("result") Object result, + @JsonProperty("isError") boolean isError, + @JsonProperty("isCancelled") boolean isCancelled, + @JsonProperty("children") List children, + @JsonProperty("submittedByTask") LinkWithMetadata submittedByTask, + @JsonProperty("blockingTask") LinkWithMetadata blockingTask, + @JsonProperty("blockingDetails") String blockingDetails, + @JsonProperty("detailedStatus") String detailedStatus, + @JsonProperty("streams") Map streams, + @JsonProperty("links") Map links) { + this.id = id; + this.displayName = displayName; + this.description = description; + this.entityId = entityId; + this.entityDisplayName = entityDisplayName; + this.tags = (tags == null) ? ImmutableList.of() : ImmutableList. copyOf(tags); + this.submitTimeUtc = submitTimeUtc; + this.startTimeUtc = startTimeUtc; + this.endTimeUtc = endTimeUtc; + this.currentStatus = currentStatus; + this.result = result; + this.isError = isError; + this.isCancelled = isCancelled; + this.children = children; + this.blockingDetails = blockingDetails; + this.blockingTask = blockingTask; + this.submittedByTask = submittedByTask; + this.detailedStatus = detailedStatus; + this.streams = streams; + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } + @Override + public String getId() { + return id; + } - @Override - public String getId() { - return id; - } - - public String getDisplayName() { - return displayName; - } + public String getDisplayName() { + return displayName; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public String getEntityId() { - return entityId; - } - - public String getEntityDisplayName() { - return entityDisplayName; - } - - public Collection getTags() { - List result = new ArrayList(); - for (Object t: tags) { - // TODO if we had access to a mapper we could use it to give better json - result.add(Jsonya.convertToJsonPrimitive(t)); - } - return result; - } + public String getEntityId() { + return entityId; + } - @JsonIgnore - public Collection getRawTags() { - return tags; + public String getEntityDisplayName() { + return entityDisplayName; } - public Long getSubmitTimeUtc() { - return submitTimeUtc; - } + public Collection getTags() { + List result = new ArrayList(); + for (Object t : tags) { + // TODO if we had access to a mapper we could use it to give better json + result.add(Jsonya.convertToJsonPrimitive(t)); + } + return result; + } - public Long getStartTimeUtc() { - return startTimeUtc; - } + @JsonIgnore + public Collection getRawTags() { + return tags; + } - public Long getEndTimeUtc() { - return endTimeUtc; - } + public Long getSubmitTimeUtc() { + return submitTimeUtc; + } - public String getCurrentStatus() { - return currentStatus; - } + public Long getStartTimeUtc() { + return startTimeUtc; + } - public Object getResult() { - return result; - } + public Long getEndTimeUtc() { + return endTimeUtc; + } - /** @deprecated since 0.7.0 use {@link #isError} instead. */ - @Deprecated - @JsonIgnore - public boolean getIsError() { - return isError; - } + public String getCurrentStatus() { + return currentStatus; + } - /** @deprecated since 0.7.0 use {@link #isCancelled} instead. */ - @Deprecated - @JsonIgnore - public boolean getIsCancelled() { - return isCancelled; - } + public Object getResult() { + return result; + } - public boolean isError() { - return isError; - } + /** @deprecated since 0.7.0 use {@link #isError} instead. */ + @Deprecated + @JsonIgnore + public boolean getIsError() { + return isError; + } - public boolean isCancelled() { - return isCancelled; - } + /** @deprecated since 0.7.0 use {@link #isCancelled} instead. */ + @Deprecated + @JsonIgnore + public boolean getIsCancelled() { + return isCancelled; + } - public List getChildren() { - return children; - } + public boolean isError() { + return isError; + } - public LinkWithMetadata getSubmittedByTask() { - return submittedByTask; - } - - public LinkWithMetadata getBlockingTask() { - return blockingTask; - } - - public String getBlockingDetails() { - return blockingDetails; - } + public boolean isCancelled() { + return isCancelled; + } - public String getDetailedStatus() { - return detailedStatus; - } - - public Map getStreams() { - return streams; - } + public List getChildren() { + return children; + } - public Map getLinks() { - return links; - } - - @Override - public String toString() { - return "TaskSummary{" + - "id='" + id + '\'' + - ", displayName='" + displayName + '\'' + - ", currentStatus='" + currentStatus + '\'' + - ", startTimeUtc='" + startTimeUtc + '\'' + - ", endTimeUtc='" + endTimeUtc + '\'' + - '}'; + public LinkWithMetadata getSubmittedByTask() { + return submittedByTask; + } + + public LinkWithMetadata getBlockingTask() { + return blockingTask; + } + + public String getBlockingDetails() { + return blockingDetails; + } + + public String getDetailedStatus() { + return detailedStatus; + } + + public Map getStreams() { + return streams; + } + + public Map getLinks() { + return links; + } + + @Override + public String toString() { + return "TaskSummary{" + + "id='" + id + '\'' + + ", displayName='" + displayName + '\'' + + ", currentStatus='" + currentStatus + '\'' + + ", startTimeUtc='" + startTimeUtc + '\'' + + ", endTimeUtc='" + endTimeUtc + '\'' + + '}'; } } diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistic.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistic.java index 64dfe97655..1292f96fa0 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistic.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistic.java @@ -40,10 +40,14 @@ public class UsageStatistic implements HasId { private final long duration; private final Map metadata; - public UsageStatistic(@JsonProperty("status") Status status, @JsonProperty("id") String id, @JsonProperty("applicationId") String applicationId, - @JsonProperty("start") String start, - @JsonProperty("end") String end, - @JsonProperty("duration") long duration, @JsonProperty("metadata") Map metadata) { + public UsageStatistic( + @JsonProperty("status") Status status, + @JsonProperty("id") String id, + @JsonProperty("applicationId") String applicationId, + @JsonProperty("start") String start, + @JsonProperty("end") String end, + @JsonProperty("duration") long duration, + @JsonProperty("metadata") Map metadata) { this.status = checkNotNull(status, "status"); this.id = checkNotNull(id, "id"); this.applicationId = applicationId; diff --git a/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistics.java b/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistics.java index c26a987401..e654165d31 100644 --- a/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistics.java +++ b/usage/rest-api/src/main/java/brooklyn/rest/domain/UsageStatistics.java @@ -32,19 +32,18 @@ * @author Aled Sage */ public class UsageStatistics { - - // TODO populate links with /apps endpoint to link to /usage/applications/{id}, to make it more RESTy - + + // TODO populate links with /apps endpoint to link to /usage/applications/{id}, to make it more + // RESTy + private final List statistics; private final Map links; - public UsageStatistics( - @JsonProperty("statistics") List statistics, - @JsonProperty("links") Map links - ) { - this.statistics = statistics == null ? ImmutableList.of() : ImmutableList.copyOf(statistics); - this.links = (links == null) ? ImmutableMap.of() : ImmutableMap.copyOf(links); - } + public UsageStatistics(@JsonProperty("statistics") List statistics, + @JsonProperty("links") Map links) { + this.statistics = statistics == null ? ImmutableList. of() : ImmutableList.copyOf(statistics); + this.links = (links == null) ? ImmutableMap. of() : ImmutableMap.copyOf(links); + } public List getStatistics() { return statistics; @@ -53,12 +52,13 @@ public List getStatistics() { public Map getLinks() { return links; } - + @Override public boolean equals(Object o) { - if (!(o instanceof UsageStatistics)) return false; + if (!(o instanceof UsageStatistics)) + return false; UsageStatistics other = (UsageStatistics) o; - return Objects.equal(statistics, other.statistics); + return Objects.equal(statistics, other.statistics); } @Override @@ -68,9 +68,6 @@ public int hashCode() { @Override public String toString() { - return "UsageStatistics{" + - "statistics=" + statistics + - ", links=" + links + - '}'; + return "UsageStatistics{" + "statistics=" + statistics + ", links=" + links + '}'; } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/domain/ApplicationSpecTest.java b/usage/rest-api/src/test/java/brooklyn/rest/domain/ApplicationSpecTest.java index 7b1ecdcbad..6a4c54077f 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/domain/ApplicationSpecTest.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/domain/ApplicationSpecTest.java @@ -32,25 +32,22 @@ public class ApplicationSpecTest { - final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp", - ImmutableMap.of( - "initialSize", "1", - "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql" - )); - - final ApplicationSpec applicationSpec = ApplicationSpec.builder().name("myapp"). - entities(ImmutableSet.of(entitySpec)).locations(ImmutableSet.of("/v1/locations/1")). - build(); - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(applicationSpec), jsonFixture("fixtures/application-spec.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/application-spec.json"), - ApplicationSpec.class), applicationSpec); - } - + final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp", + ImmutableMap.of( + "initialSize", "1", + "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql")); + + final ApplicationSpec applicationSpec = ApplicationSpec.builder().name("myapp") + .entities(ImmutableSet.of(entitySpec)).locations(ImmutableSet.of("/v1/locations/1")) + .build(); + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(applicationSpec), jsonFixture("fixtures/application-spec.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/application-spec.json"), ApplicationSpec.class), applicationSpec); + } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/domain/EffectorSummaryTest.java b/usage/rest-api/src/test/java/brooklyn/rest/domain/EffectorSummaryTest.java index 21ef760152..e2821ef4db 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/domain/EffectorSummaryTest.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/domain/EffectorSummaryTest.java @@ -33,23 +33,21 @@ public class EffectorSummaryTest { - final EffectorSummary effectorSummary = new EffectorSummary( - "stop", - "void", - ImmutableSet.>of(), - "Effector description", - ImmutableMap.of( - "self", URI.create("/v1/applications/redis-app/entities/redis-ent/effectors/stop") - ) - ); - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(effectorSummary), jsonFixture("fixtures/effector-summary.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/effector-summary.json"), EffectorSummary.class), effectorSummary); - } + final EffectorSummary effectorSummary = new EffectorSummary( + "stop", + "void", + ImmutableSet.>of(), + "Effector description", + ImmutableMap.of( + "self", URI.create("/v1/applications/redis-app/entities/redis-ent/effectors/stop"))); + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(effectorSummary), jsonFixture("fixtures/effector-summary.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/effector-summary.json"), EffectorSummary.class), effectorSummary); + } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySpecTest.java b/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySpecTest.java index b53bdaa057..08b47e5c7d 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySpecTest.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySpecTest.java @@ -29,22 +29,22 @@ public class EntitySpecTest { - final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp"); - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(new EntitySpec[]{entitySpec}), jsonFixture("fixtures/entity.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/entity.json"), EntitySpec[].class), new EntitySpec[]{entitySpec}); - } - - @Test - public void testDeserializeFromJSONOnlyWithType() throws IOException { - EntitySpec actual = fromJson(jsonFixture("fixtures/entity-only-type.json"), EntitySpec.class); - assertEquals(actual.getName(), actual.getType()); - assertEquals(actual.getConfig().size(), 0); - } + final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp"); + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(new EntitySpec[] { entitySpec }), jsonFixture("fixtures/entity.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/entity.json"), EntitySpec[].class), new EntitySpec[] { entitySpec }); + } + + @Test + public void testDeserializeFromJSONOnlyWithType() throws IOException { + EntitySpec actual = fromJson(jsonFixture("fixtures/entity-only-type.json"), EntitySpec.class); + assertEquals(actual.getName(), actual.getType()); + assertEquals(actual.getConfig().size(), 0); + } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySummaryTest.java b/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySummaryTest.java index 242be13ab0..fb976e1d92 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySummaryTest.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/domain/EntitySummaryTest.java @@ -33,29 +33,29 @@ public class EntitySummaryTest { - static final Map links; - static { - links = Maps.newLinkedHashMap(); - links.put("self", URI.create("/v1/applications/tesr/entities/zQsqdXzi")); - links.put("catalog", URI.create("/v1/catalog/entities/brooklyn.entity.webapp.tomcat.TomcatServer")); - links.put("application", URI.create("/v1/applications/tesr")); - links.put("children", URI.create("/v1/applications/tesr/entities/zQsqdXzi/children")); - links.put("effectors", URI.create("fixtures/effector-summary-list.json")); - links.put("sensors", URI.create("fixtures/sensor-summary-list.json")); - links.put("activities", URI.create("fixtures/task-summary-list.json")); - } - - static final EntitySummary entitySummary = new EntitySummary( - "zQsqdXzi", "MyTomcat", "brooklyn.entity.webapp.tomcat.TomcatServer", null, links); - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(entitySummary), jsonFixture("fixtures/entity-summary.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/entity-summary.json"), EntitySummary.class), entitySummary); - } + static final Map links; + static { + links = Maps.newLinkedHashMap(); + links.put("self", URI.create("/v1/applications/tesr/entities/zQsqdXzi")); + links.put("catalog", URI.create("/v1/catalog/entities/brooklyn.entity.webapp.tomcat.TomcatServer")); + links.put("application", URI.create("/v1/applications/tesr")); + links.put("children", URI.create("/v1/applications/tesr/entities/zQsqdXzi/children")); + links.put("effectors", URI.create("fixtures/effector-summary-list.json")); + links.put("sensors", URI.create("fixtures/sensor-summary-list.json")); + links.put("activities", URI.create("fixtures/task-summary-list.json")); + } + + static final EntitySummary entitySummary = new EntitySummary("zQsqdXzi", "MyTomcat", + "brooklyn.entity.webapp.tomcat.TomcatServer", null, links); + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(entitySummary), jsonFixture("fixtures/entity-summary.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/entity-summary.json"), EntitySummary.class), entitySummary); + } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/domain/LocationSpecTest.java b/usage/rest-api/src/test/java/brooklyn/rest/domain/LocationSpecTest.java index 6bd98638da..84ac29f28d 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/domain/LocationSpecTest.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/domain/LocationSpecTest.java @@ -33,26 +33,26 @@ public class LocationSpecTest { // TODO when removing the deprecated class this tests, change the tests here to point at LocationSummary - final LocationSpec locationSpec = LocationSpec.localhost(); + final LocationSpec locationSpec = LocationSpec.localhost(); - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(locationSpec), jsonFixture("fixtures/location.json")); - } + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(locationSpec), jsonFixture("fixtures/location.json")); + } - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/location.json"), LocationSpec.class), locationSpec); - } + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/location.json"), LocationSpec.class), locationSpec); + } - @Test - public void testDeserializeFromJSONWithNoCredential() throws IOException { - LocationSpec loaded = fromJson(jsonFixture("fixtures/location-without-credential.json"), LocationSpec.class); + @Test + public void testDeserializeFromJSONWithNoCredential() throws IOException { + LocationSpec loaded = fromJson(jsonFixture("fixtures/location-without-credential.json"), LocationSpec.class); - assertEquals(loaded.getSpec(), locationSpec.getSpec()); - - assertEquals(loaded.getConfig().size(), 1); - assertEquals(loaded.getConfig().get("identity"), "bob"); - assertNull(loaded.getConfig().get("credential")); - } + assertEquals(loaded.getSpec(), locationSpec.getSpec()); + + assertEquals(loaded.getConfig().size(), 1); + assertEquals(loaded.getConfig().get("identity"), "bob"); + assertNull(loaded.getConfig().get("credential")); + } } diff --git a/usage/rest-api/src/test/java/brooklyn/rest/util/RestApiTestUtils.java b/usage/rest-api/src/test/java/brooklyn/rest/util/RestApiTestUtils.java index ec83ac0c29..9f6d7f1dcb 100644 --- a/usage/rest-api/src/test/java/brooklyn/rest/util/RestApiTestUtils.java +++ b/usage/rest-api/src/test/java/brooklyn/rest/util/RestApiTestUtils.java @@ -55,5 +55,4 @@ public static T fromJson(String text, TypeReference type) { throw Exceptions.propagate(e); } } - } From bfac921f7a4c211e5ff5ce48e262843095a47493 Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Fri, 9 Jan 2015 01:11:14 +0000 Subject: [PATCH 2/2] Fix indents in rest-server --- .../rest/resources/ActivityResource.java | 53 +- .../rest/resources/EntityConfigResource.java | 142 +-- .../rest/resources/EntityResource.java | 216 ++--- .../rest/resources/PolicyConfigResource.java | 121 ++- .../rest/resources/PolicyResource.java | 5 +- .../rest/resources/ScriptResource.java | 5 +- .../rest/resources/VersionResource.java | 9 +- .../provider/AbstractSecurityProvider.java | 2 - .../provider/AnyoneSecurityProvider.java | 1 - .../provider/BlackholeSecurityProvider.java | 1 - ...serWithRandomPasswordSecurityProvider.java | 1 - .../provider/DelegatingSecurityProvider.java | 1 - .../ExplicitUsersSecurityProvider.java | 1 - .../provider/LdapSecurityProvider.java | 1 - .../rest/transform/CatalogTransformer.java | 1 - .../rest/transform/EntityTransformer.java | 1 - .../rest/transform/LocationTransformer.java | 1 - .../rest/transform/PolicyTransformer.java | 1 - .../rest/transform/TaskTransformer.java | 1 - .../rest/util/BrooklynRestResourceUtils.java | 1 - .../rest/util/DefaultExceptionMapper.java | 1 - .../rest/util/EntityLocationUtils.java | 1 - .../brooklyn/rest/util/FormMapProvider.java | 1 - .../brooklyn/rest/util/WebResourceUtils.java | 1 - .../json/BrooklynJacksonJsonProvider.java | 1 - .../json/ConfigurableSerializerProvider.java | 3 +- ...ErrorAndToStringUnknownTypeSerializer.java | 1 - .../rest/util/json/MultimapSerializer.java | 1 - ...rictPreferringFieldsVisibilityChecker.java | 2 +- .../brooklyn/rest/domain/ApplicationTest.java | 87 +- .../rest/domain/LocationSummaryTest.java | 35 +- .../rest/domain/SensorSummaryTest.java | 108 +-- .../resources/ApplicationResourceTest.java | 877 +++++++++--------- .../rest/resources/CatalogResourceTest.java | 420 +++++---- .../rest/resources/LocationResourceTest.java | 103 +- .../rest/resources/VersionResourceTest.java | 33 +- 36 files changed, 1099 insertions(+), 1141 deletions(-) diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/ActivityResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/ActivityResource.java index 9e68b25816..362dd09dc1 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/resources/ActivityResource.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/ActivityResource.java @@ -36,33 +36,32 @@ public class ActivityResource extends AbstractBrooklynRestResource implements ActivityApi { - @Override - public TaskSummary get(String taskId) { - Task t = mgmt().getExecutionManager().getTask(taskId); - if (t==null) - throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); - return TaskTransformer.FROM_TASK.apply(t); - } + @Override + public TaskSummary get(String taskId) { + Task t = mgmt().getExecutionManager().getTask(taskId); + if (t == null) + throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); + return TaskTransformer.FROM_TASK.apply(t); + } - @Override - public List children(String taskId) { - Task t = mgmt().getExecutionManager().getTask(taskId); - if (t==null) - throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); - if (!(t instanceof HasTaskChildren)) - return Collections.emptyList(); - return new LinkedList(Collections2.transform(Lists.newArrayList(((HasTaskChildren)t).getChildren()), - TaskTransformer.FROM_TASK)); - } + @Override + public List children(String taskId) { + Task t = mgmt().getExecutionManager().getTask(taskId); + if (t == null) + throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); + if (!(t instanceof HasTaskChildren)) + return Collections.emptyList(); + return new LinkedList(Collections2.transform(Lists.newArrayList(((HasTaskChildren) t).getChildren()), + TaskTransformer.FROM_TASK)); + } - public String stream(String taskId, String streamId) { - Task t = mgmt().getExecutionManager().getTask(taskId); - if (t==null) - throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); - WrappedStream stream = BrooklynTaskTags.stream(t, streamId); - if (stream==null) - throw WebResourceUtils.notFound("Cannot find stream '%s' in task '%s'", streamId, taskId); - return stream.streamContents.get(); - } - + public String stream(String taskId, String streamId) { + Task t = mgmt().getExecutionManager().getTask(taskId); + if (t == null) + throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); + WrappedStream stream = BrooklynTaskTags.stream(t, streamId); + if (stream == null) + throw WebResourceUtils.notFound("Cannot find stream '%s' in task '%s'", streamId, taskId); + return stream.streamContents.get(); + } } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityConfigResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityConfigResource.java index efcd2486bd..8af5ab753e 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityConfigResource.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/EntityConfigResource.java @@ -50,19 +50,19 @@ public class EntityConfigResource extends AbstractBrooklynRestResource implement private static final Logger LOG = LoggerFactory.getLogger(EntityConfigResource.class); - @Override - public List list(final String application, final String entityToken) { - final EntityLocal entity = brooklyn().getEntity(application, entityToken); - - return Lists.newArrayList(transform( - entity.getEntityType().getConfigKeys(), - new Function, EntityConfigSummary>() { - @Override - public EntityConfigSummary apply(ConfigKey config) { - return EntityTransformer.entityConfigSummary(entity, config); - } - })); - } + @Override + public List list(final String application, final String entityToken) { + final EntityLocal entity = brooklyn().getEntity(application, entityToken); + + return Lists.newArrayList(transform( + entity.getEntityType().getConfigKeys(), + new Function, EntityConfigSummary>() { + @Override + public EntityConfigSummary apply(ConfigKey config) { + return EntityTransformer.entityConfigSummary(entity, config); + } + })); + } // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} // (and in sensors class) @@ -82,15 +82,15 @@ public Map batchConfigRead(String application, String entityToke return result; } - @Override - public Object get(String application, String entityToken, String configKeyName, Boolean raw) { - return get(true, application, entityToken, configKeyName, raw); - } - - @Override - public String getPlain(String application, String entityToken, String configKeyName, Boolean raw) { - return Strings.toString(get(false, application, entityToken, configKeyName, raw)); - } + @Override + public Object get(String application, String entityToken, String configKeyName, Boolean raw) { + return get(true, application, entityToken, configKeyName, raw); + } + + @Override + public String getPlain(String application, String entityToken, String configKeyName, Boolean raw) { + return Strings.toString(get(false, application, entityToken, configKeyName, raw)); + } public Object get(boolean preferJson, String application, String entityToken, String configKeyName, Boolean raw) { EntityLocal entity = brooklyn().getEntity(application, entityToken); @@ -102,54 +102,54 @@ public Object get(boolean preferJson, String application, String entityToken, St return getValueForDisplay(value, preferJson, true); } - private ConfigKey findConfig(EntityLocal entity, String configKeyName) { - ConfigKey ck = entity.getEntityType().getConfigKey(configKeyName); - if (ck==null) ck = new BasicConfigKey(Object.class, configKeyName); - return ck; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void setFromMap(String application, String entityToken, Boolean recurse, Map newValues) { - final EntityLocal entity = brooklyn().getEntity(application, entityToken); - if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { - throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", - Entitlements.getEntitlementContext().user(), entity); - } - - if (LOG.isDebugEnabled()) - LOG.debug("REST user "+Entitlements.getEntitlementContext()+" setting configs "+newValues); - for (Object entry: newValues.entrySet()) { - String configName = Strings.toString(((Map.Entry)entry).getKey()); - Object newValue = ((Map.Entry)entry).getValue(); - - ConfigKey ck = findConfig(entity, configName); - ((EntityInternal) entity).setConfig(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); - if (Boolean.TRUE.equals(recurse)) { - for (Entity e2: Entities.descendants(entity, Predicates.alwaysTrue(), false)) { - ((EntityInternal) e2).setConfig(ck, newValue); - } - } - } - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void set(String application, String entityToken, String configName, Boolean recurse, Object newValue) { - final EntityLocal entity = brooklyn().getEntity(application, entityToken); - if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { - throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", - Entitlements.getEntitlementContext().user(), entity); - } - - ConfigKey ck = findConfig(entity, configName); - LOG.debug("REST setting config "+configName+" on "+entity+" to "+newValue); - ((EntityInternal) entity).setConfig(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); - if (Boolean.TRUE.equals(recurse)) { - for (Entity e2: Entities.descendants(entity, Predicates.alwaysTrue(), false)) { - ((EntityInternal) e2).setConfig(ck, newValue); - } - } - } + private ConfigKey findConfig(EntityLocal entity, String configKeyName) { + ConfigKey ck = entity.getEntityType().getConfigKey(configKeyName); + if (ck == null) + ck = new BasicConfigKey(Object.class, configKeyName); + return ck; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void setFromMap(String application, String entityToken, Boolean recurse, Map newValues) { + final EntityLocal entity = brooklyn().getEntity(application, entityToken); + if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { + throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", + Entitlements.getEntitlementContext().user(), entity); + } + if (LOG.isDebugEnabled()) + LOG.debug("REST user " + Entitlements.getEntitlementContext() + " setting configs " + newValues); + for (Object entry : newValues.entrySet()) { + String configName = Strings.toString(((Map.Entry) entry).getKey()); + Object newValue = ((Map.Entry) entry).getValue(); + + ConfigKey ck = findConfig(entity, configName); + ((EntityInternal) entity).setConfig(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); + if (Boolean.TRUE.equals(recurse)) { + for (Entity e2 : Entities.descendants(entity, Predicates.alwaysTrue(), false)) { + ((EntityInternal) e2).setConfig(ck, newValue); + } + } + } + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public void set(String application, String entityToken, String configName, Boolean recurse, Object newValue) { + final EntityLocal entity = brooklyn().getEntity(application, entityToken); + if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { + throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", + Entitlements.getEntitlementContext().user(), entity); + } + + ConfigKey ck = findConfig(entity, configName); + LOG.debug("REST setting config " + configName + " on " + entity + " to " + newValue); + ((EntityInternal) entity).setConfig(ck, TypeCoercions.coerce(newValue, ck.getTypeToken())); + if (Boolean.TRUE.equals(recurse)) { + for (Entity e2 : Entities.descendants(entity, Predicates.alwaysTrue(), false)) { + ((EntityInternal) e2).setConfig(ck, newValue); + } + } + } } 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 caa26c63eb..239139fe5e 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 @@ -75,57 +75,57 @@ public class EntityResource extends AbstractBrooklynRestResource implements Enti @Context private UriInfo uriInfo; - @Override - public List list(final String application) { - return FluentIterable - .from(brooklyn().getApplication(application).getChildren()) - .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY)) - .transform(EntityTransformer.FROM_ENTITY) - .toList(); - } - - @Override - public EntitySummary get(String application, String entityName) { - Entity entity = brooklyn().getEntity(application, entityName); - if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { - return EntityTransformer.entitySummary(entity); - } - throw WebResourceUtils.unauthorized("User '%s' is not authorized to get entity '%s'", - Entitlements.getEntitlementContext().user(), entity); - } - - @Override - public List getChildren(final String application, final String entity) { - return FluentIterable - .from(brooklyn().getEntity(application, entity).getChildren()) - .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY)) - .transform(EntityTransformer.FROM_ENTITY) - .toList(); - } - - @Override - public List getChildrenOld(String application, String entity) { + @Override + public List list(final String application) { + return FluentIterable + .from(brooklyn().getApplication(application).getChildren()) + .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY)) + .transform(EntityTransformer.FROM_ENTITY) + .toList(); + } + + @Override + public EntitySummary get(String application, String entityName) { + Entity entity = brooklyn().getEntity(application, entityName); + if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { + return EntityTransformer.entitySummary(entity); + } + throw WebResourceUtils.unauthorized("User '%s' is not authorized to get entity '%s'", + Entitlements.getEntitlementContext().user(), entity); + } + + @Override + public List getChildren(final String application, final String entity) { + return FluentIterable + .from(brooklyn().getEntity(application, entity).getChildren()) + .filter(EntitlementPredicates.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY)) + .transform(EntityTransformer.FROM_ENTITY) + .toList(); + } + + @Override + public List getChildrenOld(String application, String entity) { log.warn("Using deprecated call to /entities when /children should be used"); return getChildren(application, entity); - } - + } + @Override public Response addChildren(String applicationToken, String entityToken, Boolean start, String timeoutS, String yaml) { final EntityLocal parent = brooklyn().getEntity(applicationToken, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, parent)) { throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", - Entitlements.getEntitlementContext().user(), entityToken); + Entitlements.getEntitlementContext().user(), entityToken); } CreationResult, List> added = EntityManagementUtils.addChildren(parent, yaml, start) - .blockUntilComplete(timeoutS==null ? Duration.millis(20) : Duration.of(timeoutS)); + .blockUntilComplete(timeoutS==null ? Duration.millis(20) : Duration.of(timeoutS)); ResponseBuilder response; if (added.get().size()==1) { Entity child = Iterables.getOnlyElement(added.get()); URI ref = uriInfo.getBaseUriBuilder() - .path(EntityApi.class) - .path(EntityApi.class, "get") - .build(child.getApplicationId(), child.getId()); + .path(EntityApi.class) + .path(EntityApi.class, "get") + .build(child.getApplicationId(), child.getId()); response = created(ref); } else { response = Response.status(Status.CREATED); @@ -133,48 +133,48 @@ public Response addChildren(String applicationToken, String entityToken, Boolean return response.entity(TaskTransformer.taskSummary(added.task())).build(); } - @Override - public List listTasks(String applicationId, String entityId) { - Entity entity = brooklyn().getEntity(applicationId, entityId); - Set> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), entity); - return new LinkedList(Collections2.transform(tasks, TaskTransformer.FROM_TASK)); - } - - @Override - public TaskSummary getTask(final String application, final String entityToken, String taskId) { - // TODO deprecate in favour of ActivityApi.get ? - Task t = mgmt().getExecutionManager().getTask(taskId); - if (t==null) - throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); - return TaskTransformer.FROM_TASK.apply(t); - } - - @SuppressWarnings("unchecked") - @Override - public List listTags(String applicationId, String entityId) { - Entity entity = brooklyn().getEntity(applicationId, entityId); - return (List) getValueForDisplay(MutableList.copyOf(entity.tags().getTags()), true, true); - } - - @Override - public Response getIcon(String applicationId, String entityId) { - EntityLocal entity = brooklyn().getEntity(applicationId, entityId); - String url = entity.getIconUrl(); - if (url==null) - return Response.status(Status.NO_CONTENT).build(); - - if (brooklyn().isUrlServerSideAndSafe(url)) { - // classpath URL's we will serve IF they end with a recognised image format; - // paths (ie non-protocol) and - // NB, for security, file URL's are NOT served - MediaType mime = WebResourceUtils.getImageMediaTypeFromExtension(Files.getFileExtension(url)); - Object content = ResourceUtils.create(brooklyn().getCatalog().getRootClassLoader()).getResourceFromUrl(url); - return Response.ok(content, mime).build(); - } - - // for anything else we do a redirect (e.g. http / https; perhaps ftp) - return Response.temporaryRedirect(URI.create(url)).build(); - } + @Override + public List listTasks(String applicationId, String entityId) { + Entity entity = brooklyn().getEntity(applicationId, entityId); + Set> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), entity); + return new LinkedList(Collections2.transform(tasks, TaskTransformer.FROM_TASK)); + } + + @Override + public TaskSummary getTask(final String application, final String entityToken, String taskId) { + // TODO deprecate in favour of ActivityApi.get ? + Task t = mgmt().getExecutionManager().getTask(taskId); + if (t == null) + throw WebResourceUtils.notFound("Cannot find task '%s'", taskId); + return TaskTransformer.FROM_TASK.apply(t); + } + + @SuppressWarnings("unchecked") + @Override + public List listTags(String applicationId, String entityId) { + Entity entity = brooklyn().getEntity(applicationId, entityId); + return (List) getValueForDisplay(MutableList.copyOf(entity.tags().getTags()), true, true); + } + + @Override + public Response getIcon(String applicationId, String entityId) { + EntityLocal entity = brooklyn().getEntity(applicationId, entityId); + String url = entity.getIconUrl(); + if (url == null) + return Response.status(Status.NO_CONTENT).build(); + + if (brooklyn().isUrlServerSideAndSafe(url)) { + // classpath URL's we will serve IF they end with a recognised image format; + // paths (ie non-protocol) and + // NB, for security, file URL's are NOT served + MediaType mime = WebResourceUtils.getImageMediaTypeFromExtension(Files.getFileExtension(url)); + Object content = ResourceUtils.create(brooklyn().getCatalog().getRootClassLoader()).getResourceFromUrl(url); + return Response.ok(content, mime).build(); + } + + // for anything else we do a redirect (e.g. http / https; perhaps ftp) + return Response.temporaryRedirect(URI.create(url)).build(); + } @Override public Response rename(String application, String entity, String newName) { @@ -191,33 +191,33 @@ public Response expunge(String application, String entity, boolean release) { return status(ACCEPTED).entity(summary).build(); } - @Override - public List getDescendants(String application, String entity, String typeRegex) { - return EntityTransformer.entitySummaries(brooklyn().descendantsOfType(application, entity, typeRegex)); - } - - @Override - public Map getDescendantsSensor(String application, String entity, String sensor, String typeRegex) { - Iterable descs = brooklyn().descendantsOfType(application, entity, typeRegex); - return ApplicationResource.getSensorMap(sensor, descs); - } - - @Override - public List getLocations(String application, String entity) { - List result = Lists.newArrayList(); - EntityLocal e = brooklyn().getEntity(application, entity); - for (Location l: e.getLocations()) { - result.add(LocationTransformer.newInstance(mgmt(), l, LocationDetailLevel.NONE)); - } - return result; - } - - @Override - public String getSpec(String applicationToken, String entityToken) { - EntityLocal entity = brooklyn().getEntity(applicationToken, entityToken); - NamedStringTag spec = BrooklynTags.findFirst(BrooklynTags.YAML_SPEC_KIND, entity.tags().getTags()); - if (spec==null) return null; - return (String) getValueForDisplay(spec.getContents(), true, true); - } - + @Override + public List getDescendants(String application, String entity, String typeRegex) { + return EntityTransformer.entitySummaries(brooklyn().descendantsOfType(application, entity, typeRegex)); + } + + @Override + public Map getDescendantsSensor(String application, String entity, String sensor, String typeRegex) { + Iterable descs = brooklyn().descendantsOfType(application, entity, typeRegex); + return ApplicationResource.getSensorMap(sensor, descs); + } + + @Override + public List getLocations(String application, String entity) { + List result = Lists.newArrayList(); + EntityLocal e = brooklyn().getEntity(application, entity); + for (Location l : e.getLocations()) { + result.add(LocationTransformer.newInstance(mgmt(), l, LocationDetailLevel.NONE)); + } + return result; + } + + @Override + public String getSpec(String applicationToken, String entityToken) { + EntityLocal entity = brooklyn().getEntity(applicationToken, entityToken); + NamedStringTag spec = BrooklynTags.findFirst(BrooklynTags.YAML_SPEC_KIND, entity.tags().getTags()); + if (spec == null) + return null; + return (String) getValueForDisplay(spec.getContents(), true, true); + } } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyConfigResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyConfigResource.java index 4136daf313..5c2a1ba926 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyConfigResource.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/PolicyConfigResource.java @@ -40,68 +40,67 @@ public class PolicyConfigResource extends AbstractBrooklynRestResource implements PolicyConfigApi { - @Override - public List list( - final String application, final String entityToken, final String policyToken - ) { - EntityLocal entity = brooklyn().getEntity(application, entityToken); - Policy policy = brooklyn().getPolicy(entity, policyToken); - - List result = Lists.newArrayList(); - for (ConfigKey key : policy.getPolicyType().getConfigKeys()) { - result.add(PolicyTransformer.policyConfigSummary(brooklyn(), entity, policy, key)); + @Override + public List list( + final String application, final String entityToken, final String policyToken) { + EntityLocal entity = brooklyn().getEntity(application, entityToken); + Policy policy = brooklyn().getPolicy(entity, policyToken); + + List result = Lists.newArrayList(); + for (ConfigKey key : policy.getPolicyType().getConfigKeys()) { + result.add(PolicyTransformer.policyConfigSummary(brooklyn(), entity, policy, key)); + } + return result; + } + + // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} + // (and in sensors class) + @Override + public Map batchConfigRead(String application, String entityToken, String policyToken) { + // TODO: add test + Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); + Map, Object> source = policy.getAllConfig(); + Map result = Maps.newLinkedHashMap(); + for (Map.Entry, Object> ek : source.entrySet()) { + result.put(ek.getKey().getName(), getStringValueForDisplay(brooklyn(), policy, ek.getValue())); + } + return result; } - return result; - } - - // TODO support parameters ?show=value,summary&name=xxx &format={string,json,xml} - // (and in sensors class) - @Override - public Map batchConfigRead(String application, String entityToken, String policyToken) { - // TODO: add test - Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); - Map, Object> source = policy.getAllConfig(); - Map result = Maps.newLinkedHashMap(); - for (Map.Entry, Object> ek: source.entrySet()) { - result.put(ek.getKey().getName(), getStringValueForDisplay(brooklyn(), policy, ek.getValue())); + + @Override + public String get(String application, String entityToken, String policyToken, String configKeyName) { + Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); + ConfigKey ck = policy.getPolicyType().getConfigKey(configKeyName); + if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); + + return getStringValueForDisplay(brooklyn(), policy, policy.getConfig(ck)); + } + + @Override + @Deprecated + public Response set(String application, String entityToken, String policyToken, String configKeyName, String value) { + return set(application, entityToken, policyToken, configKeyName, (Object) value); } - return result; - } - - @Override - public String get(String application, String entityToken, String policyToken, String configKeyName) { - Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); - ConfigKey ck = policy.getPolicyType().getConfigKey(configKeyName); - if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); - - return getStringValueForDisplay(brooklyn(), policy, policy.getConfig(ck)); - } - - @Override @Deprecated - public Response set(String application, String entityToken, String policyToken, String configKeyName, String value) { - return set(application, entityToken, policyToken, configKeyName, (Object)value); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public Response set(String application, String entityToken, String policyToken, String configKeyName, Object value) { - Entity entity = brooklyn().getEntity(application, entityToken); - if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { - throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", - Entitlements.getEntitlementContext().user(), entity); - } - - Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); - ConfigKey ck = policy.getPolicyType().getConfigKey(configKeyName); - if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); - - policy.setConfig((ConfigKey) ck, TypeCoercions.coerce(value, ck.getTypeToken())); - - return Response.status(Response.Status.OK).build(); - } - - public static String getStringValueForDisplay(BrooklynRestResourceUtils utils, Policy policy, Object value) { - return utils.getStringValueForDisplay(value); - } + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + public Response set(String application, String entityToken, String policyToken, String configKeyName, Object value) { + Entity entity = brooklyn().getEntity(application, entityToken); + if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { + throw WebResourceUtils.unauthorized("User '%s' is not authorized to modify entity '%s'", + Entitlements.getEntitlementContext().user(), entity); + } + + Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); + ConfigKey ck = policy.getPolicyType().getConfigKey(configKeyName); + if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); + + policy.setConfig((ConfigKey) ck, TypeCoercions.coerce(value, ck.getTypeToken())); + + return Response.status(Response.Status.OK).build(); + } + + public static String getStringValueForDisplay(BrooklynRestResourceUtils utils, Policy policy, Object value) { + return utils.getStringValueForDisplay(value); + } } 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 38d577c41e..06e283daa7 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 @@ -74,12 +74,11 @@ public Map batchConfigRead( String application, String entityTo return result; } + // TODO would like to make 'config' arg optional but jersey complains if we do @SuppressWarnings("unchecked") @Override public PolicySummary addPolicy( String application,String entityToken, String policyTypeName, - // TODO would like to make this optional but jersey complains if we do - Map config - ) { + Map config) { EntityLocal entity = brooklyn().getEntity(application, entityToken); Class policyType; try { diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/ScriptResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/ScriptResource.java index 917d7f64bb..84909daecc 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/resources/ScriptResource.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/ScriptResource.java @@ -92,8 +92,7 @@ public ScriptExecutionSummary groovy(HttpServletRequest request, String script) // call toString on the result, in case it is not serializable return new ScriptExecutionSummary( value!=null ? value.toString() : null, - problem!=null ? problem.toString() : null, - stdout.toString(), stderr.toString()); + problem!=null ? problem.toString() : null, + stdout.toString(), stderr.toString()); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/resources/VersionResource.java b/usage/rest-server/src/main/java/brooklyn/rest/resources/VersionResource.java index ec90b3ba6a..44e26ab5e3 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/resources/VersionResource.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/resources/VersionResource.java @@ -25,9 +25,8 @@ @Deprecated public class VersionResource extends AbstractBrooklynRestResource implements VersionApi { - @Override - public String getVersion() { - return BrooklynVersion.get(); - } - + @Override + public String getVersion() { + return BrooklynVersion.get(); + } } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AbstractSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AbstractSecurityProvider.java index 6fd2f30e99..6ff5007ff7 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AbstractSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AbstractSecurityProvider.java @@ -53,6 +53,4 @@ protected boolean allow(HttpSession session, String user) { protected String getAuthenticationKey() { return getClass().getName() + ".AUTHENTICATED"; } - - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AnyoneSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AnyoneSecurityProvider.java index 9719584605..13d520eae6 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AnyoneSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/AnyoneSecurityProvider.java @@ -37,5 +37,4 @@ public boolean authenticate(HttpSession session, String user, String password) { public boolean logout(HttpSession session) { return true; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BlackholeSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BlackholeSecurityProvider.java index 0ad2086a44..4add0ebdb5 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BlackholeSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BlackholeSecurityProvider.java @@ -37,5 +37,4 @@ public boolean authenticate(HttpSession session, String user, String password) { public boolean logout(HttpSession session) { return true; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java index 90b7a1afc4..9cf63cac74 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/BrooklynUserWithRandomPasswordSecurityProvider.java @@ -65,5 +65,4 @@ private boolean isRemoteAddressLocalhost(HttpSession session) { return false; } } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/DelegatingSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/DelegatingSecurityProvider.java index 7b49bdd708..e7669ba166 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/DelegatingSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/DelegatingSecurityProvider.java @@ -145,5 +145,4 @@ public boolean logout(HttpSession session) { private String getModificationCountKey() { return getClass().getName() + ".ModCount"; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java index 7e5119f523..fc5e3c6262 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/ExplicitUsersSecurityProvider.java @@ -98,5 +98,4 @@ public boolean authenticate(HttpSession session, String user, String password) { return false; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/LdapSecurityProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/LdapSecurityProvider.java index bc905fb750..a9fa4531c2 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/security/provider/LdapSecurityProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/security/provider/LdapSecurityProvider.java @@ -98,5 +98,4 @@ public synchronized static void checkCanLoad() { throw Exceptions.propagate(new ClassNotFoundException("Unable to load LDAP classes ("+LDAP_CONTEXT_FACTORY+") required for Brooklyn LDAP security provider")); } } - } 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 1bcdf00b28..261dfb98ee 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 @@ -100,5 +100,4 @@ private static String tidyIconLink(BrooklynRestResourceUtils b, CatalogItem return "/v1/catalog/icon/"+item.getSymbolicName() + "/" + item.getVersion(); return iconUrl; } - } 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 3f5b9a798f..92e2165362 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 @@ -152,5 +152,4 @@ public static EntityConfigSummary entityConfigSummary(ConfigKey config, Field Double priority = catalogConfig==null ? null : catalogConfig.priority(); return entityConfigSummary(config, label, priority, null); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/LocationTransformer.java b/usage/rest-server/src/main/java/brooklyn/rest/transform/LocationTransformer.java index fdf837ac77..a77e386067 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/transform/LocationTransformer.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/LocationTransformer.java @@ -181,5 +181,4 @@ public static LocationSummary newInstance(ManagementContext mgmt, Location l, Lo .addIfNotNull("spec", specId!=null ? URI.create("/v1/locations/"+specId) : null) .asUnmodifiable() ); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/PolicyTransformer.java b/usage/rest-server/src/main/java/brooklyn/rest/transform/PolicyTransformer.java index 0d9d9f03fa..84baf3bcbc 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/transform/PolicyTransformer.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/PolicyTransformer.java @@ -82,5 +82,4 @@ public static PolicyConfigSummary policyConfigSummary(BrooklynRestResourceUtils config.isReconfigurable(), links); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/TaskTransformer.java b/usage/rest-server/src/main/java/brooklyn/rest/transform/TaskTransformer.java index bf2cb7111f..b36385f741 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/transform/TaskTransformer.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/TaskTransformer.java @@ -144,5 +144,4 @@ public static LinkWithMetadata asLink(Task t) { } return new LinkWithMetadata("/v1/activities/"+t.getId(), data); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/BrooklynRestResourceUtils.java b/usage/rest-server/src/main/java/brooklyn/rest/util/BrooklynRestResourceUtils.java index c9ba5f4201..5ddf037afc 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/BrooklynRestResourceUtils.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/BrooklynRestResourceUtils.java @@ -554,5 +554,4 @@ public boolean apply(Entity entity) { public void reloadBrooklynProperties() { mgmt.reloadBrooklynProperties(); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/DefaultExceptionMapper.java b/usage/rest-server/src/main/java/brooklyn/rest/util/DefaultExceptionMapper.java index 7963e480b4..a3a3b6f71e 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/DefaultExceptionMapper.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/DefaultExceptionMapper.java @@ -99,5 +99,4 @@ public Response toResponse(Throwable throwable1) { rb.message("Internal error. Contact server administrator to consult logs for more details."); return rb.build().asResponse(Status.INTERNAL_SERVER_ERROR, MediaType.APPLICATION_JSON_TYPE); } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/EntityLocationUtils.java b/usage/rest-server/src/main/java/brooklyn/rest/util/EntityLocationUtils.java index 5bc51cd370..2325926e3c 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/EntityLocationUtils.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/EntityLocationUtils.java @@ -82,5 +82,4 @@ protected boolean isLocatedLocation(Entity target) { protected boolean isLocatedLocation(Location l) { return l.getConfig(LocationConfigKeys.LATITUDE)!=null && l.getConfig(LocationConfigKeys.LONGITUDE)!=null; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/FormMapProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/util/FormMapProvider.java index eb6a60a5ee..a8a084cadb 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/FormMapProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/FormMapProvider.java @@ -78,5 +78,4 @@ public Map readFrom(Class> type, Type generi } return map; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/WebResourceUtils.java b/usage/rest-server/src/main/java/brooklyn/rest/util/WebResourceUtils.java index 06c81b1085..2a4f5e2e94 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/WebResourceUtils.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/WebResourceUtils.java @@ -139,5 +139,4 @@ public static String getPathFromVersionedId(String versionedId) { return Urls.encode(versionedId); } } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/json/BrooklynJacksonJsonProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/util/json/BrooklynJacksonJsonProvider.java index b79de3f27d..85c6072581 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/json/BrooklynJacksonJsonProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/json/BrooklynJacksonJsonProvider.java @@ -169,5 +169,4 @@ public static ManagementContext getManagementContext(ServletContext servletConte public void injectManagementContext(ManagementContext mgmt) { this.mgmt = mgmt; } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/json/ConfigurableSerializerProvider.java b/usage/rest-server/src/main/java/brooklyn/rest/util/json/ConfigurableSerializerProvider.java index 81099e65c9..73d502f645 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/json/ConfigurableSerializerProvider.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/json/ConfigurableSerializerProvider.java @@ -91,5 +91,4 @@ protected void onSerializationException(JsonStreamContext ctxt, JsonGenerator jg unknownTypeSerializer.serialize(value, jgen, this); } } - -} \ No newline at end of file +} diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/json/ErrorAndToStringUnknownTypeSerializer.java b/usage/rest-server/src/main/java/brooklyn/rest/util/json/ErrorAndToStringUnknownTypeSerializer.java index f4afbd562d..c059a04d7f 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/json/ErrorAndToStringUnknownTypeSerializer.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/json/ErrorAndToStringUnknownTypeSerializer.java @@ -122,5 +122,4 @@ protected boolean allowEmpty(Class clazz) { return false; } } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/json/MultimapSerializer.java b/usage/rest-server/src/main/java/brooklyn/rest/util/json/MultimapSerializer.java index 294f771987..f43350038c 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/json/MultimapSerializer.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/json/MultimapSerializer.java @@ -59,5 +59,4 @@ private void writeEntries(Multimap value, JsonGenerator jgen, SerializerPr provider.defaultSerializeValue(Lists.newArrayList(entry.getValue()), jgen); } } - } diff --git a/usage/rest-server/src/main/java/brooklyn/rest/util/json/PossiblyStrictPreferringFieldsVisibilityChecker.java b/usage/rest-server/src/main/java/brooklyn/rest/util/json/PossiblyStrictPreferringFieldsVisibilityChecker.java index 3f8e79dad0..dc033bc63e 100644 --- a/usage/rest-server/src/main/java/brooklyn/rest/util/json/PossiblyStrictPreferringFieldsVisibilityChecker.java +++ b/usage/rest-server/src/main/java/brooklyn/rest/util/json/PossiblyStrictPreferringFieldsVisibilityChecker.java @@ -104,4 +104,4 @@ public boolean isFieldVisible(Field f) { public boolean isFieldVisible(AnnotatedField f) { return isFieldVisible(f.getAnnotated()); } -} \ No newline at end of file +} diff --git a/usage/rest-server/src/test/java/brooklyn/rest/domain/ApplicationTest.java b/usage/rest-server/src/test/java/brooklyn/rest/domain/ApplicationTest.java index f3fa08de11..cb98129255 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/domain/ApplicationTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/domain/ApplicationTest.java @@ -41,57 +41,54 @@ public class ApplicationTest { - final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp", - ImmutableMap.of( - "initialSize", "1", - "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql" - )); + final EntitySpec entitySpec = new EntitySpec("Vanilla Java App", "brooklyn.entity.java.VanillaJavaApp", + ImmutableMap.of( + "initialSize", "1", + "creationScriptUrl", "http://my.brooklyn.io/storage/foo.sql")); - final ApplicationSpec applicationSpec = ApplicationSpec.builder().name("myapp"). - entities(ImmutableSet.of(entitySpec)). - locations(ImmutableSet.of("/v1/locations/1")). - build(); + final ApplicationSpec applicationSpec = ApplicationSpec.builder().name("myapp") + .entities(ImmutableSet.of(entitySpec)) + .locations(ImmutableSet.of("/v1/locations/1")) + .build(); - final ApplicationSummary application = new ApplicationSummary(null, applicationSpec, Status.STARTING, null); + final ApplicationSummary application = new ApplicationSummary(null, applicationSpec, Status.STARTING, null); - @Test - public void testSerializeToJSON() throws IOException { - ApplicationSummary application1 = new ApplicationSummary("myapp_id", applicationSpec, Status.STARTING, null) { - @Override - public Map getLinks() { - return ImmutableMap.of( - "self", URI.create("/v1/applications/" + applicationSpec.getName()), - "entities", URI.create("fixtures/entity-summary-list.json") - ); - } - }; - assertEquals(asJson(application1), jsonFixture("fixtures/application.json")); - } + @Test + public void testSerializeToJSON() throws IOException { + ApplicationSummary application1 = new ApplicationSummary("myapp_id", applicationSpec, Status.STARTING, null) { + @Override + public Map getLinks() { + return ImmutableMap.of( + "self", URI.create("/v1/applications/" + applicationSpec.getName()), + "entities", URI.create("fixtures/entity-summary-list.json")); + } + }; + assertEquals(asJson(application1), jsonFixture("fixtures/application.json")); + } - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/application.json"), - ApplicationSummary.class), application); - } + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/application.json"), + ApplicationSummary.class), application); + } - @Test - public void testTransitionToRunning() { + @Test + public void testTransitionToRunning() { ApplicationSummary running = application.transitionTo(Status.RUNNING); assertEquals(running.getStatus(), Status.RUNNING); - } - - @Test - public void testAppInAppTest() throws IOException { - TestApplicationImpl app = new TestApplicationImpl(); - ManagementContext mgmt = Entities.startManagement(app); - try { - Entity e2 = app.addChild(new TestApplicationImpl()); - Entities.manage(e2); - if (mgmt.getApplications().size()!=1) - Assert.fail("Apps in Apps should not be listed at top level: "+mgmt.getApplications()); - } finally { - Entities.destroyAll(mgmt); - } - } + } + @Test + public void testAppInAppTest() throws IOException { + TestApplicationImpl app = new TestApplicationImpl(); + ManagementContext mgmt = Entities.startManagement(app); + try { + Entity e2 = app.addChild(new TestApplicationImpl()); + Entities.manage(e2); + if (mgmt.getApplications().size()!=1) + Assert.fail("Apps in Apps should not be listed at top level: "+mgmt.getApplications()); + } finally { + Entities.destroyAll(mgmt); + } + } } diff --git a/usage/rest-server/src/test/java/brooklyn/rest/domain/LocationSummaryTest.java b/usage/rest-server/src/test/java/brooklyn/rest/domain/LocationSummaryTest.java index 35e7dd65b9..061dde785b 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/domain/LocationSummaryTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/domain/LocationSummaryTest.java @@ -34,22 +34,21 @@ public class LocationSummaryTest { - final LocationSummary summary = LocationTransformer.newInstance("123", LocationSpec.localhost()); - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(summary), jsonFixture("fixtures/location-summary.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/location-summary.json"), LocationSummary.class), summary); - } - - @Test - public void testDeserializeListFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/location-list.json"), new TypeReference>() {}), - Collections.singletonList(summary)); - } - + final LocationSummary summary = LocationTransformer.newInstance("123", LocationSpec.localhost()); + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(summary), jsonFixture("fixtures/location-summary.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/location-summary.json"), LocationSummary.class), summary); + } + + @Test + public void testDeserializeListFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/location-list.json"), new TypeReference>() {}), + Collections.singletonList(summary)); + } } diff --git a/usage/rest-server/src/test/java/brooklyn/rest/domain/SensorSummaryTest.java b/usage/rest-server/src/test/java/brooklyn/rest/domain/SensorSummaryTest.java index a524966cdb..f7a0fcf1bd 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/domain/SensorSummaryTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/domain/SensorSummaryTest.java @@ -45,58 +45,58 @@ public class SensorSummaryTest { - private SensorSummary sensorSummary = new SensorSummary("redis.uptime", "Integer", - "Description", ImmutableMap.of( - "self", URI.create("/v1/applications/redis-app/entities/redis-ent/sensors/redis.uptime"))); - - private TestApplication app; - private TestEntity entity; - private ManagementContext mgmt; - - @BeforeMethod(alwaysRun=true) - public void setUp() throws Exception { - app = TestApplication.Factory.newManagedInstanceForTests(); - mgmt = app.getManagementContext(); - entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() throws Exception { - if (mgmt != null) Entities.destroyAll(mgmt); - } - - @Test - public void testSerializeToJSON() throws IOException { - assertEquals(asJson(sensorSummary), jsonFixture("fixtures/sensor-summary.json")); - } - - @Test - public void testDeserializeFromJSON() throws IOException { - assertEquals(fromJson(jsonFixture("fixtures/sensor-summary.json"), SensorSummary.class), sensorSummary); - } - - @Test - public void testEscapesUriForSensorName() throws IOException { - Sensor sensor = Sensors.newStringSensor("name with space"); - SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor); - URI selfUri = summary.getLinks().get("self"); - - String expectedUri = "/v1/applications/" + entity.getApplicationId() + "/entities/" + entity.getId() + "/sensors/" + "name%20with%20space"; - - assertEquals(selfUri, URI.create(expectedUri)); - } - - // Previously failed because immutable-map builder threw exception if put same key multiple times, - // and the NamedActionWithUrl did not have equals/hashCode - @Test - public void testSensorWithMultipleOpenUrlActionsRegistered() throws IOException { - AttributeSensor sensor = Sensors.newStringSensor("sensor1"); - entity.setAttribute(sensor, "http://myval"); - RendererHints.register(sensor, RendererHints.namedActionWithUrl()); - RendererHints.register(sensor, RendererHints.namedActionWithUrl()); - - SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor); - - assertEquals(summary.getLinks().get("action:open"), URI.create("http://myval")); - } + private SensorSummary sensorSummary = new SensorSummary("redis.uptime", "Integer", + "Description", ImmutableMap.of( + "self", URI.create("/v1/applications/redis-app/entities/redis-ent/sensors/redis.uptime"))); + + private TestApplication app; + private TestEntity entity; + private ManagementContext mgmt; + + @BeforeMethod(alwaysRun = true) + public void setUp() throws Exception { + app = TestApplication.Factory.newManagedInstanceForTests(); + mgmt = app.getManagementContext(); + entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() throws Exception { + if (mgmt != null) Entities.destroyAll(mgmt); + } + + @Test + public void testSerializeToJSON() throws IOException { + assertEquals(asJson(sensorSummary), jsonFixture("fixtures/sensor-summary.json")); + } + + @Test + public void testDeserializeFromJSON() throws IOException { + assertEquals(fromJson(jsonFixture("fixtures/sensor-summary.json"), SensorSummary.class), sensorSummary); + } + + @Test + public void testEscapesUriForSensorName() throws IOException { + Sensor sensor = Sensors.newStringSensor("name with space"); + SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor); + URI selfUri = summary.getLinks().get("self"); + + String expectedUri = "/v1/applications/" + entity.getApplicationId() + "/entities/" + entity.getId() + "/sensors/" + "name%20with%20space"; + + assertEquals(selfUri, URI.create(expectedUri)); + } + + // Previously failed because immutable-map builder threw exception if put same key multiple times, + // and the NamedActionWithUrl did not have equals/hashCode + @Test + public void testSensorWithMultipleOpenUrlActionsRegistered() throws IOException { + AttributeSensor sensor = Sensors.newStringSensor("sensor1"); + entity.setAttribute(sensor, "http://myval"); + RendererHints.register(sensor, RendererHints.namedActionWithUrl()); + RendererHints.register(sensor, RendererHints.namedActionWithUrl()); + + SensorSummary summary = SensorTransformer.sensorSummary(entity, sensor); + + assertEquals(summary.getLinks().get("action:open"), URI.create("http://myval")); + } } 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 e009302ac1..a6c26abdbe 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 @@ -112,469 +112,462 @@ public class ApplicationResourceTest extends BrooklynRestResourceTest { .locations(ImmutableSet.of("localhost")) .build(); - // Convenience for finding an EntitySummary within a collection, based on its name - private static Predicate withName(final String name) { - return new Predicate() { - public boolean apply(EntitySummary input) { - return name.equals(input.getName()); - } - }; - } - - // Convenience for finding a Map within a collection, based on the value of one of its keys - private static Predicate> withValueForKey(final Object key, final Object value) { - return new Predicate() { - public boolean apply(Object input) { - if (!(input instanceof Map)) return false; - return value.equals(((Map) input).get(key)); - } - }; - } - - @Test - public void testGetUndefinedApplication() { - try { - client().resource("/v1/applications/dummy-not-found").get(ApplicationSummary.class); - } catch (UniformInterfaceException e) { - assertEquals(e.getResponse().getStatus(), 404); + // Convenience for finding an EntitySummary within a collection, based on its name + private static Predicate withName(final String name) { + return new Predicate() { + public boolean apply(EntitySummary input) { + return name.equals(input.getName()); + } + }; } - } - - private static void assertRegexMatches(String actual, String patternExpected) { - if (actual==null) Assert.fail("Actual value is null; expected "+patternExpected); - if (!actual.matches(patternExpected)) { - Assert.fail("Text '"+actual+"' does not match expected pattern "+patternExpected); - } - } - - @Test - public void testDeployApplication() throws Exception { - ClientResponse response = clientDeploy(simpleSpec); - - HttpTestUtils.assertHealthyStatusCode(response.getStatus()); - assertEquals(getManagementContext().getApplications().size(), 1); - assertRegexMatches(response.getLocation().getPath(), "/v1/applications/.*"); -// Object taskO = response.getEntity(Object.class); - TaskSummary task = response.getEntity(TaskSummary.class); - log.info("deployed, got "+task); - assertEquals(task.getEntityId(), - getManagementContext().getApplications().iterator().next().getApplicationId()); - - waitForApplicationToBeRunning(response.getLocation()); - } - - @Test(dependsOnMethods = {"testDeleteApplication"}) - // this must happen after we've deleted the main application, as testLocatedLocations assumes a single location - public void testDeployApplicationImpl() throws Exception { + + // Convenience for finding a Map within a collection, based on the value of one of its keys + private static Predicate> withValueForKey(final Object key, final Object value) { + return new Predicate() { + public boolean apply(Object input) { + if (!(input instanceof Map)) return false; + return value.equals(((Map) input).get(key)); + } + }; + } + + @Test + public void testGetUndefinedApplication() { + try { + client().resource("/v1/applications/dummy-not-found").get(ApplicationSummary.class); + } catch (UniformInterfaceException e) { + assertEquals(e.getResponse().getStatus(), 404); + } + } + + private static void assertRegexMatches(String actual, String patternExpected) { + if (actual==null) Assert.fail("Actual value is null; expected "+patternExpected); + if (!actual.matches(patternExpected)) { + Assert.fail("Text '"+actual+"' does not match expected pattern "+patternExpected); + } + } + + @Test + public void testDeployApplication() throws Exception { + ClientResponse response = clientDeploy(simpleSpec); + + HttpTestUtils.assertHealthyStatusCode(response.getStatus()); + assertEquals(getManagementContext().getApplications().size(), 1); + assertRegexMatches(response.getLocation().getPath(), "/v1/applications/.*"); + // Object taskO = response.getEntity(Object.class); + TaskSummary task = response.getEntity(TaskSummary.class); + log.info("deployed, got " + task); + assertEquals(task.getEntityId(), getManagementContext().getApplications().iterator().next().getApplicationId()); + + waitForApplicationToBeRunning(response.getLocation()); + } + + @Test(dependsOnMethods = { "testDeleteApplication" }) + // this must happen after we've deleted the main application, as testLocatedLocations assumes a single location + public void testDeployApplicationImpl() throws Exception { ApplicationSpec spec = ApplicationSpec.builder() .type(RestMockApp.class.getCanonicalName()) .name("simple-app-impl") .locations(ImmutableSet.of("localhost")) .build(); - - ClientResponse response = clientDeploy(spec); - assertTrue(response.getStatus()/100 == 2, "response is "+response); - - // Expect app to be running - URI appUri = response.getLocation(); - waitForApplicationToBeRunning(response.getLocation()); - assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-impl"); - } - - @Test(dependsOnMethods = {"testDeployApplication", "testLocatedLocation"}) - public void testDeployApplicationFromInterface() throws Exception { - ApplicationSpec spec = ApplicationSpec.builder() - .type(BasicApplication.class.getCanonicalName()) - .name("simple-app-interface") - .locations(ImmutableSet.of("localhost")) - .build(); - - ClientResponse response = clientDeploy(spec); - assertTrue(response.getStatus()/100 == 2, "response is "+response); - - // Expect app to be running - URI appUri = response.getLocation(); - waitForApplicationToBeRunning(response.getLocation()); - assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-interface"); - } - - @Test(dependsOnMethods = {"testDeployApplication", "testLocatedLocation"}) - public void testDeployApplicationFromBuilder() throws Exception { - ApplicationSpec spec = ApplicationSpec.builder() - .type(RestMockAppBuilder.class.getCanonicalName()) - .name("simple-app-builder") - .locations(ImmutableSet.of("localhost")) - .build(); - - ClientResponse response = clientDeploy(spec); - assertTrue(response.getStatus()/100 == 2, "response is "+response); - - // Expect app to be running - URI appUri = response.getLocation(); - waitForApplicationToBeRunning(response.getLocation(), Duration.TEN_SECONDS); - assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-builder"); - - // Expect app to have the child-entity - Set entities = client().resource(appUri.toString() + "/entities") - .get(new GenericType>() {}); - assertEquals(entities.size(), 1); - assertEquals(Iterables.getOnlyElement(entities).getName(), "child1"); - assertEquals(Iterables.getOnlyElement(entities).getType(), RestMockSimpleEntity.class.getCanonicalName()); - } - - - @Test(dependsOnMethods = {"testDeployApplication", "testLocatedLocation"}) - public void testDeployApplicationYaml() throws Exception { - String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: "+BasicApplication.class.getCanonicalName()+" } ] }"; - - ClientResponse response = client().resource("/v1/applications") - .entity(yaml, "application/x-yaml") - .post(ClientResponse.class); - assertTrue(response.getStatus()/100 == 2, "response is "+response); - - // Expect app to be running - URI appUri = response.getLocation(); - waitForApplicationToBeRunning(response.getLocation()); - assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml"); - } - - @SuppressWarnings("deprecation") - @Test - public void testReferenceCatalogEntity() throws Exception { - getManagementContext().getCatalog().addItem(BasicEntity.class); - - String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: " + BasicEntity.class.getName() + " } ] }"; - - ClientResponse response = client().resource("/v1/applications") - .entity(yaml, "application/x-yaml") - .post(ClientResponse.class); - assertTrue(response.getStatus()/100 == 2, "response is "+response); - - // Expect app to be running - URI appUri = response.getLocation(); - waitForApplicationToBeRunning(response.getLocation()); - assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml"); - - ClientResponse response2 = client().resource(appUri.getPath()) - .delete(ClientResponse.class); - assertEquals(response2.getStatus(), Response.Status.ACCEPTED.getStatusCode()); - } - - @Test - 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() - ); - - } catch (UniformInterfaceException e) { - ApiError error = e.getResponse().getEntity(ApiError.class); - assertEquals(error.getMessage(), "Undefined type 'not.existing.entity'"); + + ClientResponse response = clientDeploy(spec); + assertTrue(response.getStatus() / 100 == 2, "response is " + response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation()); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-impl"); } - } - - @Test - public void testDeployWithInvalidLocation() { - try { - clientDeploy( - ApplicationSpec.builder().name("invalid-app") - .entities(ImmutableSet.of(new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()))) - .locations(ImmutableSet.of("3423")) - .build() - ); - - } catch (UniformInterfaceException e) { - ApiError error = e.getResponse().getEntity(ApiError.class); - assertEquals(error.getMessage(), "Undefined location '3423'"); + + @Test(dependsOnMethods = { "testDeployApplication", "testLocatedLocation" }) + public void testDeployApplicationFromInterface() throws Exception { + ApplicationSpec spec = ApplicationSpec.builder() + .type(BasicApplication.class.getCanonicalName()) + .name("simple-app-interface") + .locations(ImmutableSet.of("localhost")) + .build(); + + ClientResponse response = clientDeploy(spec); + assertTrue(response.getStatus() / 100 == 2, "response is " + response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation()); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-interface"); } - } - - @Test(dependsOnMethods = "testDeployApplication") - public void testListEntities() { - Set entities = client().resource("/v1/applications/simple-app/entities") - .get(new GenericType>() {}); - - assertEquals(entities.size(), 2); - - EntitySummary entity = Iterables.find(entities, withName("simple-ent"), null); - EntitySummary group = Iterables.find(entities, withName("simple-group"), null); - Assert.assertNotNull(entity); - Assert.assertNotNull(group); - - client().resource(entity.getLinks().get("self")).get(ClientResponse.class); - - Set children = client().resource(entity.getLinks().get("children")) - .get(new GenericType>() {}); - assertEquals(children.size(), 0); - } - - @Test(dependsOnMethods = "testDeployApplication") - public void testListApplications() { - Set applications = client().resource("/v1/applications") - .get(new GenericType>() { }); - log.info("Applications listed are: "+applications); - for (ApplicationSummary app: applications) { - if (simpleSpec.getName().equals(app.getSpec().getName())) return; + + @Test(dependsOnMethods = { "testDeployApplication", "testLocatedLocation" }) + public void testDeployApplicationFromBuilder() throws Exception { + ApplicationSpec spec = ApplicationSpec.builder() + .type(RestMockAppBuilder.class.getCanonicalName()) + .name("simple-app-builder") + .locations(ImmutableSet.of("localhost")) + .build(); + + ClientResponse response = clientDeploy(spec); + assertTrue(response.getStatus() / 100 == 2, "response is " + response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation(), Duration.TEN_SECONDS); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-builder"); + + // Expect app to have the child-entity + Set entities = client().resource(appUri.toString() + "/entities") + .get(new GenericType>() {}); + assertEquals(entities.size(), 1); + assertEquals(Iterables.getOnlyElement(entities).getName(), "child1"); + assertEquals(Iterables.getOnlyElement(entities).getType(), RestMockSimpleEntity.class.getCanonicalName()); } - Assert.fail("simple-app not found in list of applications: "+applications); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test(dependsOnMethods = "testDeployApplication") - public void testFetchApplicationsAndEntity() { - Collection apps = client().resource("/v1/applications/fetch").get(Collection.class); - log.info("Applications fetched are: "+apps); - - Map app = null; - for (Object appI: apps) { - Object name = ((Map)appI).get("name"); - if ("simple-app".equals( name )) { - app = (Map) appI; + + @Test(dependsOnMethods = { "testDeployApplication", "testLocatedLocation" }) + public void testDeployApplicationYaml() throws Exception { + String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: "+BasicApplication.class.getCanonicalName()+" } ] }"; + + ClientResponse response = client().resource("/v1/applications") + .entity(yaml, "application/x-yaml") + .post(ClientResponse.class); + assertTrue(response.getStatus()/100 == 2, "response is "+response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation()); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml"); + } + + @SuppressWarnings("deprecation") + @Test + public void testReferenceCatalogEntity() throws Exception { + getManagementContext().getCatalog().addItem(BasicEntity.class); + + String yaml = "{ name: simple-app-yaml, location: localhost, services: [ { serviceType: " + BasicEntity.class.getName() + " } ] }"; + + ClientResponse response = client().resource("/v1/applications") + .entity(yaml, "application/x-yaml") + .post(ClientResponse.class); + assertTrue(response.getStatus()/100 == 2, "response is "+response); + + // Expect app to be running + URI appUri = response.getLocation(); + waitForApplicationToBeRunning(response.getLocation()); + assertEquals(client().resource(appUri).get(ApplicationSummary.class).getSpec().getName(), "simple-app-yaml"); + + ClientResponse response2 = client().resource(appUri.getPath()) + .delete(ClientResponse.class); + assertEquals(response2.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + } + + @Test + 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()); + + } catch (UniformInterfaceException e) { + ApiError error = e.getResponse().getEntity(ApiError.class); + assertEquals(error.getMessage(), "Undefined type 'not.existing.entity'"); } - if (ImmutableSet.of("simple-ent", "simple-group").contains(name)) - Assert.fail(name+" should not be listed at high level: "+apps); } - - Assert.assertNotNull(app); - Collection children = (Collection) app.get("children"); - Assert.assertEquals(children.size(), 2); - - Map entitySummary = (Map) Iterables.find(children, withValueForKey("name", "simple-ent"), null); - Map groupSummary = (Map) Iterables.find(children, withValueForKey("name", "simple-group"), null); - Assert.assertNotNull(entitySummary); - 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); - log.info("Applications+Entities fetched are: "+entities); - - Assert.assertEquals(entities.size(), apps.size()+2); - Map entityDetails = (Map) Iterables.find(entities, withValueForKey("name", "simple-ent"), null); - Map groupDetails = (Map) Iterables.find(entities, withValueForKey("name", "simple-group"), null); - Assert.assertNotNull(entityDetails); - Assert.assertNotNull(groupDetails); - - Assert.assertEquals(entityDetails.get("parentId"), app.get("id")); - Assert.assertNull(entityDetails.get("children")); - Assert.assertEquals(groupDetails.get("parentId"), app.get("id")); - Assert.assertNull(groupDetails.get("children")); - - Collection entityGroupIds = (Collection) entityDetails.get("groupIds"); - Assert.assertNotNull(entityGroupIds); - Assert.assertEquals(entityGroupIds.size(), 1); - Assert.assertEquals(entityGroupIds.iterator().next(), groupDetails.get("id")); - - Collection groupMembers = (Collection) groupDetails.get("members"); - Assert.assertNotNull(groupMembers); - - for (Application appi: getManagementContext().getApplications()) { - Entities.dumpInfo(appi); + + @Test + public void testDeployWithInvalidLocation() { + try { + clientDeploy(ApplicationSpec.builder() + .name("invalid-app") + .entities(ImmutableSet.of(new EntitySpec("simple-ent", RestMockSimpleEntity.class.getName()))) + .locations(ImmutableSet.of("3423")) + .build()); + + } catch (UniformInterfaceException e) { + ApiError error = e.getResponse().getEntity(ApiError.class); + assertEquals(error.getMessage(), "Undefined location '3423'"); + } } - log.info("MEMBERS: "+groupMembers); - - Assert.assertEquals(groupMembers.size(), 1); - Map entityMemberDetails = (Map) Iterables.find(groupMembers, withValueForKey("name", "simple-ent"), null); - Assert.assertNotNull(entityMemberDetails); - Assert.assertEquals(entityMemberDetails.get("id"), entityDetails.get("id")); - } - - @Test(dependsOnMethods = "testDeployApplication") - public void testListSensors() { - Set sensors = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors") - .get(new GenericType>() { }); - assertTrue(sensors.size() > 0); - SensorSummary sample = Iterables.find(sensors, new Predicate() { - @Override - public boolean apply(SensorSummary sensorSummary) { - return sensorSummary.getName().equals(RestMockSimpleEntity.SAMPLE_SENSOR.getName()); - } - }); - assertEquals(sample.getType(), "java.lang.String"); - } - - @Test(dependsOnMethods = "testDeployApplication") - public void testListConfig() { - Set config = client().resource("/v1/applications/simple-app/entities/simple-ent/config") - .get(new GenericType>() { }); - assertTrue(config.size() > 0); - System.out.println(("CONFIG: "+config)); - } - - @Test(dependsOnMethods = "testListConfig") - public void testListConfig2() { - Set config = client().resource("/v1/applications/simple-app/entities/simple-ent/config") - .get(new GenericType>() { - }); - assertTrue(config.size() > 0); - System.out.println(("CONFIG: "+config)); - } - - @Test(dependsOnMethods = "testDeployApplication") - public void testListEffectors() { - Set effectors = client().resource("/v1/applications/simple-app/entities/simple-ent/effectors") - .get(new GenericType>() { + + @Test(dependsOnMethods = "testDeployApplication") + public void testListEntities() { + Set entities = client().resource("/v1/applications/simple-app/entities") + .get(new GenericType>() {}); + + assertEquals(entities.size(), 2); + + EntitySummary entity = Iterables.find(entities, withName("simple-ent"), null); + EntitySummary group = Iterables.find(entities, withName("simple-group"), null); + Assert.assertNotNull(entity); + Assert.assertNotNull(group); + + client().resource(entity.getLinks().get("self")).get(ClientResponse.class); + + Set children = client().resource(entity.getLinks().get("children")) + .get(new GenericType>() {}); + assertEquals(children.size(), 0); + } + + @Test(dependsOnMethods = "testDeployApplication") + public void testListApplications() { + Set applications = client().resource("/v1/applications") + .get(new GenericType>() { }); + log.info("Applications listed are: " + applications); + for (ApplicationSummary app : applications) { + if (simpleSpec.getName().equals(app.getSpec().getName())) return; + } + Assert.fail("simple-app not found in list of applications: "+applications); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test(dependsOnMethods = "testDeployApplication") + public void testFetchApplicationsAndEntity() { + Collection apps = client().resource("/v1/applications/fetch").get(Collection.class); + log.info("Applications fetched are: " + apps); + + Map app = null; + for (Object appI : apps) { + Object name = ((Map) appI).get("name"); + if ("simple-app".equals(name)) { + app = (Map) appI; + } + if (ImmutableSet.of("simple-ent", "simple-group").contains(name)) + Assert.fail(name + " should not be listed at high level: " + apps); + } + + Assert.assertNotNull(app); + Collection children = (Collection) app.get("children"); + Assert.assertEquals(children.size(), 2); + + Map entitySummary = (Map) Iterables.find(children, withValueForKey("name", "simple-ent"), null); + Map groupSummary = (Map) Iterables.find(children, withValueForKey("name", "simple-group"), null); + Assert.assertNotNull(entitySummary); + 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); + log.info("Applications+Entities fetched are: " + entities); + + Assert.assertEquals(entities.size(), apps.size() + 2); + Map entityDetails = (Map) Iterables.find(entities, withValueForKey("name", "simple-ent"), null); + Map groupDetails = (Map) Iterables.find(entities, withValueForKey("name", "simple-group"), null); + Assert.assertNotNull(entityDetails); + Assert.assertNotNull(groupDetails); + + Assert.assertEquals(entityDetails.get("parentId"), app.get("id")); + Assert.assertNull(entityDetails.get("children")); + Assert.assertEquals(groupDetails.get("parentId"), app.get("id")); + Assert.assertNull(groupDetails.get("children")); + + Collection entityGroupIds = (Collection) entityDetails.get("groupIds"); + Assert.assertNotNull(entityGroupIds); + Assert.assertEquals(entityGroupIds.size(), 1); + Assert.assertEquals(entityGroupIds.iterator().next(), groupDetails.get("id")); + + Collection groupMembers = (Collection) groupDetails.get("members"); + Assert.assertNotNull(groupMembers); + + for (Application appi : getManagementContext().getApplications()) { + Entities.dumpInfo(appi); + } + log.info("MEMBERS: " + groupMembers); + + Assert.assertEquals(groupMembers.size(), 1); + Map entityMemberDetails = (Map) Iterables.find(groupMembers, withValueForKey("name", "simple-ent"), null); + Assert.assertNotNull(entityMemberDetails); + Assert.assertEquals(entityMemberDetails.get("id"), entityDetails.get("id")); + } + + @Test(dependsOnMethods = "testDeployApplication") + public void testListSensors() { + Set sensors = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors") + .get(new GenericType>() { }); + assertTrue(sensors.size() > 0); + SensorSummary sample = Iterables.find(sensors, new Predicate() { + @Override + public boolean apply(SensorSummary sensorSummary) { + return sensorSummary.getName().equals(RestMockSimpleEntity.SAMPLE_SENSOR.getName()); + } }); + assertEquals(sample.getType(), "java.lang.String"); + } - assertTrue(effectors.size() > 0); - - EffectorSummary sampleEffector = find(effectors, new Predicate() { - @Override - public boolean apply(EffectorSummary input) { - return input.getName().equals("sampleEffector"); - } - }); - assertEquals(sampleEffector.getReturnType(), "java.lang.String"); - } - - @Test(dependsOnMethods = "testListSensors") - public void testTriggerSampleEffector() throws InterruptedException, IOException { - ClientResponse response = client().resource("/v1/applications/simple-app/entities/simple-ent/effectors/"+ - RestMockSimpleEntity.SAMPLE_EFFECTOR.getName()) - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, ImmutableMap.of("param1", "foo", "param2", 4)); - - assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); - - String result = response.getEntity(String.class); - assertEquals(result, "foo4"); - } - - @Test(dependsOnMethods = "testListSensors") - public void testTriggerSampleEffectorWithFormData() throws InterruptedException, IOException { - MultivaluedMap data = new MultivaluedMapImpl(); - data.add("param1", "foo"); - data.add("param2", "4"); - ClientResponse response = client().resource("/v1/applications/simple-app/entities/simple-ent/effectors/"+ - RestMockSimpleEntity.SAMPLE_EFFECTOR.getName()) - .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE) - .post(ClientResponse.class, data); - - assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); - - String result = response.getEntity(String.class); - assertEquals(result, "foo4"); - } - - @Test(dependsOnMethods = "testTriggerSampleEffector") - public void testBatchSensorValues() { - WebResource resource = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors/current-state"); - Map sensors = resource.get(new GenericType>() {}); - assertTrue(sensors.size() > 0); - assertEquals(sensors.get(RestMockSimpleEntity.SAMPLE_SENSOR.getName()), "foo4"); - } - - @Test(dependsOnMethods = "testBatchSensorValues") - public void testReadEachSensor() { - Set sensors = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors") - .get(new GenericType>() { + @Test(dependsOnMethods = "testDeployApplication") + public void testListConfig() { + Set config = client().resource("/v1/applications/simple-app/entities/simple-ent/config") + .get(new GenericType>() { }); + assertTrue(config.size() > 0); + System.out.println(("CONFIG: " + config)); + } + + @Test(dependsOnMethods = "testListConfig") + public void testListConfig2() { + Set config = client().resource("/v1/applications/simple-app/entities/simple-ent/config") + .get(new GenericType>() {}); + assertTrue(config.size() > 0); + System.out.println(("CONFIG: " + config)); + } + + @Test(dependsOnMethods = "testDeployApplication") + public void testListEffectors() { + Set effectors = client().resource("/v1/applications/simple-app/entities/simple-ent/effectors") + .get(new GenericType>() {}); + + assertTrue(effectors.size() > 0); + + EffectorSummary sampleEffector = find(effectors, new Predicate() { + @Override + public boolean apply(EffectorSummary input) { + return input.getName().equals("sampleEffector"); + } }); + assertEquals(sampleEffector.getReturnType(), "java.lang.String"); + } + + @Test(dependsOnMethods = "testListSensors") + public void testTriggerSampleEffector() throws InterruptedException, IOException { + ClientResponse response = client() + .resource("/v1/applications/simple-app/entities/simple-ent/effectors/"+RestMockSimpleEntity.SAMPLE_EFFECTOR.getName()) + .type(MediaType.APPLICATION_JSON_TYPE) + .post(ClientResponse.class, ImmutableMap.of("param1", "foo", "param2", 4)); + + assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + + String result = response.getEntity(String.class); + assertEquals(result, "foo4"); + } + + @Test(dependsOnMethods = "testListSensors") + public void testTriggerSampleEffectorWithFormData() throws InterruptedException, IOException { + MultivaluedMap data = new MultivaluedMapImpl(); + data.add("param1", "foo"); + data.add("param2", "4"); + ClientResponse response = client() + .resource("/v1/applications/simple-app/entities/simple-ent/effectors/"+RestMockSimpleEntity.SAMPLE_EFFECTOR.getName()) + .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE) + .post(ClientResponse.class, data); + + assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + + String result = response.getEntity(String.class); + assertEquals(result, "foo4"); + } + + @Test(dependsOnMethods = "testTriggerSampleEffector") + public void testBatchSensorValues() { + WebResource resource = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors/current-state"); + Map sensors = resource.get(new GenericType>() {}); + assertTrue(sensors.size() > 0); + assertEquals(sensors.get(RestMockSimpleEntity.SAMPLE_SENSOR.getName()), "foo4"); + } - Map readings = Maps.newHashMap(); - for (SensorSummary sensor : sensors) { - try { - readings.put(sensor.getName(), client().resource(sensor.getLinks().get("self")).accept(MediaType.TEXT_PLAIN).get(String.class)); - } catch (UniformInterfaceException uie) { - if (uie.getResponse().getStatus() == 204) { // no content - readings.put(sensor.getName(), null); - } else { - Exceptions.propagate(uie); + @Test(dependsOnMethods = "testBatchSensorValues") + public void testReadEachSensor() { + Set sensors = client().resource("/v1/applications/simple-app/entities/simple-ent/sensors") + .get(new GenericType>() {}); + + Map readings = Maps.newHashMap(); + for (SensorSummary sensor : sensors) { + try { + readings.put(sensor.getName(), client().resource(sensor.getLinks().get("self")).accept(MediaType.TEXT_PLAIN).get(String.class)); + } catch (UniformInterfaceException uie) { + if (uie.getResponse().getStatus() == 204) { // no content + readings.put(sensor.getName(), null); + } else { + Exceptions.propagate(uie); + } + } } - } + + assertEquals(readings.get(RestMockSimpleEntity.SAMPLE_SENSOR.getName()), "foo4"); } - assertEquals(readings.get(RestMockSimpleEntity.SAMPLE_SENSOR.getName()), "foo4"); - } - - @Test(dependsOnMethods = "testTriggerSampleEffector") - public void testPolicyWhichCapitalizes() { - String policiesEndpoint = "/v1/applications/simple-app/entities/simple-ent/policies"; - Set policies = client().resource(policiesEndpoint).get(new GenericType>(){}); - assertEquals(policies.size(), 0); - - ClientResponse response = client().resource(policiesEndpoint) - .queryParam("type", CapitalizePolicy.class.getCanonicalName()) - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, Maps.newHashMap()); - assertEquals(response.getStatus(), 200); - PolicySummary policy = response.getEntity(PolicySummary.class); - assertNotNull(policy.getId()); - String newPolicyId = policy.getId(); - log.info("POLICY CREATED: "+newPolicyId); - policies = client().resource(policiesEndpoint).get(new GenericType>(){}); - assertEquals(policies.size(), 1); - - Lifecycle status = client().resource(policiesEndpoint+"/"+newPolicyId).get(Lifecycle.class); - log.info("POLICY STATUS: "+status); - - response = client().resource(policiesEndpoint+"/"+newPolicyId+"/start") - .post(ClientResponse.class); - assertEquals(response.getStatus(), 204); - status = client().resource(policiesEndpoint+"/"+newPolicyId).get(Lifecycle.class); - assertEquals(status, Lifecycle.RUNNING); - - response = client().resource(policiesEndpoint+"/"+newPolicyId+"/stop") - .post(ClientResponse.class); - assertEquals(response.getStatus(), 204); - status = client().resource(policiesEndpoint+"/"+newPolicyId).get(Lifecycle.class); - assertEquals(status, Lifecycle.STOPPED); - - 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()); - assertEquals(response.getStatus(), 404); - - policies = client().resource(policiesEndpoint).get(new GenericType>(){}); - assertEquals(0, policies.size()); - } - - @SuppressWarnings({ "rawtypes" }) - @Test(dependsOnMethods = "testDeployApplication") - public void testLocatedLocation() { - log.info("starting testLocatedLocations"); - testListApplications(); - - Location l = getManagementContext().getApplications().iterator().next().getLocations().iterator().next(); - if (!l.hasConfig(LocationConfigKeys.LATITUDE, false)) { - log.info("Supplying fake locations for localhost because could not be autodetected"); - ((AbstractLocation)l).setHostGeoInfo(new HostGeoInfo("localhost", "localhost", 50, 0)); + @Test(dependsOnMethods = "testTriggerSampleEffector") + public void testPolicyWhichCapitalizes() { + String policiesEndpoint = "/v1/applications/simple-app/entities/simple-ent/policies"; + Set policies = client().resource(policiesEndpoint).get(new GenericType>(){}); + assertEquals(policies.size(), 0); + + ClientResponse response = client().resource(policiesEndpoint) + .queryParam("type", CapitalizePolicy.class.getCanonicalName()) + .type(MediaType.APPLICATION_JSON_TYPE) + .post(ClientResponse.class, Maps.newHashMap()); + assertEquals(response.getStatus(), 200); + PolicySummary policy = response.getEntity(PolicySummary.class); + assertNotNull(policy.getId()); + String newPolicyId = policy.getId(); + log.info("POLICY CREATED: " + newPolicyId); + policies = client().resource(policiesEndpoint).get(new GenericType>() {}); + assertEquals(policies.size(), 1); + + Lifecycle status = client().resource(policiesEndpoint + "/" + newPolicyId).get(Lifecycle.class); + log.info("POLICY STATUS: " + status); + + response = client().resource(policiesEndpoint+"/"+newPolicyId+"/start") + .post(ClientResponse.class); + assertEquals(response.getStatus(), 204); + status = client().resource(policiesEndpoint + "/" + newPolicyId).get(Lifecycle.class); + assertEquals(status, Lifecycle.RUNNING); + + response = client().resource(policiesEndpoint+"/"+newPolicyId+"/stop") + .post(ClientResponse.class); + assertEquals(response.getStatus(), 204); + status = client().resource(policiesEndpoint + "/" + newPolicyId).get(Lifecycle.class); + assertEquals(status, Lifecycle.STOPPED); + + 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()); + assertEquals(response.getStatus(), 404); + + policies = client().resource(policiesEndpoint).get(new GenericType>() {}); + assertEquals(0, policies.size()); } - Map result = client().resource("/v1/locations/usage/LocatedLocations") - .get(Map.class); - log.info("LOCATIONS: "+result); - Assert.assertEquals(result.size(), 1); - Map details = (Map) result.values().iterator().next(); - assertEquals(details.get("leafEntityCount"), 2); - } - - @Test(dependsOnMethods = {"testListEffectors", "testFetchApplicationsAndEntity", "testTriggerSampleEffector", "testListApplications","testReadEachSensor","testPolicyWhichCapitalizes","testLocatedLocation"}) - public void testDeleteApplication() throws TimeoutException, InterruptedException { - waitForPageFoundResponse("/v1/applications/simple-app", ApplicationSummary.class); - Collection apps = getManagementContext().getApplications(); - log.info("Deleting simple-app from "+apps); - int size = apps.size(); - - ClientResponse response = client().resource("/v1/applications/simple-app") - .delete(ClientResponse.class); - assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); - TaskSummary task = response.getEntity(TaskSummary.class); - assertTrue(task.getDescription().toLowerCase().contains("destroy"), task.getDescription()); - assertTrue(task.getDescription().toLowerCase().contains("simple-app"), task.getDescription()); - - waitForPageNotFoundResponse("/v1/applications/simple-app", ApplicationSummary.class); + @SuppressWarnings({ "rawtypes" }) + @Test(dependsOnMethods = "testDeployApplication") + public void testLocatedLocation() { + log.info("starting testLocatedLocations"); + testListApplications(); - log.info("App appears gone, apps are: "+getManagementContext().getApplications()); - // more logging above, for failure in the check below + Location l = getManagementContext().getApplications().iterator().next().getLocations().iterator().next(); + if (!l.hasConfig(LocationConfigKeys.LATITUDE, false)) { + log.info("Supplying fake locations for localhost because could not be autodetected"); + ((AbstractLocation) l).setHostGeoInfo(new HostGeoInfo("localhost", "localhost", 50, 0)); + } + Map result = client().resource("/v1/locations/usage/LocatedLocations") + .get(Map.class); + log.info("LOCATIONS: " + result); + Assert.assertEquals(result.size(), 1); + Map details = (Map) result.values().iterator().next(); + assertEquals(details.get("leafEntityCount"), 2); + } - Asserts.eventually( - EntityFunctions.applications(getManagementContext()), - Predicates.compose(Predicates.equalTo(size-1), CollectionFunctionals.sizeFunction()) ); - } + @Test(dependsOnMethods = {"testListEffectors", "testFetchApplicationsAndEntity", "testTriggerSampleEffector", "testListApplications","testReadEachSensor","testPolicyWhichCapitalizes","testLocatedLocation"}) + public void testDeleteApplication() throws TimeoutException, InterruptedException { + waitForPageFoundResponse("/v1/applications/simple-app", ApplicationSummary.class); + Collection apps = getManagementContext().getApplications(); + log.info("Deleting simple-app from " + apps); + int size = apps.size(); + + ClientResponse response = client().resource("/v1/applications/simple-app") + .delete(ClientResponse.class); + + assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); + TaskSummary task = response.getEntity(TaskSummary.class); + assertTrue(task.getDescription().toLowerCase().contains("destroy"), task.getDescription()); + assertTrue(task.getDescription().toLowerCase().contains("simple-app"), task.getDescription()); + + waitForPageNotFoundResponse("/v1/applications/simple-app", ApplicationSummary.class); + + log.info("App appears gone, apps are: " + getManagementContext().getApplications()); + // more logging above, for failure in the check below + + Asserts.eventually( + EntityFunctions.applications(getManagementContext()), + Predicates.compose(Predicates.equalTo(size-1), CollectionFunctionals.sizeFunction()) ); + } } 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 049a0fae4f..060e3c8aa7 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 @@ -72,217 +72,215 @@ protected void addBrooklynResources() { addResource(new CatalogResource()); } - @Test - /** based on CampYamlLiteTest */ - public void testRegisterCustomEntityWithBundleWhereEntityIsFromCoreAndIconFromBundle() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String symbolicName = "my.catalog.entity.id"; - String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; - String yaml = - "brooklyn.catalog:\n"+ - " id: " + symbolicName + "\n"+ - " name: My Catalog App\n"+ - " description: My description\n"+ - " icon_url: classpath:/brooklyn/osgi/tests/icon.gif\n"+ - " version: " + TEST_VERSION + "\n"+ - " libraries:\n"+ - " - url: " + bundleUrl + "\n"+ - "\n"+ - "services:\n"+ - "- type: brooklyn.test.entity.TestEntity\n"; - - ClientResponse response = client().resource("/v1/catalog") - .post(ClientResponse.class, yaml); - - assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); - - CatalogEntitySummary entityItem = client().resource("/v1/catalog/entities/"+symbolicName + "/" + TEST_VERSION) - .get(CatalogEntitySummary.class); - - Assert.assertNotNull(entityItem.getPlanYaml()); - Assert.assertTrue(entityItem.getPlanYaml().contains("brooklyn.test.entity.TestEntity")); - - assertEquals(entityItem.getId(), ver(symbolicName)); - assertEquals(entityItem.getSymbolicName(), symbolicName); - assertEquals(entityItem.getVersion(), TEST_VERSION); - - // and internally let's check we have libraries - CatalogItem item = getManagementContext().getCatalog().getCatalogItem(symbolicName, TEST_VERSION); - Assert.assertNotNull(item); - Collection libs = item.getLibraries(); - assertEquals(libs.size(), 1); - assertEquals(Iterables.getOnlyElement(libs).getUrl(), bundleUrl); - - // now let's check other things on the item - assertEquals(entityItem.getName(), "My Catalog App"); - assertEquals(entityItem.getDescription(), "My description"); - assertEquals(entityItem.getIconUrl(), "/v1/catalog/icon/" + symbolicName + "/" + entityItem.getVersion()); - assertEquals(item.getIconUrl(), "classpath:/brooklyn/osgi/tests/icon.gif"); - - byte[] iconData = client().resource("/v1/catalog/icon/"+symbolicName + "/" + TEST_VERSION).get(byte[].class); - assertEquals(iconData.length, 43); - } - - @Test - public void testRegisterOSGiPolicy() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String symbolicName = "my.catalog.policy.id"; - String policyType = "brooklyn.osgi.tests.SimplePolicy"; - String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; - - String yaml = - "brooklyn.catalog:\n"+ - " id: " + symbolicName + "\n"+ - " name: My Catalog App\n"+ - " description: My description\n"+ - " version: " + TEST_VERSION + "\n" + - " libraries:\n"+ - " - url: " + bundleUrl + "\n"+ - "\n"+ - "brooklyn.policies:\n"+ - "- type: " + policyType; - - CatalogPolicySummary entityItem = client().resource("/v1/catalog") - .post(CatalogPolicySummary.class, yaml); - - Assert.assertNotNull(entityItem.getPlanYaml()); - Assert.assertTrue(entityItem.getPlanYaml().contains(policyType)); - assertEquals(entityItem.getId(), ver(symbolicName)); - assertEquals(entityItem.getSymbolicName(), symbolicName); - assertEquals(entityItem.getVersion(), TEST_VERSION); - } - - @Test - public void testListAllEntities() { - List entities = client().resource("/v1/catalog/entities") - .get(new GenericType>() { - }); - assertTrue(entities.size() > 0); - } - - @Test - public void testFilterListOfEntitiesByName() { - List entities = client().resource("/v1/catalog/entities") - .queryParam("fragment", "reDISclusTER").get(new GenericType>() {}); - assertEquals(entities.size(), 1); - - log.info("RedisCluster-like entities are: "+entities); - - List entities2 = client().resource("/v1/catalog/entities") - .queryParam("regex", "[Rr]ed.[sulC]+ter").get(new GenericType>() {}); - assertEquals(entities2.size(), 1); - - assertEquals(entities, entities2); - - List entities3 = client().resource("/v1/catalog/entities") - .queryParam("fragment", "bweqQzZ").get(new GenericType>() {}); - assertEquals(entities3.size(), 0); - - List entities4 = client().resource("/v1/catalog/entities") - .queryParam("regex", "bweq+z+").get(new GenericType>() {}); - assertEquals(entities4.size(), 0); - } - - @Test - @Deprecated - //If we move to using a yaml catalog item, the details will be of the wrapping app, - //not of the entity itself, so the test won't make sense any more. - public void testGetCatalogEntityDetails() { - CatalogEntitySummary details = client().resource( - URI.create("/v1/catalog/entities/brooklyn.entity.nosql.redis.RedisStore")) - .get(CatalogEntitySummary.class); - assertTrue(details.toString().contains("redis.port"), "expected more config, only got: "+details); - String iconUrl = "/v1/catalog/icon/" + details.getSymbolicName(); - assertTrue(details.getIconUrl().contains(iconUrl), "expected brooklyn URL for icon image, but got: "+details.getIconUrl()); - } - - @Test - @Deprecated - //If we move to using a yaml catalog item, the details will be of the wrapping app, - //not of the entity itself, so the test won't make sense any more. - public void testGetCatalogEntityPlusVersionDetails() { - CatalogEntitySummary details = client().resource( - URI.create("/v1/catalog/entities/brooklyn.entity.nosql.redis.RedisStore:0.0.0.SNAPSHOT")) - .get(CatalogEntitySummary.class); - assertTrue(details.toString().contains("redis.port"), "expected more config, only got: "+details); - String expectedIconUrl = "/v1/catalog/icon/" + details.getSymbolicName() + "/" + details.getVersion(); - assertEquals(details.getIconUrl(), expectedIconUrl, "expected brooklyn URL for icon image ("+expectedIconUrl+"), but got: "+details.getIconUrl()); - } - - @Test - public void testGetCatalogEntityIconDetails() throws IOException { - String catalogItemId = "testGetCatalogEntityIconDetails"; - addTestCatalogItem(catalogItemId); - ClientResponse response = client().resource(URI.create("/v1/catalog/icon/" + catalogItemId + "/" + TEST_VERSION)) - .get(ClientResponse.class); - response.bufferEntity(); - Assert.assertEquals(response.getStatus(), 200); - Assert.assertEquals(response.getType(), MediaType.valueOf("image/png")); - Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.getEntityInputStream())); - Assert.assertNotNull(image); - } - - private void addTestCatalogItem(String catalogItemId) { - 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"+ - "\n"+ - "services:\n"+ - "- type: brooklyn.entity.nosql.redis.RedisStore\n"; - - client().resource("/v1/catalog").post(yaml); - } - - @Test - public void testListPolicies() { - Set policies = client().resource("/v1/catalog/policies") - .get(new GenericType>() { - }); - - assertTrue(policies.size() > 0); - CatalogItemSummary asp = null; - for (CatalogItemSummary p: policies) { - if (AutoScalerPolicy.class.getName().equals(p.getType())) - asp = p; + @Test + /** based on CampYamlLiteTest */ + public void testRegisterCustomEntityWithBundleWhereEntityIsFromCoreAndIconFromBundle() { + TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); + + String symbolicName = "my.catalog.entity.id"; + String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; + String yaml = + "brooklyn.catalog:\n"+ + " id: " + symbolicName + "\n"+ + " name: My Catalog App\n"+ + " description: My description\n"+ + " icon_url: classpath:/brooklyn/osgi/tests/icon.gif\n"+ + " version: " + TEST_VERSION + "\n"+ + " libraries:\n"+ + " - url: " + bundleUrl + "\n"+ + "\n"+ + "services:\n"+ + "- type: brooklyn.test.entity.TestEntity\n"; + + ClientResponse response = client().resource("/v1/catalog") + .post(ClientResponse.class, yaml); + + assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + + CatalogEntitySummary entityItem = client().resource("/v1/catalog/entities/"+symbolicName + "/" + TEST_VERSION) + .get(CatalogEntitySummary.class); + + Assert.assertNotNull(entityItem.getPlanYaml()); + Assert.assertTrue(entityItem.getPlanYaml().contains("brooklyn.test.entity.TestEntity")); + + assertEquals(entityItem.getId(), ver(symbolicName)); + assertEquals(entityItem.getSymbolicName(), symbolicName); + assertEquals(entityItem.getVersion(), TEST_VERSION); + + // and internally let's check we have libraries + CatalogItem item = getManagementContext().getCatalog().getCatalogItem(symbolicName, TEST_VERSION); + Assert.assertNotNull(item); + Collection libs = item.getLibraries(); + assertEquals(libs.size(), 1); + assertEquals(Iterables.getOnlyElement(libs).getUrl(), bundleUrl); + + // now let's check other things on the item + assertEquals(entityItem.getName(), "My Catalog App"); + assertEquals(entityItem.getDescription(), "My description"); + assertEquals(entityItem.getIconUrl(), "/v1/catalog/icon/" + symbolicName + "/" + entityItem.getVersion()); + assertEquals(item.getIconUrl(), "classpath:/brooklyn/osgi/tests/icon.gif"); + + byte[] iconData = client().resource("/v1/catalog/icon/" + symbolicName + "/" + TEST_VERSION).get(byte[].class); + assertEquals(iconData.length, 43); + } + + @Test + public void testRegisterOSGiPolicy() { + TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); + + String symbolicName = "my.catalog.policy.id"; + String policyType = "brooklyn.osgi.tests.SimplePolicy"; + String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; + + String yaml = + "brooklyn.catalog:\n"+ + " id: " + symbolicName + "\n"+ + " name: My Catalog App\n"+ + " description: My description\n"+ + " version: " + TEST_VERSION + "\n" + + " libraries:\n"+ + " - url: " + bundleUrl + "\n"+ + "\n"+ + "brooklyn.policies:\n"+ + "- type: " + policyType; + + CatalogPolicySummary entityItem = client().resource("/v1/catalog") + .post(CatalogPolicySummary.class, yaml); + + Assert.assertNotNull(entityItem.getPlanYaml()); + Assert.assertTrue(entityItem.getPlanYaml().contains(policyType)); + assertEquals(entityItem.getId(), ver(symbolicName)); + assertEquals(entityItem.getSymbolicName(), symbolicName); + assertEquals(entityItem.getVersion(), TEST_VERSION); + } + + @Test + public void testListAllEntities() { + List entities = client().resource("/v1/catalog/entities") + .get(new GenericType>() {}); + assertTrue(entities.size() > 0); } - Assert.assertNotNull(asp, "didn't find AutoScalerPolicy"); - } - - @Test - public void testDeleteCustomEntityFromCatalog() { - String symbolicName = "my.catalog.app.id.to.subsequently.delete"; - String yaml = - "name: "+symbolicName+"\n"+ - // FIXME name above should be unnecessary when brooklyn.catalog below is working - "brooklyn.catalog:\n"+ - " id: " + symbolicName + "\n"+ - " name: My Catalog App To Be Deleted\n"+ - " description: My description\n"+ - " version: " + TEST_VERSION + "\n"+ - "\n"+ - "services:\n"+ - "- type: brooklyn.test.entity.TestEntity\n"; - - client().resource("/v1/catalog") - .post(ClientResponse.class, yaml); + + @Test + public void testFilterListOfEntitiesByName() { + List entities = client().resource("/v1/catalog/entities") + .queryParam("fragment", "reDISclusTER").get(new GenericType>() {}); + assertEquals(entities.size(), 1); + + log.info("RedisCluster-like entities are: " + entities); + + List entities2 = client().resource("/v1/catalog/entities") + .queryParam("regex", "[Rr]ed.[sulC]+ter").get(new GenericType>() {}); + assertEquals(entities2.size(), 1); + + assertEquals(entities, entities2); - ClientResponse deleteResponse = client().resource("/v1/catalog/entities/"+symbolicName+"/"+TEST_VERSION) - .delete(ClientResponse.class); - - assertEquals(deleteResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); - - ClientResponse getPostDeleteResponse = client().resource("/v1/catalog/entities/"+symbolicName+"/"+TEST_VERSION) - .get(ClientResponse.class); - assertEquals(getPostDeleteResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); - } - - private static String ver(String id) { - return CatalogUtils.getVersionedId(id, TEST_VERSION); - } + List entities3 = client().resource("/v1/catalog/entities") + .queryParam("fragment", "bweqQzZ").get(new GenericType>() {}); + assertEquals(entities3.size(), 0); + + List entities4 = client().resource("/v1/catalog/entities") + .queryParam("regex", "bweq+z+").get(new GenericType>() {}); + assertEquals(entities4.size(), 0); + } + + @Test + @Deprecated + // If we move to using a yaml catalog item, the details will be of the wrapping app, + // not of the entity itself, so the test won't make sense any more. + public void testGetCatalogEntityDetails() { + CatalogEntitySummary details = client() + .resource(URI.create("/v1/catalog/entities/brooklyn.entity.nosql.redis.RedisStore")) + .get(CatalogEntitySummary.class); + assertTrue(details.toString().contains("redis.port"), "expected more config, only got: "+details); + String iconUrl = "/v1/catalog/icon/" + details.getSymbolicName(); + assertTrue(details.getIconUrl().contains(iconUrl), "expected brooklyn URL for icon image, but got: " + details.getIconUrl()); + } + + @Test + @Deprecated + // If we move to using a yaml catalog item, the details will be of the wrapping app, + // not of the entity itself, so the test won't make sense any more. + public void testGetCatalogEntityPlusVersionDetails() { + CatalogEntitySummary details = client() + .resource(URI.create("/v1/catalog/entities/brooklyn.entity.nosql.redis.RedisStore:0.0.0.SNAPSHOT")) + .get(CatalogEntitySummary.class); + assertTrue(details.toString().contains("redis.port"), "expected more config, only got: "+details); + String expectedIconUrl = "/v1/catalog/icon/" + details.getSymbolicName() + "/" + details.getVersion(); + assertEquals(details.getIconUrl(), expectedIconUrl, "expected brooklyn URL for icon image ("+expectedIconUrl+"), but got: "+details.getIconUrl()); + } + + @Test + public void testGetCatalogEntityIconDetails() throws IOException { + String catalogItemId = "testGetCatalogEntityIconDetails"; + addTestCatalogItem(catalogItemId); + ClientResponse response = client().resource(URI.create("/v1/catalog/icon/" + catalogItemId + "/" + TEST_VERSION)) + .get(ClientResponse.class); + response.bufferEntity(); + Assert.assertEquals(response.getStatus(), 200); + Assert.assertEquals(response.getType(), MediaType.valueOf("image/png")); + Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.getEntityInputStream())); + Assert.assertNotNull(image); + } + + private void addTestCatalogItem(String catalogItemId) { + 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"+ + "\n"+ + "services:\n"+ + "- type: brooklyn.entity.nosql.redis.RedisStore\n"; + + client().resource("/v1/catalog").post(yaml); + } + + @Test + public void testListPolicies() { + Set policies = client().resource("/v1/catalog/policies") + .get(new GenericType>() {}); + + assertTrue(policies.size() > 0); + CatalogItemSummary asp = null; + for (CatalogItemSummary p : policies) { + if (AutoScalerPolicy.class.getName().equals(p.getType())) + asp = p; + } + Assert.assertNotNull(asp, "didn't find AutoScalerPolicy"); + } + + @Test + public void testDeleteCustomEntityFromCatalog() { + String symbolicName = "my.catalog.app.id.to.subsequently.delete"; + String yaml = + "name: "+symbolicName+"\n"+ + // FIXME name above should be unnecessary when brooklyn.catalog below is working + "brooklyn.catalog:\n"+ + " id: " + symbolicName + "\n"+ + " name: My Catalog App To Be Deleted\n"+ + " description: My description\n"+ + " version: " + TEST_VERSION + "\n"+ + "\n"+ + "services:\n"+ + "- type: brooklyn.test.entity.TestEntity\n"; + + client().resource("/v1/catalog") + .post(ClientResponse.class, yaml); + + ClientResponse deleteResponse = client().resource("/v1/catalog/entities/"+symbolicName+"/"+TEST_VERSION) + .delete(ClientResponse.class); + + assertEquals(deleteResponse.getStatus(), Response.Status.NO_CONTENT.getStatusCode()); + + ClientResponse getPostDeleteResponse = client().resource("/v1/catalog/entities/"+symbolicName+"/"+TEST_VERSION) + .get(ClientResponse.class); + assertEquals(getPostDeleteResponse.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); + } + + private static String ver(String id) { + return CatalogUtils.getVersionedId(id, TEST_VERSION); + } } diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/LocationResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/LocationResourceTest.java index a3573fa046..0511ca47e3 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/resources/LocationResourceTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/LocationResourceTest.java @@ -53,63 +53,62 @@ public class LocationResourceTest extends BrooklynRestResourceTest { private static final Logger log = LoggerFactory.getLogger(LocationResourceTest.class); private URI addedLocationUri; - @Test - public void testAddNewLocation() { - Map expectedConfig = ImmutableMap.of( - "identity", "bob", - "credential", "CR3dential", - "location", "us-east-1"); - ClientResponse response = client().resource("/v1/locations") - .type(MediaType.APPLICATION_JSON_TYPE) - .post(ClientResponse.class, new LocationSpec("my-jungle", "aws-ec2", expectedConfig)); + @Test + public void testAddNewLocation() { + Map expectedConfig = ImmutableMap.of( + "identity", "bob", + "credential", "CR3dential", + "location", "us-east-1"); + ClientResponse response = client().resource("/v1/locations") + .type(MediaType.APPLICATION_JSON_TYPE) + .post(ClientResponse.class, new LocationSpec("my-jungle", "aws-ec2", expectedConfig)); - addedLocationUri = response.getLocation(); - log.info("added, at: "+addedLocationUri); - LocationSummary location = client().resource(response.getLocation()).get(LocationSummary.class); - log.info(" contents: "+location); - assertThat(location.getSpec(), is("aws-ec2")); + addedLocationUri = response.getLocation(); + log.info("added, at: " + addedLocationUri); + LocationSummary location = client().resource(response.getLocation()).get(LocationSummary.class); + log.info(" contents: " + location); + assertThat(location.getSpec(), is("aws-ec2")); - assertThat(location.getConfig().get("identity"), is((Object)"bob")); - assertFalse(location.getConfig().containsKey("CR3dential")); - Assert.assertTrue(addedLocationUri.toString().startsWith("/v1/locations/")); - - JcloudsLocation l = (JcloudsLocation) getManagementContext().getLocationRegistry().resolve(location.getId()); - Assert.assertEquals(l.getProvider(), "aws-ec2"); - } + assertThat(location.getConfig().get("identity"), is((Object) "bob")); + assertFalse(location.getConfig().containsKey("CR3dential")); + Assert.assertTrue(addedLocationUri.toString().startsWith("/v1/locations/")); + + JcloudsLocation l = (JcloudsLocation) getManagementContext().getLocationRegistry().resolve(location.getId()); + Assert.assertEquals(l.getProvider(), "aws-ec2"); + } - @Test(dependsOnMethods={"testAddNewLocation"}) - public void testListAllLocations() { - Set locations = client().resource("/v1/locations") - .get(new GenericType>() { + @Test(dependsOnMethods = { "testAddNewLocation" }) + public void testListAllLocations() { + Set locations = client().resource("/v1/locations") + .get(new GenericType>() {}); + Iterable matching = Iterables.filter(locations, new Predicate() { + @Override + public boolean apply(@Nullable LocationSummary l) { + return "my-jungle".equals(l.getName()); + } }); - Iterable matching = Iterables.filter(locations, new Predicate() { - @Override - public boolean apply(@Nullable LocationSummary l) { - return "my-jungle".equals(l.getName()); - } - }); - LocationSummary location = Iterables.getOnlyElement(matching); - assertThat(location.getSpec(), is("aws-ec2")); - Assert.assertEquals(location.getLinks().get("self"), addedLocationUri); - } + LocationSummary location = Iterables.getOnlyElement(matching); + assertThat(location.getSpec(), is("aws-ec2")); + Assert.assertEquals(location.getLinks().get("self"), addedLocationUri); + } - @Test(dependsOnMethods={"testListAllLocations"}) - public void testGetASpecificLocation() { - LocationSummary location = client().resource(addedLocationUri.toString()).get(LocationSummary.class); - assertThat(location.getSpec(), is("aws-ec2")); - } + @Test(dependsOnMethods = { "testListAllLocations" }) + public void testGetASpecificLocation() { + LocationSummary location = client().resource(addedLocationUri.toString()).get(LocationSummary.class); + assertThat(location.getSpec(), is("aws-ec2")); + } - @Test(dependsOnMethods = {"testGetASpecificLocation"}) - public void testDeleteLocation() { - final int size = getLocationRegistry().getDefinedLocations().size(); + @Test(dependsOnMethods = { "testGetASpecificLocation" }) + public void testDeleteLocation() { + final int size = getLocationRegistry().getDefinedLocations().size(); - ClientResponse response = client().resource(addedLocationUri).delete(ClientResponse.class); - assertThat(response.getStatus(), is(Response.Status.NO_CONTENT.getStatusCode())); - Asserts.succeedsEventually(new Runnable() { - @Override - public void run() { - assertThat(getLocationRegistry().getDefinedLocations().size(), is(size - 1)); - } - }); - } + ClientResponse response = client().resource(addedLocationUri).delete(ClientResponse.class); + assertThat(response.getStatus(), is(Response.Status.NO_CONTENT.getStatusCode())); + Asserts.succeedsEventually(new Runnable() { + @Override + public void run() { + assertThat(getLocationRegistry().getDefinedLocations().size(), is(size - 1)); + } + }); + } } diff --git a/usage/rest-server/src/test/java/brooklyn/rest/resources/VersionResourceTest.java b/usage/rest-server/src/test/java/brooklyn/rest/resources/VersionResourceTest.java index ce9aece343..fb8ac95a50 100644 --- a/usage/rest-server/src/test/java/brooklyn/rest/resources/VersionResourceTest.java +++ b/usage/rest-server/src/test/java/brooklyn/rest/resources/VersionResourceTest.java @@ -31,21 +31,20 @@ public class VersionResourceTest extends BrooklynRestResourceTest { - @Test - public void testGetVersion() { - ClientResponse response = client().resource("/v1/version") - .get(ClientResponse.class); - - assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); - String version = response.getEntity(String.class); - - assertTrue(version.matches("^\\d+\\.\\d+\\.\\d+.*")); - } - - @SuppressWarnings("deprecation") - @Override - protected void addBrooklynResources() { - addResource(new VersionResource()); - } - + @Test + public void testGetVersion() { + ClientResponse response = client().resource("/v1/version") + .get(ClientResponse.class); + + assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); + String version = response.getEntity(String.class); + + assertTrue(version.matches("^\\d+\\.\\d+\\.\\d+.*")); + } + + @SuppressWarnings("deprecation") + @Override + protected void addBrooklynResources() { + addResource(new VersionResource()); + } }