use of org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats in project pulsar by apache.
the class TransactionsBase method internalGetPendingAckInternalStats.
protected void internalGetPendingAckInternalStats(AsyncResponse asyncResponse, boolean authoritative, TopicName topicName, String subName, boolean metadata) {
try {
if (pulsar().getConfig().isTransactionCoordinatorEnabled()) {
validateTopicOwnership(topicName, authoritative);
CompletableFuture<Optional<Topic>> topicFuture = pulsar().getBrokerService().getTopics().get(topicName.toString());
if (topicFuture != null) {
topicFuture.whenComplete((optionalTopic, e) -> {
if (e != null) {
asyncResponse.resume(new RestException(e));
return;
}
if (!optionalTopic.isPresent()) {
asyncResponse.resume(new RestException(TEMPORARY_REDIRECT, "Topic is not owned by this broker!"));
return;
}
Topic topicObject = optionalTopic.get();
if (topicObject instanceof PersistentTopic) {
try {
ManagedLedger managedLedger = ((PersistentTopic) topicObject).getPendingAckManagedLedger(subName).get();
TransactionPendingAckInternalStats stats = new TransactionPendingAckInternalStats();
TransactionLogStats pendingAckLogStats = new TransactionLogStats();
pendingAckLogStats.managedLedgerName = managedLedger.getName();
pendingAckLogStats.managedLedgerInternalStats = managedLedger.getManagedLedgerInternalStats(metadata).get();
stats.pendingAckLogStats = pendingAckLogStats;
asyncResponse.resume(stats);
} catch (Exception exception) {
if (exception instanceof ExecutionException) {
if (exception.getCause() instanceof ServiceUnitNotReadyException) {
asyncResponse.resume(new RestException(SERVICE_UNAVAILABLE, exception.getCause()));
return;
} else if (exception.getCause() instanceof NotAllowedException) {
asyncResponse.resume(new RestException(METHOD_NOT_ALLOWED, exception.getCause()));
return;
} else if (exception.getCause() instanceof SubscriptionNotFoundException) {
asyncResponse.resume(new RestException(NOT_FOUND, exception.getCause()));
return;
}
}
asyncResponse.resume(new RestException(exception));
}
} else {
asyncResponse.resume(new RestException(BAD_REQUEST, "Topic is not a persistent topic!"));
}
});
} else {
asyncResponse.resume(new RestException(TEMPORARY_REDIRECT, "Topic is not owned by this broker!"));
}
} else {
asyncResponse.resume(new RestException(SERVICE_UNAVAILABLE, "This Broker is not configured with transactionCoordinatorEnabled=true."));
}
} catch (Exception e) {
asyncResponse.resume(new RestException(e.getCause()));
}
}
use of org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats in project pulsar by apache.
the class TransactionsImpl method getPendingAckInternalStatsAsync.
@Override
public CompletableFuture<TransactionPendingAckInternalStats> getPendingAckInternalStatsAsync(String topic, String subName, boolean metadata) {
TopicName tn = TopicName.get(topic);
WebTarget path = adminV3Transactions.path("pendingAckInternalStats");
path = path.path(tn.getRestPath(false));
path = path.path(subName);
path = path.queryParam("metadata", metadata);
final CompletableFuture<TransactionPendingAckInternalStats> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<TransactionPendingAckInternalStats>() {
@Override
public void completed(TransactionPendingAckInternalStats 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.TransactionPendingAckInternalStats in project pulsar by yahoo.
the class TransactionsBase method internalGetPendingAckInternalStats.
protected CompletableFuture<TransactionPendingAckInternalStats> internalGetPendingAckInternalStats(boolean authoritative, String subName, boolean metadata) {
return getExistingPersistentTopicAsync(authoritative).thenCompose(topic -> topic.getPendingAckManagedLedger(subName)).thenCompose(managedLedger -> managedLedger.getManagedLedgerInternalStats(metadata).thenApply(internalStats -> {
TransactionLogStats pendingAckLogStats = new TransactionLogStats();
pendingAckLogStats.managedLedgerName = managedLedger.getName();
pendingAckLogStats.managedLedgerInternalStats = internalStats;
return pendingAckLogStats;
}).thenApply(pendingAckLogStats -> {
TransactionPendingAckInternalStats stats = new TransactionPendingAckInternalStats();
stats.pendingAckLogStats = pendingAckLogStats;
return stats;
}));
}
use of org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats in project pulsar by yahoo.
the class TransactionsImpl method getPendingAckInternalStatsAsync.
@Override
public CompletableFuture<TransactionPendingAckInternalStats> getPendingAckInternalStatsAsync(String topic, String subName, boolean metadata) {
TopicName tn = TopicName.get(topic);
WebTarget path = adminV3Transactions.path("pendingAckInternalStats");
path = path.path(tn.getRestPath(false));
path = path.path(subName);
path = path.queryParam("metadata", metadata);
final CompletableFuture<TransactionPendingAckInternalStats> future = new CompletableFuture<>();
asyncGetRequest(path, new InvocationCallback<TransactionPendingAckInternalStats>() {
@Override
public void completed(TransactionPendingAckInternalStats 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.TransactionPendingAckInternalStats in project incubator-pulsar by apache.
the class AdminApiTransactionTest method testGetPendingAckInternalStats.
@Test(timeOut = 20000)
public void testGetPendingAckInternalStats() throws Exception {
initTransaction(1);
TransactionImpl transaction = (TransactionImpl) getTransaction();
final String topic = "persistent://public/default/testGetPendingAckInternalStats";
final String subName = "test";
try {
admin.transactions().getPendingAckInternalStatsAsync(topic, subName, true).get();
fail("Should failed here");
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof PulsarAdminException.NotFoundException);
PulsarAdminException.NotFoundException cause = (PulsarAdminException.NotFoundException) ex.getCause();
assertEquals(cause.getMessage(), "Topic not found");
}
try {
pulsar.getBrokerService().getTopic(topic, false);
admin.transactions().getPendingAckInternalStatsAsync(topic, subName, true).get();
fail("Should failed here");
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof PulsarAdminException.NotFoundException);
PulsarAdminException.NotFoundException cause = (PulsarAdminException.NotFoundException) ex.getCause();
assertEquals(cause.getMessage(), "Topic not found");
}
admin.topics().createNonPartitionedTopic(topic);
Producer<byte[]> producer = pulsarClient.newProducer(Schema.BYTES).topic(topic).create();
Consumer<byte[]> consumer = pulsarClient.newConsumer(Schema.BYTES).topic(topic).subscriptionName(subName).subscribe();
MessageId messageId = producer.send("Hello pulsar!".getBytes());
consumer.acknowledgeAsync(messageId, transaction).get();
TransactionPendingAckInternalStats stats = admin.transactions().getPendingAckInternalStatsAsync(topic, subName, true).get();
ManagedLedgerInternalStats managedLedgerInternalStats = stats.pendingAckLogStats.managedLedgerInternalStats;
assertEquals(TopicName.get(TopicDomain.persistent.toString(), "public", "default", "testGetPendingAckInternalStats" + "-" + subName + SystemTopicNames.PENDING_ACK_STORE_SUFFIX).getPersistenceNamingEncoding(), stats.pendingAckLogStats.managedLedgerName);
verifyManagedLegerInternalStats(managedLedgerInternalStats, 16);
ManagedLedgerInternalStats finalManagedLedgerInternalStats = managedLedgerInternalStats;
managedLedgerInternalStats.cursors.forEach((s, cursorStats) -> {
assertEquals(s, SystemTopicNames.PENDING_ACK_STORE_CURSOR_NAME);
assertEquals(cursorStats.readPosition, finalManagedLedgerInternalStats.lastConfirmedEntry);
});
stats = admin.transactions().getPendingAckInternalStatsAsync(topic, subName, false).get();
managedLedgerInternalStats = stats.pendingAckLogStats.managedLedgerInternalStats;
assertEquals(TopicName.get(TopicDomain.persistent.toString(), "public", "default", "testGetPendingAckInternalStats" + "-" + subName + SystemTopicNames.PENDING_ACK_STORE_SUFFIX).getPersistenceNamingEncoding(), stats.pendingAckLogStats.managedLedgerName);
assertNull(managedLedgerInternalStats.ledgers.get(0).metadata);
}
Aggregations