Repository: sqoop Updated Branches: refs/heads/sqoop2 1192c2a4c -> c812ec586
SQOOP-2366: Sqoop2: Create infrastructure providers for hadoop, tomcat, and database providers (Abraham Elmahrek via Richard Zhou) Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/c812ec58 Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/c812ec58 Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/c812ec58 Branch: refs/heads/sqoop2 Commit: c812ec586bf566095b050913e42ed74dc65a1368 Parents: 1192c2a Author: Richard Zhou <[email protected]> Authored: Wed Jul 8 16:44:14 2015 +0800 Committer: Richard Zhou <[email protected]> Committed: Wed Jul 8 16:44:14 2015 +0800 ---------------------------------------------------------------------- .../DatabaseInfrastructureProvider.java | 75 +++++++++++++++++ .../providers/HadoopInfrastructureProvider.java | 87 ++++++++++++++++++++ .../providers/InfrastructureProvider.java | 65 +++++++++++++++ .../providers/SqoopInfrastructureProvider.java | 79 ++++++++++++++++++ 4 files changed, 306 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sqoop/blob/c812ec58/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/DatabaseInfrastructureProvider.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/DatabaseInfrastructureProvider.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/DatabaseInfrastructureProvider.java new file mode 100644 index 0000000..e4481c4 --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/DatabaseInfrastructureProvider.java @@ -0,0 +1,75 @@ +/** + * 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.test.infrastructure.providers; + +import org.apache.hadoop.conf.Configuration; +import org.apache.log4j.Logger; +import org.apache.sqoop.common.test.db.DatabaseProvider; +import org.apache.sqoop.common.test.db.DatabaseProviderFactory; + +/** + * Database infrastructure provider. + */ +public class DatabaseInfrastructureProvider extends InfrastructureProvider { + private static final Logger LOG = Logger.getLogger(DatabaseInfrastructureProvider.class); + + private DatabaseProvider instance; + private Configuration conf; + + public DatabaseInfrastructureProvider() { + try { + instance = DatabaseProviderFactory.getProvider(System.getProperties()); + } catch (Exception e) { + LOG.error("Error fetching Hadoop runner.", e); + } + } + + @Override + public void start() { + instance.start(); + } + + @Override + public void stop() { + instance.stop(); + } + + @Override + public void setHadoopConfiguration(Configuration conf) { + this.conf = conf; + } + + @Override + public Configuration getHadoopConfiguration() { + return conf; + } + + @Override + public void setRootPath(String path) { + // No-op. + } + + @Override + public String getRootPath() { + return null; + } + + public DatabaseProvider getInstance() { + return instance; + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/c812ec58/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/HadoopInfrastructureProvider.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/HadoopInfrastructureProvider.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/HadoopInfrastructureProvider.java new file mode 100644 index 0000000..f6ba23c --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/HadoopInfrastructureProvider.java @@ -0,0 +1,87 @@ +/** + * 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.test.infrastructure.providers; + +import org.apache.hadoop.conf.Configuration; +import org.apache.log4j.Logger; +import org.apache.sqoop.test.hadoop.HadoopMiniClusterRunner; +import org.apache.sqoop.test.hadoop.HadoopRunner; +import org.apache.sqoop.test.hadoop.HadoopRunnerFactory; + +/** + * Hadoop infrastructure provider. + */ +public class HadoopInfrastructureProvider extends InfrastructureProvider { + private static final Logger LOG = Logger.getLogger(HadoopInfrastructureProvider.class); + + private HadoopRunner instance; + + public HadoopInfrastructureProvider() { + try { + instance = HadoopRunnerFactory.getHadoopCluster(System.getProperties(), HadoopMiniClusterRunner.class); + } catch (Exception e) { + LOG.error("Error fetching Hadoop runner.", e); + } + } + + @Override + public void start() { + try { + instance.start(); + } catch(Exception e) { + LOG.error("Could not start hadoop runner.", e); + } + } + + @Override + public void stop() { + try { + instance.stop(); + } catch(Exception e) { + LOG.error("Could not stop hadoop runner.", e); + } + } + + @Override + public void setHadoopConfiguration(Configuration conf) { + try { + instance.setConfiguration(instance.prepareConfiguration(conf)); + } catch (Exception e) { + LOG.error("Could not set configuration.", e); + } + } + + @Override + public Configuration getHadoopConfiguration() { + return instance.getConfiguration(); + } + + @Override + public void setRootPath(String path) { + instance.setTemporaryPath(path); + } + + @Override + public String getRootPath() { + return instance.getTemporaryPath(); + } + + public HadoopRunner getInstance() { + return instance; + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/c812ec58/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/InfrastructureProvider.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/InfrastructureProvider.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/InfrastructureProvider.java new file mode 100644 index 0000000..d904b3e --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/InfrastructureProvider.java @@ -0,0 +1,65 @@ +/** + * 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.test.infrastructure.providers; + +import org.apache.hadoop.conf.Configuration; + +/** + * Infrastructure classes enable the development of integration tests. + * These are usually scripts to start miniclusters. + */ +public abstract class InfrastructureProvider { + /** + * Start miniclusters. + */ + abstract public void start(); + + /** + * Stop miniclusters. + */ + abstract public void stop(); + + /** + * Set Hadoop configuration to be used. + * + * Called before ``start()`` method. + * + * @param conf + */ + abstract public void setHadoopConfiguration(Configuration conf); + + /** + * @return hadoop configuration used + */ + abstract public Configuration getHadoopConfiguration(); + + /** + * Set the root path to be used by this infrastructure component. + * This is intended to provide some level of containment. + * + * Called before ``start()`` method. + * + * @param path + */ + abstract public void setRootPath(String path); + + /** + * @return root path for component. + */ + abstract public String getRootPath(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/sqoop/blob/c812ec58/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java ---------------------------------------------------------------------- diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java new file mode 100644 index 0000000..5b4f595 --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/providers/SqoopInfrastructureProvider.java @@ -0,0 +1,79 @@ +/** + * 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.test.infrastructure.providers; + +import org.apache.hadoop.conf.Configuration; +import org.apache.log4j.Logger; +import org.apache.sqoop.test.minicluster.SqoopMiniCluster; +import org.apache.sqoop.test.minicluster.TomcatSqoopMiniCluster; + +/** + * Sqoop infrastructure provider. + */ +public class SqoopInfrastructureProvider extends InfrastructureProvider { + private static final Logger LOG = Logger.getLogger(SqoopInfrastructureProvider.class); + + private SqoopMiniCluster instance; + private String rootPath; + private Configuration hadoopConf; + + public SqoopInfrastructureProvider() {} + + @Override + public void start() { + try { + instance = new TomcatSqoopMiniCluster(rootPath, hadoopConf); + instance.start(); + } catch (Exception e) { + LOG.error("Could not start Sqoop mini cluster.", e); + } + } + + @Override + public void stop() { + try { + instance.stop(); + } catch (Exception e) { + LOG.error("Could not stop Sqoop mini cluster.", e); + } + } + + @Override + public void setHadoopConfiguration(Configuration conf) { + hadoopConf = conf; + } + + @Override + public Configuration getHadoopConfiguration() { + return hadoopConf; + } + + @Override + public void setRootPath(String path) { + rootPath = path; + } + + @Override + public String getRootPath() { + return rootPath; + } + + public SqoopMiniCluster getInstance() { + return instance; + } +}
