You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2014/09/02 14:12:33 UTC

[06/16] git commit: BUG-22021 GET /api/v1/clusters/cluster/configurations endpoint is throwing 500 (dsen)

BUG-22021 GET /api/v1/clusters/cluster/configurations endpoint is throwing 500 (dsen)


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

Branch: refs/heads/branch-alerts-dev
Commit: b21759ea422a457e49fc5b0efaf5905deabe4226
Parents: bd60b32
Author: Dmytro Sen <ds...@hortonworks.com>
Authored: Mon Sep 1 14:56:22 2014 +0300
Committer: Dmytro Sen <ds...@hortonworks.com>
Committed: Mon Sep 1 14:56:22 2014 +0300

----------------------------------------------------------------------
 .../apache/ambari/server/state/ConfigImpl.java  |  2 +-
 .../state/configgroup/ConfigGroupImpl.java      |  3 ++-
 .../server/state/cluster/ClusterTest.java       | 22 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b21759ea/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
index 2f844d5..0211b68 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java
@@ -95,7 +95,7 @@ public class ConfigImpl implements Config {
 
   @Override
   public synchronized Long getVersion() {
-    if (this.version == null) {
+    if (this.version == null && cluster != null) {
       this.version = cluster.getNextConfigVersion(type);
     }
     return version;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b21759ea/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
index 96bedf8..9ec0370 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java
@@ -400,13 +400,14 @@ public class ConfigGroupImpl implements ConfigGroup {
           (cluster.getClusterId(), config.getType(), config.getTag());
 
         if (clusterConfigEntity == null) {
+          config.setVersion(cluster.getNextConfigVersion(config.getType()));
           // Create configuration
           clusterConfigEntity = new ClusterConfigEntity();
           clusterConfigEntity.setClusterId(clusterEntity.getClusterId());
           clusterConfigEntity.setClusterEntity(clusterEntity);
           clusterConfigEntity.setType(config.getType());
+          clusterConfigEntity.setVersion(config.getVersion());
           clusterConfigEntity.setTag(config.getTag());
-          clusterConfigEntity.setVersion(cluster.getNextConfigVersion(config.getType()));
           clusterConfigEntity.setData(gson.toJson(config.getProperties()));
           if (null != config.getPropertiesAttributes()) {
             clusterConfigEntity.setAttributes(gson.toJson(config.getPropertiesAttributes()));

http://git-wip-us.apache.org/repos/asf/ambari/blob/b21759ea/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index b2bb602..919fbd5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -64,6 +64,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.ConfigImpl;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostHealthStatus;
@@ -808,6 +809,27 @@ public class ClusterTest {
 
     assertEquals("Configurations should be rolled back to a:c ", "c", configProperties.get("a"));
 
+    //check config with empty cluster
+
+    Config config4 = new ConfigImpl("hdfs-site");
+    config4.setProperties(new HashMap<String, String>() {{
+      put("a", "b");
+    }});
+
+    ConfigGroup configGroup2 =
+        configGroupFactory.createNew(c1, "test group 2", "HDFS", "descr", Collections.singletonMap("hdfs-site", config4),
+            Collections.<String, Host>emptyMap());
+
+    configGroup2.persist();
+    c1.addConfigGroup(configGroup2);
+
+    scvResponse = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup2);
+    assertEquals("SCV 5 should be created", Long.valueOf(5), scvResponse.getVersion());
+
+    activeServiceConfigVersions = c1.getActiveServiceConfigVersions();
+    Assert.assertEquals("Three service config versions should be active, for default and test groups",
+        3, activeServiceConfigVersions.get("HDFS").size());
+    assertEquals("Five total scvs", 5, c1.getServiceConfigVersions().size());
 
   }