ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject ambari git commit: AMBARI-9006. Variable replacement fails for some (complicated) values in org.apache.ambari.server.state.kerberos.AbstractKerberosDescriptor#replaceVariables (rlevas)
Date Thu, 08 Jan 2015 22:02:54 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 0455aac03 -> 818d1afad


AMBARI-9006. Variable replacement fails for some (complicated) values in org.apache.ambari.server.state.kerberos.AbstractKerberosDescriptor#replaceVariables
(rlevas)


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

Branch: refs/heads/trunk
Commit: 818d1afadbb21920d5d813ad50c10d251424d574
Parents: 0455aac
Author: Robert Levas <rlevas@hortonworks.com>
Authored: Thu Jan 8 17:02:49 2015 -0500
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Thu Jan 8 17:02:49 2015 -0500

----------------------------------------------------------------------
 .../kerberos/AbstractKerberosDescriptor.java    |  2 +-
 .../state/kerberos/KerberosDescriptorTest.java  | 63 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/818d1afa/ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/AbstractKerberosDescriptor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/AbstractKerberosDescriptor.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/AbstractKerberosDescriptor.java
index cd44fe5..41d100b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/AbstractKerberosDescriptor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/AbstractKerberosDescriptor.java
@@ -44,7 +44,7 @@ public abstract class AbstractKerberosDescriptor {
   /**
    * a regular expression Pattern used to find "variable" placeholders in strings
    */
-  private static final Pattern PATTERN_VARIABLE = Pattern.compile("\\$\\{(?:(.+?)/)?(.+?)\\}");
+  private static final Pattern PATTERN_VARIABLE = Pattern.compile("\\$\\{(?:([\\w\\-\\.]+)/)?([\\w\\-\\.]+)\\}");
 
   /**
    * An AbstractKerberosDescriptor serving as the parent (or container) for this

http://git-wip-us.apache.org/repos/asf/ambari/blob/818d1afa/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
index 3b201b6..e4e9776 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java
@@ -292,6 +292,21 @@ public class KerberosDescriptorTest {
       {
         put("", new HashMap<String, String>() {{
           put("global_variable", "Hello World");
+          put("variable-name", "dash");
+          put("variable_name", "underscore");
+          put("variable.name", "dot");
+        }});
+
+        put("config_type", new HashMap<String, String>() {{
+          put("variable-name", "config_type_dash");
+          put("variable_name", "config_type_underscore");
+          put("variable.name", "config_type_dot");
+        }});
+
+        put("config.type", new HashMap<String, String>() {{
+          put("variable-name", "config.type_dash");
+          put("variable_name", "config.type_underscore");
+          put("variable.name", "config.type_dot");
         }});
 
         put("config-type", new HashMap<String, String>() {{
@@ -329,10 +344,38 @@ public class KerberosDescriptorTest {
     Assert.assertEquals("Replacement1_reference",
         KerberosDescriptor.replaceVariables("${config-type/variable.name}_reference", configurations));
 
+    Assert.assertEquals("dash",
+        KerberosDescriptor.replaceVariables("${variable-name}", configurations));
+
+    Assert.assertEquals("underscore",
+        KerberosDescriptor.replaceVariables("${variable_name}", configurations));
+
+    Assert.assertEquals("config_type_dot",
+        KerberosDescriptor.replaceVariables("${config_type/variable.name}", configurations));
+
+    Assert.assertEquals("config_type_dash",
+        KerberosDescriptor.replaceVariables("${config_type/variable-name}", configurations));
+
+    Assert.assertEquals("config_type_underscore",
+        KerberosDescriptor.replaceVariables("${config_type/variable_name}", configurations));
+
+    Assert.assertEquals("config.type_dot",
+        KerberosDescriptor.replaceVariables("${config.type/variable.name}", configurations));
+
+    Assert.assertEquals("config.type_dash",
+        KerberosDescriptor.replaceVariables("${config.type/variable-name}", configurations));
+
+    Assert.assertEquals("config.type_underscore",
+        KerberosDescriptor.replaceVariables("${config.type/variable_name}", configurations));
+
+    Assert.assertEquals("dot",
+        KerberosDescriptor.replaceVariables("${variable.name}", configurations));
+
     // Replacement yields an empty string
     Assert.assertEquals("",
         KerberosDescriptor.replaceVariables("${config-type/variable.name2}", configurations));
 
+
     // This might cause an infinite loop... we assume protection is in place...
     try {
       Assert.assertEquals("${config-type2/self_reference}",
@@ -341,6 +384,26 @@ public class KerberosDescriptorTest {
     } catch (AmbariException e) {
       // This is expected...
     }
+  }
+
+  @Test
+  public void testReplaceComplicatedVariables() throws AmbariException {
+    Map<String, Map<String, String>> configurations = new HashMap<String,
Map<String, String>>() {
+      {
+        put("", new HashMap<String, String>() {{
+          put("host", "c6401.ambari.apache.org");
+          put("realm", "EXAMPLE.COM");
+        }});
+      }
+    };
+
+    Assert.assertEquals("hive.metastore.local=false,hive.metastore.uris=thrift://c6401.ambari.apache.org:9083,hive.metastore.sasl.enabled=true,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse,hive.exec.mode.local.auto=false,hive.metastore.kerberos.principal=hive/_HOST@EXAMPLE.COM",
+        KerberosDescriptor.replaceVariables("hive.metastore.local=false,hive.metastore.uris=thrift://${host}:9083,hive.metastore.sasl.enabled=true,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse,hive.exec.mode.local.auto=false,hive.metastore.kerberos.principal=hive/_HOST@${realm}",
configurations));
+
+    Assert.assertEquals("Hello my realm is {EXAMPLE.COM}",
+        KerberosDescriptor.replaceVariables("Hello my realm is {${realm}}", configurations));
 
+    Assert.assertEquals("$c6401.ambari.apache.org",
+        KerberosDescriptor.replaceVariables("$${host}", configurations));
   }
 }
\ No newline at end of file


Mime
View raw message