Search in sources :

Example 21 with Options

use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.

the class EventMetadataBuilderTest method testEventMetadata.

@Test
public void testEventMetadata() throws IOException {
    PubSubToElasticsearchOptions options = TestPipeline.testingPipelineOptions().as(PubSubToElasticsearchOptions.class);
    options.setErrorOutputTopic("projects/test/topics/test-error-topic");
    options.setApiKey("key");
    options.setDataset(Dataset.AUDIT);
    options.setNamespace("test-namespace");
    options.setElasticsearchTemplateVersion("999.999.999");
    String inputMessage = readInputMessage(INPUT_MESSAGE_FILE_PATH);
    EventMetadataBuilder eventMetadataBuilder = EventMetadataBuilder.build(inputMessage, options);
    JsonNode enrichedMessageAsJson = eventMetadataBuilder.getEnrichedMessageAsJsonNode();
    String enrichedMessageAsString = eventMetadataBuilder.getEnrichedMessageAsString();
    Assert.assertTrue(StringUtils.isNotBlank(enrichedMessageAsString));
    Assert.assertEquals(inputMessage, enrichedMessageAsJson.get("message").textValue());
    Assert.assertEquals("999.999.999", enrichedMessageAsJson.get("agent").get("version").textValue());
    Assert.assertEquals(Dataset.AUDIT.getKeyWithPrefix(), enrichedMessageAsJson.get("data_stream").get("dataset").textValue());
    Assert.assertEquals("test-namespace", enrichedMessageAsJson.get("data_stream").get("namespace").textValue());
    Assert.assertEquals(Dataset.AUDIT.getKeyWithPrefix(), enrichedMessageAsJson.get("service").get("type").textValue());
    Assert.assertEquals("2021-07-14T10:35:17.528142Z", enrichedMessageAsJson.get("@timestamp").textValue());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) PubSubToElasticsearchOptions(com.google.cloud.teleport.v2.elasticsearch.options.PubSubToElasticsearchOptions) Test(org.junit.Test)

Example 22 with Options

use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.

the class WriteToElasticsearchTest method testNullConnectionInformation.

/**
 * Tests {@link WriteToElasticsearch} throws an exception if a null ConnectionInformation is
 * provided.
 */
@Test
public void testNullConnectionInformation() {
    exceptionRule.expect(IllegalArgumentException.class);
    ElasticsearchWriteOptions options = PipelineOptionsFactory.create().as(ElasticsearchWriteOptions.class);
    options.setConnectionUrl(null);
    options.setApiKey("key");
    pipeline.apply("CreateInput", Create.of("test")).apply(WriteToElasticsearch.newBuilder().setOptions(options).build());
    pipeline.run();
}
Also used : ElasticsearchWriteOptions(com.google.cloud.teleport.v2.elasticsearch.options.ElasticsearchWriteOptions) Test(org.junit.Test)

Example 23 with Options

use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.

the class WriteToElasticsearchTest method testNullType.

/**
 * Tests {@link WriteToElasticsearch} throws an exception if a null index is provided.
 */
@Test
public void testNullType() {
    exceptionRule.expect(IllegalArgumentException.class);
    ElasticsearchWriteOptions options = PipelineOptionsFactory.create().as(ElasticsearchWriteOptions.class);
    options.setConnectionUrl("https://host.domain");
    options.setApiKey("key");
    pipeline.apply("CreateInput", Create.of("test")).apply(WriteToElasticsearch.newBuilder().setOptions(options).build());
    pipeline.run();
}
Also used : ElasticsearchWriteOptions(com.google.cloud.teleport.v2.elasticsearch.options.ElasticsearchWriteOptions) Test(org.junit.Test)

Example 24 with Options

use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.

the class WriteToElasticsearchTest method testElasticsearchWriteOptionsRetryConfigMaxAttempts.

/**
 * Tests that {@link WriteToElasticsearch} throws an exception if {@link
 * org.apache.beam.sdk.io.elasticsearch.ElasticsearchIO.RetryConfiguration} are invalid.
 */
@Test
public void testElasticsearchWriteOptionsRetryConfigMaxAttempts() {
    exceptionRule.expect(IllegalArgumentException.class);
    ElasticsearchWriteOptions options = PipelineOptionsFactory.create().as(ElasticsearchWriteOptions.class);
    options.setConnectionUrl("https://host.domain");
    options.setApiKey("key");
    options.setMaxRetryDuration(500L);
    options.setMaxRetryAttempts(null);
    pipeline.apply("CreateInput", Create.of("test")).apply("TestWriteToElasticsearchBadMaxAttempts", WriteToElasticsearch.newBuilder().setOptions(options).build());
    pipeline.run();
}
Also used : ElasticsearchWriteOptions(com.google.cloud.teleport.v2.elasticsearch.options.ElasticsearchWriteOptions) Test(org.junit.Test)

Example 25 with Options

use of com.google.cloud.teleport.v2.transforms.DeleteBigQueryDataFn.Options in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamToSpanner method getSourceType.

private static String getSourceType(Options options) {
    if (options.getDatastreamSourceType() != null) {
        return options.getDatastreamSourceType();
    }
    if (options.getStreamName() == null) {
        throw new IllegalArgumentException("Stream name cannot be empty. ");
    }
    GcpOptions gcpOptions = options.as(GcpOptions.class);
    DataStreamClient datastreamClient;
    SourceConfig sourceConfig;
    try {
        datastreamClient = new DataStreamClient(gcpOptions.getGcpCredential());
        sourceConfig = datastreamClient.getSourceConnectionProfile(options.getStreamName());
    } catch (IOException e) {
        LOG.error("IOException Occurred: DataStreamClient failed initialization.");
        throw new IllegalArgumentException("Unable to initialize DatastreamClient: " + e);
    }
    if (sourceConfig.getMysqlSourceConfig() != null) {
        return DatastreamConstants.MYSQL_SOURCE_TYPE;
    } else if (sourceConfig.getOracleSourceConfig() != null) {
        return DatastreamConstants.ORACLE_SOURCE_TYPE;
    }
    LOG.error("Source Connection Profile Type Not Supported");
    throw new IllegalArgumentException("Unsupported source connection profile type in Datastream");
}
Also used : DataStreamClient(com.google.cloud.teleport.v2.utils.DataStreamClient) GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) SourceConfig(com.google.api.services.datastream.v1alpha1.model.SourceConfig) IOException(java.io.IOException)

Aggregations

Test (org.junit.Test)63 PCollectionTuple (org.apache.beam.sdk.values.PCollectionTuple)25 FailsafeElement (com.google.cloud.teleport.v2.values.FailsafeElement)20 Pipeline (org.apache.beam.sdk.Pipeline)19 CoderRegistry (org.apache.beam.sdk.coders.CoderRegistry)19 BigQueryTable (com.google.cloud.teleport.v2.values.BigQueryTable)15 GenericRecord (org.apache.avro.generic.GenericRecord)12 Category (org.junit.experimental.categories.Category)12 Filter (com.google.cloud.teleport.v2.utils.BigQueryMetadataLoader.Filter)10 BigQueryTablePartition (com.google.cloud.teleport.v2.values.BigQueryTablePartition)10 PubSubToElasticsearchOptions (com.google.cloud.teleport.v2.elasticsearch.options.PubSubToElasticsearchOptions)9 TableRow (com.google.api.services.bigquery.model.TableRow)8 DataplexClient (com.google.cloud.teleport.v2.clients.DataplexClient)8 FileFormatConversionOptions (com.google.cloud.teleport.v2.templates.FileFormatConversion.FileFormatConversionOptions)8 KV (org.apache.beam.sdk.values.KV)8 ArrayList (java.util.ArrayList)7 ElasticsearchWriteOptions (com.google.cloud.teleport.v2.elasticsearch.options.ElasticsearchWriteOptions)6 GCSToElasticsearchOptions (com.google.cloud.teleport.v2.elasticsearch.options.GCSToElasticsearchOptions)6 FileFormatConversionOptions (com.google.cloud.teleport.v2.templates.DataplexFileFormatConversion.FileFormatConversionOptions)6 PubSubProtoToBigQueryOptions (com.google.cloud.teleport.v2.templates.PubsubProtoToBigQuery.PubSubProtoToBigQueryOptions)6