Search in sources :

Example 31 with HttpServiceResponse

use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.

the class TestHttpService method testListBookieInfoService.

@Test
public void testListBookieInfoService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    HttpEndpointService listBookieInfoService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_BOOKIE_INFO);
    // 1,  PUT method, should return NOT_FOUND
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = listBookieInfoService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2, GET method, expected get 6 bookies info and the cluster total info
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = listBookieInfoService.handle(request2);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
    @SuppressWarnings("unchecked") LinkedHashMap<String, String> respBody = JsonUtil.fromJson(response2.getBody(), LinkedHashMap.class);
    assertEquals(numberOfBookies + 1, respBody.size());
    for (int i = 0; i < numberOfBookies; i++) {
        assertEquals(true, respBody.containsKey(getBookie(i).toString()));
    }
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Example 32 with HttpServiceResponse

use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.

the class TestHttpService method testListUnderReplicatedLedgerService.

private void testListUnderReplicatedLedgerService(LedgerManagerFactory mFactory) throws Exception {
    startAuditorElector();
    HttpEndpointService listUnderReplicatedLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_UNDER_REPLICATED_LEDGER);
    // 1,  PUT, should return error, because only support GET.
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = listUnderReplicatedLedgerService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  GET, should return success.
    // first put ledger into rereplicate. then use api to list ur ledger.
    @Cleanup LedgerManager ledgerManager = mFactory.newLedgerManager();
    @Cleanup final LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
    LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32, "passwd".getBytes());
    LedgerMetadata md = LedgerHandleAdapter.getLedgerMetadata(lh);
    List<BookieSocketAddress> ensemble = md.getEnsembles().get(0L);
    ensemble.set(0, new BookieSocketAddress("1.1.1.1", 1000));
    TestCallbacks.GenericCallbackFuture<Void> cb = new TestCallbacks.GenericCallbackFuture<Void>();
    ledgerManager.writeLedgerMetadata(lh.getId(), md, cb);
    cb.get();
    long underReplicatedLedger = -1;
    for (int i = 0; i < 10; i++) {
        underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
        if (underReplicatedLedger != -1) {
            break;
        }
        Thread.sleep(1000);
    }
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = listUnderReplicatedLedgerService.handle(request2);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
    stopAuditorElector();
}
Also used : LedgerManager(org.apache.bookkeeper.meta.LedgerManager) LedgerUnderreplicationManager(org.apache.bookkeeper.meta.LedgerUnderreplicationManager) HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) Cleanup(lombok.Cleanup) TestCallbacks(org.apache.bookkeeper.test.TestCallbacks) LedgerMetadata(org.apache.bookkeeper.client.LedgerMetadata) BookieSocketAddress(org.apache.bookkeeper.net.BookieSocketAddress) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse)

Example 33 with HttpServiceResponse

use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.

the class TestHttpService method testGetLastLogMarkService.

@Test
public void testGetLastLogMarkService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    BookKeeper.DigestType digestType = BookKeeper.DigestType.CRC32;
    int numLedgers = 4;
    int numMsgs = 100;
    LedgerHandle[] lh = new LedgerHandle[numLedgers];
    // create ledgers
    for (int i = 0; i < numLedgers; i++) {
        lh[i] = bkc.createLedger(digestType, "".getBytes());
    }
    String content = "Apache BookKeeper is cool!";
    // add entries
    for (int i = 0; i < numMsgs; i++) {
        for (int j = 0; j < numLedgers; j++) {
            lh[j].addEntry(content.getBytes());
        }
    }
    // close ledgers
    for (int i = 0; i < numLedgers; i++) {
        lh[i].close();
    }
    HttpEndpointService getLastLogMarkService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LAST_LOG_MARK);
    // 1,  null parameters of PUT, should fail
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = getLastLogMarkService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  null parameters of GET, should return 1 file
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = getLastLogMarkService.handle(request2);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
    @SuppressWarnings("unchecked") HashMap<String, String> respBody = JsonUtil.fromJson(response2.getBody(), HashMap.class);
    assertEquals(1, respBody.size());
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) LedgerHandle(org.apache.bookkeeper.client.LedgerHandle) BookKeeper(org.apache.bookkeeper.client.BookKeeper) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Example 34 with HttpServiceResponse

use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.

the class TestHttpService method testConfigServiceGet.

@Test
public void testConfigServiceGet() throws Exception {
    try {
        // test config service
        String testProperty = "TEST_PROPERTY";
        String testValue = "TEST_VALUE";
        baseConf.setProperty(testProperty, testValue);
        HttpEndpointService configService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.SERVER_CONFIG);
        HttpServiceRequest getRequest = new HttpServiceRequest(null, HttpServer.Method.GET, null);
        HttpServiceResponse response = configService.handle(getRequest);
        Map configMap = JsonUtil.fromJson(response.getBody(), Map.class);
        assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode());
        assertEquals(testValue, configMap.get(testProperty));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Test(org.junit.Test)

Example 35 with HttpServiceResponse

use of org.apache.bookkeeper.http.service.HttpServiceResponse in project bookkeeper by apache.

the class TestHttpService method testDecommissionService.

@Test
public void testDecommissionService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    startAuditorElector();
    HttpEndpointService decommissionService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.DECOMMISSION);
    // 1,  PUT with null, should return error, because should contains {"bookie_src": <bookie_address>}.
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = decommissionService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  GET, should fail for not support get
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = decommissionService.handle(request2);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode());
    // 3, PUT, with body, should success.
    String putBody3 = "{\"bookie_src\": \"" + getBookie(1).toString() + "\"}";
    HttpServiceRequest request3 = new HttpServiceRequest(putBody3, HttpServer.Method.PUT, null);
    // after bookie kill, request should success
    killBookie(1);
    HttpServiceResponse response3 = decommissionService.handle(request3);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
    stopAuditorElector();
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceRequest(org.apache.bookkeeper.http.service.HttpServiceRequest) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Aggregations

HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)35 HttpServiceRequest (org.apache.bookkeeper.http.service.HttpServiceRequest)19 HttpEndpointService (org.apache.bookkeeper.http.service.HttpEndpointService)18 Test (org.junit.Test)16 BookKeeper (org.apache.bookkeeper.client.BookKeeper)8 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)7 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)6 Map (java.util.Map)4 File (java.io.File)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)3 LedgerManagerFactory (org.apache.bookkeeper.meta.LedgerManagerFactory)3 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)2 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)2 ErrorHttpService (org.apache.bookkeeper.http.service.ErrorHttpService)2 LedgerUnderreplicationManager (org.apache.bookkeeper.meta.LedgerUnderreplicationManager)2 JsonUtil (org.apache.bookkeeper.util.JsonUtil)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Lists (com.google.common.collect.Lists)1