5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-19 02:10:54 +08:00

SQOOP-997: Sqoop2: Upgrade: Provide ability to disable the automatic upgrade

(Mengwei Ding via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2013-07-02 12:54:44 -07:00
parent 226044d3b3
commit 8c74223b59
7 changed files with 56 additions and 12 deletions

View File

@ -53,6 +53,11 @@ public class ConnectorManager implements Reconfigurable {
*/ */
private static ConnectorManager instance; private static ConnectorManager instance;
/**
* Default connector auto upgrade option value
*/
private static boolean DEFAULT_AUTO_UPGRADE = false;
/** /**
* Create default object by default. * Create default object by default.
* *
@ -185,7 +190,9 @@ public synchronized void initialize() {
throw new SqoopException(ConnectorError.CONN_0001, ex); throw new SqoopException(ConnectorError.CONN_0001, ex);
} }
registerConnectors(); boolean autoUpgrade = SqoopConfiguration.getInstance().getContext().getBoolean(
ConfigurationConstants.CONNECTOR_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE);
registerConnectors(autoUpgrade);
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this)); SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));
@ -194,7 +201,7 @@ public synchronized void initialize() {
} }
} }
private synchronized void registerConnectors() { private synchronized void registerConnectors(boolean autoUpgrade) {
Repository repository = RepositoryManager.getInstance().getRepository(); Repository repository = RepositoryManager.getInstance().getRepository();
RepositoryTransaction rtx = null; RepositoryTransaction rtx = null;
@ -205,7 +212,7 @@ private synchronized void registerConnectors() {
ConnectorHandler handler = handlerMap.get(name); ConnectorHandler handler = handlerMap.get(name);
MConnector connectorMetadata = handler.getMetadata(); MConnector connectorMetadata = handler.getMetadata();
MConnector registeredMetadata = MConnector registeredMetadata =
repository.registerConnector(connectorMetadata); repository.registerConnector(connectorMetadata, autoUpgrade);
// Set registered metadata instead of connector metadata as they will // Set registered metadata instead of connector metadata as they will
// have filled persistent ids. We should be confident at this point that // have filled persistent ids. We should be confident at this point that

View File

@ -70,6 +70,11 @@ public final class ConfigurationConstants {
public static final String PROPERTIES_PROVIDER_SLEEP = public static final String PROPERTIES_PROVIDER_SLEEP =
PREFIX_PROPERTIES_PROVIDER_CONFIG + "sleep"; PREFIX_PROPERTIES_PROVIDER_CONFIG + "sleep";
public static final String CONNECTOR_AUTO_UPGRADE =
"org.apache.sqoop.connector.autoupgrade";
public static final String FRAMEWORK_AUTO_UPGRADE =
"org.apache.sqoop.framework.autoupgrade";
private ConfigurationConstants() { private ConfigurationConstants() {
// Disable explicit object creation // Disable explicit object creation

View File

@ -19,6 +19,7 @@
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.sqoop.connector.spi.MetadataUpgrader; import org.apache.sqoop.connector.spi.MetadataUpgrader;
import org.apache.sqoop.core.ConfigurationConstants;
import org.apache.sqoop.core.Reconfigurable; import org.apache.sqoop.core.Reconfigurable;
import org.apache.sqoop.core.SqoopConfiguration; import org.apache.sqoop.core.SqoopConfiguration;
import org.apache.sqoop.core.SqoopConfiguration.CoreConfigurationListener; import org.apache.sqoop.core.SqoopConfiguration.CoreConfigurationListener;
@ -105,6 +106,10 @@ public static void setInstance(FrameworkManager newInstance) {
*/ */
private final MetadataUpgrader upgrader; private final MetadataUpgrader upgrader;
/**
* Default framework auto upgrade option value
*/
private static final boolean DEFAULT_AUTO_UPGRADE = false;
public Class getJobConfigurationClass(MJob.Type jobType) { public Class getJobConfigurationClass(MJob.Type jobType) {
switch (jobType) { switch (jobType) {
@ -142,7 +147,9 @@ public synchronized void initialize() {
LOG.trace("Begin submission engine manager initialization"); LOG.trace("Begin submission engine manager initialization");
// Register framework metadata in repository // Register framework metadata in repository
mFramework = RepositoryManager.getInstance().getRepository().registerFramework(mFramework); boolean autoUpgrade = SqoopConfiguration.getInstance().getContext().getBoolean(
ConfigurationConstants.FRAMEWORK_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE);
mFramework = RepositoryManager.getInstance().getRepository().registerFramework(mFramework, autoUpgrade);
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this)); SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));

View File

@ -154,7 +154,7 @@ public Object doIt(Connection conn) throws Exception {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public MConnector registerConnector(final MConnector mConnector) { public MConnector registerConnector(final MConnector mConnector, final boolean autoUpgrade) {
return (MConnector) doWithConnection(new DoWithConnection() { return (MConnector) doWithConnection(new DoWithConnection() {
@Override @Override
@ -172,8 +172,13 @@ public Object doIt(Connection conn) throws Exception {
// monotonically increasing. // monotonically increasing.
if (result.getUniqueName().equals(mConnector.getUniqueName()) && if (result.getUniqueName().equals(mConnector.getUniqueName()) &&
mConnector.getVersion().compareTo(result.getVersion()) > 0) { mConnector.getVersion().compareTo(result.getVersion()) > 0) {
upgradeConnector(result, mConnector); if (autoUpgrade) {
return mConnector; upgradeConnector(result, mConnector);
return mConnector;
} else {
throw new SqoopException(RepositoryError.JDBCREPO_0026,
"Connector: " + mConnector.getUniqueName());
}
} }
if (!result.equals(mConnector)) { if (!result.equals(mConnector)) {
throw new SqoopException(RepositoryError.JDBCREPO_0013, throw new SqoopException(RepositoryError.JDBCREPO_0013,
@ -204,7 +209,7 @@ public Object doIt(Connection conn) throws Exception {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public MFramework registerFramework(final MFramework mFramework) { public MFramework registerFramework(final MFramework mFramework, final boolean autoUpgrade) {
return (MFramework) doWithConnection(new DoWithConnection() { return (MFramework) doWithConnection(new DoWithConnection() {
@Override @Override
public Object doIt(Connection conn) { public Object doIt(Connection conn) {
@ -216,8 +221,13 @@ public Object doIt(Connection conn) {
// We're currently not serializing framework version into repository // We're currently not serializing framework version into repository
// so let's just compare the structure to see if we need upgrade. // so let's just compare the structure to see if we need upgrade.
if(!mFramework.equals(result)) { if(!mFramework.equals(result)) {
upgradeFramework(mFramework); if (autoUpgrade) {
return mFramework; upgradeFramework(mFramework);
return mFramework;
} else {
throw new SqoopException(RepositoryError.JDBCREPO_0026,
"Framework: " + mFramework.getPersistenceId());
}
} }
return result; return result;
} }

View File

@ -81,9 +81,10 @@ public abstract class Repository {
* given connector are already registered with different structure. * given connector are already registered with different structure.
* *
* @param mConnector the connector metadata to be registered * @param mConnector the connector metadata to be registered
* autoupgrade whether to upgrade framework automatically
* @return Registered connector structure * @return Registered connector structure
*/ */
public abstract MConnector registerConnector(MConnector mConnector); public abstract MConnector registerConnector(MConnector mConnector, boolean autoUpgrade);
/** /**
* Search for connector with given name in repository. * Search for connector with given name in repository.
@ -103,9 +104,10 @@ public abstract class Repository {
* given framework are already registered with different structure. * given framework are already registered with different structure.
* *
* @param mFramework framework metadata to be registered * @param mFramework framework metadata to be registered
* autoupgrade whether to upgrade framework automatically
* @return Registered connector structure * @return Registered connector structure
*/ */
public abstract MFramework registerFramework(MFramework mFramework); public abstract MFramework registerFramework(MFramework mFramework, boolean autoUpgrade);
/** /**
* Save given connection to repository. This connection must not be already * Save given connection to repository. This connection must not be already

View File

@ -118,6 +118,9 @@ public enum RepositoryError implements ErrorCode {
/** Invalid submission id **/ /** Invalid submission id **/
JDBCREPO_0025("Given submission id is invalid"), JDBCREPO_0025("Given submission id is invalid"),
/** Upgrade required but not allowed **/
JDBCREPO_0026("Upgrade required but not allowed");
; ;
private final String message; private final String message;

View File

@ -83,6 +83,16 @@ org.apache.sqoop.repository.jdbc.password=
# System properties for embedded Derby configuration # System properties for embedded Derby configuration
org.apache.sqoop.repository.sysprop.derby.stream.error.file=@LOGDIR@/derbyrepo.log org.apache.sqoop.repository.sysprop.derby.stream.error.file=@LOGDIR@/derbyrepo.log
#
# Connector configuration
#
org.apache.sqoop.connector.autoupgrade=false
#
# Framework configuration
#
org.apache.sqoop.framework.autoupgrade=false
# Sleeping period for reloading configuration file (once a minute) # Sleeping period for reloading configuration file (once a minute)
org.apache.sqoop.core.configuration.provider.properties.sleep=60000 org.apache.sqoop.core.configuration.provider.properties.sleep=60000