From df3a266c6ca1c50e01c6dd61e099f3662bcccf2f Mon Sep 17 00:00:00 2001 From: Cheolsoo Park Date: Sat, 23 Feb 2013 19:23:27 -0800 Subject: [PATCH] SQOOP-892:: Validate acceptable number of mappers and reducers (Jarcec Cecho via Cheolsoo Park) --- .../sqoop/framework/FrameworkValidator.java | 35 +++++- .../configuration/ExportJobConfiguration.java | 1 + .../framework/TestFrameworkValidator.java | 119 ++++++++++++++++++ 3 files changed, 149 insertions(+), 6 deletions(-) create mode 100644 core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java diff --git a/core/src/main/java/org/apache/sqoop/framework/FrameworkValidator.java b/core/src/main/java/org/apache/sqoop/framework/FrameworkValidator.java index 6f9a6fca..a42363d1 100644 --- a/core/src/main/java/org/apache/sqoop/framework/FrameworkValidator.java +++ b/core/src/main/java/org/apache/sqoop/framework/FrameworkValidator.java @@ -20,6 +20,9 @@ import org.apache.sqoop.framework.configuration.ConnectionConfiguration; import org.apache.sqoop.framework.configuration.ExportJobConfiguration; import org.apache.sqoop.framework.configuration.ImportJobConfiguration; +import org.apache.sqoop.framework.configuration.InputForm; +import org.apache.sqoop.framework.configuration.OutputForm; +import org.apache.sqoop.framework.configuration.ThrottlingForm; import org.apache.sqoop.model.MJob; import org.apache.sqoop.validation.Status; import org.apache.sqoop.validation.Validation; @@ -54,9 +57,8 @@ private Validation validateExportJob(Object jobConfiguration) { Validation validation = new Validation(ExportJobConfiguration.class); ExportJobConfiguration configuration = (ExportJobConfiguration)jobConfiguration; - if(configuration.input.inputDirectory == null || configuration.input.inputDirectory.isEmpty()) { - validation.addMessage(Status.UNACCEPTABLE, "input", "inputDirectory", "Input directory is empty"); - } + validateInputForm(validation, configuration.input); + validateThrottingForm(validation, configuration.throttling); return validation; } @@ -65,10 +67,31 @@ private Validation validateImportJob(Object jobConfiguration) { Validation validation = new Validation(ImportJobConfiguration.class); ImportJobConfiguration configuration = (ImportJobConfiguration)jobConfiguration; - if(configuration.output.outputDirectory == null || configuration.output.outputDirectory.isEmpty()) { - validation.addMessage(Status.UNACCEPTABLE, "output", "outputDirectory", "Input directory is empty"); - } + validateOutputForm(validation, configuration.output); + validateThrottingForm(validation, configuration.throttling); return validation; } + + private void validateInputForm(Validation validation, InputForm input) { + if(input.inputDirectory == null || input.inputDirectory.isEmpty()) { + validation.addMessage(Status.UNACCEPTABLE, "input", "inputDirectory", "Input directory is empty"); + } + } + + private void validateOutputForm(Validation validation, OutputForm output) { + if(output.outputDirectory == null || output.outputDirectory.isEmpty()) { + validation.addMessage(Status.UNACCEPTABLE, "output", "outputDirectory", "Input directory is empty"); + } + } + + private void validateThrottingForm(Validation validation, ThrottlingForm throttling) { + if(throttling.extractors != null && throttling.extractors < 1) { + validation.addMessage(Status.UNACCEPTABLE, "throttling", "extractors", "You need to specify more than one extractor"); + } + + if(throttling.loaders != null && throttling.loaders < 1) { + validation.addMessage(Status.UNACCEPTABLE, "throttling", "loaders", "You need to specify more than one loader"); + } + } } diff --git a/core/src/main/java/org/apache/sqoop/framework/configuration/ExportJobConfiguration.java b/core/src/main/java/org/apache/sqoop/framework/configuration/ExportJobConfiguration.java index d533089c..66654291 100644 --- a/core/src/main/java/org/apache/sqoop/framework/configuration/ExportJobConfiguration.java +++ b/core/src/main/java/org/apache/sqoop/framework/configuration/ExportJobConfiguration.java @@ -31,6 +31,7 @@ public class ExportJobConfiguration { @Form public ThrottlingForm throttling; public ExportJobConfiguration() { + input = new InputForm(); throttling = new ThrottlingForm(); } } diff --git a/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java b/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java new file mode 100644 index 00000000..9e1997ac --- /dev/null +++ b/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java @@ -0,0 +1,119 @@ +/** + * 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.framework; + +import org.apache.sqoop.framework.configuration.ConnectionConfiguration; +import org.apache.sqoop.framework.configuration.ExportJobConfiguration; +import org.apache.sqoop.framework.configuration.ImportJobConfiguration; +import org.apache.sqoop.model.MJob; +import org.apache.sqoop.validation.Status; +import org.apache.sqoop.validation.Validation; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * + */ +public class TestFrameworkValidator { + + FrameworkValidator validator; + + @Before + public void setUp() { + validator = new FrameworkValidator(); + } + + @Test + public void testConnectionValidation() { + ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(); + + Validation validation = validator.validateConnection(connectionConfiguration); + assertEquals(Status.FINE, validation.getStatus()); + assertEquals(0, validation.getMessages().size()); + } + + @Test + public void testExportJobValidation() { + ExportJobConfiguration configuration; + Validation validation; + + // Empty form is not allowed + configuration = new ExportJobConfiguration(); + validation = validator.validateJob(MJob.Type.EXPORT, configuration); + assertEquals(Status.UNACCEPTABLE, validation.getStatus()); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("input.inputDirectory"))); + + // Explicitly setting extractors and loaders + configuration = new ExportJobConfiguration(); + configuration.input.inputDirectory = "/czech/republic"; + configuration.throttling.extractors = 3; + configuration.throttling.loaders = 3; + + validation = validator.validateJob(MJob.Type.EXPORT, configuration); + assertEquals(Status.FINE, validation.getStatus()); + assertEquals(0, validation.getMessages().size()); + + // Negative and zero values for extractors and loaders + configuration = new ExportJobConfiguration(); + configuration.input.inputDirectory = "/czech/republic"; + configuration.throttling.extractors = 0; + configuration.throttling.loaders = -1; + + validation = validator.validateJob(MJob.Type.EXPORT, configuration); + assertEquals(Status.UNACCEPTABLE, validation.getStatus()); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.extractors"))); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.loaders"))); + } + + + @Test + public void testImportJobValidation() { + ImportJobConfiguration configuration; + Validation validation; + + // Empty form is not allowed + configuration = new ImportJobConfiguration(); + validation = validator.validateJob(MJob.Type.IMPORT, configuration); + assertEquals(Status.UNACCEPTABLE, validation.getStatus()); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("output.outputDirectory"))); + + // Explicitly setting extractors and loaders + configuration = new ImportJobConfiguration(); + configuration.output.outputDirectory = "/czech/republic"; + configuration.throttling.extractors = 3; + configuration.throttling.loaders = 3; + + validation = validator.validateJob(MJob.Type.IMPORT, configuration); + assertEquals(Status.FINE, validation.getStatus()); + assertEquals(0, validation.getMessages().size()); + + // Negative and zero values for extractors and loaders + configuration = new ImportJobConfiguration(); + configuration.output.outputDirectory = "/czech/republic"; + configuration.throttling.extractors = 0; + configuration.throttling.loaders = -1; + + validation = validator.validateJob(MJob.Type.IMPORT, configuration); + assertEquals(Status.UNACCEPTABLE, validation.getStatus()); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.extractors"))); + assertTrue(validation.getMessages().containsKey(new Validation.FormInput("throttling.loaders"))); + } +}