lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject lucene-solr:master: SOLR-9725: substitute properties in JdbcDataSource configuration
Date Sun, 25 Dec 2016 19:42:08 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master 54d8574f9 -> 5c8a70fb5


SOLR-9725: substitute properties in JdbcDataSource configuration


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/5c8a70fb
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5c8a70fb
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5c8a70fb

Branch: refs/heads/master
Commit: 5c8a70fb57fd877e336c3d90a98ae10c5a6906ae
Parents: 54d8574
Author: Mikhail Khludnev <mkhl@apache.org>
Authored: Fri Dec 23 22:54:50 2016 +0300
Committer: Mikhail Khludnev <mkhl@apache.org>
Committed: Sun Dec 25 12:41:27 2016 +0300

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 +
 .../solr/handler/dataimport/JdbcDataSource.java |  4 +-
 .../handler/dataimport/TestJdbcDataSource.java  | 43 +++++++++++++-------
 3 files changed, 33 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5c8a70fb/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a6ea07b..55aeb93 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -193,6 +193,8 @@ New Features
 
 * SOLR-9884: Add version to segments handler output (Steven Bower via Erick Erickson)
 
+* SOLR-9725: Substitute properties into JdbcDataSource configuration ( Jamie Jackson, Yuri
Sashevsky via Mikhail Khludnev)
+
 Optimizations
 ----------------------
 * SOLR-9704: Facet Module / JSON Facet API: Optimize blockChildren facets that have

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5c8a70fb/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
index ce8671a..b17650a 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
@@ -71,6 +71,7 @@ public class JdbcDataSource extends
 
   @Override
   public void init(Context context, Properties initProps) {
+    resolveVariables(context, initProps);
     initProps = decryptPwd(context, initProps);
     Object o = initProps.get(CONVERT_TYPE);
     if (o != null)
@@ -113,7 +114,7 @@ public class JdbcDataSource extends
   }
 
   private Properties decryptPwd(Context context, Properties initProps) {
-    String encryptionKey = context.replaceTokens(initProps.getProperty("encryptKeyFile"));
+    String encryptionKey = initProps.getProperty("encryptKeyFile");
     if (initProps.getProperty("password") != null && encryptionKey != null) {
       // this means the password is encrypted and use the file to decode it
       try {
@@ -143,7 +144,6 @@ public class JdbcDataSource extends
   protected Callable<Connection> createConnectionFactory(final Context context,
                                        final Properties initProps) {
 //    final VariableResolver resolver = context.getVariableResolver();
-    resolveVariables(context, initProps);
     final String jndiName = initProps.getProperty(JNDI_NAME);
     final String url = initProps.getProperty(URL);
     final String driver = initProps.getProperty(DRIVER);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5c8a70fb/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
index 7853ad1..01340bc 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
@@ -80,6 +80,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase
{
     driver = mockControl.createMock(Driver.class);
     dataSource = mockControl.createMock(DataSource.class);
     connection = mockControl.createMock(Connection.class);
+    props.clear();
   }
 
   @Override
@@ -139,20 +140,33 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase
{
   }
 
   @Test
-  public void testRetrieveFromJndiWithCredentialsWithEncryptedPwd() throws Exception {
+  public void testRetrieveFromJndiWithCredentialsEncryptedAndResolved() throws Exception
{
     MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
-
+    
+    String user = "Fred";
+    String plainPassword = "MyPassword";
+    String encryptedPassword = "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=";
+    String propsNamespace = "exampleNamespace";
+    
     props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
-    props.put("user", "Fred");
-    props.put("encryptKeyFile", createEncryptionKeyFile());
-    props.put("password", "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=");
-    props.put("holdability", "HOLD_CURSORS_OVER_COMMIT");
-    EasyMock.expect(dataSource.getConnection("Fred", "MyPassword")).andReturn(
-        connection);
+    
+    props.put("user", "${" +propsNamespace +".user}");
+    props.put("encryptKeyFile", "${" +propsNamespace +".encryptKeyFile}");
+    props.put("password", "${" +propsNamespace +".password}");
+    
+    EasyMock.expect(dataSource.getConnection(user, plainPassword)).andReturn(
+             connection);
+    
+    Map<String,Object> values = new HashMap<>();
+    values.put("user", user);
+    values.put("encryptKeyFile", createEncryptionKeyFile());
+    values.put("password", encryptedPassword);
+    context.getVariableResolver().addNamespace(propsNamespace, values);
+    
     jdbcDataSource.init(context, props);
 
     connection.setAutoCommit(false);
-    connection.setHoldability(1);
+    //connection.setHoldability(1);
 
     mockControl.replay();
 
@@ -167,10 +181,11 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase
{
   public void testRetrieveFromJndiWithCredentialsWithEncryptedAndResolvedPwd() throws Exception
{
     MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
 
-    props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
-    props.put("user", "Fred");
-    props.put("encryptKeyFile", "${foo.bar}");
-    props.put("password", "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=");
+    Properties properties = new Properties();
+    properties.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
+    properties.put("user", "Fred");
+    properties.put("encryptKeyFile", "${foo.bar}");
+    properties.put("password", "U2FsdGVkX18QMjY0yfCqlfBMvAB4d3XkwY96L7gfO2o=");
     EasyMock.expect(dataSource.getConnection("Fred", "MyPassword")).andReturn(
         connection);
     
@@ -178,7 +193,7 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase
{
     values.put("bar", createEncryptionKeyFile());
     context.getVariableResolver().addNamespace("foo", values);
     
-    jdbcDataSource.init(context, props);
+    jdbcDataSource.init(context, properties);
     
     connection.setAutoCommit(false);
 


Mime
View raw message