use of com.google.api.services.datastream.v1alpha1.DataStream 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");
}
use of com.google.api.services.datastream.v1alpha1.DataStream in project DataflowTemplates by GoogleCloudPlatform.
the class DataStreamClientTest method testDataStreamClientGetSourceConnectionProfileName.
/**
* Test whether {@link DataStreamClient#getSourceConnectionProfileName(String)} gets a Streams
* source connection profile name.
*/
@Ignore
@Test
public void testDataStreamClientGetSourceConnectionProfileName() throws IOException, GeneralSecurityException {
String projectId = "dataflow-bigstream-integration";
String streamName = "projects/dataflow-bigstream-integration/locations/us-central1/streams/dfstream1";
String connProfileName = "projects/402074789819/locations/us-central1/connectionProfiles/cp-1";
DataStreamClient datastream = new DataStreamClient(null);
SourceConfig sourceConnProfile = datastream.getSourceConnectionProfile(streamName);
String sourceConnProfileName = sourceConnProfile.getSourceConnectionProfileName();
assertEquals(sourceConnProfileName, connProfileName);
}
use of com.google.api.services.datastream.v1alpha1.DataStream in project DataflowTemplates by GoogleCloudPlatform.
the class DataStreamClientTest method testDataStreamClientDiscoverOracleTableSchema.
/**
* Test whether {@link DataStreamClient#discoverTableSchema(...)} gets a Streams source connection
* profile name.
*/
@Ignore
@Test
public void testDataStreamClientDiscoverOracleTableSchema() throws IOException, GeneralSecurityException {
String projectId = "dataflow-bigstream-integration";
String streamName = "projects/dataflow-bigstream-integration/locations/us-central1/streams/dfstream1";
String schemaName = "HR";
String tableName = "JOBS";
DataStreamClient datastream = new DataStreamClient(null);
SourceConfig sourceConnProfile = datastream.getSourceConnectionProfile(streamName);
OracleTable table = datastream.discoverOracleTableSchema(streamName, schemaName, tableName, sourceConnProfile);
String columnName = table.getOracleColumns().get(0).getColumnName();
Boolean isPrimaryKey = table.getOracleColumns().get(0).getPrimaryKey();
assertEquals(columnName, "JOB_TITLE");
assertEquals(isPrimaryKey, null);
}
use of com.google.api.services.datastream.v1alpha1.DataStream 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;
}
Aggregations