Search in sources :

Example 86 with ProjectName

use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class ErrorReportingExample method logCustomErrorEvent.

private void logCustomErrorEvent() {
    try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
        // Custom error events require an error reporting location as well.
        ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Test.java").setLineNumber(10).setFunctionName("myMethod").build()).build();
        // Report a custom error event
        ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage("custom error event").setContext(errorContext).build();
        // default project id
        ProjectName projectName = ProjectName.of(ServiceOptions.getDefaultProjectId());
        reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Exception encountered logging custom event", e);
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ErrorContext(com.google.devtools.clouderrorreporting.v1beta1.ErrorContext) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent) ReportErrorsServiceClient(com.google.cloud.errorreporting.v1beta1.ReportErrorsServiceClient) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 87 with ProjectName

use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class ListSecretsWithFilter method listSecrets.

// List all secrets for a project
public static void listSecrets(String projectId, String filter) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name.
        ProjectName projectName = ProjectName.of(projectId);
        // Get filtered secrets.
        ListSecretsRequest request = ListSecretsRequest.newBuilder().setParent(projectName.toString()).setFilter(filter).build();
        ListSecretsPagedResponse pagedResponse = client.listSecrets(request);
        // List all secrets.
        pagedResponse.iterateAll().forEach(secret -> {
            System.out.printf("Secret %s\n", secret.getName());
        });
    }
}
Also used : ProjectName(com.google.cloud.secretmanager.v1.ProjectName) ListSecretsPagedResponse(com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse) ListSecretsRequest(com.google.cloud.secretmanager.v1.ListSecretsRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 88 with ProjectName

use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method createSecret.

private static Secret createSecret() throws IOException {
    ProjectName parent = ProjectName.of(PROJECT_ID);
    CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(parent.toString()).setSecretId(randomSecretId()).setSecret(Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build()).build();
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        return client.createSecret(request);
    }
}
Also used : ProjectName(com.google.cloud.secretmanager.v1.ProjectName) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 89 with ProjectName

use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class CreateSecret method createSecret.

// Add a new version to the existing secret.
public static void createSecret(String projectId, String secretId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        // Build the parent name from the project.
        ProjectName projectName = ProjectName.of(projectId);
        // Build the secret to create.
        Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
        // Create the secret.
        Secret createdSecret = client.createSecret(projectName, secretId, secret);
        System.out.printf("Created secret %s\n", createdSecret.getName());
    }
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 90 with ProjectName

use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-bigquerydatatransfer by googleapis.

the class RunNotification method runNotification.

public static void runNotification(String projectId, TransferConfig transferConfig) throws IOException {
    try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
        TransferConfig config = dataTransferServiceClient.createTransferConfig(request);
        System.out.println("\nScheduled query with run notification created successfully :" + config.getName());
    } catch (ApiException ex) {
        System.out.print("\nScheduled query with run notification 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)

Aggregations

Test (org.junit.Test)72 StatusRuntimeException (io.grpc.StatusRuntimeException)34 AbstractMessage (com.google.protobuf.AbstractMessage)23 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)21 ProjectName (com.google.monitoring.v3.ProjectName)21 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ApiException (com.google.api.gax.rpc.ApiException)15 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)14 ProjectName (com.google.logging.v2.ProjectName)14 ApiException (com.google.api.gax.grpc.ApiException)13 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)13 ProjectName (com.google.devtools.clouderrorreporting.v1beta1.ProjectName)11 ArrayList (java.util.ArrayList)11 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)10 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)9 TimeSeries (com.google.monitoring.v3.TimeSeries)9