Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YamlTemplate ITs for JdbcToBigQuery #1993

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions cicd/cmd/run-it-yaml-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2024 Google LLC
*
* Licensed 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 main

import (
"flag"
"log"

"github.com/GoogleCloudPlatform/DataflowTemplates/cicd/internal/flags"
"github.com/GoogleCloudPlatform/DataflowTemplates/cicd/internal/workflows"
)

func main() {
flags.RegisterCommonFlags()
flags.RegisterItFlags()
flag.Parse()

// Run mvn install before running integration tests
mvnFlags := workflows.NewMavenFlags()
err := workflows.MvnCleanInstall().Run(
mvnFlags.IncludeDependencies(),
mvnFlags.IncludeDependents(),
mvnFlags.SkipDependencyAnalysis(),
mvnFlags.SkipCheckstyle(),
mvnFlags.SkipJib(),
mvnFlags.SkipTests(),
mvnFlags.SkipJacoco(),
mvnFlags.SkipShade(),
mvnFlags.ThreadCount(8),
mvnFlags.InternalMaven())
if err != nil {
log.Fatalf("%v\n", err)
}

// Run integration tests
mvnFlags = workflows.NewMavenFlags()
err = workflows.MvnVerify().Run(
mvnFlags.IncludeDependencies(),
mvnFlags.IncludeDependents(),
mvnFlags.SkipDependencyAnalysis(),
mvnFlags.SkipCheckstyle(),
mvnFlags.SkipJib(),
mvnFlags.SkipShade(),
mvnFlags.RunYamlIntegrationTests(),
mvnFlags.ThreadCount(4),
mvnFlags.IntegrationTestParallelism(3),
mvnFlags.StaticBigtableInstance("teleport"),
mvnFlags.StaticSpannerInstance("teleport"),
mvnFlags.InternalMaven(),
flags.Region(),
flags.Project(),
flags.ArtifactBucket(),
flags.StageBucket(),
flags.HostIp(),
flags.PrivateConnectivity(),
flags.SpannerHost(),
flags.FailureMode(),
flags.RetryFailures(),
flags.StaticOracleHost(),
flags.StaticOracleSysPassword(),
flags.CloudProxyHost(),
flags.CloudProxyMySqlPort(),
flags.CloudProxyPostgresPort(),
flags.CloudProxyPassword(),
flags.UnifiedWorkerHarnessContainerImage(),
flags.CloudProxyPassword())
if err != nil {
log.Fatalf("%v\n", err)
}
log.Println("Build Successful!")
}
4 changes: 4 additions & 0 deletions cicd/internal/flags/common-flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
DEFAULT = "DEFAULT" // Modules other than those excluded
KAFKA = "KAFKA"
SPANNER = "SPANNER"
YAML = "YAML"
)

// Avoid making these vars public.
Expand All @@ -48,6 +49,9 @@ var (
"v2/spanner-to-sourcedb/",
"v2/spanner-custom-shard",
"plugins/templates-maven-plugin"},
YAML: {"yaml/",
"plugins/templates-maven-plugin",
},
}
)

Expand Down
5 changes: 5 additions & 0 deletions cicd/internal/workflows/maven-workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type MavenFlags interface {
SkipIntegrationTests() string
FailAtTheEnd() string
RunIntegrationTests() string
RunYamlIntegrationTests() string
RunIntegrationSmokeTests() string
RunLoadTests() string
RunLoadTestObserver() string
Expand Down Expand Up @@ -111,6 +112,10 @@ func (*mvnFlags) RunIntegrationTests() string {
return "-PtemplatesIntegrationTests"
}

func (*mvnFlags) RunYamlIntegrationTests() string {
return "-PtemplatesYamlIntegrationTests"
}

func (*mvnFlags) RunIntegrationSmokeTests() string {
return "-PtemplatesIntegrationSmokeTests"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.function.Function;
import org.apache.beam.it.common.utils.IORedirectUtil;
import org.apache.beam.it.gcp.storage.GcsResourceManager;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,10 +38,10 @@
private static final String JAR_SUFFIX = ".jar";

// The JDBC Driver fully-qualified class names
protected static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
protected static final String POSTGRES_DRIVER = "org.postgresql.Driver";
protected static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
protected static final String MSSQL_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
public static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
public static final String POSTGRES_DRIVER = "org.postgresql.Driver";
public static final String ORACLE_DRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String MSSQL_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";

// The relative path to the JDBC drivers under Maven's `.m2/repository` directory
private static final String MYSQL_LOCAL_PATH = "mysql/mysql-connector-java";
Expand All @@ -63,6 +65,10 @@
@Before
public void setUpJDBC() throws IOException {

uploadArtifacts(gcsClient);
}

Check warning on line 69 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L68-L69

Added lines #L68 - L69 were not covered by tests

public static void uploadArtifacts(GcsResourceManager gcsClient) throws IOException {
String basePath = getMvnBaseRepoPath();

String mySqlDriverGCSRelativePath = GCS_PREFIX + mySqlDriverLocalJar();
Expand All @@ -77,19 +83,35 @@
}

protected String mySqlDriverGCSPath() {
return getGcsPath(GCS_PREFIX + mySqlDriverLocalJar());
return mySqlDriverGCSPath(this::getGcsPath);

Check warning on line 86 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L86

Added line #L86 was not covered by tests
}

public static String mySqlDriverGCSPath(Function<String, String> getGcsPath) {
return getGcsPath.apply(GCS_PREFIX + mySqlDriverLocalJar());

Check warning on line 90 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L90

Added line #L90 was not covered by tests
}

protected String postgresDriverGCSPath() {
return getGcsPath(GCS_PREFIX + postgresDriverLocalJar());
return postgresDriverGCSPath(this::getGcsPath);

Check warning on line 94 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L94

Added line #L94 was not covered by tests
}

public static String postgresDriverGCSPath(Function<String, String> getGcsPath) {
return getGcsPath.apply(GCS_PREFIX + postgresDriverLocalJar());

Check warning on line 98 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L98

Added line #L98 was not covered by tests
}

protected String oracleDriverGCSPath() {
return getGcsPath(GCS_PREFIX + oracleDriverLocalJar());
return oracleDriverGCSPath(this::getGcsPath);

Check warning on line 102 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L102

Added line #L102 was not covered by tests
}

public static String oracleDriverGCSPath(Function<String, String> getGcsPath) {
return getGcsPath.apply(GCS_PREFIX + oracleDriverLocalJar());

Check warning on line 106 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L106

Added line #L106 was not covered by tests
}

protected String msSqlDriverGCSPath() {
return getGcsPath(GCS_PREFIX + msSqlDriverLocalJar());
return msSqlDriverGCSPath(this::getGcsPath);

Check warning on line 110 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L110

Added line #L110 was not covered by tests
}

public static String msSqlDriverGCSPath(Function<String, String> getGcsPath) {
return getGcsPath.apply(GCS_PREFIX + msSqlDriverLocalJar());

Check warning on line 114 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/JDBCBaseIT.java#L114

Added line #L114 was not covered by tests
}

private static String mySqlDriverLocalJar() {
Expand Down Expand Up @@ -125,7 +147,7 @@
return String.join("/", basePath, MSSQL_LOCAL_PATH, MSSQL_VERSION, msSqlDriverLocalJar());
}

private String getMvnBaseRepoPath() {
private static String getMvnBaseRepoPath() {
// Try to get specified maven repo path from args
if (System.getProperty("mavenRepository") != null) {
String basePath = System.getProperty("mavenRepository");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,20 @@

@Before
public void setUpBase() throws ExecutionException {
setUp(null);
}

Check warning on line 141 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java#L140-L141

Added lines #L140 - L141 were not covered by tests

protected void setUp(TemplateIntegrationTest annotation) throws ExecutionException {
testId = PipelineUtils.createJobName("test", 10);

TemplateIntegrationTest annotation = null;
MultiTemplateIntegrationTest multiAnnotation =
getClass().getAnnotation(MultiTemplateIntegrationTest.class);
usingDirectRunner = System.getProperty("directRunnerTest") != null;
try {
Method testMethod = getClass().getMethod(testName);
annotation = testMethod.getAnnotation(TemplateIntegrationTest.class);
if (annotation == null) {
annotation = testMethod.getAnnotation(TemplateIntegrationTest.class);

Check warning on line 152 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java#L152

Added line #L152 was not covered by tests
}
Category category = testMethod.getAnnotation(Category.class);
if (category != null) {
usingDirectRunner =
Expand All @@ -167,7 +171,7 @@
}
if (annotation != null && multiAnnotation != null) {
LOG.warn(
"{} specifies both @TemplateIntegrationTest or @MultiTemplateIntegrationTest, please use"
"{} specifies both @TemplateIntegrationTest and @MultiTemplateIntegrationTest, please use"
+ " only of either.",
getClass());
return;
Expand Down Expand Up @@ -371,6 +375,10 @@
// Flex templates run on parent pom and -pl {path-to-folder}
moduleBuild = String.join(",", getModulesBuild(pomPath));
pomPath = pomPath.replaceAll("/v2/.*", "/pom.xml");
} else if (pomPath.contains("yaml/pom.xml")) {
// YAML templates run on parent pom and -pl {path-to-folder}
pomPath = new File(pom.getParentFile().getParentFile(), "pom.xml").getAbsolutePath();
moduleBuild = String.join(",", List.of("metadata", "yaml"));

Check warning on line 381 in it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java

View check run for this annotation

Codecov / codecov/patch

it/google-cloud-platform/src/main/java/org/apache/beam/it/gcp/TemplateTestBase.java#L380-L381

Added lines #L380 - L381 were not covered by tests
} else {
LOG.warn(
"Specific module POM was not found, so scanning all modules... Stage step may take a"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2024 Google LLC
*
* Licensed 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 com.google.cloud.teleport.metadata;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/** Annotation that marks the test of a Dataflow Template. */
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface YAMLTemplateIntegrationTest {}
60 changes: 59 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<integration.tests>com.google.cloud.teleport.metadata.TemplateIntegrationTest</integration.tests>
<load.tests>com.google.cloud.teleport.metadata.TemplateLoadTest</load.tests>
<direct-runner.tests>com.google.cloud.teleport.metadata.DirectRunnerTest</direct-runner.tests>
<yaml-integration.tests>com.google.cloud.teleport.metadata.YAMLTemplateIntegrationTest</yaml-integration.tests>
<excluded.spanner.tests></excluded.spanner.tests>

<licenseHeaderFile>JAVA_LICENSE_HEADER</licenseHeaderFile>
Expand Down Expand Up @@ -442,7 +443,10 @@
<excludes>
<exclude>**/KafkaToKafkaIT.java</exclude>
</excludes>
<excludedGroups>${direct-runner.tests}</excludedGroups>
<excludedGroups>
${direct-runner.tests}
${yaml-integration.tests}
</excludedGroups>
<groups>
${integration.tests}
</groups>
Expand Down Expand Up @@ -541,6 +545,7 @@
<include>**/*IT.java</include>
</includes>
<excludedGroups>
${yaml-integration.tests}
com.google.cloud.teleport.metadata.SkipDirectRunnerTest
</excludedGroups>
<groups>
Expand Down Expand Up @@ -587,6 +592,9 @@
<includes>
<include>**/*IT.java</include>
</includes>
<excludedGroups>
${yaml-integration.tests}
</excludedGroups>
<groups>
${direct-runner.tests}
org.apache.beam.it.testcontainers.TestContainersIntegrationTest
Expand All @@ -601,6 +609,56 @@
</plugins>
</build>
</profile>
<profile>
<id>templatesYamlIntegrationTests</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<!-- Skip coverage checks, unit tests are skipped -->
<jacoco.skip>true</jacoco.skip>
<!-- Some modules may yield no integration tests -->
<failIfNoTests>false</failIfNoTests>
<!-- Parallelism settings. Default is 2, set to consider methods -->
<itParallelismType>classesAndMethods</itParallelismType>
<itParallelism>2</itParallelism>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration combine.self="override">
<systemProperties>
<property>
<name>beamPythonVersion</name>
<value>${beam-python.version}</value>
</property>
<property>
<name>beamJavaVersion</name>
<value>${beam.version}</value>
</property>
<property>
<name>beamMavenRepo</name>
<value>${beam-maven-repo}</value>
</property>
</systemProperties>
<includes>
<include>**/*IT.java</include>
</includes>
<groups>
${yaml-integration.tests}
</groups>
<reuseForks>true</reuseForks>
<parallel>${itParallelismType}</parallel>
<threadCount>${itParallelism}</threadCount>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>pluginOutputDir</id>
<activation>
Expand Down
4 changes: 2 additions & 2 deletions python/generate_all_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ sh $SCRIPTPATH/generate_dependencies.sh $SCRIPTPATH/default_base_yaml_requiremen

cp $SCRIPTPATH/__build__/default_python_requirements.txt $SCRIPTPATH/../python/src/main/python/word-count-python/requirements.txt

cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../python/src/main/python/yaml-template/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../python/src/main/python/job-builder-server/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../python/src/main/yaml/yaml-template/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../python/src/main/yaml/job-builder-server/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../v2/googlecloud-to-elasticsearch/src/main/resources/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../v2/googlecloud-to-googlecloud/src/main/resources/requirements.txt
cp $SCRIPTPATH/__build__/default_yaml_requirements.txt $SCRIPTPATH/../v2/googlecloud-to-splunk/src/main/resources/requirements.txt
Expand Down
3 changes: 0 additions & 3 deletions python/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<!-- TODO - remove line when repo is upgraded to Beam 2.59.0 -->
<beam-python.version>2.57.0</beam-python.version>
</properties>

<dependencies>
Expand Down
Loading
Loading