Search in sources :

Example 1 with DescribeJournalKinesisStreamResult

use of com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamResult in project amazon-qldb-dmv-sample-java by aws-samples.

the class StreamJournal method createQldbStream.

/**
 * Create a QLDB Stream.
 *
 * @return the QLDB Stream description.
 * @throws InterruptedException if the thread is interrupted while waiting
 * for stream creation.
 */
public static JournalKinesisStreamDescription createQldbStream() throws InterruptedException {
    log.info("Creating Kinesis data stream with name: '{}'...", kdsName);
    createKdsIfNotExists();
    log.info("Creating QLDB stream...");
    StreamJournalToKinesisRequest request = new StreamJournalToKinesisRequest().withKinesisConfiguration(getKdsConfig()).withInclusiveStartTime(Date.from(Instant.now().minus(Duration.ofDays(1)))).withRoleArn(getOrCreateKdsRole()).withLedgerName(ledgerName).withStreamName(streamName);
    if (exclusiveEndTime != null) {
        request = request.withExclusiveEndTime(exclusiveEndTime);
    }
    StreamJournalToKinesisResult result = qldb.streamJournalToKinesis(request);
    streamId = result.getStreamId();
    DescribeJournalKinesisStreamResult describeResult = describeQldbStream();
    log.info("Created QLDB stream: {} Current status: {}.", streamId, describeResult.getStream().getStatus());
    return describeResult.getStream();
}
Also used : StreamJournalToKinesisResult(com.amazonaws.services.qldb.model.StreamJournalToKinesisResult) DescribeJournalKinesisStreamResult(com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamResult) StreamJournalToKinesisRequest(com.amazonaws.services.qldb.model.StreamJournalToKinesisRequest)

Example 2 with DescribeJournalKinesisStreamResult

use of com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamResult in project amazon-qldb-dmv-sample-java by aws-samples.

the class StreamJournal method waitForQldbStreamCompletion.

/**
 * Wait for Kinesis Data Stream completion.
 */
public static void waitForQldbStreamCompletion() {
    DescribeJournalKinesisStreamRequest describeStreamRequest = new DescribeJournalKinesisStreamRequest().withStreamId(streamId).withLedgerName(ledgerName);
    int retries = 0;
    while (retries < MAX_RETRIES) {
        DescribeJournalKinesisStreamResult describeStreamResponse = qldb.describeJournalKinesisStream(describeStreamRequest);
        String streamStatus = describeStreamResponse.getStream().getStatus();
        log.info("Waiting for Stream Completion. Current streamStatus: {}.", streamStatus);
        if (streamStatus.equals("COMPLETED")) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (Exception ignore) {
        }
        retries++;
    }
    if (retries >= MAX_RETRIES) {
        throw new RuntimeException("Kinesis Stream with name " + kdsName + " never went completed.");
    }
}
Also used : DescribeJournalKinesisStreamResult(com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamResult) DescribeJournalKinesisStreamRequest(com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamRequest) NoSuchEntityException(com.amazonaws.services.identitymanagement.model.NoSuchEntityException) ResourceNotFoundException(com.amazonaws.services.kinesis.model.ResourceNotFoundException) IOException(java.io.IOException)

Aggregations

DescribeJournalKinesisStreamResult (com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamResult)2 NoSuchEntityException (com.amazonaws.services.identitymanagement.model.NoSuchEntityException)1 ResourceNotFoundException (com.amazonaws.services.kinesis.model.ResourceNotFoundException)1 DescribeJournalKinesisStreamRequest (com.amazonaws.services.qldb.model.DescribeJournalKinesisStreamRequest)1 StreamJournalToKinesisRequest (com.amazonaws.services.qldb.model.StreamJournalToKinesisRequest)1 StreamJournalToKinesisResult (com.amazonaws.services.qldb.model.StreamJournalToKinesisResult)1 IOException (java.io.IOException)1