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());
}
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"));
}
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())));
}
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()));
}
}
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();
}
Aggregations