sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cheol...@apache.org
Subject [1/2] git commit: SQOOP-892:: Validate acceptable number of mappers and reducers
Date Sun, 24 Feb 2013 03:29:43 GMT
SQOOP-892:: Validate acceptable number of mappers and reducers

(Jarcec Cecho via Cheolsoo Park)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/df3a266c
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/df3a266c
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/df3a266c

Branch: refs/heads/sqoop2
Commit: df3a266c6ca1c50e01c6dd61e099f3662bcccf2f
Parents: cc5ae8f
Author: Cheolsoo Park <cheolsoo@apache.org>
Authored: Sat Feb 23 19:23:27 2013 -0800
Committer: Cheolsoo Park <cheolsoo@apache.org>
Committed: Sat Feb 23 19:23:27 2013 -0800

----------------------------------------------------------------------
 .../apache/sqoop/framework/FrameworkValidator.java |   33 ++++-
 .../configuration/ExportJobConfiguration.java      |    1 +
 .../sqoop/framework/TestFrameworkValidator.java    |  119 +++++++++++++++
 3 files changed, 148 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/df3a266c/core/src/main/java/org/apache/sqoop/framework/FrameworkValidator.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 6f9a6fc..a42363d 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 @@ 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.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 @@ public class FrameworkValidator extends Validator {
     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 @@ public class FrameworkValidator extends Validator {
     Validation validation = new Validation(ImportJobConfiguration.class);
     ImportJobConfiguration configuration = (ImportJobConfiguration)jobConfiguration;
 
-    if(configuration.output.outputDirectory == null || configuration.output.outputDirectory.isEmpty())
{
+    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");
     }
+  }
 
-    return validation;
+  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");
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/df3a266c/core/src/main/java/org/apache/sqoop/framework/configuration/ExportJobConfiguration.java
----------------------------------------------------------------------
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 d533089..6665429 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();
   }
 }

http://git-wip-us.apache.org/repos/asf/sqoop/blob/df3a266c/core/src/test/java/org/apache/sqoop/framework/TestFrameworkValidator.java
----------------------------------------------------------------------
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 0000000..9e1997a
--- /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")));
+  }
+}


Mime
View raw message