Bläddra i källkod

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

Mahadev Konar 12 år sedan
förälder
incheckning
ff72393920

+ 13 - 2
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);
           }

+ 69 - 0
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());
+  }
 }