Przeglądaj źródła

AMBARI-833. Add missing Path annotation to rest services for put/post/delete. (John Speidel via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1396478 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar 12 lat temu
rodzic
commit
fd8cd68cea

+ 3 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,9 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-833. Add missing Path annotation to rest services for
+  put/post/delete. (John Speidel via mahadev)
+
   AMBARI-838. HACK: Add a thread in server to inject requests for testing.
   (Jitendra via mahadev)
 

+ 7 - 4
ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterService.java

@@ -72,10 +72,11 @@ public class ClusterService extends BaseService {
    * @param clusterName cluster id
    * @return information regarding the created cluster
    */
-  @PUT
-  @Produces("text/plain")
-  public Response createCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui,
-                                @PathParam("clusterName") String clusterName) {
+   @PUT
+   @Path("{clusterName}")
+   @Produces("text/plain")
+   public Response createCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui,
+                                 @PathParam("clusterName") String clusterName) {
 
     return handleRequest(headers, body, ui, Request.Type.PUT, createResourceDefinition(clusterName));
   }
@@ -90,6 +91,7 @@ public class ClusterService extends BaseService {
    * @return information regarding the updated cluster
    */
   @POST
+  @Path("{clusterName}")
   @Produces("text/plain")
   public Response updateCluster(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("clusterName") String clusterName) {
@@ -107,6 +109,7 @@ public class ClusterService extends BaseService {
    * @return information regarding the deleted cluster
    */
   @DELETE
+  @Path("{clusterName}")
   @Produces("text/plain")
   public Response deleteCluster(@Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("clusterName") String clusterName) {

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/api/services/ComponentService.java

@@ -95,6 +95,7 @@ public class ComponentService extends BaseService {
    * @return information regarding the created component
    */
   @PUT
+  @Path("{componentName}")
   @Produces("text/plain")
   public Response createComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("componentName") String componentName) {
@@ -115,6 +116,7 @@ public class ComponentService extends BaseService {
    * @return information regarding the updated component
    */
   @POST
+  @Path("{componentName}")
   @Produces("text/plain")
   public Response updateComponent(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("componentName") String componentName) {
@@ -133,6 +135,7 @@ public class ComponentService extends BaseService {
    * @return information regarding the deleted cluster
    */
   @DELETE
+  @Path("{componentName}")
   @Produces("text/plain")
   public Response deleteComponent(@Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("componentName") String componentName) {

+ 1 - 2
ambari-server/src/main/java/org/apache/ambari/server/api/services/RequestImpl.java

@@ -127,8 +127,7 @@ public class RequestImpl implements Request {
 
   @Override
   public Map<PropertyId, String> getHttpBodyProperties() {
-    return m_body == null ? Collections.<PropertyId, String>emptyMap() :
-        getHttpBodyParser().parse(getHttpBody());
+    return getHttpBodyParser().parse(getHttpBody());
   }
 
   @Override

+ 3 - 0
ambari-server/src/main/java/org/apache/ambari/server/api/services/ServiceService.java

@@ -87,6 +87,7 @@ public class ServiceService extends BaseService {
    * @return information regarding the created service
    */
   @PUT
+  @Path("{serviceName}")
   @Produces("text/plain")
   public Response createService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("serviceName") String serviceName) {
@@ -105,6 +106,7 @@ public class ServiceService extends BaseService {
    * @return information regarding the updated service
    */
   @POST
+  @Path("{serviceName}")
   @Produces("text/plain")
   public Response updateService(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("serviceName") String serviceName) {
@@ -122,6 +124,7 @@ public class ServiceService extends BaseService {
    * @return information regarding the deleted service
    */
   @DELETE
+  @Path("{serviceName}")
   @Produces("text/plain")
   public Response deleteService(@Context HttpHeaders headers, @Context UriInfo ui,
                                 @PathParam("serviceName") String serviceName) {

+ 6 - 4
ambari-server/src/main/java/org/apache/ambari/server/api/services/parsers/JsonPropertyParser.java

@@ -39,10 +39,12 @@ public class JsonPropertyParser implements RequestBodyParser {
   public Map<PropertyId, String> parse(String s) {
     ObjectMapper mapper = new ObjectMapper();
 
-    try {
-      processNode(mapper.readValue(s, JsonNode.class), "");
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to parse json: " + e, e);
+    if (s != null && ! s.isEmpty()) {
+      try {
+        processNode(mapper.readValue(s, JsonNode.class), "");
+      } catch (IOException e) {
+        throw new RuntimeException("Unable to parse json: " + e, e);
+      }
     }
 
     return m_properties;

+ 17 - 0
ambari-server/src/test/java/org/apache/ambari/server/api/services/parsers/JsonPropertyParserTest.java

@@ -22,6 +22,7 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.controller.spi.PropertyId;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -61,6 +62,22 @@ public class JsonPropertyParserTest {
 
     assertEquals(mapExpected, mapProps);
   }
+
+  @Test
+  public void testParse_NullBody() {
+    RequestBodyParser parser = new JsonPropertyParser();
+    Map<PropertyId, String> mapProps = parser.parse(null);
+    assertNotNull(mapProps);
+    assertEquals(0, mapProps.size());
+  }
+
+  @Test
+  public void testParse_EmptyBody() {
+    RequestBodyParser parser = new JsonPropertyParser();
+    Map<PropertyId, String> mapProps = parser.parse("");
+    assertNotNull(mapProps);
+    assertEquals(0, mapProps.size());
+  }
 }