Search in sources :

Example 16 with TransferConfig

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());
    }
}
Also used : DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) ProjectName(com.google.cloud.bigquery.datatransfer.v1.ProjectName) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) CreateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest) ApiException(com.google.api.gax.rpc.ApiException)

Example 17 with TransferConfig

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());
    }
}
Also used : DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) ProjectName(com.google.cloud.bigquery.datatransfer.v1.ProjectName) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) CreateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest) ApiException(com.google.api.gax.rpc.ApiException)

Example 18 with TransferConfig

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);
}
Also used : TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) FieldMask(com.google.protobuf.FieldMask)

Example 19 with TransferConfig

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());
    }
}
Also used : DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) UpdateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.UpdateTransferConfigRequest) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) ApiException(com.google.api.gax.rpc.ApiException)

Example 20 with TransferConfig

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 :");
}
Also used : HashMap(java.util.HashMap) Value(com.google.protobuf.Value) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) Test(org.junit.Test)

Aggregations

TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)49 Value (com.google.protobuf.Value)22 HashMap (java.util.HashMap)22 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)21 ApiException (com.google.api.gax.rpc.ApiException)19 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)16 Test (org.junit.Test)13 FieldMask (com.google.protobuf.FieldMask)9 UpdateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.UpdateTransferConfigRequest)4 ListTransferConfigsPagedResponse (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 Before (org.junit.Before)3 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 GetTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.GetTransferConfigRequest)1