sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arv...@apache.org
Subject svn commit: r1208941 - in /incubator/sqoop/branches/sqoop2: ./ client/ connector/connector-generic-jdbc/ connector/connector-mysql-fastpath/ connector/connector-mysql-jdbc/ core/ core/src/main/java/org/ core/src/main/java/org/apache/ core/src/main/java...
Date Thu, 01 Dec 2011 03:30:04 GMT
Author: arvind
Date: Thu Dec  1 03:30:01 2011
New Revision: 1208941

URL: http://svn.apache.org/viewvc?rev=1208941&view=rev
Log:
SQOOP-365. Skeletal configuration and logging framework.

Added:
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/test/
    incubator/sqoop/branches/sqoop2/core/src/test/java/
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
  (with props)
    incubator/sqoop/branches/sqoop2/core/src/test/resources/
    incubator/sqoop/branches/sqoop2/core/src/test/resources/test_config.properties
    incubator/sqoop/branches/sqoop2/server/src/main/java/org/
    incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/
    incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/
    incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/
    incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
  (with props)
Modified:
    incubator/sqoop/branches/sqoop2/client/pom.xml
    incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/pom.xml
    incubator/sqoop/branches/sqoop2/connector/connector-mysql-fastpath/pom.xml
    incubator/sqoop/branches/sqoop2/connector/connector-mysql-jdbc/pom.xml
    incubator/sqoop/branches/sqoop2/core/pom.xml
    incubator/sqoop/branches/sqoop2/pom.xml
    incubator/sqoop/branches/sqoop2/server/pom.xml
    incubator/sqoop/branches/sqoop2/server/src/main/webapp/WEB-INF/web.xml

Modified: incubator/sqoop/branches/sqoop2/client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/client/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/client/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/client/pom.xml Thu Dec  1 03:30:01 2011
@@ -34,7 +34,7 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>core</artifactId>
+      <artifactId>sqoop-core</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
   </dependencies>

Modified: incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/pom.xml Thu Dec  1 03:30:01
2011
@@ -34,7 +34,7 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>spi</artifactId>
+      <artifactId>sqoop-spi</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
   </dependencies>

Modified: incubator/sqoop/branches/sqoop2/connector/connector-mysql-fastpath/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/connector/connector-mysql-fastpath/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/connector/connector-mysql-fastpath/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/connector/connector-mysql-fastpath/pom.xml Thu Dec  1
03:30:01 2011
@@ -34,7 +34,7 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>spi</artifactId>
+      <artifactId>sqoop-spi</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
   </dependencies>

Modified: incubator/sqoop/branches/sqoop2/connector/connector-mysql-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/connector/connector-mysql-jdbc/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/connector/connector-mysql-jdbc/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/connector/connector-mysql-jdbc/pom.xml Thu Dec  1 03:30:01
2011
@@ -34,7 +34,7 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>spi</artifactId>
+      <artifactId>sqoop-spi</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
   </dependencies>

Modified: incubator/sqoop/branches/sqoop2/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/core/pom.xml Thu Dec  1 03:30:01 2011
@@ -34,9 +34,14 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>spi</artifactId>
+      <artifactId>sqoop-spi</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,24 @@
+/**
+ * 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.sqoop.core;
+
+public interface ConfigurationListener {
+
+  public void configurationChanged();
+
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,31 @@
+/**
+ * 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.sqoop.core;
+
+import java.io.File;
+import java.util.Map;
+import java.util.Properties;
+
+public interface ConfigurationProvider {
+
+  public void initialize(File configDir, Properties bootstrapCongiruation);
+
+  public void registerListener(ConfigurationListener listener);
+
+  public Map<String, String> getConfiguration();
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
Thu Dec  1 03:30:01 2011
@@ -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.sqoop.core;
+
+public enum CoreError implements ErrorCode {
+
+  /** An unknown error has occurred. */
+  CORE_0000("An unknown error has occurred"),
+
+  /** The system was unable to find the configuration directory. */
+  CORE_0001("Invalid confiugration directory"),
+
+  /** The system was unable to load bootstrap configuration. */
+  CORE_0002("Invalid bootstrap configuration"),
+
+  /**
+   * The bootstrap configuration did not contain the class name of
+   * configuration provider.
+   */
+  CORE_0003("No configuration provider set for the system"),
+
+  /** The system was unable locate configuration provider implementation.*/
+  CORE_0004("Configuration provider was not found"),
+
+  /** The system was unable to load configuration provider */
+  CORE_0005("Unable to load configuration provider"),
+
+  /**
+   * The PropertiesConfigurationProvider is unable to load the configuration
+   * properties file.
+   */
+  CORE_0006("Properties configuration provider unable to load config file"),
+
+  /** The configuration system has not been initialized correctly. */
+  CORE_0007("System not initialized");
+
+  private final String message;
+
+  private CoreError(String message) {
+    this.message = message;
+  }
+
+  public String getCode() {
+    return name();
+  }
+
+  public String getMessage() {
+    return message;
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,37 @@
+/**
+ * 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.sqoop.core;
+
+/**
+ * Defines an error-code contract. Sqoop exceptions use the error code to
+ * communicate error information where possible. Each error code is associated
+ * with default message that identifies the high level information related to
+ * the underlying error condition.
+ */
+public interface ErrorCode {
+
+  /**
+   * @return the string representation of the error code.
+   */
+  public String getCode();
+
+  /**
+   * @return the message associated with error code.
+   */
+  public String getMessage();
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ErrorCode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,149 @@
+/**
+ * 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.sqoop.core;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+public class PropertiesConfigurationProvider implements ConfigurationProvider {
+
+  private static final Logger LOG =
+      Logger.getLogger(PropertiesConfigurationProvider.class);
+
+  public static final String CONFIG_FILENAME = "sqoop.properties";
+
+  private Map<String, String> configuration = new HashMap<String, String>();
+
+  private List<ConfigurationListener> listeners =
+      new ArrayList<ConfigurationListener>();
+
+  private File configFile;
+
+  public PropertiesConfigurationProvider() {
+    // Default constructor
+  }
+
+  @Override
+  public synchronized void registerListener(ConfigurationListener listener) {
+    listeners.add(listener);
+  }
+
+  @Override
+  public synchronized Map<String, String> getConfiguration() {
+    Map<String, String> config = new HashMap<String, String>();
+    config.putAll(configuration);
+
+    return config;
+  }
+
+
+  @Override
+  public synchronized void initialize(
+      File configDir, Properties bootstrapCongiruation) {
+    configFile = new File(configDir, CONFIG_FILENAME);
+    if (!configFile.exists() || !configFile.isFile() || !configFile.canRead()) {
+      throw new SqoopException(CoreError.CORE_0006, configFile.getPath());
+    }
+
+    loadConfiguration(false); // at least one load must succeed
+
+    Thread pollerThread = new Thread(new ConfigFilePoller(configFile));
+    pollerThread.setName("config-file-poller");
+    pollerThread.setDaemon(true);
+
+    LOG.info("Starting config file poller thread");
+    pollerThread.start();
+  }
+
+  private synchronized void loadConfiguration(boolean notifyListeners) {
+    Properties configProperties = new Properties();
+    InputStream fis = null;
+    try {
+      fis = new BufferedInputStream(new FileInputStream(configFile));
+      configProperties.load(fis);
+    } catch (Exception ex) {
+      throw new SqoopException(CoreError.CORE_0006, configFile.getPath());
+    } finally {
+      if (fis != null) {
+        try {
+          fis.close();
+        } catch (IOException ex) {
+          LOG.error("Failed to close file stream for configuration", ex);
+        }
+      }
+    }
+
+    configuration.clear();
+    Enumeration<?> propNameEnum = configProperties.propertyNames();
+    while (propNameEnum.hasMoreElements()) {
+      String name = (String) propNameEnum.nextElement();
+      configuration.put(name, configProperties.getProperty(name));
+    }
+
+    if (notifyListeners) {
+      for (ConfigurationListener configListener : listeners) {
+        configListener.configurationChanged();
+      }
+    }
+  }
+
+  class ConfigFilePoller implements Runnable {
+    private File file;
+
+    private long lastUpdatedAt;
+
+    ConfigFilePoller(File configFile) {
+      this.file = configFile;
+      lastUpdatedAt = configFile.lastModified();
+    }
+
+    @Override
+    public void run() {
+
+      while(true) {
+        LOG.trace("Checking config file for changes: " + file);
+
+        if (file.lastModified() > lastUpdatedAt) {
+          LOG.info("Configuration file change detected, attempting to load");
+          try {
+            loadConfiguration(true);
+          } catch (Exception ex) {
+            LOG.error("Exception while loading configuration", ex);
+          }
+        }
+
+        try {
+          Thread.sleep(30);
+        } catch (InterruptedException ex) {
+          Thread.currentThread().interrupt();
+        }
+      }
+    }
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,171 @@
+/**
+ * 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.sqoop.core;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+public class SqoopConfiguration {
+
+  public static final String SYSPROP_CONFIG_DIR = "sqoop.config.dir";
+  public static final String FILENAME_BOOTSTRAP_CONFIG =
+      "sqoop_bootstrap.properties";
+
+  public static final String BOOTPROP_CONFIG_PROVIDER = "sqoop.config.provider";
+
+  public static final Logger LOG = Logger.getLogger(SqoopConfiguration.class);
+
+  private static final String PREFIX_GLOBAL_CONFIG = "org.apache.sqoop.";
+
+  private static final String PREFIX_LOG_CONFIG = PREFIX_GLOBAL_CONFIG
+      + "log4j.";
+
+  private static File configDir = null;
+  private static boolean initialized = false;
+  private static ConfigurationProvider provider = null;
+  private static Map<String, String> config;
+
+  public synchronized static void initialize() {
+    if (initialized) {
+      LOG.warn("Attempt to reinitialize the system, ignoring");
+      return;
+    }
+
+    String configDirPath = System.getProperty(SYSPROP_CONFIG_DIR);
+    if (configDirPath == null || configDirPath.trim().length() == 0) {
+      throw new SqoopException(CoreError.CORE_0001, "Environment variable "
+          + SYSPROP_CONFIG_DIR + " is not set.");
+    }
+
+    configDir = new File(configDirPath);
+    if (!configDir.exists() || !configDir.isDirectory()) {
+      throw new SqoopException(CoreError.CORE_0001, configDirPath);
+    }
+
+    String bootstrapConfigFilePath = null;
+    try {
+      String configDirCanonicalPath = configDir.getCanonicalPath();
+      bootstrapConfigFilePath = configDirCanonicalPath
+              + "/" + FILENAME_BOOTSTRAP_CONFIG;
+
+    } catch (IOException ex) {
+      throw new SqoopException(CoreError.CORE_0001, configDirPath, ex);
+    }
+
+    File bootstrapConfig = new File(bootstrapConfigFilePath);
+    if (!bootstrapConfig.exists() || !bootstrapConfig.isFile()
+        || !bootstrapConfig.canRead()) {
+      throw new SqoopException(CoreError.CORE_0002, bootstrapConfigFilePath);
+    }
+
+    Properties bootstrapProperties = new Properties();
+    InputStream bootstrapPropStream = null;
+    try {
+      bootstrapPropStream = new FileInputStream(bootstrapConfig);
+      bootstrapProperties.load(bootstrapPropStream);
+    } catch (IOException ex) {
+      throw new SqoopException(
+          CoreError.CORE_0002, bootstrapConfigFilePath, ex);
+    }
+
+    String configProviderClassName = bootstrapProperties.getProperty(
+        BOOTPROP_CONFIG_PROVIDER);
+
+    if (configProviderClassName == null
+        || configProviderClassName.trim().length() == 0) {
+      throw new SqoopException(
+          CoreError.CORE_0003, BOOTPROP_CONFIG_PROVIDER);
+    }
+
+    Class<?> configProviderClass = null;
+    try {
+      configProviderClass = Class.forName(configProviderClassName);
+    } catch (ClassNotFoundException cnfe) {
+      LOG.warn("Exception while trying to load configuration provider", cnfe);
+    }
+
+    if (configProviderClass == null) {
+      ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+      if (ctxLoader != null) {
+        try {
+          configProviderClass = ctxLoader.loadClass(configProviderClassName);
+        } catch (ClassNotFoundException cnfe) {
+          LOG.warn("Exception while trying to load configuration provider",
+              cnfe);
+        }
+      }
+    }
+
+    if (configProviderClass == null) {
+      throw new SqoopException(CoreError.CORE_0004, configProviderClassName);
+    }
+
+    try {
+      provider = (ConfigurationProvider) configProviderClass.newInstance();
+    } catch (Exception ex) {
+      throw new SqoopException(CoreError.CORE_0005,
+          configProviderClassName, ex);
+    }
+
+    provider.initialize(configDir, bootstrapProperties);
+    refreshConfiguration();
+    provider.registerListener(new CoreConfigurationListener());
+
+    initialized = true;
+  }
+
+  public synchronized static void registerListener(
+      ConfigurationListener listener) {
+    if (!initialized) {
+      throw new SqoopException(CoreError.CORE_0007);
+    }
+    provider.registerListener(listener);
+  }
+
+  private synchronized static void configureLogging() {
+    Properties props = new Properties();
+    for (String key : config.keySet()) {
+      if (key.startsWith(PREFIX_LOG_CONFIG)) {
+        String logConfigKey = key.substring(PREFIX_GLOBAL_CONFIG.length());
+        props.put(logConfigKey, config.get(key));
+      }
+    }
+
+    PropertyConfigurator.configure(props);
+  }
+
+  private synchronized static void refreshConfiguration() {
+    config = provider.getConfiguration();
+    configureLogging();
+  }
+
+  public static class CoreConfigurationListener implements ConfigurationListener
+  {
+    @Override
+    public void configurationChanged() {
+      refreshConfiguration();
+    }
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,54 @@
+/**
+ * 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.sqoop.core;
+
+/**
+ * Base exception for Sqoop framework. This exception requires the specification
+ * of an error code for reference purposes. Where necessary the appropriate
+ * constructor can be used to pass in additional message beyond what is
+ * specified by the error code and/or the causal exception.
+ */
+@SuppressWarnings("serial")
+public class SqoopException extends RuntimeException {
+
+  private final ErrorCode code;
+
+  public SqoopException(ErrorCode code) {
+    super(code.getCode() + ":" + code.getMessage());
+    this.code = code;
+  }
+
+  public SqoopException(ErrorCode code, String extraInfo) {
+    super(code.getCode() + ":" + code.getMessage() + " - " + extraInfo);
+    this.code = code;
+  }
+
+  public SqoopException(ErrorCode code, Throwable cause) {
+    super(code.getCode() + ":" + code.getMessage(), cause);
+    this.code = code;
+  }
+
+  public SqoopException(ErrorCode code, String extraInfo, Throwable cause) {
+    super(code.getCode() + ":" + code.getMessage() + " - " + extraInfo, cause);
+    this.code = code;
+  }
+
+  public ErrorCode getErrorCode() {
+    return code;
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,43 @@
+/**
+ * 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.sqoop.core;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestConfiguration {
+
+  @Test
+  public void testConfigurationInitFailure() {
+    // Unset any configuration dir if it is set by another test
+    System.getProperties().remove(SqoopConfiguration.SYSPROP_CONFIG_DIR);
+    try {
+      SqoopConfiguration.initialize();
+    } catch (Exception ex) {
+      Assert.assertTrue(ex instanceof SqoopException);
+      Assert.assertSame(((SqoopException) ex).getErrorCode(),
+          CoreError.CORE_0001);
+    }
+  }
+
+  @Test
+  public void testConfigurationInitSuccess() throws Exception {
+    TestUtils.setupTestConfiguration();
+    SqoopConfiguration.initialize();
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,134 @@
+/**
+ * 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.sqoop.core;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+import org.apache.log4j.Logger;
+
+public class TestUtils {
+
+  private static final Logger LOG = Logger.getLogger(TestUtils.class);
+
+  public static final String NEWLINE =
+      System.getProperty("line.separator", "\n");
+
+  /**
+   * A helper method that creates a temporary directory, populates it with
+   * bootstrap and logging configuration and sets it up as the system config
+   * directory. This is useful for running tests without necessarily having to
+   * create an installation layout.
+   *
+   * @throws Exception
+   */
+  public static void setupTestConfiguration() throws Exception {
+    File tempDir = null;
+    File targetDir = new File("target");
+    if (targetDir.exists() && targetDir.isDirectory()) {
+      tempDir = targetDir;
+    } else {
+      tempDir = new File(System.getProperty("java.io.tmpdir"));
+    }
+
+    File tempFile = File.createTempFile("test", "config", tempDir);
+    String tempConfigDirPath = tempFile.getCanonicalPath() + ".dir/config";
+    if (!tempFile.delete()) {
+      throw new Exception("Unable to delete tempfile: " + tempFile);
+    }
+
+    File tempConfigDir = new File(tempConfigDirPath);
+    if (!tempConfigDir.mkdirs()) {
+      throw new Exception("Unable to create temp config dir: "
+              + tempConfigDirPath);
+    }
+
+    File bootconfigFile = new File(tempConfigDir,
+        SqoopConfiguration.FILENAME_BOOTSTRAP_CONFIG);
+
+    if (!bootconfigFile.createNewFile()) {
+      throw new Exception("Unable to create config file: " + bootconfigFile);
+    }
+
+    BufferedWriter bootconfigWriter = null;
+    try {
+      bootconfigWriter = new BufferedWriter(new FileWriter(bootconfigFile));
+
+      bootconfigWriter.write("sqoop.config.provider = "
+            + PropertiesConfigurationProvider.class.getCanonicalName()
+            + NEWLINE);
+
+      bootconfigWriter.flush();
+    } finally {
+      if (bootconfigWriter != null) {
+        try {
+          bootconfigWriter.close();
+        } catch (IOException ex) {
+          LOG.error("Failed to close config file writer", ex);
+        }
+      }
+    }
+
+    File sysconfigFile = new File(tempConfigDir,
+        PropertiesConfigurationProvider.CONFIG_FILENAME);
+
+    BufferedWriter sysconfigWriter = null;
+    BufferedReader reader = null;
+    try {
+      reader = new BufferedReader(new InputStreamReader(
+          ClassLoader.getSystemResourceAsStream("test_config.properties")));
+
+      sysconfigWriter = new BufferedWriter(new FileWriter(sysconfigFile));
+
+      String nextLine = null;
+      while ((nextLine = reader.readLine()) != null) {
+        sysconfigWriter.write(nextLine + NEWLINE);
+      }
+
+      sysconfigWriter.flush();
+    } finally {
+      if (sysconfigWriter != null) {
+        try {
+          sysconfigWriter.close();
+        } catch (IOException ex) {
+          LOG.error("Failed to close log config file writer", ex);
+        }
+      }
+
+      if (reader != null) {
+        try {
+          reader.close();
+        } catch (IOException ex) {
+          LOG.error("Failed to close log config reader", ex);
+        }
+      }
+    }
+
+    System.setProperty(SqoopConfiguration.SYSPROP_CONFIG_DIR,
+        tempConfigDirPath);
+  }
+
+
+  private TestUtils() {
+    // Disable explicit object creation
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sqoop/branches/sqoop2/core/src/test/resources/test_config.properties
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/test/resources/test_config.properties?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/resources/test_config.properties (added)
+++ incubator/sqoop/branches/sqoop2/core/src/test/resources/test_config.properties Thu Dec
 1 03:30:01 2011
@@ -0,0 +1,25 @@
+# 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.
+
+# General configuration
+org.apache.sqoop.foo = bar
+
+
+# Logging Configuration
+org.apache.sqoop.log4j.rootLogger=warn, console
+org.apache.sqoop.log4j.logger.org.apache.sqoop=debug,console
+org.apache.sqoop.log4j.appender.console=org.apache.log4j.ConsoleAppender
+org.apache.sqoop.log4j.appender.console.layout=org.apache.log4j.PatternLayout
+org.apache.sqoop.log4j.appender.console.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Modified: incubator/sqoop/branches/sqoop2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/pom.xml Thu Dec  1 03:30:01 2011
@@ -97,10 +97,29 @@ limitations under the License.
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.16</version>
     </dependency>
   </dependencies>
 
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>log4j</groupId>
+        <artifactId>log4j</artifactId>
+        <version>1.2.16</version>
+      </dependency>
+      <dependency>
+        <groupId>javax.servlet</groupId>
+        <artifactId>servlet-api</artifactId>
+        <version>2.5</version>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>4.9</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
   <modules>
     <module>spi</module>
     <module>core</module>
@@ -121,6 +140,15 @@ limitations under the License.
     <pluginManagement>
       <plugins>
         <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>2.3.2</version>
+          <configuration>
+            <source>${maven.compile.source}</source>
+            <target>${maven.compile.target}</target>
+          </configuration>
+        </plugin>
+        <plugin>
           <groupId>org.apache.rat</groupId>
           <artifactId>apache-rat-plugin</artifactId>
           <version>0.8</version>

Modified: incubator/sqoop/branches/sqoop2/server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/server/pom.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/server/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/server/pom.xml Thu Dec  1 03:30:01 2011
@@ -35,11 +35,17 @@ limitations under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.sqoop</groupId>
-      <artifactId>core</artifactId>
+      <artifactId>sqoop-core</artifactId>
       <version>2.0.0-SNAPSHOT</version>
     </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
-  
+
   <build>
     <finalName>sqoop</finalName>
   </build>

Added: incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java?rev=1208941&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
(added)
+++ incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
Thu Dec  1 03:30:01 2011
@@ -0,0 +1,41 @@
+/**
+ * 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.sqoop.server;
+
+import org.apache.sqoop.core.SqoopConfiguration;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+
+/**
+ * Initializes the Sqoop server. This listener is also responsible for
+ * cleaning up any resources occupied by the server during the system shutdown.
+ */
+public class ServerInitializer implements ServletContextListener {
+
+  public void contextDestroyed(ServletContextEvent arg0) {
+    // TODO Auto-generated method stub
+
+  }
+
+  public void contextInitialized(ServletContextEvent arg0) {
+    SqoopConfiguration.initialize();
+
+  }
+}

Propchange: incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sqoop/branches/sqoop2/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/server/src/main/webapp/WEB-INF/web.xml?rev=1208941&r1=1208940&r2=1208941&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/server/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/sqoop/branches/sqoop2/server/src/main/webapp/WEB-INF/web.xml Thu Dec  1 03:30:01
2011
@@ -17,9 +17,15 @@ limitations under the License.
 -->
 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+                       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
   <display-name>Apache Sqoop</display-name>
 
+  <!-- Listeners -->
+  <listener>
+    <listener-class>org.apache.sqoop.server.ServerInitializer</listener-class>
+  </listener>
+
 </web-app>
 



Mime
View raw message