Search in sources :

Example 1 with ManagedLedgerInfo

use of org.apache.bookkeeper.mledger.ManagedLedgerInfo in project incubator-pulsar by apache.

the class ManagedLedgerFactoryTest method testGetManagedLedgerInfoWithClose.

@Test(timeOut = 20000)
public void testGetManagedLedgerInfoWithClose() throws Exception {
    ManagedLedgerConfig conf = new ManagedLedgerConfig();
    conf.setMaxEntriesPerLedger(1);
    ManagedLedgerImpl ledger = (ManagedLedgerImpl) factory.open("testGetManagedLedgerInfo", conf);
    ManagedCursor c1 = ledger.openCursor("c1");
    PositionImpl p1 = (PositionImpl) ledger.addEntry("entry1".getBytes());
    PositionImpl p2 = (PositionImpl) ledger.addEntry("entry2".getBytes());
    PositionImpl p3 = (PositionImpl) ledger.addEntry("entry3".getBytes());
    ledger.addEntry("entry4".getBytes());
    c1.delete(p2);
    c1.delete(p3);
    ledger.close();
    ManagedLedgerInfo info = factory.getManagedLedgerInfo("testGetManagedLedgerInfo");
    assertEquals(info.ledgers.size(), 4);
    assertEquals(info.ledgers.get(0).ledgerId, 3);
    assertEquals(info.ledgers.get(1).ledgerId, 5);
    assertEquals(info.ledgers.get(2).ledgerId, 6);
    assertEquals(info.ledgers.get(3).ledgerId, 7);
    assertEquals(info.cursors.size(), 1);
    CursorInfo cursorInfo = info.cursors.get("c1");
    assertEquals(cursorInfo.markDelete.ledgerId, 3);
    assertEquals(cursorInfo.markDelete.entryId, -1);
    assertEquals(cursorInfo.individualDeletedMessages.size(), 1);
    MessageRangeInfo mri = cursorInfo.individualDeletedMessages.get(0);
    assertEquals(mri.from.ledgerId, p1.getLedgerId());
    assertEquals(mri.from.entryId, p1.getEntryId());
    assertEquals(mri.to.ledgerId, p3.getLedgerId());
    assertEquals(mri.to.entryId, p3.getEntryId());
}
Also used : CursorInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.CursorInfo) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) MessageRangeInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.MessageRangeInfo) Test(org.testng.annotations.Test)

Example 2 with ManagedLedgerInfo

use of org.apache.bookkeeper.mledger.ManagedLedgerInfo in project incubator-pulsar by apache.

the class PersistentTopicsBase method internalGetManagedLedgerInfo.

protected void internalGetManagedLedgerInfo(AsyncResponse asyncResponse) {
    validateAdminAccessOnProperty(topicName.getProperty());
    if (topicName.isGlobal()) {
        validateGlobalNamespaceOwnership(namespaceName);
    }
    String managedLedger = topicName.getPersistenceNamingEncoding();
    pulsar().getManagedLedgerFactory().asyncGetManagedLedgerInfo(managedLedger, new ManagedLedgerInfoCallback() {

        @Override
        public void getInfoComplete(ManagedLedgerInfo info, Object ctx) {
            asyncResponse.resume((StreamingOutput) output -> {
                jsonMapper().writer().writeValue(output, info);
            });
        }

        @Override
        public void getInfoFailed(ManagedLedgerException exception, Object ctx) {
            asyncResponse.resume(exception);
        }
    }, null);
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) StreamingOutput(javax.ws.rs.core.StreamingOutput) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo)

Example 3 with ManagedLedgerInfo

use of org.apache.bookkeeper.mledger.ManagedLedgerInfo in project incubator-pulsar by apache.

the class ManagedLedgerFactoryImpl method getManagedLedgerInfo.

@Override
public ManagedLedgerInfo getManagedLedgerInfo(String name) throws InterruptedException, ManagedLedgerException {
    class Result {

        ManagedLedgerInfo info = null;

        ManagedLedgerException e = null;
    }
    final Result r = new Result();
    final CountDownLatch latch = new CountDownLatch(1);
    asyncGetManagedLedgerInfo(name, new ManagedLedgerInfoCallback() {

        @Override
        public void getInfoComplete(ManagedLedgerInfo info, Object ctx) {
            r.info = info;
            latch.countDown();
        }

        @Override
        public void getInfoFailed(ManagedLedgerException exception, Object ctx) {
            r.e = exception;
            latch.countDown();
        }
    }, null);
    latch.await();
    if (r.e != null) {
        throw r.e;
    }
    return r.info;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo)

Example 4 with ManagedLedgerInfo

use of org.apache.bookkeeper.mledger.ManagedLedgerInfo in project incubator-pulsar by apache.

the class ManagedLedgerFactoryImpl method asyncGetManagedLedgerInfo.

@Override
public void asyncGetManagedLedgerInfo(String name, ManagedLedgerInfoCallback callback, Object ctx) {
    store.getManagedLedgerInfo(name, new MetaStoreCallback<MLDataFormats.ManagedLedgerInfo>() {

        @Override
        public void operationComplete(MLDataFormats.ManagedLedgerInfo pbInfo, Stat stat) {
            ManagedLedgerInfo info = new ManagedLedgerInfo();
            info.version = stat.getVersion();
            info.creationDate = DateFormatter.format(stat.getCreationTimestamp());
            info.modificationDate = DateFormatter.format(stat.getModificationTimestamp());
            info.ledgers = new ArrayList<>(pbInfo.getLedgerInfoCount());
            if (pbInfo.hasTerminatedPosition()) {
                info.terminatedPosition = new PositionInfo();
                info.terminatedPosition.ledgerId = pbInfo.getTerminatedPosition().getLedgerId();
                info.terminatedPosition.entryId = pbInfo.getTerminatedPosition().getEntryId();
            }
            for (int i = 0; i < pbInfo.getLedgerInfoCount(); i++) {
                MLDataFormats.ManagedLedgerInfo.LedgerInfo pbLedgerInfo = pbInfo.getLedgerInfo(i);
                LedgerInfo ledgerInfo = new LedgerInfo();
                ledgerInfo.ledgerId = pbLedgerInfo.getLedgerId();
                ledgerInfo.entries = pbLedgerInfo.hasEntries() ? pbLedgerInfo.getEntries() : null;
                ledgerInfo.size = pbLedgerInfo.hasSize() ? pbLedgerInfo.getSize() : null;
                info.ledgers.add(ledgerInfo);
            }
            store.getCursors(name, new MetaStoreCallback<List<String>>() {

                @Override
                public void operationComplete(List<String> cursorsList, Stat stat) {
                    // Get the info for each cursor
                    info.cursors = new ConcurrentSkipListMap<>();
                    List<CompletableFuture<Void>> cursorsFutures = new ArrayList<>();
                    for (String cursorName : cursorsList) {
                        CompletableFuture<Void> cursorFuture = new CompletableFuture<>();
                        cursorsFutures.add(cursorFuture);
                        store.asyncGetCursorInfo(name, cursorName, new MetaStoreCallback<MLDataFormats.ManagedCursorInfo>() {

                            @Override
                            public void operationComplete(ManagedCursorInfo pbCursorInfo, Stat stat) {
                                CursorInfo cursorInfo = new CursorInfo();
                                cursorInfo.version = stat.getVersion();
                                cursorInfo.creationDate = DateFormatter.format(stat.getCreationTimestamp());
                                cursorInfo.modificationDate = DateFormatter.format(stat.getModificationTimestamp());
                                cursorInfo.cursorsLedgerId = pbCursorInfo.getCursorsLedgerId();
                                if (pbCursorInfo.hasMarkDeleteLedgerId()) {
                                    cursorInfo.markDelete = new PositionInfo();
                                    cursorInfo.markDelete.ledgerId = pbCursorInfo.getMarkDeleteLedgerId();
                                    cursorInfo.markDelete.entryId = pbCursorInfo.getMarkDeleteEntryId();
                                }
                                if (pbCursorInfo.getPropertiesCount() > 0) {
                                    cursorInfo.properties = Maps.newTreeMap();
                                    for (int i = 0; i < pbCursorInfo.getPropertiesCount(); i++) {
                                        LongProperty property = pbCursorInfo.getProperties(i);
                                        cursorInfo.properties.put(property.getName(), property.getValue());
                                    }
                                }
                                if (pbCursorInfo.getIndividualDeletedMessagesCount() > 0) {
                                    cursorInfo.individualDeletedMessages = new ArrayList<>();
                                    for (int i = 0; i < pbCursorInfo.getIndividualDeletedMessagesCount(); i++) {
                                        MessageRange range = pbCursorInfo.getIndividualDeletedMessages(i);
                                        MessageRangeInfo rangeInfo = new MessageRangeInfo();
                                        rangeInfo.from.ledgerId = range.getLowerEndpoint().getLedgerId();
                                        rangeInfo.from.entryId = range.getLowerEndpoint().getEntryId();
                                        rangeInfo.to.ledgerId = range.getUpperEndpoint().getLedgerId();
                                        rangeInfo.to.entryId = range.getUpperEndpoint().getEntryId();
                                        cursorInfo.individualDeletedMessages.add(rangeInfo);
                                    }
                                }
                                info.cursors.put(cursorName, cursorInfo);
                                cursorFuture.complete(null);
                            }

                            @Override
                            public void operationFailed(MetaStoreException e) {
                                cursorFuture.completeExceptionally(e);
                            }
                        });
                    }
                    Futures.waitForAll(cursorsFutures).thenRun(() -> {
                        // Completed all the cursors info
                        callback.getInfoComplete(info, ctx);
                    }).exceptionally((ex) -> {
                        callback.getInfoFailed(getManagedLedgerException(ex.getCause()), ctx);
                        return null;
                    });
                }

                @Override
                public void operationFailed(MetaStoreException e) {
                    callback.getInfoFailed(e, ctx);
                }
            });
        }

        @Override
        public void operationFailed(MetaStoreException e) {
            callback.getInfoFailed(e, ctx);
        }
    });
}
Also used : ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) CursorInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.CursorInfo) ArrayList(java.util.ArrayList) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) LedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.LedgerInfo) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) CompletableFuture(java.util.concurrent.CompletableFuture) Stat(org.apache.bookkeeper.mledger.impl.MetaStore.Stat) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) MessageRange(org.apache.bookkeeper.mledger.proto.MLDataFormats.MessageRange) MLDataFormats(org.apache.bookkeeper.mledger.proto.MLDataFormats) LongProperty(org.apache.bookkeeper.mledger.proto.MLDataFormats.LongProperty) PositionInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.PositionInfo) List(java.util.List) ArrayList(java.util.ArrayList) MessageRangeInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.MessageRangeInfo)

Aggregations

ManagedLedgerInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo)4 ManagedLedgerInfoCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback)2 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)2 CursorInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo.CursorInfo)2 MessageRangeInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo.MessageRangeInfo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 StreamingOutput (javax.ws.rs.core.StreamingOutput)1 ManagedCursor (org.apache.bookkeeper.mledger.ManagedCursor)1 ManagedLedgerConfig (org.apache.bookkeeper.mledger.ManagedLedgerConfig)1 MetaStoreException (org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException)1 ManagedLedgerException.getManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException)1 LedgerInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo.LedgerInfo)1 PositionInfo (org.apache.bookkeeper.mledger.ManagedLedgerInfo.PositionInfo)1 MetaStoreCallback (org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback)1 Stat (org.apache.bookkeeper.mledger.impl.MetaStore.Stat)1 MLDataFormats (org.apache.bookkeeper.mledger.proto.MLDataFormats)1 LongProperty (org.apache.bookkeeper.mledger.proto.MLDataFormats.LongProperty)1