Java Code Examples for com.amazonaws.services.kinesis.model.ListStreamsResult#getStreamNames()

The following examples show how to use com.amazonaws.services.kinesis.model.ListStreamsResult#getStreamNames() . 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: KinesisUtils.java    From aws-big-data-blog with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of all Amazon Kinesis streams
 * 
 * @param kinesisClient
 *        The {@link AmazonKinesisClient} with Amazon Kinesis read privileges
 * @return list of Amazon Kinesis streams
 */
public static List<String> listAllStreams(AmazonKinesisClient kinesisClient) {

    ListStreamsRequest listStreamsRequest = new ListStreamsRequest();
    listStreamsRequest.setLimit(10);
    ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
    List<String> streamNames = listStreamsResult.getStreamNames();
    while (listStreamsResult.isHasMoreStreams()) {
        if (streamNames.size() > 0) {
            listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1));
        }

        listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
        streamNames.addAll(listStreamsResult.getStreamNames());
    }
    return streamNames;
}
 
Example 2
Source File: KinesisUtils.java    From amazon-kinesis-connectors with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a list of all Amazon Kinesis streams
 * 
 * @param kinesisClient
 *        The {@link AmazonKinesisClient} with Amazon Kinesis read privileges
 * @return list of Amazon Kinesis streams
 */
public static List<String> listAllStreams(AmazonKinesisClient kinesisClient) {

    ListStreamsRequest listStreamsRequest = new ListStreamsRequest();
    listStreamsRequest.setLimit(10);
    ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
    List<String> streamNames = listStreamsResult.getStreamNames();
    while (listStreamsResult.isHasMoreStreams()) {
        if (streamNames.size() > 0) {
            listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1));
        }

        listStreamsResult = kinesisClient.listStreams(listStreamsRequest);
        streamNames.addAll(listStreamsResult.getStreamNames());
    }
    return streamNames;
}
 
Example 3
Source File: KinesisDatasetRuntime.java    From components with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> listStreams() {
    AmazonKinesis amazonKinesis = KinesisClient.create(properties);
    ListStreamsResult listStreamsResult = amazonKinesis.listStreams();
    List<String> streamNames = listStreamsResult.getStreamNames();
    Set<String> streamNamesCollection = new HashSet(streamNames);
    while (listStreamsResult.isHasMoreStreams() && !streamNames.isEmpty()) {
        listStreamsResult = amazonKinesis.listStreams(streamNames.get(streamNames.size() - 1));
        streamNames = listStreamsResult.getStreamNames();
        streamNamesCollection.addAll(streamNames);
    }
    return streamNamesCollection;
}
 
Example 4
Source File: KinesisInventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
public static Map<String,List<DataStreamVH>> fetchDataStreamInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) {
    
    Map<String,List<DataStreamVH>> dataStream = new LinkedHashMap<>();
    AmazonKinesis amazonKinesis;
    String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource\" ,\"type\": \"datastream\"" ;
    for(Region region : RegionUtils.getRegions()) { 
        try{
            if(!skipRegions.contains(region.getName())){
                amazonKinesis = AmazonKinesisClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
                ListStreamsResult listStreamsResult = amazonKinesis.listStreams();
                List<String> streamNamesTemp = listStreamsResult.getStreamNames();
                List<String> streamNames = new ArrayList<>(streamNamesTemp);
                while (listStreamsResult.isHasMoreStreams() && !streamNamesTemp.isEmpty()) {
                    listStreamsResult = amazonKinesis.listStreams(streamNamesTemp.get(streamNamesTemp.size() - 1));
                    streamNamesTemp = listStreamsResult.getStreamNames();
                    streamNames.addAll(streamNamesTemp);
                }
                
                List<DataStreamVH> dataStreamList = new ArrayList<>();
                for(String streamName : streamNames) {
                    StreamDescription streamDescription = amazonKinesis.describeStream(new DescribeStreamRequest().withStreamName(streamName)).getStreamDescription();
                    ListTagsForStreamResult listTagsForStreamResult = amazonKinesis.listTagsForStream(new ListTagsForStreamRequest().withStreamName(streamName));
                    List<com.amazonaws.services.kinesis.model.Tag> tagsTemp = listTagsForStreamResult.getTags();
                    List<com.amazonaws.services.kinesis.model.Tag> tags = new ArrayList<>(tagsTemp);
                    while (listTagsForStreamResult.isHasMoreTags() && !tagsTemp.isEmpty()) {
                        listTagsForStreamResult = amazonKinesis.listTagsForStream(new ListTagsForStreamRequest().withExclusiveStartTagKey(tagsTemp.get(tagsTemp.size() - 1).getKey()));
                        tagsTemp = listTagsForStreamResult.getTags();
                        tags.addAll(tagsTemp);
                    }
                    dataStreamList.add(new DataStreamVH(streamDescription, tags));
                }
                if( !dataStreamList.isEmpty() ) {
                    log.debug(InventoryConstants.ACCOUNT + accountId +" Type : datastream "+region.getName() + " >> "+dataStreamList.size());
                    dataStream.put(accountId+delimiter+accountName+delimiter+region.getName(),dataStreamList);
                }
            }
        } catch(Exception e){
            log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
            ErrorManageUtil.uploadError(accountId, region.getName(),"datastream",e.getMessage());
        }
    }
    return dataStream;
}