Jelajahi Sumber

AMBARI-1627. Fix to remove host configuration overrides

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1457120 13f79535-47bb-0310-9956-ffa450edef68
Nate Cole 12 tahun lalu
induk
melakukan
9ea1663172

+ 2 - 0
CHANGES.txt

@@ -512,6 +512,8 @@ Trunk (unreleased changes):
 
 
  AMBARI-1625. Oozie start fails on secure cluster. (swagle)
  AMBARI-1625. Oozie start fails on secure cluster. (swagle)
 
 
+ AMBARI-1627. Fix to remove host configuration overrides. (ncole)
+
  AMBARI-1592. Fix configuration propagation.
  AMBARI-1592. Fix configuration propagation.
 
 
  AMBARI-1619. Fix for category path separators.
  AMBARI-1619. Fix for category path separators.

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -2777,7 +2777,7 @@ public class AmbariManagementControllerImpl implements
 
 
           Config baseConfig = c.getConfig(cr.getType(), cr.getVersionTag());
           Config baseConfig = c.getConfig(cr.getType(), cr.getVersionTag());
           if (null != baseConfig)
           if (null != baseConfig)
-            h.addDesiredConfig(c.getClusterId(), cr.getServiceName(), baseConfig);
+            h.addDesiredConfig(c.getClusterId(), cr.isSelected(), baseConfig);
 
 
         }
         }
       }
       }

+ 9 - 9
ambari-server/src/main/java/org/apache/ambari/server/controller/ConfigurationRequest.java

@@ -31,7 +31,7 @@ public class ConfigurationRequest {
   private String type;
   private String type;
   private String tag;
   private String tag;
   private Map<String, String> configs;
   private Map<String, String> configs;
-  private String serviceName;
+  private boolean selected = true;
 
 
   public ConfigurationRequest() {
   public ConfigurationRequest() {
     configs = new HashMap<String, String>();
     configs = new HashMap<String, String>();
@@ -107,18 +107,18 @@ public class ConfigurationRequest {
   }
   }
 
 
   /**
   /**
-   * Sets the service name (for host-level overrides)
-   * @param name the service name
+   * Sets if the configuration is selected
+   * @param selected <code>true</code> if the configuration is selected.
    */
    */
-  public void setServiceName(String name) {
-    serviceName = name;
+  public void setSelected(boolean selected) {
+    this.selected = selected;
   }
   }
   
   
   /**
   /**
-   * Gets the service name.
-   * @return the service name
+   * Gets if the configuration is to be selected.
+   * @return <code>true</code> if the configuration is selected.
    */
    */
-  public String getServiceName() {
-    return serviceName;
+  public boolean isSelected() {
+    return selected;
   }
   }
 }
 }

+ 3 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractResourceProvider.java

@@ -395,8 +395,9 @@ public abstract class AbstractResourceProvider extends BaseProvider implements R
           config.setType(entry.getValue().toString());
           config.setType(entry.getValue().toString());
         else if (propName.equals("tag"))
         else if (propName.equals("tag"))
           config.setVersionTag(entry.getValue().toString());
           config.setVersionTag(entry.getValue().toString());
-        else if (propName.equals("service_name"))
-          config.setServiceName(entry.getValue().toString());
+        else if (propName.equals("selected")) {
+          config.setSelected(Boolean.parseBoolean(entry.getValue().toString()));
+        }
         else if (absCategory.endsWith("/properties")) {
         else if (absCategory.endsWith("/properties")) {
           config.getProperties().put(propName, entry.getValue().toString());
           config.getProperties().put(propName, entry.getValue().toString());
         }
         }

+ 3 - 3
ambari-server/src/main/java/org/apache/ambari/server/state/Host.java

@@ -275,11 +275,11 @@ public interface Host {
   /**
   /**
    * Adds a desired configuration to the host instance.
    * Adds a desired configuration to the host instance.
    * @param clusterId the cluster id that the config applies to
    * @param clusterId the cluster id that the config applies to
-   * @param serviceName the name of the service that is the parent.  Supply
-   *        <code>null</code> if the override applies to the cluster definition.
+   * @param selected <code>true</code> if the configuration is selected.  Applies
+   *    only to remove the override, otherwise this value should always be <code>true</code>.
    * @param config the configuration object
    * @param config the configuration object
    */
    */
-  public void addDesiredConfig(long clusterId, String serviceName, Config config);
+  public void addDesiredConfig(long clusterId, boolean selected, Config config);
   
   
   /**
   /**
    * Gets all the selected configurations for the host.
    * Gets all the selected configurations for the host.

+ 5 - 2
ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java

@@ -1038,10 +1038,14 @@ public class HostImpl implements Host {
   
   
   @Override
   @Override
   @Transactional
   @Transactional
-  public void addDesiredConfig(long clusterId, String serviceName, Config config) {
+  public void addDesiredConfig(long clusterId, boolean selected, Config config) {
     
     
     HostConfigMappingEntity exist = getDesiredConfigEntity(clusterId, config.getType());
     HostConfigMappingEntity exist = getDesiredConfigEntity(clusterId, config.getType());
     if (null != exist && exist.getVersion().equals(config.getVersionTag())) {
     if (null != exist && exist.getVersion().equals(config.getVersionTag())) {
+      if (!selected) {
+        exist.setSelected(0);
+        hostConfigMappingDAO.merge(exist);
+      }
       return;
       return;
     }
     }
     
     
@@ -1060,7 +1064,6 @@ public class HostImpl implements Host {
       entity.setCreateTimestamp(Long.valueOf(new Date().getTime()));
       entity.setCreateTimestamp(Long.valueOf(new Date().getTime()));
       entity.setHostName(hostEntity.getHostName());
       entity.setHostName(hostEntity.getHostName());
       entity.setSelected(1);
       entity.setSelected(1);
-      entity.setServiceName(serviceName);
       entity.setType(config.getType());
       entity.setType(config.getType());
       entity.setVersion(config.getVersionTag());
       entity.setVersion(config.getVersionTag());
       
       

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java

@@ -355,7 +355,7 @@ public class ClusterTest {
 
 
     // setup a host that also has a config override
     // setup a host that also has a config override
     Host host = clusters.getHost("h1");
     Host host = clusters.getHost("h1");
-    host.addDesiredConfig(c1.getClusterId(), null, config2);
+    host.addDesiredConfig(c1.getClusterId(), true, config2);
 
 
     desiredConfigs = c1.getDesiredConfigs();
     desiredConfigs = c1.getDesiredConfigs();
     dc = desiredConfigs.get(config1.getType());
     dc = desiredConfigs.get(config1.getType());

+ 7 - 3
ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java

@@ -370,7 +370,7 @@ public class HostTest {
         new HashMap<String,String>() {{ put("a", "b"); put("x", "y"); }});
         new HashMap<String,String>() {{ put("a", "b"); put("x", "y"); }});
     
     
     try {
     try {
-      host.addDesiredConfig(c1.getClusterId(), null, config);
+      host.addDesiredConfig(c1.getClusterId(), true, config);
       Assert.fail("Expect failure when version is not specified.");
       Assert.fail("Expect failure when version is not specified.");
     }
     }
     catch (Exception e) {
     catch (Exception e) {
@@ -378,7 +378,7 @@ public class HostTest {
     }
     }
     
     
     config.setVersionTag("v1");
     config.setVersionTag("v1");
-    host.addDesiredConfig(c1.getClusterId(), null, config);
+    host.addDesiredConfig(c1.getClusterId(), true, config);
     
     
     Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId());
     Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId());
     Assert.assertTrue("Expect desired config to contain global", map.containsKey("global"));
     Assert.assertTrue("Expect desired config to contain global", map.containsKey("global"));
@@ -386,12 +386,16 @@ public class HostTest {
     config = configFactory.createNew(c1, "global",
     config = configFactory.createNew(c1, "global",
         new HashMap<String,String>() {{ put("c", "d"); }});
         new HashMap<String,String>() {{ put("c", "d"); }});
     config.setVersionTag("v2");
     config.setVersionTag("v2");
-    host.addDesiredConfig(c1.getClusterId(), null, config);
+    host.addDesiredConfig(c1.getClusterId(), true, config);
     
     
     map = host.getDesiredConfigs(c1.getClusterId());
     map = host.getDesiredConfigs(c1.getClusterId());
     Assert.assertTrue("Expect desired config to contain global", map.containsKey("global"));
     Assert.assertTrue("Expect desired config to contain global", map.containsKey("global"));
     Assert.assertEquals("Expect version to be 'v2'",
     Assert.assertEquals("Expect version to be 'v2'",
         "v2", map.get("global").getVersion());
         "v2", map.get("global").getVersion());
     
     
+    host.addDesiredConfig(c1.getClusterId(), false, config);
+    map = host.getDesiredConfigs(c1.getClusterId());
+    Assert.assertEquals("Expect no mapping configs", 0, map.size());
+    
   }
   }
 }
 }