Search in sources :

Example 1 with TransactionCoordinatorInternalStats

use of org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats in project pulsar by apache.

the class AdminApiTransactionTest method testGetCoordinatorInternalStats.

@Test(timeOut = 20000)
public void testGetCoordinatorInternalStats() throws Exception {
    initTransaction(1);
    Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(60, TimeUnit.SECONDS).build().get();
    TransactionCoordinatorInternalStats stats = admin.transactions().getCoordinatorInternalStatsAsync(0, true).get();
    verifyManagedLegerInternalStats(stats.transactionLogStats.managedLedgerInternalStats, 26);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
    transaction.commit().get();
    stats = admin.transactions().getCoordinatorInternalStatsAsync(0, false).get();
    assertNull(stats.transactionLogStats.managedLedgerInternalStats.ledgers.get(0).metadata);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
}
Also used : Transaction(org.apache.pulsar.client.api.transaction.Transaction) TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with TransactionCoordinatorInternalStats

use of org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats 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 TransactionCoordinatorInternalStats

use of org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats in project pulsar by yahoo.

the class AdminApiTransactionTest method testGetCoordinatorInternalStats.

@Test(timeOut = 20000)
public void testGetCoordinatorInternalStats() throws Exception {
    initTransaction(1);
    Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(60, TimeUnit.SECONDS).build().get();
    TransactionCoordinatorInternalStats stats = admin.transactions().getCoordinatorInternalStatsAsync(0, true).get();
    verifyManagedLegerInternalStats(stats.transactionLogStats.managedLedgerInternalStats, 26);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
    transaction.commit().get();
    stats = admin.transactions().getCoordinatorInternalStatsAsync(0, false).get();
    assertNull(stats.transactionLogStats.managedLedgerInternalStats.ledgers.get(0).metadata);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
}
Also used : Transaction(org.apache.pulsar.client.api.transaction.Transaction) TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 4 with TransactionCoordinatorInternalStats

use of org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats in project incubator-pulsar by apache.

the class AdminApiTransactionTest method testGetCoordinatorInternalStats.

@Test(timeOut = 20000)
public void testGetCoordinatorInternalStats() throws Exception {
    initTransaction(1);
    Transaction transaction = pulsarClient.newTransaction().withTransactionTimeout(60, TimeUnit.SECONDS).build().get();
    TransactionCoordinatorInternalStats stats = admin.transactions().getCoordinatorInternalStatsAsync(0, true).get();
    verifyManagedLegerInternalStats(stats.transactionLogStats.managedLedgerInternalStats, 26);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
    transaction.commit().get();
    stats = admin.transactions().getCoordinatorInternalStatsAsync(0, false).get();
    assertNull(stats.transactionLogStats.managedLedgerInternalStats.ledgers.get(0).metadata);
    assertEquals(TopicName.get(TopicDomain.persistent.toString(), NamespaceName.SYSTEM_NAMESPACE, MLTransactionLogImpl.TRANSACTION_LOG_PREFIX + "0").getPersistenceNamingEncoding(), stats.transactionLogStats.managedLedgerName);
}
Also used : Transaction(org.apache.pulsar.client.api.transaction.Transaction) TransactionCoordinatorInternalStats(org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 5 with TransactionCoordinatorInternalStats

use of org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats 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)

Aggregations

TransactionCoordinatorInternalStats (org.apache.pulsar.common.policies.data.TransactionCoordinatorInternalStats)9 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 WebTarget (javax.ws.rs.client.WebTarget)3 ManagedLedger (org.apache.bookkeeper.mledger.ManagedLedger)3 PulsarServerException (org.apache.pulsar.broker.PulsarServerException)3 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)3 RestException (org.apache.pulsar.broker.web.RestException)3 Transaction (org.apache.pulsar.client.api.transaction.Transaction)3 TopicName (org.apache.pulsar.common.naming.TopicName)3 TransactionLogStats (org.apache.pulsar.common.policies.data.TransactionLogStats)3 TransactionMetadataStore (org.apache.pulsar.transaction.coordinator.TransactionMetadataStore)3 CoordinatorNotFoundException (org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.CoordinatorNotFoundException)3 TransactionNotFoundException (org.apache.pulsar.transaction.coordinator.exceptions.CoordinatorException.TransactionNotFoundException)3 MLTransactionMetadataStore (org.apache.pulsar.transaction.coordinator.impl.MLTransactionMetadataStore)3 Test (org.testng.annotations.Test)3 NotAllowedException (org.apache.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 ServiceUnitNotReadyException (org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotReadyException)1 SubscriptionNotFoundException (org.apache.pulsar.broker.service.BrokerServiceException.SubscriptionNotFoundException)1