Search in sources :

Example 11 with HttpEndpointService

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

the class TestHttpService method testLostBookieRecoveryDelayService.

@Test
public void testLostBookieRecoveryDelayService() throws Exception {
    baseConf.setZkServers(zkUtil.getZooKeeperConnectString());
    HttpEndpointService lostBookieRecoveryDelayService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.LOST_BOOKIE_RECOVERY_DELAY);
    // 1,  PUT with null, should return error, because should contains {"delay_seconds": <delay_seconds>}.
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse response1 = lostBookieRecoveryDelayService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  GET, should meet exception when get delay seconds
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response2 = lostBookieRecoveryDelayService.handle(request2);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response2.getStatusCode());
    // 3, PUT, with body, should success
    String putBody3 = "{\"delay_seconds\": 17 }";
    HttpServiceRequest request3 = new HttpServiceRequest(putBody3, HttpServer.Method.PUT, null);
    HttpServiceResponse response3 = lostBookieRecoveryDelayService.handle(request3);
    assertEquals(HttpServer.StatusCode.OK.getValue(), response3.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 12 with HttpEndpointService

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

the class TestHttpService method testConfigServicePut.

@Test
public void testConfigServicePut() throws Exception {
    // test config service
    HttpEndpointService configService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.SERVER_CONFIG);
    // properties to be set
    String putBody = "{\"TEST_PROPERTY1\": \"TEST_VALUE1\", \"TEST_PROPERTY2\": 2,  \"TEST_PROPERTY3\": true }";
    // null body, should return NOT_FOUND
    HttpServiceRequest putRequest1 = new HttpServiceRequest(null, HttpServer.Method.PUT, null);
    HttpServiceResponse putResponse1 = configService.handle(putRequest1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), putResponse1.getStatusCode());
    // Method DELETE, should return NOT_FOUND
    HttpServiceRequest putRequest2 = new HttpServiceRequest(putBody, HttpServer.Method.DELETE, null);
    HttpServiceResponse putResponse2 = configService.handle(putRequest2);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), putResponse2.getStatusCode());
    // Normal PUT, should success, then verify using get method
    HttpServiceRequest putRequest3 = new HttpServiceRequest(putBody, HttpServer.Method.PUT, null);
    HttpServiceResponse putResponse3 = configService.handle(putRequest3);
    assertEquals(HttpServer.StatusCode.OK.getValue(), putResponse3.getStatusCode());
    // Get all the config
    HttpServiceRequest getRequest = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response = configService.handle(getRequest);
    Map configMap = JsonUtil.fromJson(response.getBody(), Map.class);
    // verify response code
    assertEquals(HttpServer.StatusCode.OK.getValue(), response.getStatusCode());
    // verify response body
    assertEquals("TEST_VALUE1", configMap.get("TEST_PROPERTY1"));
    assertEquals("2", configMap.get("TEST_PROPERTY2"));
    assertEquals("true", configMap.get("TEST_PROPERTY3"));
}
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) Test(org.junit.Test)

Example 13 with HttpEndpointService

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

the class TestHttpService method testGetLedgerMetaService.

@Test
public void testGetLedgerMetaService() 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, "password".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 getLedgerMetaService = bkHttpServiceProvider.provideHttpEndpointService(HttpServer.ApiType.GET_LEDGER_META);
    // 1,  null parameters of GET, should return NOT_FOUND
    HttpServiceRequest request1 = new HttpServiceRequest(null, HttpServer.Method.GET, null);
    HttpServiceResponse response1 = getLedgerMetaService.handle(request1);
    assertEquals(HttpServer.StatusCode.NOT_FOUND.getValue(), response1.getStatusCode());
    // 2,  parameters for GET first ledger, should return OK, and contains metadata
    HashMap<String, String> params = Maps.newHashMap();
    Long ledgerId = Long.valueOf(lh[0].getId());
    params.put("ledger_id", ledgerId.toString());
    HttpServiceRequest request2 = new HttpServiceRequest(null, HttpServer.Method.GET, params);
    HttpServiceResponse response2 = getLedgerMetaService.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());
    // verify LedgerMetadata content is equal
    assertTrue(respBody.get(ledgerId.toString()).toString().equals(new String(lh[0].getLedgerMetadata().serialize())));
}
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 14 with HttpEndpointService

use of org.apache.bookkeeper.http.service.HttpEndpointService 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 15 with HttpEndpointService

use of org.apache.bookkeeper.http.service.HttpEndpointService 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)

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