use of org.apache.pulsar.common.policies.data.TransactionLogStats 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.TransactionLogStats in project pulsar by apache.
the class TransactionsBase method internalGetCoordinatorInternalStats.
protected void internalGetCoordinatorInternalStats(AsyncResponse asyncResponse, boolean authoritative, boolean metadata, int coordinatorId) {
try {
if (pulsar().getConfig().isTransactionCoordinatorEnabled()) {
TopicName topicName = TopicName.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId);
validateTopicOwnership(topicName, authoritative);
TransactionMetadataStore metadataStore = pulsar().getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(coordinatorId));
if (metadataStore == null) {
asyncResponse.resume(new RestException(NOT_FOUND, "Transaction coordinator not found! coordinator id : " + coordinatorId));
return;
}
if (metadataStore instanceof MLTransactionMetadataStore) {
ManagedLedger managedLedger = ((MLTransactionMetadataStore) metadataStore).getManagedLedger();
TransactionCoordinatorInternalStats transactionCoordinatorInternalStats = new TransactionCoordinatorInternalStats();
TransactionLogStats transactionLogStats = new TransactionLogStats();
transactionLogStats.managedLedgerName = managedLedger.getName();
transactionLogStats.managedLedgerInternalStats = managedLedger.getManagedLedgerInternalStats(metadata).get();
transactionCoordinatorInternalStats.transactionLogStats = transactionLogStats;
asyncResponse.resume(transactionCoordinatorInternalStats);
} else {
asyncResponse.resume(new RestException(METHOD_NOT_ALLOWED, "Broker don't use MLTransactionMetadataStore!"));
}
} 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.TransactionLogStats 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.TransactionLogStats in project incubator-pulsar by apache.
the class TransactionsBase method internalGetCoordinatorInternalStats.
protected void internalGetCoordinatorInternalStats(AsyncResponse asyncResponse, boolean authoritative, boolean metadata, int coordinatorId) {
try {
TopicName topicName = SystemTopicNames.TRANSACTION_COORDINATOR_ASSIGN.getPartition(coordinatorId);
validateTopicOwnership(topicName, authoritative);
TransactionMetadataStore metadataStore = pulsar().getTransactionMetadataStoreService().getStores().get(TransactionCoordinatorID.get(coordinatorId));
if (metadataStore == null) {
asyncResponse.resume(new RestException(NOT_FOUND, "Transaction coordinator not found! coordinator id : " + coordinatorId));
return;
}
if (metadataStore instanceof MLTransactionMetadataStore) {
ManagedLedger managedLedger = ((MLTransactionMetadataStore) metadataStore).getManagedLedger();
TransactionCoordinatorInternalStats transactionCoordinatorInternalStats = new TransactionCoordinatorInternalStats();
TransactionLogStats transactionLogStats = new TransactionLogStats();
transactionLogStats.managedLedgerName = managedLedger.getName();
transactionLogStats.managedLedgerInternalStats = managedLedger.getManagedLedgerInternalStats(metadata).get();
transactionCoordinatorInternalStats.transactionLogStats = transactionLogStats;
asyncResponse.resume(transactionCoordinatorInternalStats);
} else {
asyncResponse.resume(new RestException(METHOD_NOT_ALLOWED, "Broker don't use MLTransactionMetadataStore!"));
}
} catch (Exception e) {
resumeAsyncResponseExceptionally(asyncResponse, e);
}
}
use of org.apache.pulsar.common.policies.data.TransactionLogStats in project incubator-pulsar by apache.
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;
}));
}
Aggregations