flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pras...@apache.org
Subject svn commit: r1311483 - in /incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src: main/java/org/apache/flume/channel/jdbc/ main/java/org/apache/flume/channel/jdbc/impl/ test/java/org/apache/flume/channel/jdbc/
Date Mon, 09 Apr 2012 21:56:29 GMT
Author: prasadm
Date: Mon Apr  9 21:56:29 2012
New Revision: 1311483

URL: http://svn.apache.org/viewvc?rev=1311483&view=rev
Log:
FLUME-1107: Configuration keys for JDBC channel contain redundant prefix.
(Arvind Prabhakar via Prasad Mujumdar)

Modified:
    incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/ConfigurationConstants.java
    incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/impl/JdbcChannelProviderImpl.java
    incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestJdbcChannelProvider.java

Modified: incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/ConfigurationConstants.java
URL: http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/ConfigurationConstants.java?rev=1311483&r1=1311482&r2=1311483&view=diff
==============================================================================
--- incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/ConfigurationConstants.java
(original)
+++ incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/ConfigurationConstants.java
Mon Apr  9 21:56:29 2012
@@ -24,44 +24,113 @@ public final class ConfigurationConstant
 
   public static final String PREFIX = "org.apache.flume.channel.jdbc.";
 
-  public static final String CONFIG_JDBC_SYSPRO_PREFIX =
-      PREFIX + "sysprop.";
+  public static final String CONFIG_JDBC_SYSPROP_PREFIX = "sysprop.";
 
-  public static final String CONFIG_JDBC_DRIVER_CLASS =
-      PREFIX + "driver.class";
+  /**
+   * @deprecated use {@link #CONFIG_JDBC_SYSPROP_PREFIX} instead
+   */
+  public static final String OLD_CONFIG_JDBC_SYSPROP_PREFIX =
+      PREFIX + CONFIG_JDBC_SYSPROP_PREFIX;
 
-  public static final String CONFIG_USERNAME =
-      PREFIX + "db.username";
+  public static final String CONFIG_JDBC_DRIVER_CLASS = "driver.class";
 
-  public static final String CONFIG_PASSWORD =
-      PREFIX + "db.password";
+  /**
+   * @deprecated use {@link #CONFIG_JDBC_DRIVER_CLASS} instead.
+   */
+  public static final String OLD_CONFIG_JDBC_DRIVER_CLASS =
+      PREFIX + CONFIG_JDBC_DRIVER_CLASS;
 
-  public static final String CONFIG_URL =
-      PREFIX + "driver.url";
+  public static final String CONFIG_USERNAME = "db.username";
 
-  public static final String CONFIG_JDBC_PROPERTIES_FILE =
-      PREFIX + "connection.properties.file";
+  /**
+   * @deprecated use {@link #CONFIG_USERNAME} instead.
+   */
+  public static final String OLD_CONFIG_USERNAME =
+      PREFIX + CONFIG_USERNAME;
 
-  public static final String CONFIG_DATABASE_TYPE =
-      PREFIX + "db.type";
+  public static final String CONFIG_PASSWORD = "db.password";
 
-  public static final String CONFIG_CREATE_SCHEMA =
-      PREFIX + "create.schema";
+  /**
+   * @deprecated use {@link #CONFIG_PASSWORD} instead.
+   */
+  public static final String OLD_CONFIG_PASSWORD =
+      PREFIX + CONFIG_PASSWORD;
+
+  public static final String CONFIG_URL = "driver.url";
 
-  public static final String CONFIG_CREATE_INDEX =
-      PREFIX + "create.index";
+  /**
+   * @deprecated use {@link #CONFIG_URL} instead.
+   */
+  public static final String OLD_CONFIG_URL =
+      PREFIX + CONFIG_URL;
 
-  public static final String CONFIG_CREATE_FK =
-      PREFIX + "create.foreignkey";
+  public static final String CONFIG_JDBC_PROPS_FILE =
+      "connection.properties.file";
+
+  /**
+   * @deprecated use {@link #CONFIG_JDBC_PROPS_FILE} instead.
+   */
+  public static final String OLD_CONFIG_JDBC_PROPS_FILE =
+      PREFIX + CONFIG_JDBC_PROPS_FILE;
+
+  public static final String CONFIG_DATABASE_TYPE = "db.type";
+
+  /**
+   * @deprecated use {@link #CONFIG_DATABASE_TYPE} instead.
+   */
+  public static final String OLD_CONFIG_DATABASE_TYPE =
+      PREFIX + CONFIG_DATABASE_TYPE;
+
+  public static final String CONFIG_CREATE_SCHEMA = "create.schema";
+
+  /**
+   * @deprecated use {@link #CONFIG_CREATE_SCHEMA} instead.
+   */
+  public static final String OLD_CONFIG_CREATE_SCHEMA =
+      PREFIX + CONFIG_CREATE_SCHEMA;
+
+
+  public static final String CONFIG_CREATE_INDEX = "create.index";
+
+  /**
+   * @deprecated use {@link #CONFIG_CREATE_INDEX} instead.
+   */
+  public static final String OLD_CONFIG_CREATE_INDEX =
+      PREFIX + CONFIG_CREATE_INDEX;
+
+  public static final String CONFIG_CREATE_FK = "create.foreignkey";
+
+  /**
+   * @deprecated use {@link #CONFIG_CREATE_FK} instead.
+   */
+  public static final String OLD_CONFIG_CREATE_FK =
+      PREFIX + CONFIG_CREATE_FK;
 
   public static final String CONFIG_TX_ISOLATION_LEVEL =
-      PREFIX + "transaction.isolation";
+      "transaction.isolation";
 
-  public static final String CONFIG_MAX_CONNECTION =
-      PREFIX + "maximum.connections";
+  /**
+   * @deprecated use {@link #CONFIG_TX_ISOLATION_LEVEL} instead.
+   */
+  public static final String OLD_CONFIG_TX_ISOLATION_LEVEL =
+      PREFIX + CONFIG_TX_ISOLATION_LEVEL;
+
+  public static final String CONFIG_MAX_CONNECTIONS = "maximum.connections";
+
+  /**
+   * @deprecated use {@link #CONFIG_MAX_CONNECTIONS} instead
+   */
+  public static final String OLD_CONFIG_MAX_CONNECTIONS =
+      PREFIX + CONFIG_MAX_CONNECTIONS;
+
+  public static final String CONFIG_MAX_CAPACITY = "maximum.capacity";
+
+  /**
+   * @deprecated use {@link #CONFIG_MAX_CAPACITY} instead.
+   */
+  public static final String OLD_CONFIG_MAX_CAPACITY =
+      PREFIX + CONFIG_MAX_CAPACITY;
 
-  public static final String CONFIG_MAX_CAPACITY =
-      PREFIX + "maximum.capacity";
 
   // Built in constants for JDBC Channel implementation
 

Modified: incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/impl/JdbcChannelProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/impl/JdbcChannelProviderImpl.java?rev=1311483&r1=1311482&r2=1311483&view=diff
==============================================================================
--- incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/impl/JdbcChannelProviderImpl.java
(original)
+++ incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/main/java/org/apache/flume/channel/jdbc/impl/JdbcChannelProviderImpl.java
Mon Apr  9 21:56:29 2012
@@ -25,6 +25,7 @@ import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -103,8 +104,28 @@ public class JdbcChannelProviderImpl imp
   }
 
   private void initializeSystemProperties(Context context) {
-    Map<String, String> sysProps = context.getSubProperties(
-        ConfigurationConstants.CONFIG_JDBC_SYSPRO_PREFIX);
+    Map<String, String> sysProps = new HashMap<String, String>();
+
+    Map<String, String> sysPropsOld = context.getSubProperties(
+        ConfigurationConstants.OLD_CONFIG_JDBC_SYSPROP_PREFIX);
+
+    if (sysPropsOld.size() > 0) {
+      LOGGER.warn("Long form configuration prefix \""
+          + ConfigurationConstants.OLD_CONFIG_JDBC_SYSPROP_PREFIX
+          + "\" is deprecated. Please use the short form prefix \""
+          + ConfigurationConstants.CONFIG_JDBC_SYSPROP_PREFIX
+          + "\" instead.");
+
+      sysProps.putAll(sysPropsOld);
+    }
+
+    Map<String, String> sysPropsNew = context.getSubProperties(
+        ConfigurationConstants.CONFIG_JDBC_SYSPROP_PREFIX);
+
+    // Override the deprecated values with the non-deprecated
+    if (sysPropsNew.size() > 0) {
+      sysProps.putAll(sysPropsNew);
+    }
 
     for (String key: sysProps.keySet()) {
       String value = sysProps.get(key);
@@ -115,8 +136,10 @@ public class JdbcChannelProviderImpl imp
   }
 
   private void initializeChannelState(Context context) {
-    String maxCapacityStr = context.getString(
-        ConfigurationConstants.CONFIG_MAX_CAPACITY, "0");
+
+    String maxCapacityStr = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_MAX_CAPACITY,
+        ConfigurationConstants.OLD_CONFIG_MAX_CAPACITY, "0");
 
     long maxCapacitySpecified = 0;
     try {
@@ -135,8 +158,9 @@ public class JdbcChannelProviderImpl imp
   }
 
   private void initializeSchema(Context context) {
-    String createSchemaFlag = context.getString(
-        ConfigurationConstants.CONFIG_CREATE_SCHEMA, "true");
+    String createSchemaFlag = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_CREATE_SCHEMA,
+        ConfigurationConstants.OLD_CONFIG_CREATE_SCHEMA, "true");
 
     boolean createSchema = Boolean.valueOf(createSchemaFlag);
     LOGGER.debug("Create schema flag set to: " + createSchema);
@@ -151,11 +175,14 @@ public class JdbcChannelProviderImpl imp
             + "schema and try again.");
       }
 
-      String createIndexFlag = context.getString(
-          ConfigurationConstants.CONFIG_CREATE_INDEX, "true");
+      String createIndexFlag = getConfigurationString(context,
+          ConfigurationConstants.CONFIG_CREATE_INDEX,
+          ConfigurationConstants.OLD_CONFIG_CREATE_INDEX, "true");
+
+      String createForeignKeysFlag = getConfigurationString(context,
+          ConfigurationConstants.CONFIG_CREATE_FK,
+          ConfigurationConstants.OLD_CONFIG_CREATE_FK, "true");
 
-      String createForeignKeysFlag = context.getString(
-          ConfigurationConstants.CONFIG_CREATE_FK, "true");
 
       boolean createIndex = Boolean.valueOf(createIndexFlag);
       if (!createIndex) {
@@ -302,21 +329,30 @@ public class JdbcChannelProviderImpl imp
    * @param properties
    */
   private void initializeDataSource(Context context) {
-    driverClassName = context.getString(
-        ConfigurationConstants.CONFIG_JDBC_DRIVER_CLASS);
-
-    connectUrl = context.getString(ConfigurationConstants.CONFIG_URL);
-
-
-    String userName = context.getString(ConfigurationConstants.CONFIG_USERNAME);
-
-    String password = context.getString(ConfigurationConstants.CONFIG_PASSWORD);
-
-    String jdbcPropertiesFile = context.getString(
-        ConfigurationConstants.CONFIG_JDBC_PROPERTIES_FILE);
-
-    String dbTypeName = context.getString(
-        ConfigurationConstants.CONFIG_DATABASE_TYPE);
+    driverClassName = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_JDBC_DRIVER_CLASS,
+        ConfigurationConstants.OLD_CONFIG_JDBC_DRIVER_CLASS, null);
+
+    connectUrl = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_URL,
+        ConfigurationConstants.OLD_CONFIG_URL, null);
+
+
+    String userName = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_USERNAME,
+        ConfigurationConstants.OLD_CONFIG_USERNAME, null);
+
+    String password = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_PASSWORD,
+        ConfigurationConstants.OLD_CONFIG_PASSWORD, null);
+
+    String jdbcPropertiesFile = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_JDBC_PROPS_FILE,
+        ConfigurationConstants.OLD_CONFIG_JDBC_PROPS_FILE, null);
+
+    String dbTypeName = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_DATABASE_TYPE,
+        ConfigurationConstants.OLD_CONFIG_DATABASE_TYPE, null);
 
     // If connect URL is not specified, use embedded Derby
     if (connectUrl == null || connectUrl.trim().length() == 0) {
@@ -453,8 +489,9 @@ public class JdbcChannelProviderImpl imp
     }
 
     // Transaction Isolation
-    String txIsolation = context.getString(
+    String txIsolation = getConfigurationString(context,
         ConfigurationConstants.CONFIG_TX_ISOLATION_LEVEL,
+        ConfigurationConstants.OLD_CONFIG_TX_ISOLATION_LEVEL,
         TransactionIsolation.READ_COMMITTED.getName());
 
     TransactionIsolation txIsolationLevel =
@@ -468,8 +505,9 @@ public class JdbcChannelProviderImpl imp
 
     connectionPool = new GenericObjectPool();
 
-    String maxActiveConnections = context.getString(
-        ConfigurationConstants.CONFIG_MAX_CONNECTION, "10");
+    String maxActiveConnections = getConfigurationString(context,
+        ConfigurationConstants.CONFIG_MAX_CONNECTIONS,
+        ConfigurationConstants.OLD_CONFIG_MAX_CONNECTIONS, "10");
 
     int maxActive = 10;
     if (maxActiveConnections != null && maxActiveConnections.length() > 0) {
@@ -495,4 +533,40 @@ public class JdbcChannelProviderImpl imp
 
     txFactory = new JdbcTransactionFactory(dataSource);
   }
+
+  /**
+   * Helper method to transition the configuration from the old long form
+   * style configuration to the new short form. If the value is specified for
+   * both the old and the new forms, the one associated with the new form
+   * takes precedence.
+   *
+   * @param context
+   * @param key the expected configuration key
+   * @param oldKey the deprecated configuration key
+   * @param  default value, null if no default
+   * @return the value associated with the key
+   */
+  private String getConfigurationString(Context context, String key,
+      String oldKey, String defaultValue) {
+
+    String oldValue = context.getString(oldKey);
+
+    if (oldValue != null && oldValue.length() > 0) {
+      LOGGER.warn("Long form configuration key \"" + oldKey
+          + "\" is deprecated. Please use the short form key \""
+          + key + "\" instead.");
+    }
+
+    String value = context.getString(key);
+
+    if (value == null) {
+      if (oldValue != null) {
+        value = oldValue;
+      } else {
+        value = defaultValue;
+      }
+    }
+
+    return value;
+  }
 }

Modified: incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestJdbcChannelProvider.java
URL: http://svn.apache.org/viewvc/incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestJdbcChannelProvider.java?rev=1311483&r1=1311482&r2=1311483&view=diff
==============================================================================
--- incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestJdbcChannelProvider.java
(original)
+++ incubator/flume/trunk/flume-ng-channels/flume-jdbc-channel/src/test/java/org/apache/flume/channel/jdbc/TestJdbcChannelProvider.java
Mon Apr  9 21:56:29 2012
@@ -69,7 +69,7 @@ public class TestJdbcChannelProvider {
     File derbyLogFile = new File(tmpDir, "derbytest.log");
     String derbyLogFilePath = derbyLogFile.getCanonicalPath();
 
-    derbyCtx.put(ConfigurationConstants.CONFIG_JDBC_SYSPRO_PREFIX
+    derbyCtx.put(ConfigurationConstants.CONFIG_JDBC_SYSPROP_PREFIX
         + "derby.stream.error.file", derbyLogFilePath);
 
     // Use a temp file to create a temporary directory



Mime
View raw message