incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject git commit: AMBARI-3129. Ambari server should log type and tag of the configuration on receiving a request to apply a configuration. (Maksim via mahadev)
Date Mon, 09 Sep 2013 17:29:04 GMT
Updated Branches:
  refs/heads/trunk 13a488d6f -> ff7239392


AMBARI-3129. Ambari server should log type and tag of the configuration on receiving a request
to apply a configuration. (Maksim via mahadev)


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

Branch: refs/heads/trunk
Commit: ff72393920d6e42ad625b297f57a0b7fb26dacbc
Parents: 13a488d
Author: Mahadev Konar <mahadev@apache.org>
Authored: Mon Sep 9 10:28:50 2013 -0700
Committer: Mahadev Konar <mahadev@apache.org>
Committed: Mon Sep 9 10:28:50 2013 -0700

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         | 15 ++++-
 .../AmbariManagementControllerImplTest.java     | 69 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ff723939/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 0c3eda4..d644537 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -20,6 +20,7 @@ package org.apache.ambari.server.controller;
 
 import java.io.File;
 import java.net.InetAddress;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -903,8 +904,9 @@ public class AmbariManagementControllerImpl implements
 
     Config config = configs.get(request.getVersionTag());
     if (configs.containsKey(request.getVersionTag())) {
-      throw new AmbariException("Configuration with that tag exists for '"
-          + request.getType() + "'");
+      throw new AmbariException(MessageFormat.format("Configuration with tag ''{0}'' exists
for ''{1}''",
+          request.getVersionTag(),
+          request.getType()));
     }
 
     config = configFactory.createNew (cluster, request.getType(),
@@ -1498,6 +1500,10 @@ public class AmbariManagementControllerImpl implements
       ConfigurationRequest cr = request.getDesiredConfig();
 
       if (null != cr.getProperties() && cr.getProperties().size() > 0) {
+        LOG.info(MessageFormat.format("Applying configuration with tag ''{0}'' to cluster
''{1}''",
+            cr.getVersionTag(),
+            request.getClusterName()));
+
         cr.setClusterName(cluster.getClusterName());
         createConfiguration(cr);
       }
@@ -3052,6 +3058,11 @@ public class AmbariManagementControllerImpl implements
           ConfigurationRequest cr = request.getDesiredConfig();
 
           if (null != cr.getProperties() && cr.getProperties().size() > 0) {
+            LOG.info(MessageFormat.format("Applying configuration with tag ''{0}'' to host
''{1}'' in cluster ''{2}''",
+                cr.getVersionTag(),
+                request.getHostname(),
+                request.getClusterName()));
+
             cr.setClusterName(c.getClusterName());
             createConfiguration(cr);
           }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/ff723939/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index e560058..943fc65 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -35,6 +35,7 @@ import static org.junit.Assert.fail;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
+import java.text.MessageFormat;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -2169,4 +2170,72 @@ public class AmbariManagementControllerImplTest {
     
   }
 
+  @Test
+  public void testApplyConfigurationWithTheSameTag() {
+    Injector injector = Guice.createInjector(new AbstractModule() {
+      @Override
+      protected void configure() {
+        Properties properties = new Properties();
+        properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, "in-memory");
+        properties.setProperty(Configuration.METADETA_DIR_PATH,
+            "src/main/resources/stacks");
+        properties.setProperty(Configuration.SERVER_VERSION_FILE,
+            "target/version");
+        properties.setProperty(Configuration.OS_VERSION_KEY,
+            "centos6");
+        try {
+          install(new ControllerModule(properties));
+        } catch (Exception e) {
+          throw new RuntimeException(e);
+        }
+      }
+    });
+    injector.getInstance(GuiceJpaInitializer.class);
+
+    String tag = "version1";
+    String type = "core-site";
+    AmbariException exception = null;
+    try {
+      AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
+      Clusters clusters = injector.getInstance(Clusters.class);
+      Gson gson = new Gson();
+
+      clusters.addHost("host1");
+      clusters.addHost("host2");
+      clusters.addHost("host3");
+      Host host = clusters.getHost("host1");
+      host.setOsType("centos6");
+      host.persist();
+      host = clusters.getHost("host2");
+      host.setOsType("centos6");
+      host.persist();
+      host = clusters.getHost("host3");
+      host.setOsType("centos6");
+      host.persist();
+
+      ClusterRequest clusterRequest = new ClusterRequest(null, "c1", "HDP-1.2.0", null);
+      amc.createCluster(clusterRequest);
+
+      Set<ServiceRequest> serviceRequests = new HashSet<ServiceRequest>();
+      serviceRequests.add(new ServiceRequest("c1", "HDFS", null, null));
+
+      amc.createServices(serviceRequests);
+
+      Type confType = new TypeToken<Map<String, String>>() {
+      }.getType();
+
+      ConfigurationRequest configurationRequest = new ConfigurationRequest("c1", type, tag,
+          gson.<Map<String, String>>fromJson("{ \"fs.default.name\" : \"localhost:8020\"}",
confType));
+      amc.createConfiguration(configurationRequest);
+
+      amc.createConfiguration(configurationRequest);
+    } catch (AmbariException e) {
+      exception = e;
+    }
+
+    assertNotNull(exception);
+    String exceptionMessage = MessageFormat.format("Configuration with tag ''{0}'' exists
for ''{1}''",
+        tag, type);
+    assertEquals(exceptionMessage, exception.getMessage());
+  }
 }


Mime
View raw message