Search in sources :

Example 11 with LedgerManagerFactory

use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.

the class GetLedgerMetaService method handle.

@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
    HttpServiceResponse response = new HttpServiceResponse();
    Map<String, String> params = request.getParams();
    if (HttpServer.Method.GET == request.getMethod() && (params != null) && params.containsKey("ledger_id")) {
        Long ledgerId = Long.parseLong(params.get("ledger_id"));
        LedgerManagerFactory mFactory = bookieServer.getBookie().getLedgerManagerFactory();
        LedgerManager manager = mFactory.newLedgerManager();
        // output <ledgerId: ledgerMetadata>
        Map<String, String> output = Maps.newHashMap();
        ListLedgerService.ReadLedgerMetadataCallback cb = new ListLedgerService.ReadLedgerMetadataCallback(ledgerId);
        manager.readLedgerMetadata(ledgerId, cb);
        LedgerMetadata md = cb.get();
        output.put(ledgerId.toString(), new String(md.serialize(), UTF_8));
        manager.close();
        String jsonResponse = JsonUtil.toJson(output);
        LOG.debug("output body:" + jsonResponse);
        response.setBody(jsonResponse);
        response.setCode(HttpServer.StatusCode.OK);
        return response;
    } else {
        response.setCode(HttpServer.StatusCode.NOT_FOUND);
        response.setBody("Not found method. Should be GET method");
        return response;
    }
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory)

Example 12 with LedgerManagerFactory

use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.

the class AuditorPeriodicCheckTest method testIndexCorruption.

/**
 * test that the period checker will detect corruptions in
 * the bookie index files.
 */
@Test
public void testIndexCorruption() throws Exception {
    LedgerManagerFactory mFactory = driver.getLedgerManagerFactory();
    LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
    LedgerHandle lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
    long ledgerToCorrupt = lh.getId();
    for (int i = 0; i < 100; i++) {
        lh.addEntry("testdata".getBytes());
    }
    lh.close();
    // push ledgerToCorrupt out of page cache (bookie is configured to only use 1 page)
    lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
    for (int i = 0; i < 100; i++) {
        lh.addEntry("testdata".getBytes());
    }
    lh.close();
    BookieAccessor.forceFlush(bs.get(0).getBookie());
    File ledgerDir = bsConfs.get(0).getLedgerDirs()[0];
    ledgerDir = Bookie.getCurrentDirectory(ledgerDir);
    // corrupt of entryLogs
    File index = new File(ledgerDir, IndexPersistenceMgr.getLedgerName(ledgerToCorrupt));
    LOG.info("file to corrupt{}", index);
    ByteBuffer junk = ByteBuffer.allocate(1024 * 1024);
    FileOutputStream out = new FileOutputStream(index);
    out.getChannel().write(junk);
    out.close();
    long underReplicatedLedger = -1;
    for (int i = 0; i < 10; i++) {
        underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
        if (underReplicatedLedger != -1) {
            break;
        }
        Thread.sleep(CHECK_INTERVAL * 1000);
    }
    assertEquals("Ledger should be under replicated", ledgerToCorrupt, underReplicatedLedger);
    underReplicationManager.close();
}
Also used : LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) Test(org.junit.Test)

Example 13 with LedgerManagerFactory

use of org.apache.bookkeeper.meta.LedgerManagerFactory in project bookkeeper by apache.

the class ZKMetadataDriverBaseTest method testGetLedgerManagerFactory.

@Test
public void testGetLedgerManagerFactory() throws Exception {
    driver.initialize(conf, NullStatsLogger.INSTANCE, retryPolicy, Optional.empty());
    mockStatic(AbstractZkLedgerManagerFactory.class);
    LedgerManagerFactory factory = mock(LedgerManagerFactory.class);
    PowerMockito.when(AbstractZkLedgerManagerFactory.class, "newLedgerManagerFactory", same(conf), same(driver.layoutManager)).thenReturn(factory);
    assertSame(factory, driver.getLedgerManagerFactory());
    assertSame(factory, driver.lmFactory);
    verifyStatic(AbstractZkLedgerManagerFactory.class, times(1));
    AbstractZkLedgerManagerFactory.newLedgerManagerFactory(same(conf), same(driver.layoutManager));
    driver.close();
    verify(factory, times(1)).close();
    assertNull(driver.lmFactory);
}
Also used : AbstractZkLedgerManagerFactory(org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory) LedgerManagerFactory(org.apache.bookkeeper.meta.LedgerManagerFactory) AbstractZkLedgerManagerFactory(org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

LedgerManagerFactory (org.apache.bookkeeper.meta.LedgerManagerFactory)13 Test (org.junit.Test)8 LedgerUnderreplicationManager (org.apache.bookkeeper.meta.LedgerUnderreplicationManager)7 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)6 AbstractZkLedgerManagerFactory (org.apache.bookkeeper.meta.AbstractZkLedgerManagerFactory)4 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)4 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Cleanup (lombok.Cleanup)2 ServerConfiguration (org.apache.bookkeeper.conf.ServerConfiguration)2 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)2 MetadataClientDriver (org.apache.bookkeeper.meta.MetadataClientDriver)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1 FilenameFilter (java.io.FilenameFilter)1