Search in sources :

Example 1 with Stream

use of com.google.api.services.datastream.v1alpha1.model.Stream 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)

Example 2 with Stream

use of com.google.api.services.datastream.v1alpha1.model.Stream in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method getSourceConnectionProfile.

/**
 * Return a {@link SourceConfig} ConnectionProfile object which can be used for schema discovery
 * and connection information.
 *
 * @param streamName The ID of a DataStream Stream (ie. project/my-project/stream/my-stream).
 */
public SourceConfig getSourceConnectionProfile(String streamName) throws IOException {
    Stream stream = getStream(streamName);
    SourceConfig sourceConnProfile = stream.getSourceConfig();
    return sourceConnProfile;
}
Also used : SourceConfig(com.google.api.services.datastream.v1alpha1.model.SourceConfig) DataStream(com.google.api.services.datastream.v1alpha1.DataStream) Stream(com.google.api.services.datastream.v1alpha1.model.Stream)

Example 3 with Stream

use of com.google.api.services.datastream.v1alpha1.model.Stream in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method discoverMysqlTableSchema.

/**
 * Return a {@link MysqlTable} object with schema and PK information.
 *
 * @param streamName A fully qualified Stream name (ie. projects/my-project/stream/my-stream)
 * @param schemaName The name of the schema for the table being discovered.
 * @param tableName The name of the table to discover.
 * @param sourceConnProfile The SourceConfig connection profile to be discovered.
 */
public MysqlTable discoverMysqlTableSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    DataStream.Projects.Locations.ConnectionProfiles.Discover discoverConnProfile = getDiscoverTableRequest(streamName, schemaName, tableName, sourceConnProfile);
    MysqlRdbms tableResponse = discoverConnProfile.execute().getMysqlRdbms();
    MysqlDatabase schema = tableResponse.getMysqlDatabases().get(0);
    MysqlTable table = schema.getMysqlTables().get(0);
    return table;
}
Also used : MysqlRdbms(com.google.api.services.datastream.v1alpha1.model.MysqlRdbms) MysqlTable(com.google.api.services.datastream.v1alpha1.model.MysqlTable) MysqlDatabase(com.google.api.services.datastream.v1alpha1.model.MysqlDatabase)

Example 4 with Stream

use of com.google.api.services.datastream.v1alpha1.model.Stream in project camel by apache.

the class ShardIteratorHandlerTest method setup.

@Before
public void setup() throws Exception {
    endpoint.setAmazonDynamoDbStreamsClient(amazonDynamoDBStreams);
    undertest = new ShardIteratorHandler(endpoint);
    when(amazonDynamoDBStreams.listStreams(any(ListStreamsRequest.class))).thenReturn(new ListStreamsResult().withStreams(new Stream().withStreamArn("arn:aws:dynamodb:region:12345:table/table_name/stream/timestamp")));
    when(amazonDynamoDBStreams.describeStream(any(DescribeStreamRequest.class))).thenReturn(new DescribeStreamResult().withStreamDescription(new StreamDescription().withTableName("table_name").withShards(ShardListTest.createShardsWithSequenceNumbers(null, "a", "1", "5", "b", "8", "15", "c", "16", "16", "d", "20", null))));
    when(amazonDynamoDBStreams.getShardIterator(any(GetShardIteratorRequest.class))).thenAnswer(new Answer<GetShardIteratorResult>() {

        @Override
        public GetShardIteratorResult answer(InvocationOnMock invocation) throws Throwable {
            return new GetShardIteratorResult().withShardIterator("shard_iterator_" + ((GetShardIteratorRequest) invocation.getArguments()[0]).getShardId() + "_000");
        }
    });
}
Also used : GetShardIteratorRequest(com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest) ListStreamsRequest(com.amazonaws.services.dynamodbv2.model.ListStreamsRequest) DescribeStreamRequest(com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest) StreamDescription(com.amazonaws.services.dynamodbv2.model.StreamDescription) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListStreamsResult(com.amazonaws.services.dynamodbv2.model.ListStreamsResult) GetShardIteratorResult(com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult) Stream(com.amazonaws.services.dynamodbv2.model.Stream) DescribeStreamResult(com.amazonaws.services.dynamodbv2.model.DescribeStreamResult) Before(org.junit.Before)

Example 5 with Stream

use of com.google.api.services.datastream.v1alpha1.model.Stream in project DataflowTemplates by GoogleCloudPlatform.

the class DataStreamClient method discoverOracleTableSchema.

/**
 * Return a {@link OracleTable} object with schema and PK information.
 *
 * @param streamName A fully qualified Stream name (ie. projects/my-project/stream/my-stream)
 * @param schemaName The name of the schema for the table being discovered.
 * @param tableName The name of the table to discover.
 * @param sourceConnProfile The SourceConfig connection profile to be discovered.
 */
public OracleTable discoverOracleTableSchema(String streamName, String schemaName, String tableName, SourceConfig sourceConnProfile) throws IOException {
    DataStream.Projects.Locations.ConnectionProfiles.Discover discoverConnProfile = getDiscoverTableRequest(streamName, schemaName, tableName, sourceConnProfile);
    OracleRdbms tableResponse = discoverConnProfile.execute().getOracleRdbms();
    OracleSchema schema = tableResponse.getOracleSchemas().get(0);
    OracleTable table = schema.getOracleTables().get(0);
    return table;
}
Also used : OracleSchema(com.google.api.services.datastream.v1alpha1.model.OracleSchema) OracleTable(com.google.api.services.datastream.v1alpha1.model.OracleTable) OracleRdbms(com.google.api.services.datastream.v1alpha1.model.OracleRdbms)

Aggregations

DataStream (com.google.api.services.datastream.v1alpha1.DataStream)2 SourceConfig (com.google.api.services.datastream.v1alpha1.model.SourceConfig)2 Stream (com.google.api.services.datastream.v1alpha1.model.Stream)2 DescribeStreamRequest (com.amazonaws.services.dynamodbv2.model.DescribeStreamRequest)1 DescribeStreamResult (com.amazonaws.services.dynamodbv2.model.DescribeStreamResult)1 GetShardIteratorRequest (com.amazonaws.services.dynamodbv2.model.GetShardIteratorRequest)1 GetShardIteratorResult (com.amazonaws.services.dynamodbv2.model.GetShardIteratorResult)1 ListStreamsRequest (com.amazonaws.services.dynamodbv2.model.ListStreamsRequest)1 ListStreamsResult (com.amazonaws.services.dynamodbv2.model.ListStreamsResult)1 Stream (com.amazonaws.services.dynamodbv2.model.Stream)1 StreamDescription (com.amazonaws.services.dynamodbv2.model.StreamDescription)1 MysqlDatabase (com.google.api.services.datastream.v1alpha1.model.MysqlDatabase)1 MysqlRdbms (com.google.api.services.datastream.v1alpha1.model.MysqlRdbms)1 MysqlTable (com.google.api.services.datastream.v1alpha1.model.MysqlTable)1 OracleRdbms (com.google.api.services.datastream.v1alpha1.model.OracleRdbms)1 OracleSchema (com.google.api.services.datastream.v1alpha1.model.OracleSchema)1 OracleTable (com.google.api.services.datastream.v1alpha1.model.OracleTable)1 DataStreamClient (com.google.cloud.teleport.v2.utils.DataStreamClient)1 IOException (java.io.IOException)1 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)1