Author: arvind
Date: Wed Dec 14 04:00:38 2011
New Revision: 1214050
URL: http://svn.apache.org/viewvc?rev=1214050&view=rev
Log:
SQOOP-365. Skeletal connector code wired in for initialization.
Added:
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
(with props)
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/
incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/sqoopconnector.properties
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorError.java
(with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
(with props)
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
(with props)
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java
(with props)
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java
(with props)
incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java
(with props)
Modified:
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/SqoopConfiguration.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
incubator/sqoop/branches/sqoop2/server/pom.xml
incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
Added: incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
(added)
+++ incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,33 @@
+/**
+ * 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.connector.jdbc;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+import org.apache.sqoop.spi.SqoopConnector;
+
+public class GenericJdbcConnector implements SqoopConnector {
+
+ @Override
+ public ResourceBundle getBundle(Locale locale) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/sqoopconnector.properties
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/sqoopconnector.properties?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/sqoopconnector.properties
(added)
+++ incubator/sqoop/branches/sqoop2/connector/connector-generic-jdbc/src/main/resources/sqoopconnector.properties
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,17 @@
+# 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.
+
+# Generic JDBC Connector Properties
+org.apache.sqoop.connector = org.apache.sqoop.connector.jdbc.GenericJdbcConnector
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorError.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorError.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorError.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,55 @@
+/**
+ * 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.connector;
+
+import org.apache.sqoop.core.ErrorCode;
+
+public enum ConnectorError implements ErrorCode {
+
+ /** An unknown error has occurred. */
+ CONN_0000("An unknown error has occurred"),
+
+ /** The system was not able to initialize the configured connectors. */
+ CONN_0001("Unable to initialize connectors"),
+
+ /** No connectors were found in the system. */
+ CONN_0002("No connectors were found in the system"),
+
+ /** A problem was encountered while loading the connector configuration. */
+ CONN_0003("Failed to load connector configuration"),
+
+ /** A connector configuration file did not include the provider class name.*/
+ CONN_0004("Connector configuration did not include provider class name"),
+
+ /** An exception occurred while attempting to instantiate the connector. */
+ CONN_0005("Failed to instantiate connector class");
+
+ private final String message;
+
+ private ConnectorError(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/connector/ConnectorError.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,76 @@
+/**
+ * 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.connector;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.core.ConfigurationConstants;
+import org.apache.sqoop.core.SqoopException;
+import org.apache.sqoop.spi.SqoopConnector;
+
+public final class ConnectorHandler {
+
+ private static final Logger LOG = Logger.getLogger(ConnectorHandler.class);
+
+ private final Properties properties = new Properties();
+
+ private final String connectorClassName;
+ private final SqoopConnector connector;
+
+ public ConnectorHandler(URL configFileUrl) {
+ try {
+ properties.load(configFileUrl.openStream());
+ } catch (IOException ex) {
+ throw new SqoopException(ConnectorError.CONN_0003,
+ configFileUrl.toString(), ex);
+ }
+
+ connectorClassName =
+ properties.getProperty(ConfigurationConstants.CONPROP_PROVIDER_CLASS);
+
+ if (connectorClassName == null || connectorClassName.trim().length() == 0) {
+ throw new SqoopException(ConnectorError.CONN_0004,
+ ConfigurationConstants.CONPROP_PROVIDER_CLASS);
+ }
+
+ Class<?> connectorClass = null;
+ try {
+ connectorClass = Class.forName(connectorClassName);
+ } catch (ClassNotFoundException ex) {
+ throw new SqoopException(ConnectorError.CONN_0005,
+ connectorClassName, ex);
+ }
+
+ try {
+ connector = (SqoopConnector) connectorClass.newInstance();
+ } catch (IllegalAccessException ex) {
+ throw new SqoopException(ConnectorError.CONN_0005,
+ connectorClassName, ex);
+ } catch (InstantiationException ex) {
+ throw new SqoopException(ConnectorError.CONN_0005,
+ connectorClassName, ex);
+ }
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Connector [" + connectorClassName + "] initialized.");
+ }
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
(added)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,86 @@
+/**
+ * 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.connector;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.sqoop.core.ConfigurationConstants;
+import org.apache.sqoop.core.SqoopException;
+
+public class ConnectorManager {
+
+ private static final Logger LOG = Logger.getLogger(ConnectorManager.class);
+
+ private static List<ConnectorHandler> handlers =
+ new ArrayList<ConnectorHandler>();
+
+ public static synchronized void initialize() {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Begin connector manager initialization");
+ }
+
+ List<URL> connectorConfigs = new ArrayList<URL>();
+
+ try {
+ Enumeration<URL> appPathConfigs =
+ ConnectorManager.class.getClassLoader().getResources(
+ ConfigurationConstants.FILENAME_CONNECTOR_PROPERTIES);
+
+ while (appPathConfigs.hasMoreElements()) {
+ connectorConfigs.add(appPathConfigs.nextElement());
+ }
+
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+
+ if (ctxLoader != null) {
+ Enumeration<URL> ctxPathConfigs = ctxLoader.getResources(
+ ConfigurationConstants.FILENAME_CONNECTOR_PROPERTIES);
+
+ while (ctxPathConfigs.hasMoreElements()) {
+ URL configUrl = ctxPathConfigs.nextElement();
+ if (!connectorConfigs.contains(configUrl)) {
+ connectorConfigs.add(configUrl);
+ }
+ }
+ }
+
+ LOG.info("Connector config urls: " + connectorConfigs);
+
+ if (connectorConfigs.size() == 0) {
+ throw new SqoopException(ConnectorError.CONN_0002);
+ }
+
+ for (URL url : connectorConfigs) {
+ handlers.add(new ConnectorHandler(url));
+ }
+ } catch (IOException ex) {
+ throw new SqoopException(ConnectorError.CONN_0001, ex);
+ }
+ }
+
+
+ public static synchronized void destroy() {
+ // FIXME
+ }
+
+}
Propchange: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/connector/ConnectorManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationConstants.java
Wed Dec 14 04:00:38 2011
@@ -52,6 +52,13 @@ public final class ConfigurationConstant
"sqoop_bootstrap.properties";
+ public static final String FILENAME_CONNECTOR_PROPERTIES =
+ "sqoopconnector.properties";
+
+ public static final String CONPROP_PROVIDER_CLASS =
+ "org.apache.sqoop.connector";
+
+
private ConfigurationConstants() {
// Disable explicit object creation
}
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/ConfigurationProvider.java
Wed Dec 14 04:00:38 2011
@@ -25,6 +25,8 @@ public interface ConfigurationProvider {
public void initialize(File configDir, Properties bootstrapCongiruation);
+ public void destroy();
+
public void registerListener(ConfigurationListener listener);
public Map<String, String> getConfiguration();
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/core/PropertiesConfigurationProvider.java
Wed Dec 14 04:00:38 2011
@@ -45,6 +45,9 @@ public class PropertiesConfigurationProv
private File configFile;
+ private ConfigFilePoller poller;
+ private Thread pollerThread;
+
public PropertiesConfigurationProvider() {
// Default constructor
}
@@ -62,6 +65,23 @@ public class PropertiesConfigurationProv
return config;
}
+ @Override
+ public synchronized void destroy() {
+ LOG.info("Shutting down configuration poller thread");
+ if (poller != null) {
+ poller.setShutdown();
+ }
+ if (pollerThread != null) {
+ pollerThread.interrupt();
+ try {
+ pollerThread.join();
+ } catch (InterruptedException ex) {
+ // No handling requried - best effort only
+ }
+ }
+ poller = null;
+ pollerThread = null;
+ }
@Override
public synchronized void initialize(
@@ -72,9 +92,9 @@ public class PropertiesConfigurationProv
}
loadConfiguration(false); // at least one load must succeed
-
- Thread pollerThread = new Thread(new ConfigFilePoller(configFile));
- pollerThread.setName("config-file-poller");
+ poller = new ConfigFilePoller(configFile);
+ pollerThread = new Thread(poller);
+ pollerThread.setName("sqoop-config-file-poller");
pollerThread.setDaemon(true);
LOG.info("Starting config file poller thread");
@@ -113,16 +133,26 @@ public class PropertiesConfigurationProv
}
}
- class ConfigFilePoller implements Runnable {
+ private class ConfigFilePoller implements Runnable {
private File file;
private long lastUpdatedAt;
+ private boolean shutdown;
+
ConfigFilePoller(File configFile) {
this.file = configFile;
lastUpdatedAt = configFile.lastModified();
}
+ synchronized void setShutdown() {
+ shutdown = true;
+ }
+
+ private synchronized boolean isShutdown() {
+ return shutdown;
+ }
+
@Override
public void run() {
@@ -143,6 +173,10 @@ public class PropertiesConfigurationProv
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
+
+ if (isShutdown()) {
+ break;
+ }
}
}
}
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=1214050&r1=1214049&r2=1214050&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
Wed Dec 14 04:00:38 2011
@@ -140,10 +140,17 @@ public final class SqoopConfiguration {
}
public synchronized static void destroy() {
- initialized = false;
- configDir = null;
+ if (provider != null) {
+ try {
+ provider.destroy();
+ } catch (Exception ex) {
+ LOG.error("Failed to shutdown configuration provider", ex);
+ }
+ }
provider = null;
+ configDir = null;
config = null;
+ initialized = false;
}
private synchronized static void configureLogging() {
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryContext.java
Wed Dec 14 04:00:38 2011
@@ -95,6 +95,10 @@ public final class JdbcRepositoryContext
String txIsolation = context.getString(
RepoConfigurationConstants.SYSCFG_REPO_JDBC_TX_ISOLATION);
+ if (txIsolation == null || txIsolation.trim().length() == 0) {
+ throw new SqoopException(RepositoryError.JDBCREPO_0004);
+ }
+
try {
transactionIsolation = JdbcTransactionIsolation.getByName(txIsolation);
} catch (IllegalArgumentException ex) {
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryHandler.java
Wed Dec 14 04:00:38 2011
@@ -24,6 +24,8 @@ public interface JdbcRepositoryHandler {
public void initialize(DataSource dataSource,
JdbcRepositoryContext repoContext);
+ public void shutdown();
+
public Repository getRepository();
}
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcRepositoryProvider.java
Wed Dec 14 04:00:38 2011
@@ -17,6 +17,9 @@
*/
package org.apache.sqoop.repository;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
@@ -47,6 +50,8 @@ public class JdbcRepositoryProvider impl
private DataSource dataSource;
private JdbcRepositoryHandler handler;
+ private Driver driver;
+
public JdbcRepositoryProvider() {
// Default constructor
@@ -61,6 +66,29 @@ public class JdbcRepositoryProvider impl
LOG.info("JdbcRepository initialized.");
}
+ @Override
+ public synchronized void destroy() {
+ try {
+ connectionPool.close();
+ } catch (Exception ex) {
+ LOG.error("Failed to shutdown connection pool", ex);
+ }
+
+ handler.shutdown();
+
+ if (driver != null) {
+ try {
+ DriverManager.deregisterDriver(driver);
+ } catch (SQLException ex) {
+ LOG.error("Failed to deregister driver", ex);
+ }
+ }
+ handler = null;
+ driver = null;
+ dataSource = null;
+
+ }
+
private void initializeRepositoryHandler() {
String jdbcHandlerClassName = repoContext.getHandlerClassName();
@@ -90,7 +118,9 @@ public class JdbcRepositoryProvider impl
}
// Initialize a datasource
- if (ClassLoadingUtils.loadClass(jdbcDriverClassName) == null) {
+ Class<?> driverClass = ClassLoadingUtils.loadClass(jdbcDriverClassName);
+
+ if (driverClass == null) {
throw new SqoopException(RepositoryError.JDBCREPO_0003,
jdbcDriverClassName);
}
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/JdbcTransactionIsolation.java
Wed Dec 14 04:00:38 2011
@@ -47,6 +47,9 @@ public enum JdbcTransactionIsolation {
}
public static JdbcTransactionIsolation getByName(String name) {
+ if (name == null || name.trim().length() == 0) {
+ return null;
+ }
return valueOf(name.trim().toUpperCase());
}
}
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryError.java
Wed Dec 14 04:00:38 2011
@@ -62,7 +62,10 @@ public enum RepositoryError implements E
JDBCREPO_0008("Attempt to commit a transaction marked for rollback"),
/** The system was unable to finalize the transaction. */
- JDBCREPO_0009("Failed to finalize transaction");
+ JDBCREPO_0009("Failed to finalize transaction"),
+
+ /** The system was not able to dergeister the driver during shutdown. */
+ JDBCREPO_0010("Unable to deregister driver during shutdown");
private final String message;
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryManager.java
Wed Dec 14 04:00:38 2011
@@ -67,7 +67,15 @@ public final class RepositoryManager {
LOG.info("Repository initialized: OK");
}
- public synchronized Repository getRepository() {
+ public static synchronized void destroy() {
+ try {
+ provider.destroy();
+ } catch (Exception ex) {
+ LOG.error("Failed to shutdown repository provider", ex);
+ }
+ }
+
+ public static synchronized Repository getRepository() {
return provider.getRepository();
}
}
Modified: incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/main/java/org/apache/sqoop/repository/RepositoryProvider.java
Wed Dec 14 04:00:38 2011
@@ -23,6 +23,8 @@ public interface RepositoryProvider {
public void initialize(Context context);
+ public void destroy();
+
public Repository getRepository();
}
Modified: incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
(original)
+++ incubator/sqoop/branches/sqoop2/core/src/test/java/org/apache/sqoop/core/MockInvalidConfigurationProvider.java
Wed Dec 14 04:00:38 2011
@@ -45,4 +45,10 @@ public class MockInvalidConfigurationPro
return null;
}
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/pom.xml Wed Dec 14 04:00:38
2011
@@ -39,6 +39,11 @@ limitations under the License.
</dependency>
<dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
(original)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepoError.java
Wed Dec 14 04:00:38 2011
@@ -25,7 +25,10 @@ public enum DerbyRepoError implements Er
DERBYREPO_0000("An unknown error has occurred"),
/** The Derby Repository handler was unable to determine if schema exists.*/
- DERBYREPO_0001("Unable to determine if schema exists");
+ DERBYREPO_0001("Unable to determine if schema exists"),
+
+ /** The system was unable to shutdown embedded derby repository server. */
+ DERBYREPO_0002("Unable to shutdown embedded Derby instance");
private final String message;
Modified: incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
(original)
+++ incubator/sqoop/branches/sqoop2/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java
Wed Dec 14 04:00:38 2011
@@ -18,6 +18,7 @@
package org.apache.sqoop.repository.derby;
import java.sql.Connection;
+import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@@ -41,6 +42,10 @@ public class DerbyRepositoryHandler impl
"SELECT SCHEMAID FROM SYS.SYSSCHEMAS WHERE SCHEMANAME = '"
+ SCHEMA_SQOOP + "'";
+ private static final String EMBEDDED_DERBY_DRIVER_CLASSNAME =
+ "org.apache.derby.jdbc.EmbeddedDriver";
+
+
private JdbcRepositoryContext repoContext;
private DataSource dataSource;
@@ -51,6 +56,7 @@ public class DerbyRepositoryHandler impl
LOG.trace("DerbyRepositoryHandler begin initialization");
}
+ this.dataSource = dataSource;
repoContext = ctx;
if (repoContext.shouldCreateSchema()) {
@@ -68,6 +74,45 @@ public class DerbyRepositoryHandler impl
return null;
}
+ @Override
+ public synchronized void shutdown() {
+ String driver = repoContext.getDriverClass();
+ if (driver != null && driver.equals(EMBEDDED_DERBY_DRIVER_CLASSNAME)) {
+ // Using embedded derby. Needs explicit shutdown
+ String connectUrl = repoContext.getConnectionUrl();
+ if (connectUrl.startsWith("jdbc:derby:")) {
+ int index = connectUrl.indexOf(";");
+ String baseUrl = null;
+ if (index != -1) {
+ baseUrl = connectUrl.substring(0, index+1);
+ } else {
+ baseUrl = connectUrl + ";";
+ }
+ String shutDownUrl = baseUrl + "shutdown=true";
+
+ LOG.debug("Attempting to shutdown embedded Derby using URL: "
+ + shutDownUrl);
+
+ try {
+ DriverManager.getConnection(shutDownUrl);
+ } catch (SQLException ex) {
+ // Shutdown for one db instance is expected to raise SQL STATE 45000
+ if (ex.getErrorCode() != 45000) {
+ throw new SqoopException(
+ DerbyRepoError.DERBYREPO_0002, shutDownUrl, ex);
+ }
+ LOG.info("Embedded Derby shutdown raised SQL STATE "
+ + "45000 as expected.");
+ }
+ } else {
+ LOG.warn("Even though embedded Derby drvier was loaded, the connect "
+ + "URL is of an unexpected form: " + connectUrl + ". Therfore no "
+ + "attempt will be made to shutdown embedded Derby instance.");
+ }
+
+ }
+ }
+
private void createSchema() {
// TODO implement this
@@ -91,10 +136,12 @@ public class DerbyRepositoryHandler impl
connection.commit();
} catch (SQLException ex) {
- try {
- connection.rollback();
- } catch (SQLException ex2) {
- LOG.error("Unable to rollback transaction", ex2);
+ if (connection != null) {
+ try {
+ connection.rollback();
+ } catch (SQLException ex2) {
+ LOG.error("Unable to rollback transaction", ex2);
+ }
}
throw new SqoopException(DerbyRepoError.DERBYREPO_0001, ex);
} finally {
Modified: incubator/sqoop/branches/sqoop2/server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/server/pom.xml?rev=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/server/pom.xml (original)
+++ incubator/sqoop/branches/sqoop2/server/pom.xml Wed Dec 14 04:00:38 2011
@@ -40,6 +40,18 @@ limitations under the License.
</dependency>
<dependency>
+ <groupId>org.apache.sqoop.repository</groupId>
+ <artifactId>sqoop-repository-derby</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sqoop.connector</groupId>
+ <artifactId>sqoop-connector-generic-jdbc</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
Modified: 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=1214050&r1=1214049&r2=1214050&view=diff
==============================================================================
--- incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
(original)
+++ incubator/sqoop/branches/sqoop2/server/src/main/java/org/apache/sqoop/server/ServerInitializer.java
Wed Dec 14 04:00:38 2011
@@ -17,11 +17,15 @@
*/
package org.apache.sqoop.server;
-import org.apache.sqoop.core.SqoopConfiguration;
-
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import org.apache.log4j.Logger;
+import org.apache.sqoop.connector.ConnectorManager;
+import org.apache.sqoop.core.SqoopConfiguration;
+import org.apache.sqoop.core.SqoopException;
+import org.apache.sqoop.repository.RepositoryManager;
+
/**
* Initializes the Sqoop server. This listener is also responsible for
@@ -29,13 +33,23 @@ import javax.servlet.ServletContextListe
*/
public class ServerInitializer implements ServletContextListener {
- public void contextDestroyed(ServletContextEvent arg0) {
- // TODO Auto-generated method stub
+ private static final Logger LOG =
+ Logger.getLogger(ServerInitializer.class);
+ public void contextDestroyed(ServletContextEvent arg0) {
+ ConnectorManager.destroy();
+ RepositoryManager.destroy();
+ SqoopConfiguration.destroy();
}
public void contextInitialized(ServletContextEvent arg0) {
- SqoopConfiguration.initialize();
-
+ try {
+ SqoopConfiguration.initialize();
+ RepositoryManager.initialize();
+ ConnectorManager.initialize();
+ } catch (RuntimeException ex) {
+ LOG.error("Server startup failure", ex);
+ throw ex;
+ }
}
}
Added: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java
(added)
+++ incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,69 @@
+/**
+ * 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.spi;
+
+import java.util.Locale;
+
+public class Parameter {
+
+ private final ParameterType type;
+ private final String name;
+ private final String label;
+
+ private String value;
+ private boolean error;
+ private String errorMessage;
+
+ public Parameter(ParameterType type, String name, String label) {
+ this.type = type;
+ this.name = name;
+ this.label = label;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public ParameterType getType() {
+ return type;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public boolean isError() {
+ return error;
+ }
+
+ public void setError(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public String getErrorMessage(Locale locale) {
+ return errorMessage;
+ }
+}
Propchange: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/Parameter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java
(added)
+++ incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java
Wed Dec 14 04:00:38 2011
@@ -0,0 +1,29 @@
+/**
+ * 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.spi;
+
+public enum ParameterType {
+
+ BOOLEAN,
+
+ STRING,
+
+ SINGLE_CHOICE,
+
+ MULTIPLE_CHOICE;
+}
Propchange: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/ParameterType.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java
URL: http://svn.apache.org/viewvc/incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java?rev=1214050&view=auto
==============================================================================
--- incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java
(added)
+++ incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java
Wed Dec 14 04:00:38 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.spi;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public interface SqoopConnector {
+
+ public ResourceBundle getBundle(Locale locale);
+
+}
Propchange: incubator/sqoop/branches/sqoop2/spi/src/main/java/org/apache/sqoop/spi/SqoopConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
|