use of org.apache.kafka.clients.admin.TransactionState in project kafka by apache.
the class ListTransactionsHandler method handleResponse.
@Override
public ApiResult<AllBrokersStrategy.BrokerKey, Collection<TransactionListing>> handleResponse(Node broker, Set<AllBrokersStrategy.BrokerKey> keys, AbstractResponse abstractResponse) {
int brokerId = broker.id();
AllBrokersStrategy.BrokerKey key = requireSingleton(keys, brokerId);
ListTransactionsResponse response = (ListTransactionsResponse) abstractResponse;
Errors error = Errors.forCode(response.data().errorCode());
if (error == Errors.COORDINATOR_LOAD_IN_PROGRESS) {
log.debug("The `ListTransactions` request sent to broker {} failed because the " + "coordinator is still loading state. Will try again after backing off", brokerId);
return ApiResult.empty();
} else if (error == Errors.COORDINATOR_NOT_AVAILABLE) {
log.debug("The `ListTransactions` request sent to broker {} failed because the " + "coordinator is shutting down", brokerId);
return ApiResult.failed(key, new CoordinatorNotAvailableException("ListTransactions " + "request sent to broker " + brokerId + " failed because the coordinator is shutting down"));
} else if (error != Errors.NONE) {
log.error("The `ListTransactions` request sent to broker {} failed because of an " + "unexpected error {}", brokerId, error);
return ApiResult.failed(key, error.exception("ListTransactions request " + "sent to broker " + brokerId + " failed with an unexpected exception"));
} else {
List<TransactionListing> listings = response.data().transactionStates().stream().map(transactionState -> new TransactionListing(transactionState.transactionalId(), transactionState.producerId(), TransactionState.parse(transactionState.transactionState()))).collect(Collectors.toList());
return ApiResult.completed(key, listings);
}
}
use of org.apache.kafka.clients.admin.TransactionState in project kafka by apache.
the class ListTransactionsHandler method buildRequest.
@Override
public ListTransactionsRequest.Builder buildRequest(int brokerId, Set<AllBrokersStrategy.BrokerKey> keys) {
ListTransactionsRequestData request = new ListTransactionsRequestData();
request.setProducerIdFilters(new ArrayList<>(options.filteredProducerIds()));
request.setStateFilters(options.filteredStates().stream().map(TransactionState::toString).collect(Collectors.toList()));
return new ListTransactionsRequest.Builder(request);
}
use of org.apache.kafka.clients.admin.TransactionState in project kafka by apache.
the class ListTransactionsHandlerTest method testBuildRequestWithFilteredState.
@Test
public void testBuildRequestWithFilteredState() {
int brokerId = 1;
BrokerKey brokerKey = new BrokerKey(OptionalInt.of(brokerId));
TransactionState filteredState = TransactionState.ONGOING;
ListTransactionsOptions options = new ListTransactionsOptions().filterStates(singleton(filteredState));
ListTransactionsHandler handler = new ListTransactionsHandler(options, logContext);
ListTransactionsRequest request = handler.buildRequest(brokerId, singleton(brokerKey)).build();
assertEquals(Collections.singletonList(filteredState.toString()), request.data().stateFilters());
assertEquals(Collections.emptyList(), request.data().producerIdFilters());
}
Aggregations