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