ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aonis...@apache.org
Subject ambari git commit: AMBARI-9449. Call to save configs of different services together not rejected (aonishuk)
Date Wed, 04 Feb 2015 16:26:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3e69d3a75 -> b8301188c


AMBARI-9449. Call to save configs of different services together not rejected (aonishuk)


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

Branch: refs/heads/trunk
Commit: b8301188c9982e7c3a6e5bcb5e743bab59a6bfe9
Parents: 3e69d3a
Author: Andrew Onishuk <aonishuk@hortonworks.com>
Authored: Wed Feb 4 18:25:52 2015 +0200
Committer: Andrew Onishuk <aonishuk@hortonworks.com>
Committed: Wed Feb 4 18:25:52 2015 +0200

----------------------------------------------------------------------
 .../org/apache/ambari/server/state/Cluster.java |  4 +--
 .../server/state/cluster/ClusterImpl.java       | 32 ++++++++++++--------
 .../server/state/cluster/ClusterTest.java       |  4 +--
 .../svccomphost/ServiceComponentHostTest.java   |  2 +-
 4 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b8301188/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 6b8a917..514c8e0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -279,7 +279,7 @@ public interface Cluster {
    * @return <code>true</code> if the config was added, or <code>false</code>
    * if the config is already set as the current
    */
-  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs);
+  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs)
throws AmbariException;
 
   /**
    * Adds and sets a DESIRED configuration to be applied to a cluster.  There
@@ -290,7 +290,7 @@ public interface Cluster {
    * @return <code>true</code> if the config was added, or <code>false</code>
    * if the config is already set as the current
    */
-  ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String
serviceConfigVersionNote);
+  ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs, String
serviceConfigVersionNote) throws AmbariException;
 
   ServiceConfigVersionResponse createServiceConfigVersion(String serviceName, String user,
String note,
                                                           ConfigGroup configGroup);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b8301188/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index db17109..4a8c020 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -1753,12 +1753,12 @@ public class ClusterImpl implements Cluster {
   }
 
   @Override
-  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs)
{
+  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs)
throws AmbariException {
     return addDesiredConfig(user, configs, null);
   }
 
   @Override
-  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs,
String serviceConfigVersionNote) {
+  public ServiceConfigVersionResponse addDesiredConfig(String user, Set<Config> configs,
String serviceConfigVersionNote) throws AmbariException {
     if (null == user) {
       throw new NullPointerException("User must be specified.");
     }
@@ -2161,26 +2161,32 @@ public class ClusterImpl implements Cluster {
   }
 
   @Transactional
-  ServiceConfigVersionResponse applyConfigs(Set<Config> configs, String user, String
serviceConfigVersionNote) {
+  ServiceConfigVersionResponse applyConfigs(Set<Config> configs, String user, String
serviceConfigVersionNote) throws AmbariException {
 
     String serviceName = null;
-    for (Config config: configs) {
-
-      selectConfig(config.getType(), config.getTag(), user);
-      //find service name for config type
+    for (Config config : configs) {
       for (Entry<String, String> entry : serviceConfigTypes.entries()) {
         if (StringUtils.equals(entry.getValue(), config.getType())) {
-          if (serviceName != null && !serviceName.equals(entry.getKey())) {
-            LOG.error("Updating configs for multiple services by a " +
-              "single API request isn't supported, config version not created");
-            return null;
+          if (serviceName == null) {
+            serviceName = entry.getKey();
+            break;
+          } else if (!serviceName.equals(entry.getKey())) {
+            String error = "Updating configs for multiple services by a " +
+                "single API request isn't supported";
+            AmbariException exception = new AmbariException(error);
+            LOG.error(error + ", config version not created");
+            throw exception;
+          } else {
+            break;
           }
-          serviceName = entry.getKey();
-          break;
         }
       }
     }
 
+    for (Config config: configs) {
+      selectConfig(config.getType(), config.getTag(), user);
+    }
+
     if (serviceName == null) {
       LOG.error("No service found for config type '{}', service config version not created");
       return null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/b8301188/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 c4dfdb8..bb6a713 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
@@ -388,7 +388,7 @@ public class ClusterTest {
 
 
   @Test
-  public void testGetAndSetConfigs() {
+  public void testGetAndSetConfigs() throws AmbariException {
 
     Map<String, Map<String, String>> c1PropAttributes = new HashMap<String,
Map<String,String>>();
     c1PropAttributes.put("final", new HashMap<String, String>());
@@ -724,7 +724,7 @@ public class ClusterTest {
   }
 
   @Test
-  public void testSingleServiceVersionForMultipleConfigs() {
+  public void testSingleServiceVersionForMultipleConfigs() throws AmbariException {
     Config config1 = configFactory.createNew(c1, "hdfs-site",
       new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>());
     config1.setTag("version1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/b8301188/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index 8ebf2ce..f65bbd9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -1061,7 +1061,7 @@ public class ServiceComponentHostTest {
    * @param tag the config tag
    * @param values the values for the config
    */
-  private void makeConfig(Cluster cluster, String type, String tag, Map<String, String>
values, Map<String, Map<String, String>> attributes) {
+  private void makeConfig(Cluster cluster, String type, String tag, Map<String, String>
values, Map<String, Map<String, String>> attributes) throws AmbariException {
     Config config = configFactory.createNew(cluster, type, values, attributes);
     config.setTag(tag);
     config.persist();


Mime
View raw message