brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/4] brooklyn-server git commit: Allow passing "latest" as version for catalog endpoint
Date Fri, 14 Apr 2017 12:11:00 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master c80e38969 -> a069cc533


Allow passing "latest" as version for catalog endpoint


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

Branch: refs/heads/master
Commit: 7ba584cc249fff1dc138a6e2d8cdf7e81c042578
Parents: 1772845
Author: Thomas Bouron <thomas.bouron@cloudsoftcorp.com>
Authored: Thu Apr 13 08:11:52 2017 +0100
Committer: Thomas Bouron <thomas.bouron@cloudsoftcorp.com>
Committed: Thu Apr 13 18:14:19 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/rest/api/CatalogApi.java    | 49 ++++++++++++++++----
 .../rest/resources/CatalogResource.java         | 29 ++++++++++++
 2 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ba584cc/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
----------------------------------------------------------------------
diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
index a95aa9f..dd50bed 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/CatalogApi.java
@@ -153,7 +153,11 @@ public interface CatalogApi {
 
     @DELETE
     @Path("/applications/{symbolicName}/{version}")
-    @ApiOperation(value = "Deletes a specific version of an application's definition from
the catalog")
+    @ApiOperation(
+            value = "Deletes a specific version of an application's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'symbolicName'"
+    )
     @ApiResponses(value = {
         @ApiResponse(code = 404, message = "Entity not found")
     })
@@ -166,7 +170,11 @@ public interface CatalogApi {
 
     @DELETE
     @Path("/entities/{symbolicName}/{version}")
-    @ApiOperation(value = "Deletes a specific version of an entity's definition from the
catalog")
+    @ApiOperation(
+            value = "Deletes a specific version of an entity's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'symbolicName'"
+    )
     @ApiResponses(value = {
         @ApiResponse(code = 404, message = "Entity not found")
     })
@@ -179,7 +187,10 @@ public interface CatalogApi {
 
     @DELETE
     @Path("/policies/{policyId}/{version}")
-    @ApiOperation(value = "Deletes a specific version of an policy's definition from the
catalog")
+    @ApiOperation(
+            value = "Deletes a specific version of an policy's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'policyId'")
     @ApiResponses(value = {
         @ApiResponse(code = 404, message = "Policy not found")
     })
@@ -192,7 +203,11 @@ public interface CatalogApi {
 
     @DELETE
     @Path("/locations/{locationId}/{version}")
-    @ApiOperation(value = "Deletes a specific version of an location's definition from the
catalog")
+    @ApiOperation(
+            value = "Deletes a specific version of an location's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'locationId'"
+    )
     @ApiResponses(value = {
         @ApiResponse(code = 404, message = "Location not found")
     })
@@ -245,7 +260,10 @@ public interface CatalogApi {
 
     @GET
     @Path("/entities/{symbolicName}/{version}")
-    @ApiOperation(value = "Fetch a specific version of an entity's definition from the catalog",

+    @ApiOperation(
+            value = "Fetch a specific version of an entity's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'symbolicName'",
             response = CatalogEntitySummary.class,
             responseContainer = "List")
     @ApiResponses(value = {
@@ -274,7 +292,10 @@ public interface CatalogApi {
 
     @GET
     @Path("/applications/{symbolicName}/{version}")
-    @ApiOperation(value = "Fetch a specific version of an application's definition from the
catalog", 
+    @ApiOperation(
+            value = "Fetch a specific version of an application's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'symbolicName'",
             response = CatalogEntitySummary.class,
             responseContainer = "List")
     @ApiResponses(value = {
@@ -316,7 +337,10 @@ public interface CatalogApi {
 
     @GET
     @Path("/policies/{policyId}/{version}")
-    @ApiOperation(value = "Fetch a policy's definition from the catalog", 
+    @ApiOperation(
+            value = "Fetch a policy's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'policyId'",
             response = CatalogItemSummary.class,
             responseContainer = "List")
     @ApiResponses(value = {
@@ -357,7 +381,10 @@ public interface CatalogApi {
 
     @GET
     @Path("/locations/{locationId}/{version}")
-    @ApiOperation(value = "Fetch a location's definition from the catalog", 
+    @ApiOperation(
+            value = "Fetch a location's definition from the catalog",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'locationId'",
             response = CatalogItemSummary.class,
             responseContainer = "List")
     @ApiResponses(value = {
@@ -384,7 +411,11 @@ public interface CatalogApi {
 
     @GET
     @Path("/icon/{itemId}/{version}")
-    @ApiOperation(value = "Return the icon for a given catalog entry (application/image or
HTTP redirect)")
+    @ApiOperation(
+            value = "Return the icon for a given catalog entry (application/image or HTTP
redirect)",
+            notes = "Version must exists, otherwise the API will return a 404. Alternatively,
passing 'latest' will" +
+                    "pick up the latest version for the given 'itemId'"
+    )
     @ApiResponses(value = {
             @ApiResponse(code = 404, message = "Item not found")
         })

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ba584cc/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
index 1421bd1..713cdb9 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/CatalogResource.java
@@ -102,6 +102,7 @@ import com.google.common.io.Files;
 public class CatalogResource extends AbstractBrooklynRestResource implements CatalogApi {
 
     private static final Logger log = LoggerFactory.getLogger(CatalogResource.class);
+    private static final String LATEST = "latest";
     
     @SuppressWarnings("rawtypes")
     private Function<CatalogItem, CatalogItemSummary> toCatalogItemSummary(final UriInfo
ui) {
@@ -331,6 +332,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to modify catalog",
                 Entitlements.getEntitlementContext().user());
         }
+
+        if (LATEST.equals(version)) {
+            version = null;
+        }
         
         RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, version);
         if (item == null) {
@@ -348,6 +353,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to modify catalog",
                 Entitlements.getEntitlementContext().user());
         }
+
+        if (LATEST.equals(version)) {
+            version = null;
+        }
         
         RegisteredType item = mgmt().getTypeRegistry().get(policyId, version);
         if (item == null) {
@@ -365,6 +374,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to modify catalog",
                 Entitlements.getEntitlementContext().user());
         }
+
+        if (LATEST.equals(version)) {
+            version = null;
+        }
         
         RegisteredType item = mgmt().getTypeRegistry().get(locationId, version);
         if (item == null) {
@@ -422,6 +435,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
                 Entitlements.getEntitlementContext().user());
         }
 
+        if (LATEST.equals(version)) {
+            version = null;
+        }
+
         //TODO These casts are not pretty, we could just provide separate get methods for
the different types?
         //Or we could provide asEntity/asPolicy cast methods on the CataloItem doing a safety
check internally
         @SuppressWarnings("unchecked")
@@ -481,6 +498,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
                 Entitlements.getEntitlementContext().user());
         }
 
+        if (LATEST.equals(version)) {
+            version = null;
+        }
+
         @SuppressWarnings("unchecked")
         CatalogItem<? extends Policy, PolicySpec<?>> result =
                 (CatalogItem<? extends Policy, PolicySpec<?>>)brooklyn().getCatalog().getCatalogItem(policyId,
version);
@@ -527,6 +548,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
                 Entitlements.getEntitlementContext().user());
         }
 
+        if (LATEST.equals(version)) {
+            version = null;
+        }
+
         @SuppressWarnings("unchecked")
         CatalogItem<? extends Location, LocationSpec<?>> result =
                 (CatalogItem<? extends Location, LocationSpec<?>>)brooklyn().getCatalog().getCatalogItem(locationId,
version);
@@ -575,6 +600,10 @@ public class CatalogResource extends AbstractBrooklynRestResource implements
Cat
             throw WebResourceUtils.forbidden("User '%s' is not authorized to see catalog
entry",
                 Entitlements.getEntitlementContext().user());
         }
+
+        if (LATEST.equals(version)) {
+            version = null;
+        }
         
         return getCatalogItemIcon(mgmt().getTypeRegistry().get(itemId, version));
     }


Mime
View raw message