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:
parent
226044d3b3
commit
8c74223b59
@ -53,6 +53,11 @@ public class ConnectorManager implements Reconfigurable {
|
||||
*/
|
||||
private static ConnectorManager instance;
|
||||
|
||||
/**
|
||||
* Default connector auto upgrade option value
|
||||
*/
|
||||
private static boolean DEFAULT_AUTO_UPGRADE = false;
|
||||
|
||||
/**
|
||||
* Create default object by default.
|
||||
*
|
||||
@ -185,7 +190,9 @@ public synchronized void initialize() {
|
||||
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));
|
||||
|
||||
@ -194,7 +201,7 @@ public synchronized void initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void registerConnectors() {
|
||||
private synchronized void registerConnectors(boolean autoUpgrade) {
|
||||
Repository repository = RepositoryManager.getInstance().getRepository();
|
||||
|
||||
RepositoryTransaction rtx = null;
|
||||
@ -205,7 +212,7 @@ private synchronized void registerConnectors() {
|
||||
ConnectorHandler handler = handlerMap.get(name);
|
||||
MConnector connectorMetadata = handler.getMetadata();
|
||||
MConnector registeredMetadata =
|
||||
repository.registerConnector(connectorMetadata);
|
||||
repository.registerConnector(connectorMetadata, autoUpgrade);
|
||||
|
||||
// Set registered metadata instead of connector metadata as they will
|
||||
// have filled persistent ids. We should be confident at this point that
|
||||
|
@ -70,6 +70,11 @@ public final class ConfigurationConstants {
|
||||
public static final String PROPERTIES_PROVIDER_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() {
|
||||
// Disable explicit object creation
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.sqoop.connector.spi.MetadataUpgrader;
|
||||
import org.apache.sqoop.core.ConfigurationConstants;
|
||||
import org.apache.sqoop.core.Reconfigurable;
|
||||
import org.apache.sqoop.core.SqoopConfiguration;
|
||||
import org.apache.sqoop.core.SqoopConfiguration.CoreConfigurationListener;
|
||||
@ -105,6 +106,10 @@ public static void setInstance(FrameworkManager newInstance) {
|
||||
*/
|
||||
private final MetadataUpgrader upgrader;
|
||||
|
||||
/**
|
||||
* Default framework auto upgrade option value
|
||||
*/
|
||||
private static final boolean DEFAULT_AUTO_UPGRADE = false;
|
||||
|
||||
public Class getJobConfigurationClass(MJob.Type jobType) {
|
||||
switch (jobType) {
|
||||
@ -142,7 +147,9 @@ public synchronized void initialize() {
|
||||
LOG.trace("Begin submission engine manager initialization");
|
||||
|
||||
// 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));
|
||||
|
||||
|
@ -154,7 +154,7 @@ public Object doIt(Connection conn) throws Exception {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public MConnector registerConnector(final MConnector mConnector) {
|
||||
public MConnector registerConnector(final MConnector mConnector, final boolean autoUpgrade) {
|
||||
|
||||
return (MConnector) doWithConnection(new DoWithConnection() {
|
||||
@Override
|
||||
@ -172,8 +172,13 @@ public Object doIt(Connection conn) throws Exception {
|
||||
// monotonically increasing.
|
||||
if (result.getUniqueName().equals(mConnector.getUniqueName()) &&
|
||||
mConnector.getVersion().compareTo(result.getVersion()) > 0) {
|
||||
if (autoUpgrade) {
|
||||
upgradeConnector(result, mConnector);
|
||||
return mConnector;
|
||||
} else {
|
||||
throw new SqoopException(RepositoryError.JDBCREPO_0026,
|
||||
"Connector: " + mConnector.getUniqueName());
|
||||
}
|
||||
}
|
||||
if (!result.equals(mConnector)) {
|
||||
throw new SqoopException(RepositoryError.JDBCREPO_0013,
|
||||
@ -204,7 +209,7 @@ public Object doIt(Connection conn) throws Exception {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public MFramework registerFramework(final MFramework mFramework) {
|
||||
public MFramework registerFramework(final MFramework mFramework, final boolean autoUpgrade) {
|
||||
return (MFramework) doWithConnection(new DoWithConnection() {
|
||||
@Override
|
||||
public Object doIt(Connection conn) {
|
||||
@ -216,8 +221,13 @@ public Object doIt(Connection conn) {
|
||||
// We're currently not serializing framework version into repository
|
||||
// so let's just compare the structure to see if we need upgrade.
|
||||
if(!mFramework.equals(result)) {
|
||||
if (autoUpgrade) {
|
||||
upgradeFramework(mFramework);
|
||||
return mFramework;
|
||||
} else {
|
||||
throw new SqoopException(RepositoryError.JDBCREPO_0026,
|
||||
"Framework: " + mFramework.getPersistenceId());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -81,9 +81,10 @@ public abstract class Repository {
|
||||
* given connector are already registered with different structure.
|
||||
*
|
||||
* @param mConnector the connector metadata to be registered
|
||||
* autoupgrade whether to upgrade framework automatically
|
||||
* @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.
|
||||
@ -103,9 +104,10 @@ public abstract class Repository {
|
||||
* given framework are already registered with different structure.
|
||||
*
|
||||
* @param mFramework framework metadata to be registered
|
||||
* autoupgrade whether to upgrade framework automatically
|
||||
* @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
|
||||
|
@ -118,6 +118,9 @@ public enum RepositoryError implements ErrorCode {
|
||||
/** Invalid submission id **/
|
||||
JDBCREPO_0025("Given submission id is invalid"),
|
||||
|
||||
/** Upgrade required but not allowed **/
|
||||
JDBCREPO_0026("Upgrade required but not allowed");
|
||||
|
||||
;
|
||||
|
||||
private final String message;
|
||||
|
10
dist/src/main/server/conf/sqoop.properties
vendored
10
dist/src/main/server/conf/sqoop.properties
vendored
@ -83,6 +83,16 @@ org.apache.sqoop.repository.jdbc.password=
|
||||
# System properties for embedded Derby configuration
|
||||
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)
|
||||
org.apache.sqoop.core.configuration.provider.properties.sleep=60000
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user