Search in sources :

Example 1 with ManagedLedgerFactoryImpl

use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.

the class PersistentTopicConcurrentTest method setup.

@BeforeMethod
public void setup(Method m) throws Exception {
    super.setUp(m);
    ServiceConfiguration svcConfig = spy(new ServiceConfiguration());
    PulsarService pulsar = spy(new PulsarService(svcConfig));
    doReturn(svcConfig).when(pulsar).getConfiguration();
    mlFactoryMock = mock(ManagedLedgerFactory.class);
    ManagedLedgerFactory factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
    ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig().setMaxEntriesPerLedger(2));
    final ManagedCursor cursor = ledger.openCursor("c1");
    cursorMock = cursor;
    ledgerMock = ledger;
    mlFactoryMock = factory;
    doReturn(mlFactoryMock).when(pulsar).getManagedLedgerFactory();
    ZooKeeper mockZk = mock(ZooKeeper.class);
    doReturn(mockZk).when(pulsar).getZkClient();
    brokerService = spy(new BrokerService(pulsar));
    doReturn(brokerService).when(pulsar).getBrokerService();
    serverCnx = spy(new ServerCnx(brokerService));
    doReturn(true).when(serverCnx).isActive();
    NamespaceService nsSvc = mock(NamespaceService.class);
    doReturn(nsSvc).when(pulsar).getNamespaceService();
    doReturn(true).when(nsSvc).isServiceUnitOwned(any(NamespaceBundle.class));
    doReturn(true).when(nsSvc).isServiceUnitActive(any(DestinationName.class));
    final List<Position> addedEntries = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        Position pos = ledger.addEntry("entry".getBytes());
        addedEntries.add(pos);
    }
}
Also used : NamespaceBundle(com.yahoo.pulsar.common.naming.NamespaceBundle) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ServerCnx(com.yahoo.pulsar.broker.service.ServerCnx) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ZooKeeper(org.apache.zookeeper.ZooKeeper) ServiceConfiguration(com.yahoo.pulsar.broker.ServiceConfiguration) PulsarService(com.yahoo.pulsar.broker.PulsarService) NamespaceService(com.yahoo.pulsar.broker.namespace.NamespaceService) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with ManagedLedgerFactoryImpl

use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.

the class PersistentTopics method getBacklog.

@GET
@Path("{property}/{cluster}/{namespace}/{destination}/backlog")
@ApiOperation(value = "Get estimated backlog for offline topic.")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Namespace does not exist") })
public PersistentOfflineTopicStats getBacklog(@PathParam("property") String property, @PathParam("cluster") String cluster, @PathParam("namespace") String namespace, @PathParam("destination") @Encoded String destination, @QueryParam("authoritative") @DefaultValue("false") boolean authoritative) {
    destination = decode(destination);
    validateAdminAccessOnProperty(property);
    // note that we do not want to load the topic and hence skip validateAdminOperationOnDestination()
    try {
        policiesCache().get(path("policies", property, cluster, namespace));
    } catch (KeeperException.NoNodeException e) {
        log.warn("[{}] Failed to get topic backlog {}/{}/{}: Namespace does not exist", clientAppId(), property, cluster, namespace);
        throw new RestException(Status.NOT_FOUND, "Namespace does not exist");
    } catch (Exception e) {
        log.error("[{}] Failed to get topic backlog {}/{}/{}", clientAppId(), property, cluster, namespace, e);
        throw new RestException(e);
    }
    DestinationName dn = DestinationName.get(domain(), property, cluster, namespace, destination);
    PersistentOfflineTopicStats offlineTopicStats = null;
    try {
        offlineTopicStats = pulsar().getBrokerService().getOfflineTopicStat(dn);
        if (offlineTopicStats != null) {
            // offline topic stat has a cost - so use cached value until TTL
            long elapsedMs = System.currentTimeMillis() - offlineTopicStats.statGeneratedAt.getTime();
            if (TimeUnit.MINUTES.convert(elapsedMs, TimeUnit.MILLISECONDS) < OFFLINE_TOPIC_STAT_TTL_MINS) {
                return offlineTopicStats;
            }
        }
        final ManagedLedgerConfig config = pulsar().getBrokerService().getManagedLedgerConfig(dn).get();
        ManagedLedgerOfflineBacklog offlineTopicBacklog = new ManagedLedgerOfflineBacklog(config.getDigestType(), config.getPassword(), pulsar().getAdvertisedAddress(), false);
        offlineTopicStats = offlineTopicBacklog.estimateUnloadedTopicBacklog((ManagedLedgerFactoryImpl) pulsar().getManagedLedgerFactory(), dn);
        pulsar().getBrokerService().cacheOfflineTopicStats(dn, offlineTopicStats);
    } catch (Exception exception) {
        throw new RestException(exception);
    }
    return offlineTopicStats;
}
Also used : ManagedLedgerOfflineBacklog(org.apache.bookkeeper.mledger.impl.ManagedLedgerOfflineBacklog) PersistentOfflineTopicStats(com.yahoo.pulsar.common.policies.data.PersistentOfflineTopicStats) RestException(com.yahoo.pulsar.broker.web.RestException) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) KeeperException(org.apache.zookeeper.KeeperException) RestException(com.yahoo.pulsar.broker.web.RestException) TopicBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException) WebApplicationException(javax.ws.rs.WebApplicationException) PulsarClientException(com.yahoo.pulsar.client.api.PulsarClientException) PreconditionFailedException(com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) SubscriptionBusyException(com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException) NotFoundException(com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException) NotAllowedException(com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with ManagedLedgerFactoryImpl

use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.

the class MockedBookKeeperTestCase method setUp.

@BeforeMethod
public void setUp(Method method) throws Exception {
    LOG.info(">>>>>> starting {}", method);
    try {
        // start bookkeeper service
        startBookKeeper();
    } catch (Exception e) {
        LOG.error("Error setting up", e);
        throw e;
    }
    executor = new OrderedSafeExecutor(2, "test");
    cachedExecutor = Executors.newCachedThreadPool();
    ManagedLedgerFactoryConfig conf = new ManagedLedgerFactoryConfig();
    conf.setUseProtobufBinaryFormatInZK(protobufFormat == ZNodeProtobufFormat.Binary);
    factory = new ManagedLedgerFactoryImpl(bkc, zkc, conf);
}
Also used : ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) OrderedSafeExecutor(org.apache.bookkeeper.util.OrderedSafeExecutor) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with ManagedLedgerFactoryImpl

use of org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl in project pulsar by yahoo.

the class PersistentTopicE2ETest method testUnloadNamespace.

@Test(enabled = false)
public void testUnloadNamespace() throws Exception {
    String topicName = "persistent://prop/use/ns-abc/topic-9";
    DestinationName destinationName = DestinationName.get(topicName);
    pulsarClient.createProducer(topicName);
    pulsarClient.close();
    assertTrue(pulsar.getBrokerService().getTopicReference(topicName) != null);
    assertTrue(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(destinationName.getPersistenceNamingEncoding()));
    admin.namespaces().unload("prop/use/ns-abc");
    int i = 0;
    for (i = 0; i < 30; i++) {
        if (pulsar.getBrokerService().getTopicReference(topicName) == null) {
            break;
        }
        Thread.sleep(1000);
    }
    if (i == 30) {
        fail("The topic reference should be null");
    }
    // ML should have been closed as well
    assertFalse(((ManagedLedgerFactoryImpl) pulsar.getManagedLedgerFactory()).getManagedLedgers().containsKey(destinationName.getPersistenceNamingEncoding()));
}
Also used : DestinationName(com.yahoo.pulsar.common.naming.DestinationName) ManagedLedgerFactoryImpl(org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl) Test(org.testng.annotations.Test)

Aggregations

ManagedLedgerFactoryImpl (org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl)4 DestinationName (com.yahoo.pulsar.common.naming.DestinationName)3 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)2 BeforeMethod (org.testng.annotations.BeforeMethod)2 PulsarService (com.yahoo.pulsar.broker.PulsarService)1 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)1 NamespaceService (com.yahoo.pulsar.broker.namespace.NamespaceService)1 BrokerService (com.yahoo.pulsar.broker.service.BrokerService)1 NotAllowedException (com.yahoo.pulsar.broker.service.BrokerServiceException.NotAllowedException)1 SubscriptionBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.SubscriptionBusyException)1 TopicBusyException (com.yahoo.pulsar.broker.service.BrokerServiceException.TopicBusyException)1 ServerCnx (com.yahoo.pulsar.broker.service.ServerCnx)1 RestException (com.yahoo.pulsar.broker.web.RestException)1 NotFoundException (com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException)1 PreconditionFailedException (com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException)1 PulsarClientException (com.yahoo.pulsar.client.api.PulsarClientException)1 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)1 PersistentOfflineTopicStats (com.yahoo.pulsar.common.policies.data.PersistentOfflineTopicStats)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1