Search in sources :

Example 1 with DataStreamClient

use of com.google.cloud.teleport.v2.utils.DataStreamClient 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

SourceConfig (com.google.api.services.datastream.v1alpha1.model.SourceConfig)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