You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sqoop.apache.org by ar...@apache.org on 2011/12/02 04:32:13 UTC
svn commit: r1209352 - in /incubator/sqoop/branches/sqoop2: ./ core/
core/src/main/java/org/apache/sqoop/core/
core/src/test/java/org/apache/sqoop/core/ repository/
repository/repository-derby/ repository/repository-derby/src/
repository/repository-der...
Author: arvind
Date: Fri Dec 2 03:32:03 2011
New Revision: 1209352
URL: http://svn.apache.org/viewvc?rev=1209352&view=rev
Log:
SQOOP-365. Adding skeletal repository code.
Added:
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java (with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java (with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java (with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java (with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java (with props)
incubator/sqoop/branches/sqoop2/repository/
incubator/sqoop/branches/sqoop2/repository/pom.xml
incubator/sqoop/branches/sqoop2/repository/repository-derby/ (with props)
incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java (with props)
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java (with props)
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java (with props)
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/test/
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/test/java/
Modified:
incubator/sqoop/branches/sqoop2/core/pom.xml
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java
incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java
incubator/sqoop/branches/sqoop2/pom.xml
Modified: incubator/sqoop/branches/sqoop2/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/pom.xml?rev=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/core/pom.xml Fri Dec 2 03:32:03 2011
@@ -44,4 +44,20 @@ limitations under the License.
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java (added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,116 @@
+/**
+ * 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 final class ConfigurationConstants {
+
+ /**
+ * All configuration keys are prefixed with this:
+ * <tt>org.apache.sqoop.</tt>
+ */
+ public static final String PREFIX_GLOBAL_CONFIG = "org.apache.sqoop.";
+
+ /**
+ * All logging related configuration is prefixed with this:
+ * <tt>org.apache.sqoop.log4j.</tt>
+ */
+ public static final String PREFIX_LOG_CONFIG = PREFIX_GLOBAL_CONFIG
+ + "log4j.";
+
+ /**
+ * All repository related configuration is prefixed with this:
+ * <tt>org.apache.sqoop.repository.</tt>
+ */
+ public static final String PREFIX_REPO_CONFIG = PREFIX_GLOBAL_CONFIG
+ + "repository.";
+
+ /**
+ * The system property that must be set for specifying the system
+ * configuration directory: <tt>sqoop.config.dir</tt>.
+ */
+ public static final String SYSPROP_CONFIG_DIR = "sqoop.config.dir";
+
+ /**
+ * Bootstrap configuration property that specifies the system configuration
+ * provider: <tt>sqoop.config.provider</tt>.
+ */
+ public static final String BOOTCFG_CONFIG_PROVIDER = "sqoop.config.provider";
+
+ /**
+ * Filename for the bootstrap configuration file:
+ * <tt>sqoop_bootstrap.properties</tt>.
+ */
+ public static final String FILENAME_BOOTCFG_FILE =
+ "sqoop_bootstrap.properties";
+
+ /**
+ * Class name of the repository implementation specified by:
+ * <tt>org.apache.sqoop.repository.provider</tt>
+ */
+ public static final String SYSCFG_REPO_PROVIDER = PREFIX_REPO_CONFIG
+ + "provider";
+
+ /**
+ * Indicates if the repository should create the schema objects as necessary,
+ * specified as a boolean value for the key:
+ * <tt>org.apache.sqoop.repository.create.schema</tt>
+ */
+ public static final String SYSCFG_REPO_CREATE_SCHEMA = PREFIX_REPO_CONFIG
+ + "create.schema";
+
+ /**
+ * JDBC connection URL specified by:
+ * <tt>org.apache.sqoop.repository.jdbc.url</tt>
+ */
+ public static final String SYSCFG_REPO_JDBC_URL = PREFIX_REPO_CONFIG
+ + "jdbc.url";
+
+ /**
+ * JDBC driver to be used, specified by:
+ * <tt>org.apache.sqoop.repository.jdbc.driver</tt>
+ */
+ public static final String SYSCFG_REPO_JDBC_DRIVER = PREFIX_REPO_CONFIG
+ + "jdbc.driver";
+
+ /**
+ * JDBC connection user name, specified by:
+ * <tt>org.apache.sqoop.repository.jdbc.user</tt>
+ */
+ public static final String SYSCFG_REPO_JDBC_USER = PREFIX_REPO_CONFIG
+ + "jdbc.user";
+
+ /**
+ * JDBC connection password, specified by:
+ * <tt>org.apache.sqoop.repository.jdbc.password</tt>
+ */
+ public static final String SYSCFG_REPO_JDBC_PASSWORD = PREFIX_REPO_CONFIG
+ + "jdbc.password";
+
+ /**
+ * Prefix that is used to provide any JDBC specific properties for the
+ * system. Configuration keys which start with this prefix will be stripped
+ * of the prefix and used as regular properties for JDBC connection
+ * initialization.
+ */
+ public static final String PREFIX_SYSCFG_REPO_JDBC_PROPERTIES =
+ PREFIX_REPO_CONFIG + "jdbc.properties.";
+
+ private ConfigurationConstants() {
+ // Disable explicit object creation
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java (added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,67 @@
+/**
+ * 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.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents a configuration snapshot view for the system. Also provides
+ * convenience methods for accessing configuration values.
+ */
+public final class Context {
+
+ private final Map<String, String> parameters;
+
+ public Context(Map<String, String> parameters) {
+ this.parameters = parameters;
+ }
+
+ public String getString(String key) {
+ return parameters.get(key);
+ }
+
+ public String getString(String key, String defaultValue) {
+ String value = getString(key);
+ if (value == null || value.trim().length() == 0) {
+ value = defaultValue;
+ }
+ return value;
+ }
+
+ public boolean getBoolean(String key) {
+ String value = getString(key);
+ boolean result = false;
+ if (value != null) {
+ result = Boolean.valueOf(value);
+ }
+
+ return result;
+ }
+
+ public Map<String, String> getNestedProperties(String prefix) {
+ Map<String, String> subProps = new HashMap<String, String>();
+ for (String key : parameters.keySet()) {
+ if (key.startsWith(prefix)) {
+ subProps.put(key.substring(prefix.length()), parameters.get(key));
+ }
+ }
+
+ return subProps;
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Context.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java (original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/CoreError.java Fri Dec 2 03:32:03 2011
@@ -47,7 +47,13 @@ public enum CoreError implements ErrorCo
CORE_0006("Properties configuration provider unable to load config file"),
/** The configuration system has not been initialized correctly. */
- CORE_0007("System not initialized");
+ CORE_0007("System not initialized"),
+
+ /** The system was unable to find or load the repository provider. */
+ CORE_0008("Invalid repository provider specified"),
+
+ /** An invalid JDBC connection URL was specified. */
+ CORE_0009("Invalid JDBC connection URL specified");
private final String message;
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java (added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,36 @@
+/**
+ * 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 the contract of a Repository used by Sqoop. A Repository allows
+ * Sqoop to store metadata, statistics and other state relevant to Sqoop
+ * Jobs in the system.
+ */
+public interface Repository {
+
+
+ /**
+ * Initializes the repository. If the flag <tt>createSchema</tt> is set to
+ * <tt>true</tt>, the repository implementation will create the necessary
+ * schema objects if they are missing.
+ * @param context
+ */
+ public void initialize(RepositoryContext context);
+
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/Repository.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java (added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,133 @@
+/**
+ * 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.util.Map;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+
+
+public final class RepositoryContext {
+
+ private static final Logger LOG = Logger.getLogger(RepositoryContext.class);
+
+ private final Context context;
+ private final String provider;
+ private final boolean createSchema;
+ private final String jdbcConnectUrl;
+ private final String jdbcDriverClass;
+ private final String jdbcUserName;
+ private final char[] jdbcPassword;
+ private final Properties jdbcConnectionProperties;
+
+ public RepositoryContext(Context context) {
+ this.context = context;
+
+ provider = context.getString(
+ ConfigurationConstants.SYSCFG_REPO_PROVIDER);
+
+ createSchema = context.getBoolean(
+ ConfigurationConstants.SYSCFG_REPO_CREATE_SCHEMA);
+
+ jdbcConnectUrl = context.getString(
+ ConfigurationConstants.SYSCFG_REPO_JDBC_URL);
+
+ jdbcDriverClass = context.getString(
+ ConfigurationConstants.SYSCFG_REPO_JDBC_DRIVER);
+
+ jdbcUserName = context.getString(
+ ConfigurationConstants.SYSCFG_REPO_JDBC_USER);
+
+ String password = context.getString(
+ ConfigurationConstants.SYSCFG_REPO_JDBC_PASSWORD);
+
+ if (password != null) {
+ jdbcPassword = password.toCharArray();
+ } else {
+ jdbcPassword = null;
+ }
+
+ jdbcConnectionProperties = new Properties();
+
+ Map<String, String> params = context.getNestedProperties(
+ ConfigurationConstants.PREFIX_SYSCFG_REPO_JDBC_PROPERTIES);
+ for (String key : params.keySet()) {
+ jdbcConnectionProperties.setProperty(key, params.get(key));
+ }
+
+ if (LOG.isInfoEnabled()) {
+ StringBuilder sb = new StringBuilder("[repo-ctx] ");
+ sb.append("provider=").append(provider).append(", ");
+ sb.append("create-schema=").append(createSchema).append(", ");
+ sb.append("conn-url=").append(jdbcConnectUrl).append(", ");
+ sb.append("driver=").append(jdbcDriverClass).append(", ");
+ sb.append("user=").append(jdbcUserName).append(", ");
+ sb.append("password=").append("*****").append(", ");
+ sb.append("jdbc-props={");
+ boolean first = true;
+ for (String key : params.keySet()) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(key).append("=");
+ if (key.equalsIgnoreCase("password")) {
+ sb.append("*****");
+ } else {
+ sb.append(params.get(key));
+ }
+ }
+ sb.append("}");
+
+ LOG.info(sb.toString());
+ }
+ }
+
+ public String getProviderClass() {
+ return provider;
+ }
+
+ public String getJdbcConnectionUrl() {
+ return jdbcConnectUrl;
+ }
+
+ public String getJdbcDriverClass() {
+ return jdbcDriverClass;
+ }
+
+ public String getJdbcUserName() {
+ return jdbcUserName;
+ }
+
+ public boolean shouldCreateSchema() {
+ return createSchema;
+ }
+
+ public char[] getJdbcPassword() {
+ return jdbcPassword;
+ }
+
+ public Properties getJdbcConnectionProperties() {
+ Properties props = new Properties();
+ props.putAll(jdbcConnectionProperties);
+
+ return props;
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java (added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,80 @@
+/**
+ * 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.apache.log4j.Logger;
+
+public final class RepositoryManager {
+
+ private static final Logger LOG = Logger.getLogger(RepositoryManager.class);
+
+ private static Repository instance;
+ private static RepositoryContext repoContext;
+
+ public synchronized static void initialize() {
+ repoContext = new RepositoryContext(SqoopConfiguration.getContext());
+
+ String repoProviderClassName = repoContext.getProviderClass();
+
+ if (repoProviderClassName == null
+ || repoProviderClassName.trim().length() == 0) {
+ throw new SqoopException(CoreError.CORE_0008,
+ ConfigurationConstants.SYSCFG_REPO_PROVIDER);
+ }
+
+ Class<?> rpClass = null;
+ try {
+ rpClass = Class.forName(repoProviderClassName);
+ } catch (ClassNotFoundException ex) {
+ LOG.debug("Exception while loading class: " + repoProviderClassName, ex);
+ }
+
+ if (rpClass == null) {
+ // try context loader
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ if (ctxLoader != null) {
+ try {
+ rpClass = ctxLoader.loadClass(repoProviderClassName);
+ } catch (ClassNotFoundException ex) {
+ LOG.debug("Exception while load class: " + repoProviderClassName, ex);
+ }
+ }
+ }
+
+ if (rpClass == null) {
+ throw new SqoopException(CoreError.CORE_0008, repoProviderClassName);
+ }
+
+ try {
+ instance = (Repository) rpClass.newInstance();
+ } catch (Exception ex) {
+ throw new SqoopException(CoreError.CORE_0008, repoProviderClassName, ex);
+ }
+
+ String connectUrl = repoContext.getJdbcConnectionUrl();
+ if (connectUrl == null || connectUrl.trim().length() == 0) {
+ throw new SqoopException(CoreError.CORE_0009);
+ }
+
+ instance.initialize(repoContext);
+ }
+
+ public synchronized static Repository getInstance() {
+ return instance;
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/RepositoryManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java (original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java Fri Dec 2 03:32:03 2011
@@ -21,31 +21,21 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.HashMap;
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 final class SqoopConfiguration {
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;
+ private static Map<String, String> config = null;
public synchronized static void initialize() {
if (initialized) {
@@ -53,10 +43,11 @@ public class SqoopConfiguration {
return;
}
- String configDirPath = System.getProperty(SYSPROP_CONFIG_DIR);
+ String configDirPath = System.getProperty(
+ ConfigurationConstants.SYSPROP_CONFIG_DIR);
if (configDirPath == null || configDirPath.trim().length() == 0) {
throw new SqoopException(CoreError.CORE_0001, "Environment variable "
- + SYSPROP_CONFIG_DIR + " is not set.");
+ + ConfigurationConstants.SYSPROP_CONFIG_DIR + " is not set.");
}
configDir = new File(configDirPath);
@@ -68,7 +59,7 @@ public class SqoopConfiguration {
try {
String configDirCanonicalPath = configDir.getCanonicalPath();
bootstrapConfigFilePath = configDirCanonicalPath
- + "/" + FILENAME_BOOTSTRAP_CONFIG;
+ + "/" + ConfigurationConstants.FILENAME_BOOTCFG_FILE;
} catch (IOException ex) {
throw new SqoopException(CoreError.CORE_0001, configDirPath, ex);
@@ -91,12 +82,12 @@ public class SqoopConfiguration {
}
String configProviderClassName = bootstrapProperties.getProperty(
- BOOTPROP_CONFIG_PROVIDER);
+ ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER);
if (configProviderClassName == null
|| configProviderClassName.trim().length() == 0) {
throw new SqoopException(
- CoreError.CORE_0003, BOOTPROP_CONFIG_PROVIDER);
+ CoreError.CORE_0003, ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER);
}
Class<?> configProviderClass = null;
@@ -112,8 +103,8 @@ public class SqoopConfiguration {
try {
configProviderClass = ctxLoader.loadClass(configProviderClassName);
} catch (ClassNotFoundException cnfe) {
- LOG.warn("Exception while trying to load configuration provider",
- cnfe);
+ LOG.warn("Exception while trying to load configuration provider: "
+ + configProviderClassName, cnfe);
}
}
}
@@ -129,6 +120,7 @@ public class SqoopConfiguration {
configProviderClassName, ex);
}
+ // Initialize the configuration provider
provider.initialize(configDir, bootstrapProperties);
refreshConfiguration();
provider.registerListener(new CoreConfigurationListener());
@@ -136,19 +128,23 @@ public class SqoopConfiguration {
initialized = true;
}
- public synchronized static void registerListener(
- ConfigurationListener listener) {
+ public synchronized static Context getContext() {
if (!initialized) {
throw new SqoopException(CoreError.CORE_0007);
}
- provider.registerListener(listener);
+
+ Map<String,String> parameters = new HashMap<String, String>();
+ parameters.putAll(config);
+
+ return new Context(parameters);
}
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());
+ if (key.startsWith(ConfigurationConstants.PREFIX_LOG_CONFIG)) {
+ String logConfigKey = key.substring(
+ ConfigurationConstants.PREFIX_GLOBAL_CONFIG.length());
props.put(logConfigKey, config.get(key));
}
}
@@ -156,11 +152,16 @@ public class SqoopConfiguration {
PropertyConfigurator.configure(props);
}
- private synchronized static void refreshConfiguration() {
+ private synchronized static void refreshConfiguration()
+ {
config = provider.getConfiguration();
configureLogging();
}
+ private SqoopConfiguration() {
+ // Disable explicit object creation
+ }
+
public static class CoreConfigurationListener implements ConfigurationListener
{
@Override
Modified: 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=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java (original)
+++ incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestConfiguration.java Fri Dec 2 03:32:03 2011
@@ -25,7 +25,7 @@ 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);
+ System.getProperties().remove(ConfigurationConstants.SYSPROP_CONFIG_DIR);
try {
SqoopConfiguration.initialize();
} catch (Exception ex) {
@@ -37,7 +37,7 @@ public class TestConfiguration {
@Test
public void testConfigurationInitSuccess() throws Exception {
- TestUtils.setupTestConfiguration();
+ TestUtils.setupTestConfiguration(null);
SqoopConfiguration.initialize();
}
}
Modified: 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=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java (original)
+++ incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/TestUtils.java Fri Dec 2 03:32:03 2011
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.Properties;
import org.apache.log4j.Logger;
@@ -39,9 +40,11 @@ public class TestUtils {
* directory. This is useful for running tests without necessarily having to
* create an installation layout.
*
+ * @param config any properties that you would like to set in the system
* @throws Exception
*/
- public static void setupTestConfiguration() throws Exception {
+ public static void setupTestConfiguration(Properties config) throws Exception
+ {
File tempDir = null;
File targetDir = new File("target");
if (targetDir.exists() && targetDir.isDirectory()) {
@@ -63,7 +66,7 @@ public class TestUtils {
}
File bootconfigFile = new File(tempConfigDir,
- SqoopConfiguration.FILENAME_BOOTSTRAP_CONFIG);
+ ConfigurationConstants.FILENAME_BOOTCFG_FILE);
if (!bootconfigFile.createNewFile()) {
throw new Exception("Unable to create config file: " + bootconfigFile);
@@ -123,7 +126,7 @@ public class TestUtils {
}
}
- System.setProperty(SqoopConfiguration.SYSPROP_CONFIG_DIR,
+ System.setProperty(ConfigurationConstants.SYSPROP_CONFIG_DIR,
tempConfigDirPath);
}
Modified: incubator/sqoop/branches/sqoop2/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/pom.xml?rev=1209352&r1=1209351&r2=1209352&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/pom.xml Fri Dec 2 03:32:03 2011
@@ -123,6 +123,7 @@ limitations under the License.
<modules>
<module>spi</module>
<module>core</module>
+ <module>repository</module>
<module>server</module>
<module>client</module>
<module>docs</module>
@@ -168,6 +169,11 @@ limitations under the License.
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.2</version>
+ </plugin>
</plugins>
</pluginManagement>
</build>
Added: incubator/sqoop/branches/sqoop2/repository/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/pom.xml?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/pom.xml (added)
+++ incubator/sqoop/branches/sqoop2/repository/pom.xml Fri Dec 2 03:32:03 2011
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>sqoop</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>repository</artifactId>
+ <name>Sqoop Repository</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>repository-derby</module>
+ </modules>
+
+</project>
Propchange: incubator/sqoop/branches/sqoop2/repository/repository-derby/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Dec 2 03:32:03 2011
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target
Added: incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml (added)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml Fri Dec 2 03:32:03 2011
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>repository</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.sqoop.repository</groupId>
+ <artifactId>sqoop-repository-derby</artifactId>
+ <name>Sqoop Derby Repository</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-core</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sqoop</groupId>
+ <artifactId>sqoop-core</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
Added: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java (added)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,27 @@
+/**
+ * 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.repository.derby;
+
+public final class DerbyRepoConfigurationConstants {
+
+ public static final String PREFIX_DERBY = "derby.";
+
+ private DerbyRepoConfigurationConstants() {
+ // Disable explicit object creation
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoConfigurationConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java (added)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java Fri Dec 2 03:32:03 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.repository.derby;
+
+import org.apache.sqoop.core.ErrorCode;
+
+public enum DerbyRepoError implements ErrorCode {
+
+ /** An unknown error has occurred. */
+ DERBYREPO_0000("An unknown error has occurred");
+
+
+ private final String message;
+
+ private DerbyRepoError(String message) {
+ this.message = message;
+ }
+
+ public String getCode() {
+ return name();
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java?rev=1209352&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java (added)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java Fri Dec 2 03:32:03 2011
@@ -0,0 +1,30 @@
+/**
+ * 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.repository.derby;
+
+import org.apache.sqoop.core.Repository;
+import org.apache.sqoop.core.RepositoryContext;
+
+public class DerbyRepository implements Repository {
+
+ @Override
+ public void initialize(RepositoryContext context) {
+ // FIXME
+ }
+
+}
Propchange: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepository.java
------------------------------------------------------------------------------
svn:eol-style = native