org.apache.flink.streaming.connectors.kinesis.proxy.GetShardListResult Java Examples

The following examples show how to use org.apache.flink.streaming.connectors.kinesis.proxy.GetShardListResult. 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: FakeKinesisBehavioursFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public static KinesisProxyInterface noShardsFoundForRequestedStreamsBehaviour() {

		return new KinesisProxyInterface() {
			@Override
			public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
				return new GetShardListResult(); // not setting any retrieved shards for result
			}

			@Override
			public String getShardIterator(StreamShardHandle shard, String shardIteratorType, Object startingMarker) {
				return null;
			}

			@Override
			public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
				return null;
			}
		};

	}
 
Example #2
Source File: KinesisPubsubClient.java    From flink with Apache License 2.0 6 votes vote down vote up
public List<String> readAllMessages(String streamName) throws Exception {
	KinesisProxyInterface kinesisProxy = KinesisProxy.create(properties);
	Map<String, String> streamNamesWithLastSeenShardIds = new HashMap<>();
	streamNamesWithLastSeenShardIds.put(streamName, null);

	GetShardListResult shardListResult = kinesisProxy.getShardList(streamNamesWithLastSeenShardIds);
	int maxRecordsToFetch = 10;

	List<String> messages = new ArrayList<>();
	// retrieve records from all shards
	for (StreamShardHandle ssh : shardListResult.getRetrievedShardListOfStream(streamName)) {
		String shardIterator = kinesisProxy.getShardIterator(ssh, "TRIM_HORIZON", null);
		GetRecordsResult getRecordsResult = kinesisProxy.getRecords(shardIterator, maxRecordsToFetch);
		List<Record> aggregatedRecords = getRecordsResult.getRecords();
		for (Record record : aggregatedRecords) {
			messages.add(new String(record.getData().array()));
		}
	}
	return messages;
}
 
Example #3
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (StreamShardHandle.compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #4
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #5
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
public static KinesisProxyInterface noShardsFoundForRequestedStreamsBehaviour() {

		return new KinesisProxyInterface() {
			@Override
			public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
				return new GetShardListResult(); // not setting any retrieved shards for result
			}

			@Override
			public String getShardIterator(StreamShardHandle shard, String shardIteratorType, Object startingMarker) {
				return null;
			}

			@Override
			public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
				return null;
			}
		};

	}
 
Example #6
Source File: KinesisDataFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}
 
Example #7
Source File: KinesisPubsubClient.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> readAllMessages(String streamName) throws Exception {
	KinesisProxyInterface kinesisProxy = KinesisProxy.create(properties);
	Map<String, String> streamNamesWithLastSeenShardIds = new HashMap<>();
	streamNamesWithLastSeenShardIds.put(streamName, null);

	GetShardListResult shardListResult = kinesisProxy.getShardList(streamNamesWithLastSeenShardIds);
	int maxRecordsToFetch = 10;

	List<String> messages = new ArrayList<>();
	// retrieve records from all shards
	for (StreamShardHandle ssh : shardListResult.getRetrievedShardListOfStream(streamName)) {
		String shardIterator = kinesisProxy.getShardIterator(ssh, "TRIM_HORIZON", null);
		GetRecordsResult getRecordsResult = kinesisProxy.getRecords(shardIterator, maxRecordsToFetch);
		List<Record> aggregatedRecords = getRecordsResult.getRecords();
		for (Record record : aggregatedRecords) {
			messages.add(new String(record.getData().array()));
		}
	}
	return messages;
}
 
Example #8
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (StreamShardHandle.compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #9
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #10
Source File: KinesisDataFetcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}
 
Example #11
Source File: KinesisPubsubClient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> readAllMessages(String streamName) throws Exception {
	KinesisProxyInterface kinesisProxy = KinesisProxy.create(properties);
	Map<String, String> streamNamesWithLastSeenShardIds = new HashMap<>();
	streamNamesWithLastSeenShardIds.put(streamName, null);

	GetShardListResult shardListResult = kinesisProxy.getShardList(streamNamesWithLastSeenShardIds);
	int maxRecordsToFetch = 10;

	List<String> messages = new ArrayList<>();
	// retrieve records from all shards
	for (StreamShardHandle ssh : shardListResult.getRetrievedShardListOfStream(streamName)) {
		String shardIterator = kinesisProxy.getShardIterator(ssh, "TRIM_HORIZON", null);
		GetRecordsResult getRecordsResult = kinesisProxy.getRecords(shardIterator, maxRecordsToFetch);
		List<Record> aggregatedRecords = getRecordsResult.getRecords();
		for (Record record : aggregatedRecords) {
			messages.add(new String(record.getData().array()));
		}
	}
	return messages;
}
 
Example #12
Source File: FakeKinesisBehavioursFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (StreamShardHandle.compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #13
Source File: FakeKinesisBehavioursFactory.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	GetShardListResult result = new GetShardListResult();
	for (Map.Entry<String, List<StreamShardHandle>> streamsWithShards : streamsWithListOfShards.entrySet()) {
		String streamName = streamsWithShards.getKey();
		for (StreamShardHandle shard : streamsWithShards.getValue()) {
			if (streamNamesWithLastSeenShardIds.get(streamName) == null) {
				result.addRetrievedShardToStream(streamName, shard);
			} else {
				if (compareShardIds(
					shard.getShard().getShardId(), streamNamesWithLastSeenShardIds.get(streamName)) > 0) {
					result.addRetrievedShardToStream(streamName, shard);
				}
			}
		}
	}
	return result;
}
 
Example #14
Source File: KinesisDataFetcher.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * A utility function that does the following:
 *
 * <p>1. Find new shards for each stream that we haven't seen before
 * 2. For each new shard, determine whether this consumer subtask should subscribe to them;
 * 	  if yes, it is added to the returned list of shards
 * 3. Update the subscribedStreamsToLastDiscoveredShardIds state so that we won't get shards
 *    that we have already seen before the next time this function is called
 */
public List<StreamShardHandle> discoverNewShardsToSubscribe() throws InterruptedException {

	List<StreamShardHandle> newShardsToSubscribe = new LinkedList<>();

	GetShardListResult shardListResult = kinesis.getShardList(subscribedStreamsToLastDiscoveredShardIds);
	if (shardListResult.hasRetrievedShards()) {
		Set<String> streamsWithNewShards = shardListResult.getStreamsWithRetrievedShards();

		for (String stream : streamsWithNewShards) {
			List<StreamShardHandle> newShardsOfStream = shardListResult.getRetrievedShardListOfStream(stream);
			for (StreamShardHandle newShard : newShardsOfStream) {
				int hashCode = shardAssigner.assign(newShard, totalNumberOfConsumerSubtasks);
				if (isThisSubtaskShouldSubscribeTo(hashCode, totalNumberOfConsumerSubtasks, indexOfThisConsumerSubtask)) {
					newShardsToSubscribe.add(newShard);
				}
			}

			advanceLastDiscoveredShardOfStream(
				stream, shardListResult.getLastSeenShardOfStream(stream).getShard().getShardId());
		}
	}

	return newShardsToSubscribe;
}
 
Example #15
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 5 votes vote down vote up
public static KinesisProxyInterface noShardsFoundForRequestedStreamsBehaviour() {

		return new KinesisProxyInterface() {
			@Override
			public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
				return new GetShardListResult(); // not setting any retrieved shards for result
			}

			@Override
			public String getShardIterator(StreamShardHandle shard, String shardIteratorType, Object startingMarker) {
				return null;
			}

			@Override
			public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) {
				return null;
			}
		};

	}
 
Example #16
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}
 
Example #17
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}
 
Example #18
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}
 
Example #19
Source File: FakeKinesisBehavioursFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}
 
Example #20
Source File: FakeKinesisBehavioursFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}
 
Example #21
Source File: FakeKinesisBehavioursFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public GetShardListResult getShardList(Map<String, String> streamNamesWithLastSeenShardIds) {
	return null;
}