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

refactor YAML_Template to yaml module #1984

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
28 changes: 28 additions & 0 deletions .github/workflows/java-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,34 @@ jobs:
- name: Cleanup Java Environment
uses: ./.github/actions/cleanup-java-env
if: always()
java_yaml_integration_tests_templates:
name: Dataflow Templates YAML Integration Tests
timeout-minutes: 240
# Run on any runner that matches all the specified runs-on values.
runs-on: [self-hosted, it]
steps:
- name: Checkout Code
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
- name: Setup Environment
id: setup-env
uses: ./.github/actions/setup-env
- name: Run Integration Tests
run: |
./cicd/run-it-yaml-tests \
--modules-to-build="YAML" \
--it-region="us-central1" \
--it-project="cloud-teleport-testing" \
--it-artifact-bucket="cloud-teleport-testing-it-gitactions"
- name: Upload Integration Tests Report
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
if: always() # always run even if the previous step fails
with:
name: surefire-test-results
path: '**/surefire-reports/TEST-*.xml'
retention-days: 1
- name: Cleanup Java Environment
uses: ./.github/actions/cleanup-java-env
if: always()
java_load_tests_templates:
if: contains(github.event.pull_request.labels.*.name, 'run-load-tests')
name: Dataflow Templates Load Tests
Expand Down
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) 2022 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!")
}
2 changes: 2 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,7 @@ var (
"v2/spanner-to-sourcedb/",
"v2/spanner-custom-shard",
"plugins/templates-maven-plugin"},
YAML: {"yaml/"},
}
)

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 @@ -387,7 +391,7 @@
"mvn",
"compile",
"package",
"-q",
// "-q",
"-f",
pomPath,
"-pl",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2022 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 {}
Loading
Loading