diff --git a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java index df41fb10..4a502b0e 100644 --- a/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java +++ b/repository/repository-common/src/main/java/org/apache/sqoop/repository/common/CommonRepoUtils.java @@ -27,6 +27,8 @@ public class CommonRepoUtils { public static final String QUOTE_CHARACTER = "\""; + public static final String SINGLE_QUOTO_CHARACTER = "\'"; + public static final String escapeTableName(String tableName) { return QUOTE_CHARACTER + tableName + QUOTE_CHARACTER; } @@ -47,6 +49,10 @@ public static final String escapeConstraintName(String constraintName) { return QUOTE_CHARACTER + constraintName + QUOTE_CHARACTER; } + public static final String escapeLiteralString(String literalString) { + return SINGLE_QUOTO_CHARACTER + literalString + SINGLE_QUOTO_CHARACTER; + } + public static final String getTableName(String schemaName, String tableName) { if (schemaName != null) { return escapeSchemaName(schemaName) + "." + escapeTableName(tableName); diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java index 45c7447c..03021500 100644 --- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java +++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbyRepositoryHandler.java @@ -312,6 +312,12 @@ public void createOrUpgradeRepository(Connection conn) { runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn); runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn); runQuery(QUERY_CREATE_TABLE_SQ_CONTEXT, conn); + + runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn); + runQuery(QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn); + runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn); + runQuery(QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn); + runQuery(QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn); } // last step upgrade the repository version to the latest value in the code diff --git a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java index 6adf9599..5081b82a 100644 --- a/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java +++ b/repository/repository-derby/src/main/java/org/apache/sqoop/repository/derby/DerbySchemaUpgradeQuery.java @@ -633,6 +633,35 @@ public static final String getDropConstraintQuery(String schemaName, String tabl + QUERY_SELECT_DIRECTION_CONFIG_BY_DIRECTION_NAME + ")"; + public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME = + "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME) + + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + + " = " + CommonRepoUtils.escapeLiteralString("link_") + " || " + + "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID) + "))" + + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + + " NOT NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME = + "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME) + + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + + " = " + CommonRepoUtils.escapeLiteralString("job_") + " || " + + "TRIM(CHAR(" + CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID) + "))" + + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + + " NOT NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME) + + " NOT NULL"; + private DerbySchemaUpgradeQuery() { // Disable explicit object creation } diff --git a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java index 46493a3c..47f12fe4 100644 --- a/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java +++ b/repository/repository-mysql/src/main/java/org/apache/sqoop/repository/mysql/MySqlSchemaCreateQuery.java @@ -42,7 +42,7 @@ public class MySqlSchemaCreateQuery { public static final String QUERY_CREATE_TABLE_SQ_CONFIGURABLE = "CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME) + " (" + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, " - + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64)," + + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_NAME) + " VARCHAR(64) NOT NULL," + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_TYPE) + " VARCHAR(32), " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_CLASS) + " VARCHAR(255), " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQC_VERSION) + " VARCHAR(64), " @@ -135,7 +135,7 @@ public class MySqlSchemaCreateQuery { "CREATE TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME) + " (" + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CONFIGURABLE) + " BIGINT, " - + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32), " + + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME) + " VARCHAR(32) NOT NULL, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_DATE) + " TIMESTAMP, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQ_LNK_UPDATE_DATE) + " TIMESTAMP, " @@ -154,7 +154,7 @@ public class MySqlSchemaCreateQuery { + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_ID) + " BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_FROM_LINK) + " BIGINT, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_TO_LINK) + " BIGINT, " - + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64), " + + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_NAME) + " VARCHAR(64) NOT NULL, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_DATE) + " TIMESTAMP, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_CREATION_USER) + " VARCHAR(32) DEFAULT NULL, " + CommonRepoUtils.escapeColumnName(CommonRepositorySchemaConstants.COLUMN_SQB_UPDATE_DATE) + " TIMESTAMP, " diff --git a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java index 5ada2d0c..400d706c 100644 --- a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java +++ b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlRepositoryHandler.java @@ -139,6 +139,12 @@ public void createOrUpgradeRepository(Connection conn) { runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_TYPE, conn); runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT_PROPERTY, conn); runQuery(PostgresqlSchemaCreateQuery.QUERY_CREATE_TABLE_SQ_CONTEXT, conn); + + runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME, conn); + runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL, conn); + runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME, conn); + runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn); + runQuery(PostgresqlSchemaUpgradeQuery.QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL, conn); } try (PreparedStatement stmtDel = conn.prepareStatement(PostgresqlSchemaQuery.STMT_DELETE_SYSTEM); diff --git a/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java new file mode 100644 index 00000000..52954e69 --- /dev/null +++ b/repository/repository-postgresql/src/main/java/org/apache/sqoop/repository/postgresql/PostgresqlSchemaUpgradeQuery.java @@ -0,0 +1,61 @@ +/** + * 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.repository.postgresql; + +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_ID; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQC_NAME; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_ID; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQ_LNK_NAME; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.COLUMN_SQB_NAME; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.SCHEMA_SQOOP; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_CONFIGURABLE_NAME; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_JOB_NAME; +import static org.apache.sqoop.repository.common.CommonRepositorySchemaConstants.TABLE_SQ_LINK_NAME; + +import org.apache.sqoop.repository.common.CommonRepoUtils; + +public class PostgresqlSchemaUpgradeQuery { + public static final String QUERY_UPGRADE_TABLE_SQ_LINK_UPDATE_COLUMN_SQ_LINK_NAME = + "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME) + + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + + " = " + CommonRepoUtils.escapeLiteralString("link_") + " || " + + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_ID) + + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + " IS NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_LINK_ALTER_COLUMN_SQ_LINK_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_LINK_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQ_LNK_NAME) + + " SET NOT NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_JOB_UPDATE_COLUMN_SQB_NAME = + "UPDATE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME) + + " SET " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + + " = " + CommonRepoUtils.escapeLiteralString("job_") + " || " + + CommonRepoUtils.escapeColumnName(COLUMN_SQB_ID) + + " WHERE " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + " IS NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_JOB_ALTER_COLUMN_SQB_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_JOB_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQB_NAME) + + " SET NOT NULL"; + + public static final String QUERY_UPGRADE_TABLE_SQ_CONFIGURABLE_ALTER_COLUMN_SQB_NAME_NOT_NULL = + "ALTER TABLE " + CommonRepoUtils.getTableName(SCHEMA_SQOOP, TABLE_SQ_CONFIGURABLE_NAME) + + " ALTER COLUMN " + CommonRepoUtils.escapeColumnName(COLUMN_SQC_NAME) + + " SET NOT NULL"; +} diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java b/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java index 63b12673..8b5f380b 100644 --- a/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java +++ b/shell/src/main/java/org/apache/sqoop/shell/utils/ConfigFiller.java @@ -888,7 +888,13 @@ static String getName(ConsoleReader reader, String name) throws IOException { nameInput.setValue(name); } - fillInputStringWithBundle(nameInput, reader, getResourceBundle()); + do { + fillInputStringWithBundle(nameInput, reader, getResourceBundle()); + if (StringUtils.isEmpty(nameInput.getValue())) { + errorMessage(nameInput, "Job name or link name cannot be null"); + continue; + } + } while (false); return nameInput.getValue(); } diff --git a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java index 82043eaf..386b7011 100644 --- a/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java +++ b/test/src/main/java/org/apache/sqoop/test/infrastructure/SqoopTestCase.java @@ -40,6 +40,7 @@ import org.apache.sqoop.test.infrastructure.providers.InfrastructureProvider; import org.apache.sqoop.test.infrastructure.providers.SqoopInfrastructureProvider; import org.apache.sqoop.test.utils.HdfsUtils; +import org.apache.sqoop.test.utils.SqoopUtils; import org.apache.sqoop.validation.Status; import org.testng.ITest; import org.testng.ITestContext; @@ -330,6 +331,7 @@ public SqoopClient getClient() { * @param link */ public void saveLink(MLink link) { + SqoopUtils.fillObjectName(link); assertEquals(Status.OK, getClient().saveLink(link)); assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, link.getPersistenceId()); } @@ -340,6 +342,7 @@ public void saveLink(MLink link) { * @param job */ public void saveJob(MJob job) { + SqoopUtils.fillObjectName(job); assertEquals(Status.OK, getClient().saveJob(job)); assertNotSame(MPersistableEntity.PERSISTANCE_ID_DEFAULT, job.getPersistenceId()); } diff --git a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java index e3e7bfe0..4452558e 100644 --- a/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java +++ b/test/src/main/java/org/apache/sqoop/test/testcases/ConnectorTestCase.java @@ -36,6 +36,7 @@ import org.apache.sqoop.test.data.Cities; import org.apache.sqoop.test.data.ShortStories; import org.apache.sqoop.test.data.UbuntuReleases; +import org.apache.sqoop.test.utils.SqoopUtils; import org.apache.sqoop.validation.Status; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -253,6 +254,7 @@ protected void assertRowInCities(Object... values) { * @param link */ protected void saveLink(MLink link) { + SqoopUtils.fillObjectName(link); assertEquals(getClient().saveLink(link), Status.OK); assertNotSame(link.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT); } @@ -265,7 +267,8 @@ protected void saveLink(MLink link) { * @param job */ protected void saveJob(MJob job) { - assertEquals(getClient().saveJob(job), Status.OK); + SqoopUtils.fillObjectName(job); + assertEquals(getClient().saveJob(job), Status.OK); assertNotSame(job.getPersistenceId(), MPersistableEntity.PERSISTANCE_ID_DEFAULT); } diff --git a/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java b/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java new file mode 100644 index 00000000..5964bcd8 --- /dev/null +++ b/test/src/main/java/org/apache/sqoop/test/utils/SqoopUtils.java @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sqoop.test.utils; + +import java.util.Random; + +import org.apache.sqoop.model.MAccountableEntity; +import org.apache.sqoop.model.MJob; +import org.apache.sqoop.model.MLink; + +public class SqoopUtils { + private static final Random rand = new Random(); + + public static void fillObjectName(MAccountableEntity object) { + String objectName = object.getName(); + if (objectName != null && !objectName.isEmpty()) { + return; + } + + String prefix = ""; + if (object instanceof MLink) { + prefix = "link_"; + } else if (object instanceof MJob) { + prefix = "job_"; + } + object.setName(prefix + rand.nextLong()); + } +} diff --git a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java new file mode 100644 index 00000000..4183d8b3 --- /dev/null +++ b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_5UpgradeTest.java @@ -0,0 +1,125 @@ +/** + * 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.integration.repository.derby.upgrade; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.sqoop.model.MJob; +import org.apache.sqoop.model.MLink; +import org.apache.sqoop.validation.Status; +import org.testng.annotations.Test; + +/** + * This version contains the following structures: + * Generic JDBC Connector link with name "Link1" and id 1 + * Generic JDBC Connector link with blank name and id 2 + * HDFS Connector link with name "Link3" and id 3 + * HDFS Connector link with blank name and id 4 + * HDFS Connector link with blank name and id 5 + * HDFS Connector link with blank name and id 6 + * Job (-f 1 -t 3) with name "Import" and id 1 + * Job (-f 1 -t 3) with name "Query" and id 2 + * Job (-f 3 -t 1) with name "Export" and id 3 + * Job (-f 3 -t 1) with blank name and id 4 + * Job (-f 3 -t 1) with blank name and id 5 + * Job (-f 1 -t 1) with name "SameConnector" and id 6 + * Job with id 1 has been executed 3 times + * Job with id 2 has been executed 3 times + * Job with id 3 has been executed 1 times + * Link with id 4 has been disabled + * Link with id 5 has been disabled + * Job with id 4 has been disabled + * Job with id 5 has been disabled + */ +public class Derby1_99_5UpgradeTest extends DerbyRepositoryUpgradeTest { + + @Override + public String getPathToRepositoryTarball() { + return "/repository/derby/derby-repository-1.99.5.tar.gz"; + } + + @Override + public int getNumberOfLinks() { + return 6; + } + + @Override + public int getNumberOfJobs() { + return 6; + } + + @Override + public Map getNumberOfSubmissions() { + HashMap ret = new HashMap(); + ret.put(1, 3); + ret.put(2, 3); + ret.put(3, 1); + ret.put(4, 0); + ret.put(5, 0); + return ret; + } + + @Override + public Integer[] getDisabledLinkIds() { + return new Integer[] {4, 5}; + } + + @Override + public Integer[] getDisabledJobIds() { + return new Integer[] {4, 5}; + } + + @Override + public Integer[] getDeleteLinkIds() { + return new Integer[] {1, 2, 3, 4, 5, 6}; + } + + @Override + public Integer[] getDeleteJobIds() { + return new Integer[] {1, 2, 3, 4, 5, 6}; + } + + @Test + public void testJobNameNotNull() { + assertEquals(getNumberOfJobs(), getClient().getJobs().size()); + for(MJob job : getClient().getJobs()) { + assertNotNull(job.getName()); + } + + MJob job = getClient().createJob(1, 1); + assertNull(job.getName()); + assertEquals(getClient().saveJob(job), Status.ERROR); + } + + @Test + public void testLinkNameNotNull() { + assertEquals(getNumberOfLinks(), getClient().getLinks().size()); + for(MLink link : getClient().getLinks()) { + assertNotNull(link.getName()); + } + + MLink link = getClient().createLink("generic-jdbc-connector"); + assertNull(link.getName()); + assertEquals(getClient().saveLink(link), Status.ERROR); + } +} diff --git a/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java new file mode 100644 index 00000000..59980c0a --- /dev/null +++ b/test/src/test/java/org/apache/sqoop/integration/repository/derby/upgrade/Derby1_99_6UpgradeTest.java @@ -0,0 +1,126 @@ +/** + * 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.integration.repository.derby.upgrade; + +import static org.testng.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.sqoop.model.MJob; +import org.apache.sqoop.model.MLink; +import org.apache.sqoop.validation.Status; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +/** + * This version contains the following structures: + * Generic JDBC Connector link with name "Link1" and id 1 + * Generic JDBC Connector link with blank name and id 2 + * HDFS Connector link with name "Link3" and id 3 + * HDFS Connector link with blank name and id 4 + * HDFS Connector link with blank name and id 5 + * HDFS Connector link with blank name and id 6 + * Job (-f 1 -t 3) with name "Import" and id 1 + * Job (-f 1 -t 3) with name "Query" and id 2 + * Job (-f 3 -t 1) with name "Export" and id 3 + * Job (-f 3 -t 1) with blank name and id 4 + * Job (-f 3 -t 1) with blank name and id 5 + * Job (-f 1 -t 1) with name "SameConnector" and id 6 + * Job with id 1 has been executed 3 times + * Job with id 2 has been executed 3 times + * Job with id 3 has been executed 1 times + * Link with id 4 has been disabled + * Link with id 5 has been disabled + * Job with id 4 has been disabled + * Job with id 5 has been disabled + */ +public class Derby1_99_6UpgradeTest extends DerbyRepositoryUpgradeTest { + + @Override + public String getPathToRepositoryTarball() { + return "/repository/derby/derby-repository-1.99.6.tar.gz"; + } + + @Override + public int getNumberOfLinks() { + return 6; + } + + @Override + public int getNumberOfJobs() { + return 6; + } + + @Override + public Map getNumberOfSubmissions() { + HashMap ret = new HashMap(); + ret.put(1, 3); + ret.put(2, 3); + ret.put(3, 1); + ret.put(4, 0); + ret.put(5, 0); + return ret; + } + + @Override + public Integer[] getDisabledLinkIds() { + return new Integer[] {4, 5}; + } + + @Override + public Integer[] getDisabledJobIds() { + return new Integer[] {4, 5}; + } + + @Override + public Integer[] getDeleteLinkIds() { + return new Integer[] {1, 2, 3, 4, 5, 6}; + } + + @Override + public Integer[] getDeleteJobIds() { + return new Integer[] {1, 2, 3, 4, 5, 6}; + } + + @Test + public void testJobNameNotNull() { + assertEquals(getNumberOfJobs(), getClient().getJobs().size()); + for(MJob job : getClient().getJobs()) { + assertNotNull(job.getName()); + } + + MJob job = getClient().createJob(1, 1); + assertNull(job.getName()); + assertEquals(getClient().saveJob(job), Status.ERROR); + } + + @Test + public void testLinkNameNotNull() { + assertEquals(getNumberOfLinks(), getClient().getLinks().size()); + for(MLink link : getClient().getLinks()) { + assertNotNull(link.getName()); + } + + MLink link = getClient().createLink("generic-jdbc-connector"); + assertNull(link.getName()); + assertEquals(getClient().saveLink(link), Status.ERROR); + } +} diff --git a/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz b/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz new file mode 100644 index 00000000..b5714250 Binary files /dev/null and b/test/src/test/resources/repository/derby/derby-repository-1.99.5.tar.gz differ diff --git a/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz b/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz new file mode 100644 index 00000000..be366b07 Binary files /dev/null and b/test/src/test/resources/repository/derby/derby-repository-1.99.6.tar.gz differ