use of com.amazonaws.services.qldb.model.ExportJournalToS3Result in project amazon-qldb-dmv-sample-java by aws-samples.
the class ExportJournal method createExport.
/**
* Request QLDB to export the contents of the journal for the given time
* period and s3 configuration. Before calling this function the S3 bucket
* should be created, see {@link #createS3BucketIfNotExists(String, AmazonS3)}.
*
* @param name
* Name of the ledger.
* @param startTime
* Time from when the journal contents should be exported.
* @param endTime
* Time until which the journal contents should be exported.
* @param bucket
* S3 bucket to write the data to.
* @param prefix
* S3 prefix to be prefixed to the files written.
* @param s3EncryptionConfiguration
* Encryption configuration for S3.
* @param roleArn
* The IAM role ARN to be used when exporting the journal.
* @return {@link ExportJournalToS3Result} from QLDB.
*/
public static ExportJournalToS3Result createExport(String name, Date startTime, Date endTime, String bucket, String prefix, S3EncryptionConfiguration s3EncryptionConfiguration, String roleArn) {
log.info("Let's create a journal export for ledger with name: {}...", name);
S3ExportConfiguration s3ExportConfiguration = new S3ExportConfiguration().withBucket(bucket).withPrefix(prefix).withEncryptionConfiguration(s3EncryptionConfiguration);
ExportJournalToS3Request request = new ExportJournalToS3Request().withName(name).withInclusiveStartTime(startTime).withExclusiveEndTime(endTime).withS3ExportConfiguration(s3ExportConfiguration).withRoleArn(roleArn);
try {
ExportJournalToS3Result result = client.exportJournalToS3(request);
log.info("Requested QLDB to export contents of the journal.");
return result;
} catch (InvalidParameterException ipe) {
log.error("The eventually consistent behavior of the IAM service may cause this export" + " to fail its first attempts, please retry.");
throw ipe;
}
}
use of com.amazonaws.services.qldb.model.ExportJournalToS3Result in project amazon-qldb-dmv-sample-java by aws-samples.
the class ExportJournal method createJournalExportAndAwaitCompletion.
/**
* Create a new journal export on a S3 bucket and wait for its completion.
*
* @param ledgerName
* The name of the bucket to be created.
* @param s3BucketName
* The name of the S3 bucket to create journal export on.
* @param s3Prefix
* The optional prefix name for the output objects of the export.
* @param roleArn
* The IAM role ARN to be used when exporting the journal.
* @param encryptionConfiguration
* The encryption settings to be used by the export job to write data in the given S3 bucket.
* @param awaitTimeoutMs
* Milliseconds to wait for export to complete.
* @return {@link ExportJournalToS3Result} from QLDB.
* @throws InterruptedException if thread is being interrupted while waiting for the export to complete.
*/
public static ExportJournalToS3Result createJournalExportAndAwaitCompletion(String ledgerName, String s3BucketName, String s3Prefix, String roleArn, S3EncryptionConfiguration encryptionConfiguration, long awaitTimeoutMs) throws InterruptedException {
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
createS3BucketIfNotExists(s3BucketName, s3Client);
if (roleArn == null) {
roleArn = createExportRole(EXPORT_ROLE_NAME, AmazonIdentityManagementClientBuilder.defaultClient(), s3BucketName, encryptionConfiguration.getKmsKeyArn(), EXPORT_ROLE_POLICY_NAME);
}
try {
Date startTime = Date.from(Instant.now().minus(JOURNAL_EXPORT_TIME_WINDOW_MINUTES, ChronoUnit.MINUTES));
Date endTime = Date.from(Instant.now());
ExportJournalToS3Result exportJournalToS3Result = createExport(ledgerName, startTime, endTime, s3BucketName, s3Prefix, encryptionConfiguration, roleArn);
// Wait for export to complete.
waitForExportToComplete(Constants.LEDGER_NAME, exportJournalToS3Result.getExportId(), awaitTimeoutMs);
log.info("JournalS3Export for exportId " + exportJournalToS3Result.getExportId() + " is completed.");
return exportJournalToS3Result;
} catch (Exception e) {
log.error("Unable to create an export!", e);
throw e;
}
}
use of com.amazonaws.services.qldb.model.ExportJournalToS3Result in project amazon-qldb-dmv-sample-java by aws-samples.
the class ValidateQldbHashChain method createExport.
/**
* Export journal contents to a S3 bucket.
*
* @return the ExportId of the journal export.
* @throws InterruptedException if the thread is interrupted while waiting for export to complete.
*/
private static String createExport() throws InterruptedException {
String accountId = AWSSecurityTokenServiceClientBuilder.defaultClient().getCallerIdentity(new GetCallerIdentityRequest()).getAccount();
String bucketName = Constants.JOURNAL_EXPORT_S3_BUCKET_NAME_PREFIX + "-" + accountId;
String prefix = Constants.LEDGER_NAME + "-" + Instant.now().getEpochSecond() + "/";
S3EncryptionConfiguration encryptionConfiguration = new S3EncryptionConfiguration().withObjectEncryptionType(S3ObjectEncryptionType.SSE_S3);
ExportJournalToS3Result exportJournalToS3Result = ExportJournal.createJournalExportAndAwaitCompletion(Constants.LEDGER_NAME, bucketName, prefix, null, encryptionConfiguration, ExportJournal.DEFAULT_EXPORT_TIMEOUT_MS);
return exportJournalToS3Result.getExportId();
}
Aggregations