software.amazon.awssdk.services.kinesis.model.KinesisException Java Examples

The following examples show how to use software.amazon.awssdk.services.kinesis.model.KinesisException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscribeToShardUnmarshallingTest.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Test
public void errorWithMessage_UnmarshalledCorrectly() throws Throwable {
    String errorCode = "InternalError";
    String message = "error message";
    AbortableInputStream content = new MessageWriter()
        .writeInitialResponse(new byte[0])
        .writeError(errorCode, message)
        .toInputStream();

    stubResponse(SdkHttpFullResponse.builder()
                                    .statusCode(200)
                                    .content(content)
                                    .putHeader("x-amzn-requestid", REQUEST_ID)
                                    .build());

    try {
        subscribeToShard();
        fail("Expected ResourceNotFoundException exception");
    } catch (KinesisException e) {
        assertThat(e.requestId()).isEqualTo(REQUEST_ID);
        assertThat(e.statusCode()).isEqualTo(500);
        assertThat(e.awsErrorDetails().errorCode()).isEqualTo(errorCode);
        assertThat(e.awsErrorDetails().errorMessage()).isEqualTo(message);
        assertThat(e.awsErrorDetails().serviceName()).isEqualTo("kinesis");
    }
}
 
Example #2
Source File: DescribeLimits.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void describeKinLimits(KinesisClient kinesisClient) {

        // snippet-end:[kinesis.java2.DescribeLimits.client]
        try {
        // snippet-start:[kinesis.java2.DescribeLimits.main]
        DescribeLimitsRequest request = DescribeLimitsRequest.builder()
                 .build();

        DescribeLimitsResponse response = kinesisClient.describeLimits(request);

        System.out.println("Number of open shards: " + response.openShardCount());
        System.out.println("Maximum shards allowed: " + response.shardLimit());
        } catch (KinesisException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
        // snippet-end:[kinesis.java2.DescribeLimits.main]
    }
 
Example #3
Source File: ListShards.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void listKinShards(KinesisClient kinesisClient, String name) {

        try {
        ListShardsRequest request = ListShardsRequest.builder()
                .streamName(name)
                .build();

            ListShardsResponse response = kinesisClient.listShards(request);
            System.out.println(request.streamName() + " has " + response.shards());

        } catch (KinesisException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
 
Example #4
Source File: DeleteDataStream.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void deleteStream(KinesisClient kinesisClient, String streamName) {

           try {

                DeleteStreamRequest delStream = DeleteStreamRequest.builder()
                        .streamName(streamName)
                        .build();

                kinesisClient.deleteStream(delStream);

            } catch (KinesisException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
 
Example #5
Source File: AddDataShards.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void addShards(KinesisClient kinesisClient, String name , int goalShards) {

        try {
             UpdateShardCountRequest request = UpdateShardCountRequest.builder()
                .scalingType("UNIFORM_SCALING")
                .streamName(name)
                .targetShardCount(goalShards)
                .build();

            UpdateShardCountResponse response = kinesisClient.updateShardCount(request);
            System.out.println(response.streamName() + " has updated shard count to " + response.currentShardCount());
           
        } catch (KinesisException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
 
Example #6
Source File: StockTradesWriter.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void setStockData( KinesisClient kinesisClient, String streamName) {

            try {
            // Repeatedly send stock trades with a 100 milliseconds wait in between
            StockTradeGenerator stockTradeGenerator = new StockTradeGenerator();

            // Put in 50 records for this example
            int index = 50;
            for (int x=0; x<index; x++){
                StockTrade trade = stockTradeGenerator.getRandomTrade();
                sendStockTrade(trade, kinesisClient, streamName);
                Thread.sleep(100);
             }

        } catch (KinesisException | InterruptedException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
 
Example #7
Source File: StockTradesWriter.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void sendStockTrade(StockTrade trade, KinesisClient kinesisClient,
                                   String streamName) {
    byte[] bytes = trade.toJsonAsBytes();
    // The bytes could be null if there is an issue with the JSON serialization by the Jackson JSON library.
    if (bytes == null) {
        System.out.println("Could not get JSON bytes for stock trade");
        return;
    }

    System.out.println("Putting trade: " + trade.toString());
    PutRecordRequest request = PutRecordRequest.builder()
            .partitionKey(trade.getTickerSymbol()) // We use the ticker symbol as the partition key, explained in the Supplemental Information section below.
            .streamName(streamName)
            .data(SdkBytes.fromByteArray(bytes))
            .build();
    try {
        kinesisClient.putRecord(request);
    } catch (KinesisException e) {
        e.getMessage();
    }
}
 
Example #8
Source File: StockTradesWriter.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void validateStream(KinesisClient kinesisClient, String streamName) {
    try {
        DescribeStreamRequest describeStreamRequest = DescribeStreamRequest.builder()
                .streamName(streamName)
                .build();

        DescribeStreamResponse describeStreamResponse = kinesisClient.describeStream(describeStreamRequest);

        if(!describeStreamResponse.streamDescription().streamStatus().toString().equals("ACTIVE")) {
            System.err.println("Stream " + streamName + " is not active. Please wait a few moments and try again.");
            System.exit(1);
        }
    }catch (KinesisException e) {
        System.err.println("Error found while describing the stream " + streamName);
        System.err.println(e);
        System.exit(1);
    }
    // snippet-end:[kinesis.java2.putrecord.main]
}
 
Example #9
Source File: ShardSyncTaskIntegrationTest.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
@BeforeClass
    public static void setUpBeforeClass() throws Exception {
//        ClientAsyncHttpConfiguration configuration = ClientAsyncHttpConfiguration.builder().httpClientFactory(
//                NettySdkHttpClientFactory.builder().trustAllCertificates(true).maxConnectionsPerEndpoint(10).build())
//                .build();
//        kinesisClient = KinesisAsyncClient.builder().asyncHttpConfiguration(configuration)
//                .endpointOverride(new URI("https://aws-kinesis-alpha.corp.amazon.com")).region(Region.US_EAST_1)
//                .build();
//
        try {
            CreateStreamRequest req = CreateStreamRequest.builder().streamName(STREAM_NAME).shardCount(1).build();
            kinesisClient.createStream(req);
        } catch (KinesisException ase) {
            ase.printStackTrace();
        }
        StreamStatus status;
//        do {
//            status = StreamStatus.fromValue(kinesisClient.describeStreamSummary(
//                    DescribeStreamSummaryRequest.builder().streamName(STREAM_NAME).build()).get()
//                    .streamDescriptionSummary().streamStatusString());
//        } while (status != StreamStatus.ACTIVE);
//
    }
 
Example #10
Source File: CreateDataStream.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void createStream(KinesisClient kinesisClient, String streamName) {

        try {
            CreateStreamRequest streamReq = CreateStreamRequest.builder()
                    .streamName(streamName)
                    .shardCount(1)
                    .build();

            kinesisClient.createStream(streamReq);
        } catch (KinesisException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
        System.out.println("Done");
    }
 
Example #11
Source File: FanOutConsumerRegistration.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
private AWSExceptionManager createExceptionManager() {
    final AWSExceptionManager exceptionManager = new AWSExceptionManager();
    exceptionManager.add(LimitExceededException.class, t -> t);
    exceptionManager.add(ResourceInUseException.class, t -> t);
    exceptionManager.add(ResourceNotFoundException.class, t -> t);
    exceptionManager.add(KinesisException.class, t -> t);

    return exceptionManager;
}
 
Example #12
Source File: KinesisDataFetcher.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
private AWSExceptionManager createExceptionManager() {
    final AWSExceptionManager exceptionManager = new AWSExceptionManager();
    exceptionManager.add(ResourceNotFoundException.class, t -> t);
    exceptionManager.add(KinesisException.class, t -> t);
    exceptionManager.add(SdkException.class, t -> t);
    return exceptionManager;
}