Search in sources :

Example 6 with HttpEndpointService

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

the class TestHttpService method testHeartbeatService.

@Test
public void testHeartbeatService() throws Exception {
    // test heartbeat service
    HttpEndpointService heartbeatService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.HEARTBEAT);
    HttpServiceResponse response = heartbeatService.handle(null);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode());
    assertEquals("OK\n", response.getBody());
}
Also used : HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService) HttpServiceResponse(org.apache.bookkeeper.http.service.HttpServiceResponse) Test(org.junit.Test)

Example 7 with HttpEndpointService

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

the class VertxHttpHandlerFactory method newHandler.

@Override
public VertxAbstractHandler newHandler(HttpServer.ApiType type) {
    return new VertxAbstractHandler() {

        @Override
        public void handle(RoutingContext context) {
            HttpEndpointService service = getHttpServiceProvider().provideHttpEndpointService(type);
            processRequest(service, context);
        }
    };
}
Also used : RoutingContext(io.vertx.ext.web.RoutingContext) HttpEndpointService(org.apache.bookkeeper.http.service.HttpEndpointService)

Example 8 with HttpEndpointService

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

the class TestHttpService method testWhoIsAuditorService.

@Test
public void testWhoIsAuditorService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    startAuditorElector();
    HttpEndpointService whoIsAuditorService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.WHO_IS_AUDITOR);
    // 1,  GET, should return success
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response1 = whoIsAuditorService.handle(request1);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response1.getStatusCode());
    LOG.info(response1.getBody());
    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)

Example 9 with HttpEndpointService

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

the class TestHttpService method testRecoveryBookieService.

@Test
public void testRecoveryBookieService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    HttpEndpointService recoveryBookieService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.RECOVERY_BOOKIE);
    // 1,  null body of GET, should return error
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response1 = recoveryBookieService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  null body of PUT, should return error
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response2 = recoveryBookieService.handle(request2);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode());
    // 3, body with bookie_src, bookie_dest and delete_cookie of PUT, should success.
    String bookieSrc = getBookie(0).toString();
    String putBody3 = "{\"bookie_src\": [ \"" + bookieSrc + "\" ]," + "\"delete_cookie\": false }";
    HttpServiceRequest request3 = new HttpServiceRequest(putBody3, HttpServer.Method.PUT, null);
    HttpServiceResponse response3 = recoveryBookieService.handle(request3);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
    // 5, body with bookie_src of PUT, should success.
    String putBody5 = "{\"bookie_src\": [ \"" + bookieSrc + "\" ] }";
    HttpServiceRequest request5 = new HttpServiceRequest(putBody5, HttpServer.Method.PUT, null);
    HttpServiceResponse response5 = recoveryBookieService.handle(request5);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response5.getStatusCode());
}
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 10 with HttpEndpointService

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

the class TestHttpService method testListLedgerService.

/**
 * Create ledgers, then test ListLedgerService.
 */
@Test
public void testListLedgerService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    BookKeeper.DigestType digestType = BookKeeper.DigestType.CRC32;
    int numLedgers = 430;
    LedgerHandle[] lh = new LedgerHandle[numLedgers];
    // create ledgers
    for (int i = 0; i < numLedgers; i++) {
        lh[i] = bkc.createLedger(digestType, "password".getBytes());
    }
    HttpEndpointService listLedgerService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LIST_LEDGER);
    // 1,  null parameters, should print ledger ids, without metadata
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response1 = listLedgerService.handle(request1);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response1.getStatusCode());
    // get response , expected get all ledgers, and without metadata
    @SuppressWarnings("unchecked") LinkedHashMap<String, String> respBody = JsonUtil.fromJson(response1.getBody(), LinkedHashMap.class);
    assertEquals(numLedgers, respBody.size());
    for (int i = 0; i < numLedgers; i++) {
        assertEquals(true, respBody.containsKey(Long.valueOf(lh[i].getId()).toString()));
        assertEquals(null, respBody.get(Long.valueOf(lh[i].getId()).toString()));
    }
    // 2, parameter: print_metadata=true, should print ledger ids, with metadata
    HashMap<String, String> params = Maps.newHashMap();
    params.put("print_metadata", "true");
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, params);
    HttpServiceResponse response2 = listLedgerService.handle(request2);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response2.getStatusCode());
    // get response, expected get all ledgers, and with metadata
    @SuppressWarnings("unchecked") LinkedHashMap<String, String> respBody2 = JsonUtil.fromJson(response2.getBody(), LinkedHashMap.class);
    assertEquals(numLedgers, respBody2.size());
    for (int i = 0; i < numLedgers; i++) {
        assertEquals(true, respBody2.containsKey(Long.valueOf(lh[i].getId()).toString()));
        assertNotNull(respBody2.get(Long.valueOf(lh[i].getId()).toString()));
    }
    // 3, parameter: print_metadata=true&page=5,
    // since each page contains 100 ledgers, page=5 should print ledger ids, with metadata for(400--430)
    HashMap<String, String> params3 = Maps.newHashMap();
    params3.put("print_metadata", "true");
    params3.put("page", "5");
    HttpServiceRequest request3 = new HttpServiceRequest(null, HttpServer.Method.GET, params3);
    HttpServiceResponse response3 = listLedgerService.handle(request3);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response3.getStatusCode());
    // get response, expected get 4 ledgers, and with metadata
    @SuppressWarnings("unchecked") LinkedHashMap<String, String> respBody3 = JsonUtil.fromJson(response3.getBody(), LinkedHashMap.class);
    assertEquals(31, respBody3.size());
    for (int i = 400; i < 430; i++) {
        assertEquals(true, respBody3.containsKey(Long.valueOf(lh[i].getId()).toString()));
        assertNotNull(respBody3.get(Long.valueOf(lh[i].getId()).toString()));
    }
}
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)

Aggregations

HttpEndpointService (org.apache.bookkeeper.http.service.HttpEndpointService)18 HttpServiceResponse (org.apache.bookkeeper.http.service.HttpServiceResponse)17 HttpServiceRequest (org.apache.bookkeeper.http.service.HttpServiceRequest)16 Test (org.junit.Test)16 LedgerHandle (org.apache.bookkeeper.client.LedgerHandle)7 BookKeeper (org.apache.bookkeeper.client.BookKeeper)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 RoutingContext (io.vertx.ext.web.RoutingContext)1 Cleanup (lombok.Cleanup)1 LedgerMetadata (org.apache.bookkeeper.client.LedgerMetadata)1 LedgerManager (org.apache.bookkeeper.meta.LedgerManager)1 LedgerUnderreplicationManager (org.apache.bookkeeper.meta.LedgerUnderreplicationManager)1 BookieSocketAddress (org.apache.bookkeeper.net.BookieSocketAddress)1 TestCallbacks (org.apache.bookkeeper.test.TestCallbacks)1