mirror of
https://github.com/apache/sqoop.git
synced 2025-05-05 02:10:01 +08:00
SQOOP-1254. Sqoop2: Tool: Add Upgrade tool
(Jarek Jarcec Cecho via Hari Shreedharan)
This commit is contained in:
parent
eab812d2f2
commit
528d1ee9db
@ -142,6 +142,10 @@ public SqoopConnector getConnector(String uniqueName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void initialize() {
|
public synchronized void initialize() {
|
||||||
|
initialize(SqoopConfiguration.getInstance().getContext().getBoolean(ConfigurationConstants.CONNECTOR_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initialize(boolean autoUpgrade) {
|
||||||
if (LOG.isTraceEnabled()) {
|
if (LOG.isTraceEnabled()) {
|
||||||
LOG.trace("Begin connector manager initialization");
|
LOG.trace("Begin connector manager initialization");
|
||||||
}
|
}
|
||||||
@ -190,8 +194,6 @@ public synchronized void initialize() {
|
|||||||
throw new SqoopException(ConnectorError.CONN_0001, ex);
|
throw new SqoopException(ConnectorError.CONN_0001, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean autoUpgrade = SqoopConfiguration.getInstance().getContext().getBoolean(
|
|
||||||
ConfigurationConstants.CONNECTOR_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE);
|
|
||||||
registerConnectors(autoUpgrade);
|
registerConnectors(autoUpgrade);
|
||||||
|
|
||||||
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));
|
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));
|
||||||
|
@ -147,11 +147,13 @@ public FrameworkManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void initialize() {
|
public synchronized void initialize() {
|
||||||
|
initialize(SqoopConfiguration.getInstance().getContext().getBoolean(ConfigurationConstants.FRAMEWORK_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE));
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initialize(boolean autoUpgrade) {
|
||||||
LOG.trace("Begin submission engine manager initialization");
|
LOG.trace("Begin submission engine manager initialization");
|
||||||
|
|
||||||
// Register framework metadata in repository
|
// Register framework metadata in repository
|
||||||
boolean autoUpgrade = SqoopConfiguration.getInstance().getContext().getBoolean(
|
|
||||||
ConfigurationConstants.FRAMEWORK_AUTO_UPGRADE, DEFAULT_AUTO_UPGRADE);
|
|
||||||
mFramework = RepositoryManager.getInstance().getRepository().registerFramework(mFramework, autoUpgrade);
|
mFramework = RepositoryManager.getInstance().getRepository().registerFramework(mFramework, autoUpgrade);
|
||||||
|
|
||||||
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));
|
SqoopConfiguration.getInstance().getProvider().registerListener(new CoreConfigurationListener(this));
|
||||||
|
@ -72,6 +72,10 @@ public static void setInstance(RepositoryManager newInstance) {
|
|||||||
private RepositoryProvider provider;
|
private RepositoryProvider provider;
|
||||||
|
|
||||||
public synchronized void initialize() {
|
public synchronized void initialize() {
|
||||||
|
initialize(SqoopConfiguration.getInstance().getContext().getBoolean(RepoConfigurationConstants.SYSCFG_REPO_SCHEMA_IMMUTABLE, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void initialize(boolean immutableRepository) {
|
||||||
MapContext context = SqoopConfiguration.getInstance().getContext();
|
MapContext context = SqoopConfiguration.getInstance().getContext();
|
||||||
|
|
||||||
Map<String, String> repoSysProps = context.getNestedProperties(
|
Map<String, String> repoSysProps = context.getNestedProperties(
|
||||||
@ -113,8 +117,7 @@ public synchronized void initialize() {
|
|||||||
|
|
||||||
provider.initialize(context);
|
provider.initialize(context);
|
||||||
|
|
||||||
if(!context.getBoolean(RepoConfigurationConstants
|
if(!immutableRepository) {
|
||||||
.SYSCFG_REPO_SCHEMA_IMMUTABLE, false)) {
|
|
||||||
LOG.info("Creating or upgrading on disk structures if necessary");
|
LOG.info("Creating or upgrading on disk structures if necessary");
|
||||||
provider.getRepository().createOrUpdateInternals();
|
provider.getRepository().createOrUpdateInternals();
|
||||||
}
|
}
|
||||||
|
@ -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.tools;
|
||||||
|
|
||||||
|
import org.apache.sqoop.core.SqoopConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Most of the tools needs to load Sqoop configuration in order to perform
|
||||||
|
* their task. To simplify the code, ConfiguredTool will make sure that
|
||||||
|
* the configuration is properly loaded prior executing the actual tool.
|
||||||
|
*/
|
||||||
|
public abstract class ConfiguredTool extends Tool {
|
||||||
|
|
||||||
|
public abstract boolean runToolWithConfiguration(String[] arguments);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean runTool(String[] arguments) {
|
||||||
|
try {
|
||||||
|
SqoopConfiguration.getInstance().initialize();
|
||||||
|
return runToolWithConfiguration(arguments);
|
||||||
|
} finally {
|
||||||
|
SqoopConfiguration.getInstance().destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -34,6 +34,7 @@ public class BuiltinTools {
|
|||||||
private static Map<String, Class<? extends Tool>> tools;
|
private static Map<String, Class<? extends Tool>> tools;
|
||||||
static {
|
static {
|
||||||
tools = new HashMap<String, Class<? extends Tool>>();
|
tools = new HashMap<String, Class<? extends Tool>>();
|
||||||
|
tools.put("upgrade", UpgradeTool.class);
|
||||||
tools.put("verify", VerifyTool.class);
|
tools.put("verify", VerifyTool.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
/**
|
||||||
|
* 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.tools.tool;
|
||||||
|
|
||||||
|
import org.apache.sqoop.connector.ConnectorManager;
|
||||||
|
import org.apache.sqoop.framework.FrameworkManager;
|
||||||
|
import org.apache.sqoop.repository.RepositoryManager;
|
||||||
|
import org.apache.sqoop.tools.ConfiguredTool;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upgrade all versionable components inside Sqoop2. This includes any
|
||||||
|
* structural changes inside repository and the Connector and Framework
|
||||||
|
* metadata. This tool is idempotent.
|
||||||
|
*/
|
||||||
|
public class UpgradeTool extends ConfiguredTool {
|
||||||
|
|
||||||
|
public static final Logger LOG = Logger.getLogger(UpgradeTool.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean runToolWithConfiguration(String[] arguments) {
|
||||||
|
try {
|
||||||
|
LOG.info("Initializing the RepositoryManager with immutable option turned off.");
|
||||||
|
RepositoryManager.getInstance().initialize(false);
|
||||||
|
|
||||||
|
LOG.info("Initializing the FrameworkManager with upgrade option turned on.");
|
||||||
|
FrameworkManager.getInstance().initialize(true);
|
||||||
|
|
||||||
|
LOG.info("Initializing the FrameworkManager with upgrade option turned on.");
|
||||||
|
ConnectorManager.getInstance().initialize(true);
|
||||||
|
|
||||||
|
LOG.info("Upgrade completed successfully.");
|
||||||
|
|
||||||
|
LOG.info("Tearing all managers down.");
|
||||||
|
ConnectorManager.getInstance().destroy();
|
||||||
|
FrameworkManager.getInstance().destroy();
|
||||||
|
RepositoryManager.getInstance().destroy();
|
||||||
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.error("Can't finish upgrading all components:", ex);
|
||||||
|
System.out.println("Upgrade has failed, please check Server logs for further details.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user