You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/01/07 02:30:21 UTC

git commit: AMBARI-4232. Config Group API request has empty response body. (swagle)

Updated Branches:
  refs/heads/trunk 2e9a93fae -> 9457a5715


AMBARI-4232. Config Group API request has empty response body. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9457a571
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9457a571
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9457a571

Branch: refs/heads/trunk
Commit: 9457a5715b5dae980529863358aa12cdbc5a2114
Parents: 2e9a93f
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Mon Jan 6 17:30:15 2014 -0800
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Mon Jan 6 17:30:15 2014 -0800

----------------------------------------------------------------------
 .../server/ConfigGroupNotFoundException.java    | 27 ++++++++++++++++++++
 .../internal/ConfigGroupResourceProvider.java   |  4 +++
 .../ConfigGroupResourceProviderTest.java        | 20 +++++++++++++++
 3 files changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9457a571/ambari-server/src/main/java/org/apache/ambari/server/ConfigGroupNotFoundException.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/ConfigGroupNotFoundException.java b/ambari-server/src/main/java/org/apache/ambari/server/ConfigGroupNotFoundException.java
new file mode 100644
index 0000000..a397c96
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/ConfigGroupNotFoundException.java
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server;
+
+public class ConfigGroupNotFoundException extends ObjectNotFoundException {
+
+  public ConfigGroupNotFoundException(String clusterName, String identifier) {
+    super("Config group not found"
+          + ", clusterName = " + clusterName
+          + ", id = " + identifier);
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/9457a571/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
index af368cf..e817473 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProvider.java
@@ -19,6 +19,7 @@ package org.apache.ambari.server.controller.internal;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ClusterNotFoundException;
+import org.apache.ambari.server.ConfigGroupNotFoundException;
 import org.apache.ambari.server.DuplicateResourceException;
 import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.ParentObjectNotFoundException;
@@ -245,6 +246,9 @@ public class ConfigGroupResourceProvider extends
           ConfigGroup configGroup = configGroupMap.get(request.getId());
           if (configGroup != null) {
             responses.add(configGroup.convertToResponse());
+          } else {
+            throw new ConfigGroupNotFoundException(cluster.getClusterName(),
+              request.getId().toString());
           }
           continue;
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/9457a571/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
index 61ecd91..49ce135 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java
@@ -17,9 +17,13 @@
  */
 package org.apache.ambari.server.controller.internal;
 
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.ConfigGroupNotFoundException;
+import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ConfigGroupResponse;
 import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.Resource;
@@ -53,6 +57,7 @@ import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
+import static org.hamcrest.CoreMatchers.instanceOf;
 
 public class ConfigGroupResourceProviderTest {
 
@@ -331,6 +336,7 @@ public class ConfigGroupResourceProviderTest {
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
     expect(cluster.getConfigGroups()).andReturn(configGroupMap).anyTimes();
+    expect(cluster.getClusterName()).andReturn("Cluster100").anyTimes();
 
     expect(configGroup1.getName()).andReturn("g1").anyTimes();
     expect(configGroup2.getName()).andReturn("g2").anyTimes();
@@ -457,6 +463,20 @@ public class ConfigGroupResourceProviderTest {
     assertEquals("h1", hostSet.iterator().next().get
       (ConfigGroupResourceProvider.CONFIGGROUP_HOSTNAME_PROPERTY_ID));
 
+    // Read by id
+    predicate = new PredicateBuilder().property(ConfigGroupResourceProvider
+      .CONFIGGROUP_ID_PROPERTY_ID).equals(11L).and().property
+      (ConfigGroupResourceProvider.CONFIGGROUP_CLUSTER_NAME_PROPERTY_ID)
+      .equals("Cluster100").toPredicate();
+
+    NoSuchResourceException resourceException = null;
+    try {
+      resourceProvider.getResources(request, predicate);
+    } catch (NoSuchResourceException ce) {
+      resourceException = ce;
+    }
+    Assert.assertNotNull(resourceException);
+
     verify(managementController, clusters, cluster, configGroup1,
       configGroup2, configGroup3, configGroup4, response1, response2,
       response3, response4);