Updated Branches:
  refs/heads/trunk 4d1dc1e85 -> 6e28d760f

AMBARI-2643. Added ability to specify custom JDBC properties in ambari.ini 
(ncole)


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

Branch: refs/heads/trunk
Commit: 6e28d760f013646d223d6ed05ac08efaea915d53
Parents: 4d1dc1e
Author: Nate Cole <[email protected]>
Authored: Fri Jul 12 14:28:47 2013 -0400
Committer: Nate Cole <[email protected]>
Committed: Fri Jul 12 14:28:47 2013 -0400

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     | 26 ++++++++
 .../server/controller/ControllerModule.java     | 14 +++++
 .../ambari/server/orm/JdbcPropertyTest.java     | 65 ++++++++++++++++++++
 3 files changed, 105 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e28d760/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 0109ae8..7e780f6 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -36,6 +36,8 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
+import java.util.Map.Entry;
 
 
 /**
@@ -132,6 +134,7 @@ public class Configuration {
   public static final String SERVER_JDBC_USER_PASSWD_KEY = 
"server.jdbc.user.passwd";
   public static final String SERVER_JDBC_DRIVER_KEY = "server.jdbc.driver";
   public static final String SERVER_JDBC_URL_KEY = "server.jdbc.url";
+  public static final String SERVER_JDBC_PROPERTIES_PREFIX = 
"server.jdbc.properties.";
 
 //  public static final String SERVER_RCA_PERSISTENCE_TYPE_KEY = 
"server.rca.persistence.type";
   public static final String SERVER_JDBC_RCA_USER_NAME_KEY = 
"server.jdbc.rca.user.name";
@@ -246,6 +249,7 @@ public class Configuration {
 
   private CredentialProvider credentialProvider = null;
   private volatile boolean credentialProviderInitialized = false;
+  private Map<String,String> customDbProperties = null;
 
   public Configuration() {
     this(readConfigFile());
@@ -743,4 +747,26 @@ public class Configuration {
   public int getTwoWayAuthPort() {
     return Integer.parseInt(properties.getProperty(SRVR_TWO_WAY_SSL_PORT_KEY, 
String.valueOf(SRVR_TWO_WAY_SSL_PORT_DEFAULT)));
   }
+
+  /**
+   * @return custom properties for database connections
+   */
+  public Map<String,String> getDatabaseCustomProperties() {
+    if (null != customDbProperties) {
+      return customDbProperties;
+    }
+    
+    customDbProperties = new HashMap<String, String>();
+    
+    for (Entry<Object, Object> entry : properties.entrySet()) {
+      String key = entry.getKey().toString();
+      String val = entry.getValue().toString();
+      if (key.startsWith(SERVER_JDBC_PROPERTIES_PREFIX)) {
+        
customDbProperties.put(key.substring(SERVER_JDBC_PROPERTIES_PREFIX.length()), 
val);
+      }
+    }
+    
+    return customDbProperties;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e28d760/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 261b2a3..5f325b5 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -42,6 +42,8 @@ import 
org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.crypto.password.StandardPasswordEncoder;
 
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Properties;
 
 /**
@@ -89,6 +91,16 @@ public class ControllerModule extends AbstractModule {
 
     Properties properties = new Properties();
 
+    // custom jdbc properties
+    Map<String, String> custom = configuration.getDatabaseCustomProperties();
+    
+    if (0 != custom.size()) {
+      for (Entry<String, String> entry : custom.entrySet()) {
+        properties.setProperty("eclipselink.jdbc.property." + entry.getKey(),
+           entry.getValue());
+      }
+    }    
+
     switch (persistenceType) {
       case IN_MEMORY:
         properties.put("javax.persistence.jdbc.url", 
Configuration.JDBC_IN_MEMORY_URL);
@@ -117,6 +129,8 @@ public class ControllerModule extends AbstractModule {
       case DROP_AND_CREATE:
         properties.setProperty("eclipselink.ddl-generation", 
"drop-and-create-tables");
         break;
+      default:
+        break;
     }
     properties.setProperty("eclipselink.ddl-generation.output-mode", "both");
     properties.setProperty("eclipselink.create-ddl-jdbc-file-name", 
"DDL-create.jdbc");

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/6e28d760/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
new file mode 100644
index 0000000..0567f09
--- /dev/null
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/JdbcPropertyTest.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.orm;
+
+import java.util.Properties;
+
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.ControllerModule;
+import org.apache.ambari.server.state.Clusters;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+
+public class JdbcPropertyTest {
+  Properties properties = new Properties();
+
+  @Before
+  public void configure() {
+    properties.setProperty(Configuration.SERVER_PERSISTENCE_TYPE_KEY, 
"in-memory");
+    properties.setProperty(Configuration.METADETA_DIR_PATH, 
"src/test/resources/stacks");
+    properties.setProperty(Configuration.SERVER_VERSION_FILE, 
"target/version");
+    properties.setProperty(Configuration.OS_VERSION_KEY, "centos5");
+  }
+  
+  @Test
+  public void testNormal() throws Exception {
+    Injector injector = Guice.createInjector(new ControllerModule(properties));
+    injector.getInstance(GuiceJpaInitializer.class);
+
+    injector.getInstance(Clusters.class);
+  }
+  
+  @Test
+  public void testJdbcProperty() throws Exception {
+    properties.setProperty(Configuration.SERVER_JDBC_PROPERTIES_PREFIX + 
"shutdown", "true");
+    Injector injector = Guice.createInjector(new ControllerModule(properties));
+    injector.getInstance(GuiceJpaInitializer.class);
+    try {
+      injector.getInstance(Clusters.class);
+      Assert.fail("Expected in-memory to fail because property 'shutdown' 
specified.");
+    } catch (Throwable t) {
+      // expect failure
+    }
+  }
+
+  
+}

Reply via email to