use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateScheduledQueryWithServiceAccount method createScheduledQueryWithServiceAccount.
public static void createScheduledQueryWithServiceAccount(String projectId, TransferConfig transferConfig, String serviceAccount) throws IOException {
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).setServiceAccountName(serviceAccount).build();
TransferConfig config = dataTransferServiceClient.createTransferConfig(request);
System.out.println("\nScheduled query with service account created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("\nScheduled query with service account was not created." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateAdsTransfer method createAdsTransfer.
public static void createAdsTransfer(String projectId, TransferConfig transferConfig) throws IOException {
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
TransferConfig config = client.createTransferConfig(request);
System.out.println("Ads transfer created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("Ads transfer was not created." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class UpdateTransferConfig method main.
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
String configId = "MY_CONFIG_ID";
TransferConfig transferConfig = TransferConfig.newBuilder().setName(configId).setDisplayName("UPDATED_DISPLAY_NAME").build();
FieldMask updateMask = FieldMaskUtil.fromString("display_name");
updateTransferConfig(transferConfig, updateMask);
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class UpdateTransferConfig method updateTransferConfig.
public static void updateTransferConfig(TransferConfig transferConfig, FieldMask updateMask) throws IOException {
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
UpdateTransferConfigRequest request = UpdateTransferConfigRequest.newBuilder().setTransferConfig(transferConfig).setUpdateMask(updateMask).build();
TransferConfig updateConfig = dataTransferServiceClient.updateTransferConfig(request);
System.out.println("Transfer config updated successfully :" + updateConfig.getDisplayName());
} catch (ApiException ex) {
System.out.print("Transfer config was not updated." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateAmazonS3TransferIT method testCreateAmazonS3Transfer.
@Test
public void testCreateAmazonS3Transfer() throws IOException {
String sourceUri = String.format("s3://%s/*", AWS_BUCKET);
String fileFormat = "CSV";
String fieldDelimiter = ",";
String skipLeadingRows = "1";
Map<String, Value> params = new HashMap<>();
params.put("destination_table_name_template", Value.newBuilder().setStringValue(tableName).build());
params.put("data_path", Value.newBuilder().setStringValue(sourceUri).build());
params.put("access_key_id", Value.newBuilder().setStringValue(AWS_ACCESS_KEY_ID).build());
params.put("secret_access_key", Value.newBuilder().setStringValue(AWS_SECRET_ACCESS_KEY).build());
params.put("file_format", Value.newBuilder().setStringValue(fileFormat).build());
params.put("field_delimiter", Value.newBuilder().setStringValue(fieldDelimiter).build());
params.put("skip_leading_rows", Value.newBuilder().setStringValue(skipLeadingRows).build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("amazon_s3").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
CreateAmazonS3Transfer.createAmazonS3Transfer(PROJECT_ID, transferConfig);
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Amazon s3 transfer created successfully :");
}
Aggregations