http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMConnector.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java index d8bc94d..89ae440 100644 --- a/common/src/test/java/org/apache/sqoop/model/TestMConnector.java +++ b/common/src/test/java/org/apache/sqoop/model/TestMConnector.java @@ -17,6 +17,13 @@ */ package org.apache.sqoop.model; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -24,39 +31,34 @@ import java.util.List; import org.apache.sqoop.common.Direction; import org.junit.Test; -import static org.junit.Assert.*; - -/** - * Test class for org.apache.sqoop.model.TestMConnector - */ public class TestMConnector { private MConnector createConnector(List<Direction> supportedDirections) { - List<MForm> forms = new ArrayList<MForm>(); - MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); - input.setValue(100); + List<MConfig> configs = new ArrayList<MConfig>(); + MIntegerInput inputs = new MIntegerInput("INTEGER-INPUT", false); + inputs.setValue(100); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); strInput.setValue("TEST-VALUE"); List<MInput<?>> list = new ArrayList<MInput<?>>(); - list.add(input); + list.add(inputs); list.add(strInput); - MForm form = new MForm("FORMNAME", list); - forms.add(form); + MConfig config = new MConfig("CONFIGNAME", list); + configs.add(config); - MConnectionForms connectionForms1 = new MConnectionForms(forms); - MJobForms fromForm = null; - MJobForms toForm = null; + MLinkConfig linkConfig = new MLinkConfig(configs); + MFromConfig fromConfig = null; + MToConfig toConfig = null; if (supportedDirections.contains(Direction.FROM)) { - fromForm = new MJobForms(forms); + fromConfig = new MFromConfig(configs); } if (supportedDirections.contains(Direction.TO)) { - toForm = new MJobForms(forms); + toConfig = new MToConfig(configs); } return new MConnector("NAME", "CLASSNAME", "1.0", - connectionForms1, fromForm, toForm); + linkConfig, fromConfig, toConfig); } /** @@ -64,32 +66,32 @@ public class TestMConnector { */ @Test public void testInitialization() { - List<MForm> fromJobForms = new ArrayList<MForm>(); - List<MForm> toJobForms = new ArrayList<MForm>(); - MConnectionForms connectionForms1 = new MConnectionForms(fromJobForms); - MJobForms fromJobForm1 = new MJobForms(fromJobForms); - MJobForms toJobForm1 = new MJobForms(toJobForms); + List<MConfig> fromJobConfig = new ArrayList<MConfig>(); + List<MConfig> toJobConfig = new ArrayList<MConfig>(); + MLinkConfig linkConfig = new MLinkConfig(fromJobConfig); + MFromConfig fromConfig1 = new MFromConfig(fromJobConfig); + MToConfig toConfig1 = new MToConfig(toJobConfig); MConnector connector1 = new MConnector("NAME", "CLASSNAME", "1.0", - connectionForms1, fromJobForm1, toJobForm1); + linkConfig, fromConfig1, toConfig1); assertEquals("NAME", connector1.getUniqueName()); assertEquals("CLASSNAME", connector1.getClassName()); assertEquals("1.0", connector1.getVersion()); MConnector connector2 = new MConnector("NAME", "CLASSNAME", "1.0", - connectionForms1, fromJobForm1, toJobForm1); + linkConfig, fromConfig1, toConfig1); assertEquals(connector2, connector1); MConnector connector3 = new MConnector("NAME1", "CLASSNAME", "2.0", - connectionForms1, fromJobForm1, toJobForm1); + linkConfig, fromConfig1, toConfig1); assertFalse(connector1.equals(connector3)); try { - connector1 = new MConnector(null, "CLASSNAME", "1.0", connectionForms1, - fromJobForm1, toJobForm1); // Expecting null pointer exception + connector1 = new MConnector(null, "CLASSNAME", "1.0", linkConfig, + fromConfig1, toConfig1); // Expecting null pointer exception } catch (NullPointerException e) { assertTrue(true); } try { - connector1 = new MConnector("NAME", null, "1.0", connectionForms1, - fromJobForm1, toJobForm1); // Expecting null pointer exception + connector1 = new MConnector("NAME", null, "1.0", linkConfig, + fromConfig1, toConfig1); // Expecting null pointer exception } catch (NullPointerException e) { assertTrue(true); } @@ -97,48 +99,48 @@ public class TestMConnector { @Test public void testClone() { - MConnector connector1 = createConnector(Arrays.asList(Direction.FROM, Direction.TO)); - assertEquals("NAME", connector1.getUniqueName()); - assertEquals("CLASSNAME", connector1.getClassName()); - assertEquals("1.0", connector1.getVersion()); - //Clone with values. Checking values copying after the cloning. But form values will be null - MConnector clone1 = connector1.clone(true); - assertEquals("NAME", clone1.getUniqueName()); - assertEquals("CLASSNAME", clone1.getClassName()); - assertEquals("1.0", clone1.getVersion()); - MForm clonedForm1 = clone1.getConnectionForms().getForms().get(0); - assertNull(clonedForm1.getInputs().get(0).getValue()); - assertNull(clonedForm1.getInputs().get(1).getValue()); - - MForm clonedForm2 = clone1.getJobForms(Direction.FROM).getForms().get(0); - assertNull(clonedForm2.getInputs().get(0).getValue()); - assertNull(clonedForm2.getInputs().get(1).getValue()); - - MForm clonedForm3 = clone1.getJobForms(Direction.TO).getForms().get(0); - assertNull(clonedForm3.getInputs().get(0).getValue()); - assertNull(clonedForm3.getInputs().get(1).getValue()); + MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO)); + assertEquals("NAME", connector.getUniqueName()); + assertEquals("CLASSNAME", connector.getClassName()); + assertEquals("1.0", connector.getVersion()); + //Clone with values. Checking values copying after the cloning. But config values will be null + MConnector cloneConnector1 = connector.clone(true); + assertEquals("NAME", cloneConnector1.getUniqueName()); + assertEquals("CLASSNAME", cloneConnector1.getClassName()); + assertEquals("1.0", cloneConnector1.getVersion()); + MConfig clonedLinkConfig = cloneConnector1.getLinkConfig().getConfigs().get(0); + assertNull(clonedLinkConfig.getInputs().get(0).getValue()); + assertNull(clonedLinkConfig.getInputs().get(1).getValue()); + + MConfig clonedFromConfig = cloneConnector1.getConfig(Direction.FROM).getConfigs().get(0); + assertNull(clonedFromConfig.getInputs().get(0).getValue()); + assertNull(clonedFromConfig.getInputs().get(1).getValue()); + + MConfig clonedToConfig = cloneConnector1.getConfig(Direction.TO).getConfigs().get(0); + assertNull(clonedToConfig.getInputs().get(0).getValue()); + assertNull(clonedToConfig.getInputs().get(1).getValue()); //Clone without values. Inputs value will be null after cloning. - MConnector clone2 = connector1.clone(false); - clonedForm1 = clone2.getConnectionForms().getForms().get(0); - assertNull(clonedForm1.getInputs().get(0).getValue()); - assertNull(clonedForm1.getInputs().get(1).getValue()); - clonedForm2 = clone2.getJobForms(Direction.FROM).getForms().get(0); - assertNull(clonedForm2.getInputs().get(0).getValue()); - assertNull(clonedForm2.getInputs().get(1).getValue()); - clonedForm3 = clone2.getJobForms(Direction.TO).getForms().get(0); - assertNull(clonedForm3.getInputs().get(0).getValue()); - assertNull(clonedForm3.getInputs().get(1).getValue()); + MConnector clonedConnector2 = connector.clone(false); + clonedLinkConfig = clonedConnector2.getLinkConfig().getConfigs().get(0); + assertNull(clonedLinkConfig.getInputs().get(0).getValue()); + assertNull(clonedLinkConfig.getInputs().get(1).getValue()); + clonedFromConfig = clonedConnector2.getConfig(Direction.FROM).getConfigs().get(0); + assertNull(clonedFromConfig.getInputs().get(0).getValue()); + assertNull(clonedFromConfig.getInputs().get(1).getValue()); + clonedToConfig = clonedConnector2.getConfig(Direction.TO).getConfigs().get(0); + assertNull(clonedToConfig.getInputs().get(0).getValue()); + assertNull(clonedToConfig.getInputs().get(1).getValue()); } @Test public void testFromDirection() { MConnector connector = createConnector(Arrays.asList(Direction.FROM)); - // Clone should clone only one job form. + // Clone should clone only one job config. MConnector clone = connector.clone(true); - assertNotNull(clone.getJobForms(Direction.FROM)); - assertNull(clone.getJobForms(Direction.TO)); + assertNotNull(clone.getFromConfig()); + assertNull(clone.getToConfig()); assertEquals(connector, clone); assertEquals(connector.toString(), clone.toString()); assertNotEquals(connector.hashCode(), clone.hashCode()); @@ -148,10 +150,10 @@ public class TestMConnector { public void testToDirection() { MConnector connector = createConnector(Arrays.asList(Direction.TO)); - // Clone should clone only one job form. + // Clone should clone only one job config. MConnector clone = connector.clone(true); - assertNull(clone.getJobForms(Direction.FROM)); - assertNotNull(clone.getJobForms(Direction.TO)); + assertNull(clone.getFromConfig()); + assertNotNull(clone.getToConfig()); assertEquals(connector, clone); assertEquals(connector.toString(), clone.toString()); assertNotEquals(connector.hashCode(), clone.hashCode()); @@ -161,10 +163,10 @@ public class TestMConnector { public void testNoDirection() { MConnector connector = createConnector(Arrays.asList(new Direction[0])); - // Clone should clone only one job form. + // Clone should clone only one job config. MConnector clone = connector.clone(true); - assertNull(clone.getJobForms(Direction.FROM)); - assertNull(clone.getJobForms(Direction.TO)); + assertNull(clone.getFromConfig()); + assertNull(clone.getToConfig()); assertEquals(connector, clone); assertEquals(connector.toString(), clone.toString()); assertNotEquals(connector.hashCode(), clone.hashCode()); @@ -174,10 +176,10 @@ public class TestMConnector { public void testBothDirections() { MConnector connector = createConnector(Arrays.asList(Direction.FROM, Direction.TO)); - // Clone should clone only one job form. + // Clone should clone only one job config. MConnector clone = connector.clone(true); - assertNotNull(clone.getJobForms(Direction.FROM)); - assertNotNull(clone.getJobForms(Direction.TO)); + assertNotNull(clone.getFromConfig()); + assertNotNull(clone.getToConfig()); assertEquals(connector, clone); assertEquals(connector.toString(), clone.toString()); assertNotEquals(connector.hashCode(), clone.hashCode());
http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMDriver.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMDriver.java b/common/src/test/java/org/apache/sqoop/model/TestMDriver.java new file mode 100644 index 0000000..aa1ee34 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/model/TestMDriver.java @@ -0,0 +1,40 @@ +/** + * 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.model; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.sqoop.json.DriverBean; +import org.junit.Test; + +public class TestMDriver { + + @Test + public void testDriver() { + List<MConfig> driverConfig = new ArrayList<MConfig>(); + driverConfig.add(new MConfig("driver-test", new ArrayList<MInput<?>>())); + MDriverConfig mDriverConfig = new MDriverConfig(driverConfig); + + MDriver driver = new MDriver(mDriverConfig, DriverBean.CURRENT_DRIVER_VERSION); + assertEquals(1, driver.getDriverConfig().getConfigs().size()); + assertEquals("driver-test", driver.getDriverConfig().getConfigs().get(0).getName()); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java deleted file mode 100644 index 9c23cc3..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMDriverConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.model; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.*; - -/** - * - */ -public class TestMDriverConfig { - - @Test - public void testForms() { - List<MForm> connectionFormList = new ArrayList<MForm>(); - List<MForm> jobFormList = new ArrayList<MForm>(); - connectionFormList.add(new MForm("connection-test", new ArrayList<MInput<?>>())); - jobFormList.add(new MForm("job-test", new ArrayList<MInput<?>>())); - MConnectionForms connectionForms = new MConnectionForms(connectionFormList); - MJobForms jobForms = new MJobForms(jobFormList); - - MDriverConfig driver = new MDriverConfig(connectionForms, jobForms, "1"); - assertEquals(1, driver.getJobForms().getForms().size()); - assertEquals("job-test", driver.getJobForms().getForms().get(0).getName()); - assertEquals(1, driver.getConnectionForms().getForms().size()); - assertEquals("connection-test", driver.getConnectionForms().getForms().get(0).getName()); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMForm.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMForm.java b/common/src/test/java/org/apache/sqoop/model/TestMForm.java deleted file mode 100644 index 536b650..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMForm.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * 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.model; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Test class for org.apache.sqoop.model.MForm - */ -public class TestMForm { - - /** - * Test for initialization - */ - @Test - public void testInitialization() { - MInput<String> input1 = new MStringInput("sqoopsqoop1", true, (short) 5); - MInput<String> input2 = new MStringInput("sqoopsqoop2", true, (short) 5); - - List<MInput<?>> list = new ArrayList<MInput<?>>(); - list.add(input1); - list.add(input2); - MForm mform = new MForm("form", list); - - assertEquals("form", mform.getName()); - assertEquals(2, mform.getInputs().size()); - } - - /** - * Test for equals method - */ - @Test - public void testEquals() { - MInput<Integer> input1 = new MIntegerInput("sqoopsqoop1", false); - MInput<Integer> input2 = new MIntegerInput("sqoopsqoop2", false); - List<MInput<?>> list1 = new ArrayList<MInput<?>>(); - list1.add(input1); - list1.add(input2); - MForm mform1 = new MForm("form", list1); - - MInput<Integer> input3 = new MIntegerInput("sqoopsqoop1", false); - MInput<Integer> input4 = new MIntegerInput("sqoopsqoop2", false); - List<MInput<?>> list2 = new ArrayList<MInput<?>>(); - list2.add(input3); - list2.add(input4); - MForm mform2 = new MForm("form", list2); - assertEquals(mform2, mform1); - } - - @Test - public void testGetInputs() { - MIntegerInput intInput = new MIntegerInput("Form.A", false); - MMapInput mapInput = new MMapInput("Form.B", false); - MStringInput stringInput = new MStringInput("Form.C", false, (short)3); - MEnumInput enumInput = new MEnumInput("Form.D", false, new String[] {"I", "V"}); - - List<MInput<?>> inputs = new ArrayList<MInput<?>>(); - inputs.add(intInput); - inputs.add(mapInput); - inputs.add(stringInput); - inputs.add(enumInput); - - MForm form = new MForm("Form", inputs); - assertEquals(intInput, form.getIntegerInput("Form.A")); - assertEquals(mapInput, form.getMapInput("Form.B")); - assertEquals(stringInput, form.getStringInput("Form.C")); - assertEquals(enumInput, form.getEnumInput("Form.D")); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMFormList.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMFormList.java b/common/src/test/java/org/apache/sqoop/model/TestMFormList.java deleted file mode 100644 index b8d3d37..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMFormList.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * 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.model; - -import org.junit.Test; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -/** - * - */ -public class TestMFormList { - @Test - public void testGetInputs() { - List<MForm> forms = new LinkedList<MForm>(); - - MIntegerInput intInput = new MIntegerInput("Form1.A", false); - MMapInput mapInput = new MMapInput("Form1.B", false); - - List<MInput<?>> inputs = new ArrayList<MInput<?>>(); - inputs.add(intInput); - inputs.add(mapInput); - forms.add(new MForm("Form1", inputs)); - - MStringInput stringInput = new MStringInput("Form2.C", false, (short)3); - MEnumInput enumInput = new MEnumInput("Form2.D", false, new String[] {"I", "V"}); - - inputs = new ArrayList<MInput<?>>(); - inputs.add(stringInput); - inputs.add(enumInput); - forms.add(new MForm("Form2", inputs)); - - MFormList form = new MFormList(forms); - assertEquals(intInput, form.getIntegerInput("Form1.A")); - assertEquals(mapInput, form.getMapInput("Form1.B")); - assertEquals(stringInput, form.getStringInput("Form2.C")); - assertEquals(enumInput, form.getEnumInput("Form2.D")); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMJob.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMJob.java b/common/src/test/java/org/apache/sqoop/model/TestMJob.java index 8f2943e..848c2cc 100644 --- a/common/src/test/java/org/apache/sqoop/model/TestMJob.java +++ b/common/src/test/java/org/apache/sqoop/model/TestMJob.java @@ -17,17 +17,15 @@ */ package org.apache.sqoop.model; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.ArrayList; import java.util.List; import org.apache.sqoop.common.Direction; import org.junit.Test; -import static org.junit.Assert.*; - -/** - * Test class for org.apache.sqoop.model.MJob - */ public class TestMJob { /** * Test class for initialization @@ -40,9 +38,9 @@ public class TestMJob { assertEquals(456l, job.getConnectorId(Direction.TO)); assertEquals("Buffy", job.getCreationUser()); assertEquals("Vampire", job.getName()); - assertEquals(fromForms(), job.getConnectorPart(Direction.FROM)); - assertEquals(toForms(), job.getConnectorPart(Direction.TO)); - assertEquals(frameworkForms(), job.getFrameworkPart()); + assertEquals(fromConfig(), job.getJobConfig(Direction.FROM)); + assertEquals(toConfig(), job.getJobConfig(Direction.TO)); + assertEquals(driverConfig(), job.getDriverConfig()); // Test copy constructor MJob copy = new MJob(job); @@ -50,19 +48,19 @@ public class TestMJob { assertEquals(456l, copy.getConnectorId(Direction.TO)); assertEquals("Buffy", copy.getCreationUser()); assertEquals("Vampire", copy.getName()); - assertEquals(fromForms(), copy.getConnectorPart(Direction.FROM)); - assertEquals(toForms(), copy.getConnectorPart(Direction.TO)); - assertEquals(frameworkForms(), copy.getFrameworkPart()); + assertEquals(fromConfig(), copy.getJobConfig(Direction.FROM)); + assertEquals(toConfig(), copy.getJobConfig(Direction.TO)); + assertEquals(driverConfig(), copy.getDriverConfig()); - // Test constructor for metadata upgrade (the order of forms is different) - MJob upgradeCopy = new MJob(job, fromForms(), toForms(), frameworkForms()); + // Test constructor for metadata upgrade (the order of configs is different) + MJob upgradeCopy = new MJob(job, fromConfig(), toConfig(), driverConfig()); assertEquals(123l, upgradeCopy.getConnectorId(Direction.FROM)); assertEquals(456l, upgradeCopy.getConnectorId(Direction.TO)); assertEquals("Buffy", upgradeCopy.getCreationUser()); assertEquals("Vampire", upgradeCopy.getName()); - assertEquals(fromForms(), upgradeCopy.getConnectorPart(Direction.FROM)); - assertEquals(toForms(), upgradeCopy.getConnectorPart(Direction.TO)); - assertEquals(frameworkForms(), upgradeCopy.getFrameworkPart()); + assertEquals(fromConfig(), upgradeCopy.getJobConfig(Direction.FROM)); + assertEquals(toConfig(), upgradeCopy.getJobConfig(Direction.TO)); + assertEquals(driverConfig(), upgradeCopy.getDriverConfig()); } @Test @@ -70,42 +68,42 @@ public class TestMJob { MJob job = job(); // Clone without value - MJob withoutValue = job.clone(false); - assertEquals(job, withoutValue); - assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); - assertNull(withoutValue.getName()); - assertNull(withoutValue.getCreationUser()); - assertEquals(fromForms(), withoutValue.getConnectorPart(Direction.FROM)); - assertEquals(toForms(), withoutValue.getConnectorPart(Direction.TO)); - assertEquals(frameworkForms(), withoutValue.getFrameworkPart()); - assertNull(withoutValue.getConnectorPart(Direction.FROM) - .getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertNull(withoutValue.getConnectorPart(Direction.FROM) - .getForm("FORMNAME").getInput("STRING-INPUT").getValue()); + MJob withoutJobValue = job.clone(false); + assertEquals(job, withoutJobValue); + assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutJobValue.getPersistenceId()); + assertNull(withoutJobValue.getName()); + assertNull(withoutJobValue.getCreationUser()); + assertEquals(fromConfig(), withoutJobValue.getJobConfig(Direction.FROM)); + assertEquals(toConfig(), withoutJobValue.getJobConfig(Direction.TO)); + assertEquals(driverConfig(), withoutJobValue.getDriverConfig()); + assertNull(withoutJobValue.getJobConfig(Direction.FROM) + .getConfig("CONFIGFROMNAME").getInput("INTEGER-INPUT").getValue()); + assertNull(withoutJobValue.getJobConfig(Direction.FROM) + .getConfig("CONFIGFROMNAME").getInput("STRING-INPUT").getValue()); // Clone with value - MJob withValue = job.clone(true); - assertEquals(job, withValue); - assertEquals(job.getPersistenceId(), withValue.getPersistenceId()); - assertEquals(job.getName(), withValue.getName()); - assertEquals(job.getCreationUser(), withValue.getCreationUser()); - assertEquals(fromForms(), withValue.getConnectorPart(Direction.FROM)); - assertEquals(toForms(), withValue.getConnectorPart(Direction.TO)); - assertEquals(frameworkForms(), withValue.getFrameworkPart()); - assertEquals(100, withValue.getConnectorPart(Direction.FROM) - .getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertEquals("TEST-VALUE", withValue.getConnectorPart(Direction.FROM) - .getForm("FORMNAME").getInput("STRING-INPUT").getValue()); } + MJob withJobValue = job.clone(true); + assertEquals(job, withJobValue); + assertEquals(job.getPersistenceId(), withJobValue.getPersistenceId()); + assertEquals(job.getName(), withJobValue.getName()); + assertEquals(job.getCreationUser(), withJobValue.getCreationUser()); + assertEquals(fromConfig(), withJobValue.getJobConfig(Direction.FROM)); + assertEquals(toConfig(), withJobValue.getJobConfig(Direction.TO)); + assertEquals(driverConfig(), withJobValue.getDriverConfig()); + assertEquals(100, withJobValue.getJobConfig(Direction.FROM) + .getConfig("CONFIGFROMNAME").getInput("INTEGER-INPUT").getValue()); + assertEquals("TEST-VALUE", withJobValue.getJobConfig(Direction.FROM) + .getConfig("CONFIGFROMNAME").getInput("STRING-INPUT").getValue()); } private MJob job() { - MJob job = new MJob(123l, 456l, 1L, 2L, fromForms(), toForms(), frameworkForms()); + MJob job = new MJob(123l, 456l, 1L, 2L, fromConfig(), toConfig(), driverConfig()); job.setName("Vampire"); job.setCreationUser("Buffy"); return job; } - private MJobForms fromForms() { - List<MForm> forms = new ArrayList<MForm>(); + private MFromConfig fromConfig() { + List<MConfig> configs = new ArrayList<MConfig>(); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); input.setValue(100); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); @@ -113,28 +111,28 @@ public class TestMJob { List<MInput<?>> list = new ArrayList<MInput<?>>(); list.add(input); list.add(strInput); - MForm form = new MForm("FORMNAME", list); - forms.add(form); - return new MJobForms(forms); + MConfig config = new MConfig("CONFIGFROMNAME", list); + configs.add(config); + return new MFromConfig(configs); } - private MJobForms toForms() { - List<MForm> forms = new ArrayList<MForm>(); + private MToConfig toConfig() { + List<MConfig> configs = new ArrayList<MConfig>(); MMapInput input = new MMapInput("MAP-INPUT", false); List<MInput<?>> list = new ArrayList<MInput<?>>(); list.add(input); - MForm form = new MForm("form", list); - forms.add(form); - return new MJobForms(forms); + MConfig config = new MConfig("CONFIGTONAME", list); + configs.add(config); + return new MToConfig(configs); } - private MJobForms frameworkForms() { - List<MForm> forms = new ArrayList<MForm>(); + private MDriverConfig driverConfig() { + List<MConfig> configs = new ArrayList<MConfig>(); MMapInput input = new MMapInput("MAP-INPUT", false); List<MInput<?>> list = new ArrayList<MInput<?>>(); list.add(input); - MForm form = new MForm("form", list); - forms.add(form); - return new MJobForms(forms); + MConfig config = new MConfig("CONFIGDRIVERNAME", list); + configs.add(config); + return new MDriverConfig(configs); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMJobConfig.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMJobConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMJobConfig.java new file mode 100644 index 0000000..7d0641e --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/model/TestMJobConfig.java @@ -0,0 +1,42 @@ +/** + * 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.model; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class TestMJobConfig { + /** + * Test for class initialization and values + */ + @Test + public void testInitialization() { + List<MConfig> configs = new ArrayList<MConfig>(); + MFromConfig fromJobConfig = new MFromConfig(configs); + List<MConfig> configs2 = new ArrayList<MConfig>(); + MFromConfig fromJobConfig2 = new MFromConfig(configs2); + assertEquals(fromJobConfig2, fromJobConfig); + MConfig c = new MConfig("test", null); + configs2.add(c); + assertFalse(fromJobConfig.equals(fromJobConfig2)); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMJobForms.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMJobForms.java b/common/src/test/java/org/apache/sqoop/model/TestMJobForms.java deleted file mode 100644 index e59b282..0000000 --- a/common/src/test/java/org/apache/sqoop/model/TestMJobForms.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * 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.model; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Test class for org.apache.sqoop.model.MJobForms - */ -public class TestMJobForms { - /** - * Test for class initialization and values - */ - @Test - public void testInitialization() { - List<MForm> forms = new ArrayList<MForm>(); - MJobForms jobform1 = new MJobForms(forms); - List<MForm> forms2 = new ArrayList<MForm>(); - MJobForms jobform2 = new MJobForms(forms2); - assertEquals(jobform2, jobform1); - // Add a form to list for checking not equals - MForm m = new MForm("test", null); - forms2.add(m); - assertFalse(jobform1.equals(jobform2)); - } -} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMLink.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMLink.java b/common/src/test/java/org/apache/sqoop/model/TestMLink.java index 77fa2a9..9ad8954 100644 --- a/common/src/test/java/org/apache/sqoop/model/TestMLink.java +++ b/common/src/test/java/org/apache/sqoop/model/TestMLink.java @@ -24,9 +24,6 @@ import org.junit.Test; import static org.junit.Assert.*; -/** - * Test class for org.apache.sqoop.model.MConnection - */ public class TestMLink { /** @@ -39,8 +36,7 @@ public class TestMLink { assertEquals(123l, link.getConnectorId()); assertEquals("Vampire", link.getName()); assertEquals("Buffy", link.getCreationUser()); - assertEquals(forms1(), link.getConnectorPart()); - assertEquals(forms2(), link.getFrameworkPart()); + assertEquals(linkConfig(), link.getConnectorLinkConfig()); // Test copy constructor MLink copy = new MLink(link); @@ -48,17 +44,7 @@ public class TestMLink { assertEquals("Vampire", copy.getName()); assertEquals("Buffy", copy.getCreationUser()); assertEquals(link.getCreationDate(), copy.getCreationDate()); - assertEquals(forms1(), copy.getConnectorPart()); - assertEquals(forms2(), copy.getFrameworkPart()); - - // Test constructor for metadata upgrade (the order of forms is different) - MLink upgradeCopy = new MLink(link, forms2(), forms1()); - assertEquals(123l, upgradeCopy.getConnectorId()); - assertEquals("Vampire", upgradeCopy.getName()); - assertEquals("Buffy", upgradeCopy.getCreationUser()); - assertEquals(link.getCreationDate(), upgradeCopy.getCreationDate()); - assertEquals(forms2(), upgradeCopy.getConnectorPart()); - assertEquals(forms1(), upgradeCopy.getFrameworkPart()); + assertEquals(linkConfig(), copy.getConnectorLinkConfig()); } @Test @@ -66,37 +52,35 @@ public class TestMLink { MLink link = link(); // Clone without value - MLink withoutValue = link.clone(false); - assertEquals(link, withoutValue); - assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutValue.getPersistenceId()); - assertNull(withoutValue.getName()); - assertNull(withoutValue.getCreationUser()); - assertEquals(forms1(), withoutValue.getConnectorPart()); - assertEquals(forms2(), withoutValue.getFrameworkPart()); - assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertNull(withoutValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); + MLink withoutLinkValue = link.clone(false); + assertEquals(link, withoutLinkValue); + assertEquals(MPersistableEntity.PERSISTANCE_ID_DEFAULT, withoutLinkValue.getPersistenceId()); + assertNull(withoutLinkValue.getName()); + assertNull(withoutLinkValue.getCreationUser()); + assertEquals(linkConfig(), withoutLinkValue.getConnectorLinkConfig()); + assertNull(withoutLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("INTEGER-INPUT").getValue()); + assertNull(withoutLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("STRING-INPUT").getValue()); // Clone with value - MLink withValue = link.clone(true); - assertEquals(link, withValue); - assertEquals(link.getPersistenceId(), withValue.getPersistenceId()); - assertEquals(link.getName(), withValue.getName()); - assertEquals(link.getCreationUser(), withValue.getCreationUser()); - assertEquals(forms1(), withValue.getConnectorPart()); - assertEquals(forms2(), withValue.getFrameworkPart()); - assertEquals(100, withValue.getConnectorPart().getForm("FORMNAME").getInput("INTEGER-INPUT").getValue()); - assertEquals("TEST-VALUE", withValue.getConnectorPart().getForm("FORMNAME").getInput("STRING-INPUT").getValue()); + MLink withLinkValue = link.clone(true); + assertEquals(link, withLinkValue); + assertEquals(link.getPersistenceId(), withLinkValue.getPersistenceId()); + assertEquals(link.getName(), withLinkValue.getName()); + assertEquals(link.getCreationUser(), withLinkValue.getCreationUser()); + assertEquals(linkConfig(), withLinkValue.getConnectorLinkConfig()); + assertEquals(100, withLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("INTEGER-INPUT").getValue()); + assertEquals("TEST-VALUE", withLinkValue.getConnectorLinkConfig().getConfig("CONFIGNAME").getInput("STRING-INPUT").getValue()); } private MLink link() { - MLink link = new MLink(123l, forms1(), forms2()); + MLink link = new MLink(123l, linkConfig()); link.setName("Vampire"); link.setCreationUser("Buffy"); return link; } - private MConnectionForms forms1() { - List<MForm> forms = new ArrayList<MForm>(); + private MLinkConfig linkConfig() { + List<MConfig> configs = new ArrayList<MConfig>(); MIntegerInput input = new MIntegerInput("INTEGER-INPUT", false); input.setValue(100); MStringInput strInput = new MStringInput("STRING-INPUT",false,(short)20); @@ -104,19 +88,9 @@ public class TestMLink { List<MInput<?>> list = new ArrayList<MInput<?>>(); list.add(input); list.add(strInput); - MForm form = new MForm("FORMNAME", list); - forms.add(form); - return new MConnectionForms(forms); - } - - private MConnectionForms forms2() { - List<MForm> forms = new ArrayList<MForm>(); - MMapInput input = new MMapInput("MAP-INPUT", false); - List<MInput<?>> list = new ArrayList<MInput<?>>(); - list.add(input); - MForm form = new MForm("form", list); - forms.add(form); - return new MConnectionForms(forms); + MConfig config = new MConfig("CONFIGNAME", list); + configs.add(config); + return new MLinkConfig(configs); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/model/TestMLinkConfig.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/model/TestMLinkConfig.java b/common/src/test/java/org/apache/sqoop/model/TestMLinkConfig.java new file mode 100644 index 0000000..62f61a6 --- /dev/null +++ b/common/src/test/java/org/apache/sqoop/model/TestMLinkConfig.java @@ -0,0 +1,45 @@ +/** + * 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.model; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class TestMLinkConfig { + + /** + * Test for class initialization and values + */ + @Test + public void testInitialization() { + List<MConfig> configs = new ArrayList<MConfig>(); + MLinkConfig linkConfig = new MLinkConfig(configs); + List<MConfig> testConfig = new ArrayList<MConfig>(); + assertEquals(testConfig, linkConfig.getConfigs()); + MLinkConfig linkConfig2 = new MLinkConfig(testConfig); + assertEquals(linkConfig2, linkConfig); + // Add a config to list for checking not equals + MConfig c = new MConfig("test", null); + testConfig.add(c); + assertFalse(linkConfig.equals(linkConfig2)); + } +} http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/validation/TestValidation.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/validation/TestValidation.java b/common/src/test/java/org/apache/sqoop/validation/TestValidation.java index 85e9e1c..16a8bbe 100644 --- a/common/src/test/java/org/apache/sqoop/validation/TestValidation.java +++ b/common/src/test/java/org/apache/sqoop/validation/TestValidation.java @@ -17,16 +17,20 @@ */ package org.apache.sqoop.validation; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.util.HashMap; import java.util.Map; import org.apache.sqoop.common.SqoopException; -import org.apache.sqoop.validation.Validation.FormInput; -import org.apache.sqoop.validation.Validation.Message; +import org.apache.sqoop.validation.ConfigValidator.ConfigInput; +import org.apache.sqoop.validation.ConfigValidator.Message; import org.junit.Test; -import static org.junit.Assert.*; - /** * Test class for org.apache.sqoop.validation.Validation */ @@ -38,42 +42,42 @@ public class TestValidation { @Test public void testInitialization() { /* Check initialization with class */ - Validation validation = new Validation(Class.class); + ConfigValidator validation = new ConfigValidator(Class.class); assertNotNull(validation); assertEquals(Status.FINE, validation.getStatus()); assertEquals(0, validation.getMessages().size()); /* Check initialization with status and message as null */ - Validation validationNull = new Validation(null, null); + ConfigValidator validationNull = new ConfigValidator(null, null); assertNotNull(validationNull); assertNull(validationNull.getStatus()); assertNull(validationNull.getMessages()); /* Check initialization with status and message with values */ Status s1 = Status.FINE; - Map<FormInput, Message> msg1 = new HashMap<Validation.FormInput, Validation.Message>(); - Validation validation1 = new Validation(s1, msg1); + Map<ConfigInput, Message> msg1 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>(); + ConfigValidator validation1 = new ConfigValidator(s1, msg1); assertNotNull(validation1); assertEquals(Status.FINE, validation1.getStatus()); assertEquals(0, validation1.getMessages().size()); /* Check initialization with status and message with values */ Status s2 = Status.ACCEPTABLE; - Map<FormInput, Message> msg2 = new HashMap<Validation.FormInput, Validation.Message>(); - Validation validation2 = new Validation(s2, msg2); + Map<ConfigInput, Message> msg2 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>(); + ConfigValidator validation2 = new ConfigValidator(s2, msg2); assertNotNull(validation2); assertEquals(Status.ACCEPTABLE, validation2.getStatus()); assertEquals(0, validation2.getMessages().size()); /* Check initialization with status and message with values */ Status s3 = Status.ACCEPTABLE; - Map<FormInput, Message> msg3 = new HashMap<Validation.FormInput, Validation.Message>(); - Validation.FormInput fi = new Validation.FormInput("form\\.input"); - Validation.Message message = new Validation.Message(Status.FINE, "sqoop"); + Map<ConfigInput, Message> msg3 = new HashMap<ConfigValidator.ConfigInput, ConfigValidator.Message>(); + ConfigValidator.ConfigInput fi = new ConfigValidator.ConfigInput("config\\.input"); + ConfigValidator.Message message = new ConfigValidator.Message(Status.FINE, "sqoop"); msg3.put(fi, message); - Validation validation3 = new Validation(s3, msg3); - Validation.FormInput fiTest = new Validation.FormInput("form\\.input"); - Validation.Message messageTest = new Validation.Message(Status.FINE, + ConfigValidator validation3 = new ConfigValidator(s3, msg3); + ConfigValidator.ConfigInput fiTest = new ConfigValidator.ConfigInput("config\\.input"); + ConfigValidator.Message messageTest = new ConfigValidator.Message(Status.FINE, "sqoop"); assertEquals(messageTest, validation3.getMessages().get(fiTest)); assertEquals(Status.ACCEPTABLE, validation3.getStatus()); @@ -82,13 +86,13 @@ public class TestValidation { /** * Test for Validation.ForInput */ - public void testFormInput() { - Validation.FormInput fi = new Validation.FormInput("test\\.test"); + public void testConfigInput() { + ConfigValidator.ConfigInput fi = new ConfigValidator.ConfigInput("test\\.test"); assertNotNull(fi); /* Passing null */ try { - new Validation.FormInput(null); + new ConfigValidator.ConfigInput(null); fail("Assert error is expected"); } catch (AssertionError e) { assertTrue(true); @@ -96,31 +100,31 @@ public class TestValidation { /* Passing empty and check exception messages */ try { - new Validation.FormInput(""); + new ConfigValidator.ConfigInput(""); fail("SqoopException is expected"); } catch (SqoopException e) { - assertEquals(ValidationError.VALIDATION_0003.getMessage(), e + assertEquals(ConfigValidationError.VALIDATION_0003.getMessage(), e .getErrorCode().getMessage()); } /* Passing value and check */ - Validation.FormInput fi2 = new Validation.FormInput("form\\.input"); - assertEquals("form\\", fi2.getForm()); + ConfigValidator.ConfigInput fi2 = new ConfigValidator.ConfigInput("config\\.input"); + assertEquals("config\\", fi2.getConfig()); assertEquals("input", fi2.getInput()); /* Check equals */ - Validation.FormInput fiOne = new Validation.FormInput("form\\.input"); - Validation.FormInput fiTwo = new Validation.FormInput("form\\.input"); + ConfigValidator.ConfigInput fiOne = new ConfigValidator.ConfigInput("config\\.input"); + ConfigValidator.ConfigInput fiTwo = new ConfigValidator.ConfigInput("config\\.input"); assertEquals(fiOne, fiTwo); /* toString() method check */ - assertEquals("form\\.input", fiOne.toString()); + assertEquals("config\\.input", fiOne.toString()); - // Checking null as input field (form validation) - Validation.FormInput fi3 = new FormInput("form"); - assertEquals("form", fi3.getForm()); + // Checking null as input field (config validation) + ConfigValidator.ConfigInput fi3 = new ConfigInput("config"); + assertEquals("config", fi3.getConfig()); assertNull(fi3.getInput()); - assertEquals("form", fi3.toString()); + assertEquals("config", fi3.toString()); } @@ -129,17 +133,17 @@ public class TestValidation { */ public void testMessage() { /* Passing null */ - Validation.Message msg1 = new Validation.Message(null, null); + ConfigValidator.Message msg1 = new ConfigValidator.Message(null, null); assertNull(msg1.getStatus()); assertNull(msg1.getMessage()); /* Passing values */ - Validation.Message msg2 = new Validation.Message(Status.FINE, "sqoop"); + ConfigValidator.Message msg2 = new ConfigValidator.Message(Status.FINE, "sqoop"); assertEquals(Status.FINE, msg2.getStatus()); assertEquals("sqoop", msg2.getMessage()); /* Check for equal */ - Validation.Message msg3 = new Validation.Message(Status.FINE, "sqoop"); + ConfigValidator.Message msg3 = new ConfigValidator.Message(Status.FINE, "sqoop"); assertEquals(msg2, msg3); } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/validation/TestValidationRunner.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/validation/TestValidationRunner.java b/common/src/test/java/org/apache/sqoop/validation/TestValidationRunner.java index 647abe0..579d1c5 100644 --- a/common/src/test/java/org/apache/sqoop/validation/TestValidationRunner.java +++ b/common/src/test/java/org/apache/sqoop/validation/TestValidationRunner.java @@ -18,8 +18,8 @@ package org.apache.sqoop.validation; import org.apache.sqoop.model.ConfigurationClass; -import org.apache.sqoop.model.Form; -import org.apache.sqoop.model.FormClass; +import org.apache.sqoop.model.Config; +import org.apache.sqoop.model.ConfigClass; import org.apache.sqoop.model.Input; import org.apache.sqoop.model.Validator; import org.apache.sqoop.validation.validators.Contains; @@ -35,18 +35,18 @@ import static org.junit.Assert.assertTrue; */ public class TestValidationRunner { - @FormClass(validators = {@Validator(FormA.FormValidator.class)}) - public static class FormA { + @ConfigClass(validators = {@Validator(ConfigA.ConfigValidator.class)}) + public static class ConfigA { @Input(validators = {@Validator(NotNull.class)}) String notNull; - public static class FormValidator extends AbstractValidator<FormA> { + public static class ConfigValidator extends AbstractValidator<ConfigA> { @Override - public void validate(FormA form) { - if(form.notNull == null) { + public void validate(ConfigA config) { + if(config.notNull == null) { addMessage(Status.UNACCEPTABLE, "null"); } - if("error".equals(form.notNull)) { + if("error".equals(config.notNull)) { addMessage(Status.UNACCEPTABLE, "error"); } } @@ -54,83 +54,83 @@ public class TestValidationRunner { } @Test - public void testValidateForm() { - FormA form = new FormA(); - ValidationRunner runner = new ValidationRunner(); - ValidationResult result; - - // Null string should fail on Input level and should not call form level validators - form.notNull = null; - result = runner.validateForm("formName", form); + public void testValidateConfig() { + ConfigA config = new ConfigA(); + ConfigValidationRunner runner = new ConfigValidationRunner(); + ConfigValidationResult result; + + // Null string should fail on Input level and should not call config level validators + config.notNull = null; + result = runner.validateConfig("configName", config); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); - assertTrue(result.getMessages().containsKey("formName.notNull")); + assertTrue(result.getMessages().containsKey("configName.notNull")); - // String "error" should trigger form level error, but not Input level - form.notNull = "error"; - result = runner.validateForm("formName", form); + // String "error" should trigger config level error, but not Input level + config.notNull = "error"; + result = runner.validateConfig("configName", config); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); - assertTrue(result.getMessages().containsKey("formName")); + assertTrue(result.getMessages().containsKey("configName")); // Acceptable state - form.notNull = "This is truly random string"; - result = runner.validateForm("formName", form); + config.notNull = "This is truly random string"; + result = runner.validateConfig("configName", config); assertEquals(Status.FINE, result.getStatus()); assertEquals(0, result.getMessages().size()); } - @FormClass - public static class FormB { + @ConfigClass + public static class ConfigB { @Input(validators = {@Validator(NotNull.class), @Validator(NotEmpty.class)}) String str; } - @FormClass - public static class FormC { + @ConfigClass + public static class ConfigC { @Input(validators = {@Validator(value = Contains.class, strArg = "findme")}) String str; } @Test public void testMultipleValidatorsOnSingleInput() { - FormB form = new FormB(); - ValidationRunner runner = new ValidationRunner(); - ValidationResult result; + ConfigB config = new ConfigB(); + ConfigValidationRunner runner = new ConfigValidationRunner(); + ConfigValidationResult result; - form.str = null; - result = runner.validateForm("formName", form); + config.str = null; + result = runner.validateConfig("configName", config); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); - assertTrue(result.getMessages().containsKey("formName.str")); - assertEquals(2, result.getMessages().get("formName.str").size()); + assertTrue(result.getMessages().containsKey("configName.str")); + assertEquals(2, result.getMessages().get("configName.str").size()); } @Test public void testValidatorWithParameters() { - FormC form = new FormC(); - ValidationRunner runner = new ValidationRunner(); - ValidationResult result; + ConfigC config = new ConfigC(); + ConfigValidationRunner runner = new ConfigValidationRunner(); + ConfigValidationResult result; // Sub string not found - form.str = "Mordor"; - result = runner.validateForm("formName", form); + config.str = "Mordor"; + result = runner.validateConfig("configName", config); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); - assertTrue(result.getMessages().containsKey("formName.str")); + assertTrue(result.getMessages().containsKey("configName.str")); // Sub string found - form.str = "Morfindmedor"; - result = runner.validateForm("formName", form); + config.str = "Morfindmedor"; + result = runner.validateConfig("configName", config); assertEquals(Status.FINE, result.getStatus()); assertEquals(0, result.getMessages().size()); } @ConfigurationClass(validators = {@Validator(ConfigurationA.ClassValidator.class)}) public static class ConfigurationA { - @Form FormA formA; + @Config ConfigA formA; public ConfigurationA() { - formA = new FormA(); + formA = new ConfigA(); } public static class ClassValidator extends AbstractValidator<ConfigurationA> { @@ -149,24 +149,24 @@ public class TestValidationRunner { @Test public void testValidate() { ConfigurationA conf = new ConfigurationA(); - ValidationRunner runner = new ValidationRunner(); - ValidationResult result; + ConfigValidationRunner runner = new ConfigValidationRunner(); + ConfigValidationResult result; - // Null string should fail on Input level and should not call form nor class level validators + // Null string should fail on Input level and should not call config nor class level validators conf.formA.notNull = null; result = runner.validate(conf); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); assertTrue(result.getMessages().containsKey("formA.notNull")); - // String "error" should trigger form level error, but not Input nor class level + // String "error" should trigger config level error, but not Input nor class level conf.formA.notNull = "error"; result = runner.validate(conf); assertEquals(Status.UNACCEPTABLE, result.getStatus()); assertEquals(1, result.getMessages().size()); assertTrue(result.getMessages().containsKey("formA")); - // String "conf-error" should trigger class level error, but not Input nor Form level + // String "conf-error" should trigger class level error, but not Input nor Config level conf.formA.notNull = "conf-error"; result = runner.validate(conf); assertEquals(Status.UNACCEPTABLE, result.getStatus()); http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/common/src/test/java/org/apache/sqoop/validation/validators/TestClassAvailable.java ---------------------------------------------------------------------- diff --git a/common/src/test/java/org/apache/sqoop/validation/validators/TestClassAvailable.java b/common/src/test/java/org/apache/sqoop/validation/validators/TestClassAvailable.java index 62b2e0a..3a15274 100644 --- a/common/src/test/java/org/apache/sqoop/validation/validators/TestClassAvailable.java +++ b/common/src/test/java/org/apache/sqoop/validation/validators/TestClassAvailable.java @@ -17,19 +17,17 @@ */ package org.apache.sqoop.validation.validators; -import org.apache.sqoop.validation.Message; -import org.apache.sqoop.validation.Status; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.util.List; -import static org.junit.Assert.assertEquals; +import org.apache.sqoop.validation.Message; +import org.apache.sqoop.validation.Status; +import org.junit.Test; -/** - */ public class TestClassAvailable { - AbstractValidator validator = new ClassAvailable(); + AbstractValidator<String> validator = new ClassAvailable(); @Test public void test() { http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java index b4b6966..87ac2af 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnector.java @@ -92,7 +92,7 @@ public class GenericJdbcConnector extends SqoopConnector { } @Override - public Validator getValidator() { + public Validator getConfigValidator() { return genericJdbcValidator; } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java index 8deddb0..a069b3e 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcConnectorUpgrader.java @@ -18,21 +18,20 @@ */ package org.apache.sqoop.connector.jdbc; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.log4j.Logger; import org.apache.sqoop.common.SqoopException; import org.apache.sqoop.connector.spi.RepositoryUpgrader; -import org.apache.sqoop.model.MConnectionForms; -import org.apache.sqoop.model.MForm; +import org.apache.sqoop.model.MConfigList; +import org.apache.sqoop.model.MConfig; import org.apache.sqoop.model.MInput; -import org.apache.sqoop.model.MJobForms; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.apache.sqoop.model.MLinkConfig; public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader { - private static final Logger LOG = - Logger.getLogger(GenericJdbcConnectorUpgrader.class); + private static final Logger LOG = Logger.getLogger(GenericJdbcConnectorUpgrader.class); /* * For now, there is no real upgrade. So copy all data over, @@ -41,41 +40,40 @@ public class GenericJdbcConnectorUpgrader extends RepositoryUpgrader { */ @Override - public void upgrade(MConnectionForms original, - MConnectionForms upgradeTarget) { - doUpgrade(original.getForms(), upgradeTarget.getForms()); + public void upgrade(MLinkConfig original, MLinkConfig upgradeTarget) { + doUpgrade(original.getConfigs(), upgradeTarget.getConfigs()); } @Override - public void upgrade(MJobForms original, MJobForms upgradeTarget) { - doUpgrade(original.getForms(), upgradeTarget.getForms()); + public void upgrade(MConfigList original, MConfigList upgradeTarget) { + doUpgrade(original.getConfigs(), upgradeTarget.getConfigs()); } @SuppressWarnings("unchecked") - private void doUpgrade(List<MForm> original, List<MForm> target) { - // Easier to find the form in the original forms list if we use a map. - // Since the constructor of MJobForms takes a list, + private void doUpgrade(List<MConfig> original, List<MConfig> target) { + // Easier to find the config in the original list if we use a map. + // Since the constructor takes a list, // index is not guaranteed to be the same, so we need to look for // equivalence - Map<String, MForm> formMap = new HashMap<String, MForm>(); - for (MForm form : original) { - formMap.put(form.getName(), form); + Map<String, MConfig> configMap = new HashMap<String, MConfig>(); + for (MConfig config : original) { + configMap.put(config.getName(), config); } - for (MForm form : target) { - List<MInput<?>> inputs = form.getInputs(); - MForm originalForm = formMap.get(form.getName()); - if (originalForm == null) { - LOG.warn("Form: '" + form.getName() + "' not present in old " + - "connector. So it and its inputs will not be transferred by the upgrader."); + for (MConfig config : target) { + List<MInput<?>> inputs = config.getInputs(); + MConfig orginalConfig = configMap.get(config.getName()); + if (orginalConfig == null) { + LOG.warn("Config: '" + config.getName() + "' not present in old " + + "generic JDBC connector. So it and its inputs will not be transferred by the upgrader."); continue; } for (MInput input : inputs) { try { - MInput originalInput = originalForm.getInput(input.getName()); + MInput originalInput = orginalConfig.getInput(input.getName()); input.setValue(originalInput.getValue()); } catch (SqoopException ex) { LOG.warn("Input: '" + input.getName() + "' not present in old " + - "connector. So it will not be transferred by the upgrader."); + "generic JDBC connector. So it will not be transferred by the upgrader."); } } } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java index e52610a..af9320b 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcExtractor.java @@ -34,12 +34,12 @@ public class GenericJdbcExtractor extends Extractor<LinkConfiguration, FromJobCo private long rowsRead = 0; @Override - public void extract(ExtractorContext context, LinkConfiguration linkConf, - FromJobConfiguration fromJobConf, GenericJdbcPartition partition) { - String driver = linkConf.link.jdbcDriver; - String url = linkConf.link.connectionString; - String username = linkConf.link.username; - String password = linkConf.link.password; + public void extract(ExtractorContext context, LinkConfiguration linkConfig, + FromJobConfiguration fromJobConfig, GenericJdbcPartition partition) { + String driver = linkConfig.linkConfig.jdbcDriver; + String url = linkConfig.linkConfig.connectionString; + String username = linkConfig.linkConfig.username; + String password = linkConfig.linkConfig.password; GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); String query = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_FROM_DATA_SQL); http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java index d3a893f..3a783be 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromDestroyer.java @@ -29,7 +29,7 @@ public class GenericJdbcFromDestroyer extends Destroyer<LinkConfiguration, FromJ Logger.getLogger(GenericJdbcFromDestroyer.class); @Override - public void destroy(DestroyerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { + public void destroy(DestroyerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { LOG.info("Running generic JDBC connector destroyer"); } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java index 9d0c178..ef4ecc4 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcFromInitializer.java @@ -45,34 +45,34 @@ public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, F private GenericJdbcExecutor executor; @Override - public void initialize(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { - configureJdbcProperties(context.getContext(), linkConf, fromJobConf); + public void initialize(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { + configureJdbcProperties(context.getContext(), linkConfig, fromJobConfig); try { - configurePartitionProperties(context.getContext(), linkConf, fromJobConf); - configureTableProperties(context.getContext(), linkConf, fromJobConf); + configurePartitionProperties(context.getContext(), linkConfig, fromJobConfig); + configureTableProperties(context.getContext(), linkConfig, fromJobConfig); } finally { executor.close(); } } @Override - public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { + public List<String> getJars(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { List<String> jars = new LinkedList<String>(); - jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); + jars.add(ClassUtils.jarForClass(linkConfig.linkConfig.jdbcDriver)); return jars; } @Override - public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { - configureJdbcProperties(context.getContext(), linkConf, fromJobConf); + public Schema getSchema(InitializerContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { + configureJdbcProperties(context.getContext(), linkConfig, fromJobConfig); - String schemaName = fromJobConf.fromJobConfig.tableName; + String schemaName = fromJobConfig.fromJobConfig.tableName; if(schemaName == null) { schemaName = "Query"; - } else if(fromJobConf.fromJobConfig.schemaName != null) { - schemaName = fromJobConf.fromJobConfig.schemaName + "." + schemaName; + } else if(fromJobConfig.fromJobConfig.schemaName != null) { + schemaName = fromJobConfig.fromJobConfig.schemaName + "." + schemaName; } Schema schema = new Schema(schemaName); @@ -117,11 +117,11 @@ public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, F } } - private void configureJdbcProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { - String driver = connectionConfig.link.jdbcDriver; - String url = connectionConfig.link.connectionString; - String username = connectionConfig.link.username; - String password = connectionConfig.link.password; + private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { + String driver = linkConfig.linkConfig.jdbcDriver; + String url = linkConfig.linkConfig.connectionString; + String username = linkConfig.linkConfig.username; + String password = linkConfig.linkConfig.password; assert driver != null; assert url != null; @@ -129,7 +129,7 @@ public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, F executor = new GenericJdbcExecutor(driver, url, username, password); } - private void configurePartitionProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { + private void configurePartitionProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { // ----- configure column name ----- String partitionColumnName = fromJobConfig.fromJobConfig.partitionColumn; @@ -234,7 +234,7 @@ public class GenericJdbcFromInitializer extends Initializer<LinkConfiguration, F } } - private void configureTableProperties(MutableContext context, LinkConfiguration connectionConfig, FromJobConfiguration fromJobConfig) { + private void configureTableProperties(MutableContext context, LinkConfiguration linkConfig, FromJobConfiguration fromJobConfig) { String dataSql; String fieldNames; http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java index 991e686..6340a70 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcLoader.java @@ -30,11 +30,11 @@ public class GenericJdbcLoader extends Loader<LinkConfiguration, ToJobConfigurat private int batchesPerTransaction = DEFAULT_BATCHES_PER_TRANSACTION; @Override - public void load(LoaderContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) throws Exception{ - String driver = linkConf.link.jdbcDriver; - String url = linkConf.link.connectionString; - String username = linkConf.link.username; - String password = linkConf.link.password; + public void load(LoaderContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) throws Exception{ + String driver = linkConfig.linkConfig.jdbcDriver; + String url = linkConfig.linkConfig.connectionString; + String username = linkConfig.linkConfig.username; + String password = linkConfig.linkConfig.password; GenericJdbcExecutor executor = new GenericJdbcExecutor(driver, url, username, password); executor.setAutoCommit(false); http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java index 6b11228..2411169 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcPartitioner.java @@ -47,7 +47,8 @@ public class GenericJdbcPartitioner extends Partitioner<LinkConfiguration, FromJ private Boolean partitionColumnNull; @Override - public List<Partition> getPartitions(PartitionerContext context,LinkConfiguration linkConf, FromJobConfiguration fromJobConf) { + public List<Partition> getPartitions(PartitionerContext context, LinkConfiguration linkConfig, + FromJobConfiguration fromJobConfig) { List<Partition> partitions = new LinkedList<Partition>(); numberPartitions = context.getMaxPartitions(); @@ -56,7 +57,7 @@ public class GenericJdbcPartitioner extends Partitioner<LinkConfiguration, FromJ partitionMinValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MINVALUE); partitionMaxValue = context.getString(GenericJdbcConnectorConstants.CONNECTOR_JDBC_PARTITION_MAXVALUE); - partitionColumnNull = fromJobConf.fromJobConfig.partitionColumnNull; + partitionColumnNull = fromJobConfig.fromJobConfig.partitionColumnNull; if (partitionColumnNull == null) { partitionColumnNull = false; } http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java index 7bed1d9..e381651 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToDestroyer.java @@ -28,26 +28,26 @@ public class GenericJdbcToDestroyer extends Destroyer<LinkConfiguration, ToJobCo private static final Logger LOG = Logger.getLogger(GenericJdbcToDestroyer.class); @Override - public void destroy(DestroyerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { + public void destroy(DestroyerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { LOG.info("Running generic JDBC connector destroyer"); - final String tableName = toJobConf.toJobConfig.tableName; - final String stageTableName = toJobConf.toJobConfig.stageTableName; + final String tableName = toJobConfig.toJobConfig.tableName; + final String stageTableName = toJobConfig.toJobConfig.stageTableName; final boolean stageEnabled = stageTableName != null && stageTableName.length() > 0; if(stageEnabled) { - moveDataToDestinationTable(linkConf, + moveDataToDestinationTable(linkConfig, context.isSuccess(), stageTableName, tableName); } } - private void moveDataToDestinationTable(LinkConfiguration linkConf, + private void moveDataToDestinationTable(LinkConfiguration linkConfig, boolean success, String stageTableName, String tableName) { GenericJdbcExecutor executor = - new GenericJdbcExecutor(linkConf.link.jdbcDriver, - linkConf.link.connectionString, - linkConf.link.username, - linkConf.link.password); + new GenericJdbcExecutor(linkConfig.linkConfig.jdbcDriver, + linkConfig.linkConfig.connectionString, + linkConfig.linkConfig.username, + linkConfig.linkConfig.password); try { if(success) { LOG.info("Job completed, transferring data from stage fromTable to " + http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java index 5d0ec93..1747347 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcToInitializer.java @@ -43,35 +43,35 @@ public class GenericJdbcToInitializer extends Initializer<LinkConfiguration, ToJ Logger.getLogger(GenericJdbcToInitializer.class); @Override - public void initialize(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { - configureJdbcProperties(context.getContext(), linkConf, toJobConf); + public void initialize(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { + configureJdbcProperties(context.getContext(), linkConfig, toJobConfig); try { - configureTableProperties(context.getContext(), linkConf, toJobConf); + configureTableProperties(context.getContext(), linkConfig, toJobConfig); } finally { executor.close(); } } @Override - public List<String> getJars(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { + public List<String> getJars(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { List<String> jars = new LinkedList<String>(); - jars.add(ClassUtils.jarForClass(linkConf.link.jdbcDriver)); + jars.add(ClassUtils.jarForClass(linkConfig.linkConfig.jdbcDriver)); return jars; } @Override - public Schema getSchema(InitializerContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { - configureJdbcProperties(context.getContext(), linkConf, toJobConf); + public Schema getSchema(InitializerContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { + configureJdbcProperties(context.getContext(), linkConfig, toJobConfig); - String schemaName = toJobConf.toJobConfig.tableName; + String schemaName = toJobConfig.toJobConfig.tableName; if (schemaName == null) { throw new SqoopException(GenericJdbcConnectorError.GENERIC_JDBC_CONNECTOR_0019, "Table name extraction not supported yet."); } - if(toJobConf.toJobConfig.schemaName != null) { - schemaName = toJobConf.toJobConfig.schemaName + "." + schemaName; + if(toJobConfig.toJobConfig.schemaName != null) { + schemaName = toJobConfig.toJobConfig.schemaName + "." + schemaName; } Schema schema = new Schema(schemaName); @@ -110,11 +110,11 @@ public class GenericJdbcToInitializer extends Initializer<LinkConfiguration, ToJ } } - private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConf) { - String driver = linkConf.link.jdbcDriver; - String url = linkConf.link.connectionString; - String username = linkConf.link.username; - String password = linkConf.link.password; + private void configureJdbcProperties(MutableContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { + String driver = linkConfig.linkConfig.jdbcDriver; + String url = linkConfig.linkConfig.connectionString; + String username = linkConfig.linkConfig.username; + String password = linkConfig.linkConfig.password; assert driver != null; assert url != null; @@ -122,7 +122,7 @@ public class GenericJdbcToInitializer extends Initializer<LinkConfiguration, ToJ executor = new GenericJdbcExecutor(driver, url, username, password); } - private void configureTableProperties(MutableContext context, LinkConfiguration linkConf, ToJobConfiguration toJobConfig) { + private void configureTableProperties(MutableContext context, LinkConfiguration linkConfig, ToJobConfiguration toJobConfig) { String dataSql; String schemaName = toJobConfig.toJobConfig.schemaName; http://git-wip-us.apache.org/repos/asf/sqoop/blob/8362c73c/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java ---------------------------------------------------------------------- diff --git a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java index ad1ee5c..93989a4 100644 --- a/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java +++ b/connector/connector-generic-jdbc/src/main/java/org/apache/sqoop/connector/jdbc/GenericJdbcValidator.java @@ -22,7 +22,7 @@ import org.apache.sqoop.connector.jdbc.configuration.LinkConfiguration; import org.apache.sqoop.connector.jdbc.configuration.FromJobConfiguration; import org.apache.sqoop.connector.jdbc.configuration.ToJobConfiguration; import org.apache.sqoop.validation.Status; -import org.apache.sqoop.validation.Validation; +import org.apache.sqoop.validation.ConfigValidator; import org.apache.sqoop.validation.Validator; import java.sql.DriverManager; @@ -34,30 +34,30 @@ import java.sql.SQLException; public class GenericJdbcValidator extends Validator { @Override - public Validation validateLink(Object configuration) { - Validation validation = new Validation(LinkConfiguration.class); - LinkConfiguration linkConf = (LinkConfiguration)configuration; + public ConfigValidator validateConfigForLink(Object configuration) { + ConfigValidator validation = new ConfigValidator(LinkConfiguration.class); + LinkConfiguration linkConfig = (LinkConfiguration)configuration; - if(linkConf.link.jdbcDriver == null) { + if(linkConfig.linkConfig.jdbcDriver == null) { validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Driver can't be empty"); } else { try { - Class.forName(linkConf.link.jdbcDriver); + Class.forName(linkConfig.linkConfig.jdbcDriver); } catch (ClassNotFoundException e) { validation.addMessage(Status.UNACCEPTABLE, "link", "jdbcDriver", "Can't load specified driver"); } } - if(linkConf.link.connectionString == null) { + if(linkConfig.linkConfig.connectionString == null) { validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "JDBC URL can't be empty"); - } else if(!linkConf.link.connectionString.startsWith("jdbc:")) { + } else if(!linkConfig.linkConfig.connectionString.startsWith("jdbc:")) { validation.addMessage(Status.UNACCEPTABLE, "link", "connectionString", "This do not seem as a valid JDBC URL"); } // See if we can connect to the database try { - DriverManager.getConnection(linkConf.link.connectionString, - linkConf.link.username, linkConf.link.password); + DriverManager.getConnection(linkConfig.linkConfig.connectionString, + linkConfig.linkConfig.username, linkConfig.linkConfig.password); } catch (SQLException e) { validation.addMessage(Status.ACCEPTABLE, "link", "Can't connect to the database with given credentials: " + e.getMessage()); } @@ -67,7 +67,7 @@ public class GenericJdbcValidator extends Validator { } @Override - public Validation validateJob(Object jobConfiguration) { + public ConfigValidator validateConfigForJob(Object jobConfiguration) { if (jobConfiguration instanceof FromJobConfiguration) { return validateFromJobConfiguration((FromJobConfiguration)jobConfiguration); } else if (jobConfiguration instanceof ToJobConfiguration) { @@ -78,8 +78,8 @@ public class GenericJdbcValidator extends Validator { } } - private Validation validateToJobConfiguration(ToJobConfiguration configuration) { - Validation validation = new Validation(FromJobConfiguration.class); + private ConfigValidator validateToJobConfiguration(ToJobConfiguration configuration) { + ConfigValidator validation = new ConfigValidator(FromJobConfiguration.class); if(configuration.toJobConfig.tableName == null && configuration.toJobConfig.sql == null) { validation.addMessage(Status.UNACCEPTABLE, "toJobConfig", "Either table name or SQL must be specified"); @@ -102,8 +102,8 @@ public class GenericJdbcValidator extends Validator { return validation; } - private Validation validateFromJobConfiguration(FromJobConfiguration configuration) { - Validation validation = new Validation(FromJobConfiguration.class); + private ConfigValidator validateFromJobConfiguration(FromJobConfiguration configuration) { + ConfigValidator validation = new ConfigValidator(FromJobConfiguration.class); if(configuration.fromJobConfig.tableName == null && configuration.fromJobConfig.sql == null) { validation.addMessage(Status.UNACCEPTABLE, "fromJobConfig", "Either table name or SQL must be specified");