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);
}
}
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());
});
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations