use of org.apache.pulsar.common.policies.data.TransactionCoordinatorStats in project pulsar by apache.
the class TransactionsBase method internalGetCoordinatorStats.
protected void internalGetCoordinatorStats(AsyncResponse asyncResponse, boolean authoritative, Integer coordinatorId) {
if (pulsar().getConfig().isTransactionCoordinatorEnabled()) {
if (coordinatorId != null) {
validateTopicOwnership(TopicName.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId), authoritative);
TransactionMetadataStore transactionMetadataStore = pulsar().getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(coordinatorId));
if (transactionMetadataStore == null) {
asyncResponse.resume(new RestException(NOT_FOUND, "Transaction coordinator not found! coordinator id : " + coordinatorId));
return;
}
asyncResponse.resume(transactionMetadataStore.getCoordinatorStats());
} else {
getPartitionedTopicMetadataAsync(TopicName.TRANSACTION_COORDINATOR_ASSIGN, false, false).thenAccept(partitionMetadata -> {
if (partitionMetadata.partitions == 0) {
asyncResponse.resume(new RestException(Response.Status.NOT_FOUND, "Transaction coordinator not found"));
return;
}
List<CompletableFuture<TransactionCoordinatorStats>> transactionMetadataStoreInfoFutures = Lists.newArrayList();
for (int i = 0; i < partitionMetadata.partitions; i++) {
try {
transactionMetadataStoreInfoFutures.add(pulsar().getAdminClient().transactions().getCoordinatorStatsByIdAsync(i));
} catch (PulsarServerException e) {
asyncResponse.resume(new RestException(e));
return;
}
}
Map<Integer, TransactionCoordinatorStats> stats = new HashMap<>();
FutureUtil.waitForAll(transactionMetadataStoreInfoFutures).whenComplete((result, e) -> {
if (e != null) {
asyncResponse.resume(new RestException(e));
return;
}
for (int i = 0; i < transactionMetadataStoreInfoFutures.size(); i++) {
try {
stats.put(i, transactionMetadataStoreInfoFutures.get(i).get());
} catch (Exception exception) {
asyncResponse.resume(new RestException(exception.getCause()));
return;
}
}
asyncResponse.resume(stats);
});
}).exceptionally(ex -> {
log.error("[{}] Failed to get transaction coordinator state.", clientAppId(), ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}
} else {
asyncResponse.resume(new RestException(SERVICE_UNAVAILABLE, "This Broker is not configured with transactionCoordinatorEnabled=true."));
}
}
use of org.apache.pulsar.common.policies.data.TransactionCoordinatorStats in project pulsar by yahoo.
the class AdminApiTransactionTest method testGetTransactionCoordinatorStats.
@Test(timeOut = 20000)
public void testGetTransactionCoordinatorStats() throws Exception {
initTransaction(2);
getTransaction().commit().get();
getTransaction().abort().get();
TransactionCoordinatorStats transactionCoordinatorstats = admin.transactions().getCoordinatorStatsByIdAsync(1).get();
verifyCoordinatorStats(transactionCoordinatorstats.state, transactionCoordinatorstats.leastSigBits, transactionCoordinatorstats.lowWaterMark);
transactionCoordinatorstats = admin.transactions().getCoordinatorStatsByIdAsync(0).get();
verifyCoordinatorStats(transactionCoordinatorstats.state, transactionCoordinatorstats.leastSigBits, transactionCoordinatorstats.lowWaterMark);
Map<Integer, TransactionCoordinatorStats> stats = admin.transactions().getCoordinatorStatsAsync().get();
assertEquals(stats.size(), 2);
transactionCoordinatorstats = stats.get(0);
verifyCoordinatorStats(transactionCoordinatorstats.state, transactionCoordinatorstats.leastSigBits, transactionCoordinatorstats.lowWaterMark);
transactionCoordinatorstats = stats.get(1);
verifyCoordinatorStats(transactionCoordinatorstats.state, transactionCoordinatorstats.leastSigBits, transactionCoordinatorstats.lowWaterMark);
}
use of org.apache.pulsar.common.policies.data.TransactionCoordinatorStats in project pulsar by yahoo.
the class TransactionsBase method internalGetCoordinatorStats.
protected void internalGetCoordinatorStats(AsyncResponse asyncResponse, boolean authoritative, Integer coordinatorId) {
if (coordinatorId != null) {
validateTopicOwnership(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId), authoritative);
TransactionMetadataStore transactionMetadataStore = pulsar().getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(coordinatorId));
if (transactionMetadataStore == null) {
asyncResponse.resume(new RestException(NOT_FOUND, "Transaction coordinator not found! coordinator id : " + coordinatorId));
return;
}
asyncResponse.resume(transactionMetadataStore.getCoordinatorStats());
} else {
getPartitionedTopicMetadataAsync(SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN, false, false).thenAccept(partitionMetadata -> {
if (partitionMetadata.partitions == 0) {
asyncResponse.resume(new RestException(Response.Status.NOT_FOUND, "Transaction coordinator not found"));
return;
}
List<CompletableFuture<TransactionCoordinatorStats>> transactionMetadataStoreInfoFutures = Lists.newArrayList();
for (int i = 0; i < partitionMetadata.partitions; i++) {
try {
transactionMetadataStoreInfoFutures.add(pulsar().getAdminClient().transactions().getCoordinatorStatsByIdAsync(i));
} catch (PulsarServerException e) {
asyncResponse.resume(new RestException(e));
return;
}
}
Map<Integer, TransactionCoordinatorStats> stats = new HashMap<>();
FutureUtil.waitForAll(transactionMetadataStoreInfoFutures).whenComplete((result, e) -> {
if (e != null) {
asyncResponse.resume(new RestException(e));
return;
}
for (int i = 0; i < transactionMetadataStoreInfoFutures.size(); i++) {
try {
stats.put(i, transactionMetadataStoreInfoFutures.get(i).get());
} catch (Exception exception) {
asyncResponse.resume(new RestException(exception.getCause()));
return;
}
}
asyncResponse.resume(stats);
});
}).exceptionally(ex -> {
log.error("[{}] Failed to get transaction coordinator state.", clientAppId(), ex);
resumeAsyncResponseExceptionally(asyncResponse, ex);
return null;
});
}
}
use of org.apache.pulsar.common.policies.data.TransactionCoordinatorStats in project incubator-pulsar by apache.
the class TransactionsImpl method getCoordinatorStatsByIdAsync.
@Override
public CompletableFuture<TransactionCoordinatorStats> getCoordinatorStatsByIdAsync(int coordinatorId) {
WebTarget path = adminV3Transactions.path("coordinatorStats");
path = path.queryParam("coordinatorId", coordinatorId);
final CompletableFuture<TransactionCoordinatorStats> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<TransactionCoordinatorStats>() {
@Override
public void completed(TransactionCoordinatorStats stats) {
future.complete(stats);
}
@Override
public void failed(Throwable throwable) {
future.completeExceptionally(getApiException(throwable.getCause()));
}
});
return future;
}
use of org.apache.pulsar.common.policies.data.TransactionCoordinatorStats in project incubator-pulsar by apache.
the class MLTransactionMetadataStore method getCoordinatorStats.
@Override
public TransactionCoordinatorStats getCoordinatorStats() {
TransactionCoordinatorStats transactionCoordinatorstats = new TransactionCoordinatorStats();
transactionCoordinatorstats.setLowWaterMark(getLowWaterMark());
transactionCoordinatorstats.setState(getState().name());
transactionCoordinatorstats.setLeastSigBits(sequenceIdGenerator.getCurrentSequenceId());
return transactionCoordinatorstats;
}
Aggregations