Search in sources :

Example 1 with TransactionLogStats

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()));
    }
}
Also used : Optional(java.util.Optional) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RestException(org.apache.pulsar.broker.web.RestException) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats) ServiceUnitNotReadyException(org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) RestException(org.apache.pulsar.broker.web.RestException) CoordinatorNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException) SubscriptionNotFoundException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) ServiceUnitNotReadyException(org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) SubscriptionNotFoundException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException) Topic(org.apache.pulsar.broker.service.Topic) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with TransactionLogStats

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()));
    }
}
Also used : TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RestException(org.apache.pulsar.broker.web.RestException) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) TransactionMetadataStore(org.apache.pulsar.transaction.coordinator.TransactionMetadataStore) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) ServiceUnitNotReadyException(org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException) NotAllowedException(org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException) RestException(org.apache.pulsar.broker.web.RestException) CoordinatorNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException) SubscriptionNotFoundException(org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 3 with TransactionLogStats

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;
    }));
}
Also used : TransactionMetadataStore(org.apache.pulsar.transaction.coordinator.TransactionMetadataStore) TopicName(org.apache.pulsar.common.naming.TopicName) Topic(org.apache.pulsar.broker.service.Topic) TransactionCoordinatorStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorStats) AdminResource(org.apache.pulsar.broker.admin.AdminResource) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) METHOD_NOT_ALLOWED(javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) SystemTopicNames(org.apache.pulsar.common.naming.SystemTopicNames) ArrayList(java.util.ArrayList) TxnID(org.apache.pulsar.client.api.transaction.TxnID) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) Lists(com.google.common.collect.Lists) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) TransactionInBufferStats(org.apache.pulsar.common.policies.data.TransactionInBufferStats) CoordinatorNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException) SERVICE_UNAVAILABLE(javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE) TransactionMetadata(org.apache.pulsar.common.policies.data.TransactionMetadata) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) AsyncResponse(javax.ws.rs.container.AsyncResponse) Transactions(org.apache.pulsar.client.admin.Transactions) TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TxnMeta(org.apache.pulsar.transaction.coordinator.TxnMeta) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) Response(javax.ws.rs.core.Response) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats) TransactionPendingAckStats(org.apache.pulsar.common.policies.data.TransactionPendingAckStats) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) Codec(org.apache.pulsar.common.util.Codec) Optional(java.util.Optional) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) TransactionInPendingAckStats(org.apache.pulsar.common.policies.data.TransactionInPendingAckStats) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats)

Example 4 with TransactionLogStats

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);
    }
}
Also used : TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) RestException(org.apache.pulsar.broker.web.RestException) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) TransactionMetadataStore(org.apache.pulsar.transaction.coordinator.TransactionMetadataStore) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) RestException(org.apache.pulsar.broker.web.RestException) CoordinatorNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) TopicName(org.apache.pulsar.common.naming.TopicName)

Example 5 with TransactionLogStats

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;
    }));
}
Also used : TransactionMetadataStore(org.apache.pulsar.transaction.coordinator.TransactionMetadataStore) TopicName(org.apache.pulsar.common.naming.TopicName) Topic(org.apache.pulsar.broker.service.Topic) TransactionCoordinatorStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorStats) AdminResource(org.apache.pulsar.broker.admin.AdminResource) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) METHOD_NOT_ALLOWED(javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PartitionedTopicMetadata(org.apache.pulsar.common.partition.PartitionedTopicMetadata) SystemTopicNames(org.apache.pulsar.common.naming.SystemTopicNames) ArrayList(java.util.ArrayList) TxnID(org.apache.pulsar.client.api.transaction.TxnID) MLTransactionMetadataStore(org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore) Lists(com.google.common.collect.Lists) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) Map(java.util.Map) RestException(org.apache.pulsar.broker.web.RestException) NamespaceName(org.apache.pulsar.common.naming.NamespaceName) TopicDomain(org.apache.pulsar.common.naming.TopicDomain) TransactionInBufferStats(org.apache.pulsar.common.policies.data.TransactionInBufferStats) CoordinatorNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException) SERVICE_UNAVAILABLE(javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE) TransactionMetadata(org.apache.pulsar.common.policies.data.TransactionMetadata) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) AsyncResponse(javax.ws.rs.container.AsyncResponse) Transactions(org.apache.pulsar.client.admin.Transactions) TransactionBufferStats(org.apache.pulsar.common.policies.data.TransactionBufferStats) TransactionNotFoundException(org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) TxnMeta(org.apache.pulsar.transaction.coordinator.TxnMeta) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) PersistentTopic(org.apache.pulsar.broker.service.persistent.PersistentTopic) FutureUtil(org.apache.pulsar.common.util.FutureUtil) TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) Response(javax.ws.rs.core.Response) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats) TransactionPendingAckStats(org.apache.pulsar.common.policies.data.TransactionPendingAckStats) PulsarServerException(org.apache.pulsar.broker.PulsarServerException) Codec(org.apache.pulsar.common.util.Codec) Optional(java.util.Optional) TransactionCoordinatorID(org.apache.pulsar.transaction.coordinator.TransactionCoordinatorID) TransactionInPendingAckStats(org.apache.pulsar.common.policies.data.TransactionInPendingAckStats) TransactionLogStats(org.apache.pulsar.common.policies.data.TransactionLogStats) TransactionPendingAckInternalStats(org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)6 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)6 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)6 RestException (org.apache.pulsar.broker.web.RestException)6 TransactionLogStats (org.apache.pulsar.common.policies.data.TransactionLogStats)6 CoordinatorNotFoundException (org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException)6 TransactionNotFoundException (org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException)6 TopicName (org.apache.pulsar.common.naming.TopicName)5 TransactionCoordinatorInternalStats (org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats)5 TransactionMetadataStore (org.apache.pulsar.transaction.coordinator.TransactionMetadataStore)5 MLTransactionMetadataStore (org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore)5 Optional (java.util.Optional)3 Topic (org.apache.pulsar.broker.service.Topic)3 PersistentTopic (org.apache.pulsar.broker.service.persistent.PersistentTopic)3 TransactionPendingAckInternalStats (org.apache.pulsar.common.policies.data.TransactionPendingAckInternalStats)3 Lists (com.google.common.collect.Lists)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2