Search in sources :

Example 1 with CreateBackupMessage

use of com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage in project java-docs-samples by GoogleCloudPlatform.

the class CreateBackup method accept.

@Override
public void accept(PubSubMessage message, Context context) {
    if (message != null && message.getData() != null) {
        logger.info("Trigger event:" + message.getData());
        try {
            String payload = new String(Base64.getDecoder().decode(message.getData().getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
            logger.info("Decoded payload:" + payload);
            CreateBackupMessage cbMessage = mapper.readValue(payload, CreateBackupMessage.class);
            logger.info("CreateBackup message:" + cbMessage.toString());
            logger.info("Submitting the create backup request");
            // Create an admin client
            BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder().setProjectId(cbMessage.getProjectId()).setInstanceId(cbMessage.getInstanceId()).build();
            try (BigtableTableAdminClient adminClient = BigtableTableAdminClient.create(adminSettings)) {
                CreateBackupRequest request = CreateBackupRequest.of(cbMessage.getClusterId(), buildBackupId(cbMessage.getTableId())).setSourceTableId(cbMessage.getTableId()).setExpireTime(buildExpireTime(cbMessage.getExpireHours()));
                Backup backupDetails = adminClient.createBackup(request);
                logger.info("Submitted backup request :" + backupDetails.getId() + ": that will expire at:" + backupDetails.getExpireTime());
            } catch (IOException e) {
                logger.log(Level.SEVERE, "Caught Exception creating backup:" + e.toString(), e);
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Caught Exception running the create backup function:" + e.toString(), e);
        }
        return;
    }
}
Also used : CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) CreateBackupMessage(com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) BigtableTableAdminSettings(com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings) BigtableTableAdminClient(com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

CreateBackupMessage (com.example.cloud.bigtable.scheduledbackups.resource.CreateBackupMessage)1 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)1 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)1 Backup (com.google.cloud.bigtable.admin.v2.models.Backup)1 CreateBackupRequest (com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest)1 IOException (java.io.IOException)1