Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bookkeeper-admin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<artifactId>bookkeeper-admin-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.List;

public class JacksonService {
Expand All @@ -21,14 +23,18 @@ public static String toJson(Object o) throws JsonProcessingException {
return MAPPER.writeValueAsString(o);
}

public static <T> T toObject(String json, Class<T> type) throws JsonProcessingException {
public static <T> T toObject(byte[] json, Class<T> type) throws IOException {
return MAPPER.readValue(json, type);
}

public static <T> T toRefer(String json, TypeReference<T> ref) throws JsonProcessingException {
public static <T> T toRefer(byte[] json, TypeReference<T> ref) throws IOException {
return MAPPER.readValue(json, ref);
}

public static byte[] toBytes(@Nullable Object o) throws JsonProcessingException {
return o == null ? null : MAPPER.writeValueAsBytes(o);
}

public static <T> List<T> toList(String json, TypeReference<List<T>> typeRef) throws JsonProcessingException {
return MAPPER.readValue(json, typeRef);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.github.protocol.bookkeeper.admin.jdk;

import com.fasterxml.jackson.core.type.TypeReference;
import io.github.openfacade.http.HttpResponse;
import io.github.protocol.bookkeeper.admin.common.JacksonService;

import java.io.IOException;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class AutoRecoveryImpl implements AutoRecovery {
private final InnerHttpClient innerHttpClient;
Expand All @@ -18,7 +19,7 @@
@Override
public AutoRecoveryStatus autoRecoveryStatus() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.AUTO_RECOVERY_STATUS);
HttpResponse resp = innerHttpClient.get(UrlConst.AUTO_RECOVERY_STATUS);
return JacksonService.toRefer(resp.body(), new TypeReference<AutoRecoveryStatus>() {
});
} catch (Exception e) {
Expand All @@ -30,7 +31,7 @@
public void recoveryBookie(RecoveryBookieReqData reqData) throws BookkeeperAdminException {
try {
innerHttpClient.put(UrlConst.AUTO_RECOVERY, reqData);
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 34 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L34

Added line #L34 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -51,9 +52,9 @@
if (reqData.getIncludingBookieId() != null && !"".equals(reqData.getIncludingBookieId())) {
url = url + "&missingreplica=" + reqData.getIncludingBookieId();
}
HttpResponse<String> resp = innerHttpClient.get(url);
HttpResponse resp = innerHttpClient.get(url);
if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());
}
return JacksonService.toRefer(resp.body(), new TypeReference<UnderReplicatedLedger>() {
});
Expand All @@ -65,10 +66,10 @@
@Override
public Auditor whoIsAuditor() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.AUTO_RECOVERY_WHO_IS_AUDITOR);
HttpResponse resp = innerHttpClient.get(UrlConst.AUTO_RECOVERY_WHO_IS_AUDITOR);

if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());
}
return JacksonService.toRefer(resp.body(), new TypeReference<Auditor>() {
});
Expand All @@ -80,23 +81,23 @@
@Override
public void triggerAudit() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_TRIGGER_AUDIT);
HttpResponse resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_TRIGGER_AUDIT);
if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 88 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L88

Added line #L88 was not covered by tests
throw new BookkeeperAdminException(e);
}
}

@Override
public void lostBookieRecoveryDelay() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_LOST_BOOKIE_RECOVERY_DELAY);
HttpResponse resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_LOST_BOOKIE_RECOVERY_DELAY);
if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 100 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L100

Added line #L100 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -106,11 +107,11 @@
Map<String, Integer> reqDate = new HashMap<>();
reqDate.put("delay_seconds", delaySeconds);
try {
HttpResponse<String> resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_LOST_BOOKIE_RECOVERY_DELAY, reqDate);
HttpResponse resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_LOST_BOOKIE_RECOVERY_DELAY, reqDate);
if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());

Check warning on line 112 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L112

Added line #L112 was not covered by tests
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 114 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L114

Added line #L114 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -123,11 +124,11 @@
Map<String, String> reqDate = new HashMap<>();
reqDate.put("bookie_src", bookieId);
try {
HttpResponse<String> resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_DECOMMISSION, reqDate);
HttpResponse resp = innerHttpClient.put(UrlConst.AUTO_RECOVERY_DECOMMISSION, reqDate);
if ((resp.statusCode() < 200 || resp.statusCode() >= 300) && resp.body() != null) {
throw new BookkeeperAdminException(resp.body());
throw new BookkeeperAdminException(resp.bodyAsString());

Check warning on line 129 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L129

Added line #L129 was not covered by tests
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 131 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/AutoRecoveryImpl.java#L131

Added line #L131 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.github.protocol.bookkeeper.admin.jdk;

import com.fasterxml.jackson.core.type.TypeReference;
import io.github.openfacade.http.HttpResponse;
import io.github.protocol.bookkeeper.admin.common.JacksonService;

import java.io.IOException;
import java.net.http.HttpResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

public class BookiesImpl implements Bookies {
Expand All @@ -21,7 +22,7 @@
@Override
public Map<String, String> bookieList() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_LIST);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_LIST);
return JacksonService.toRefer(resp.body(), new TypeReference<Map<String, String>>() {
});
} catch (Exception e) {
Expand All @@ -32,7 +33,7 @@
@Override
public Map<String, String> listBookieInfo() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_LIST_INFO);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_LIST_INFO);
return JacksonService.toRefer(resp.body(), new TypeReference<Map<String, String>>() {
});
} catch (Exception e) {
Expand All @@ -45,7 +46,7 @@
public LastLogMark lastLogMark() throws BookkeeperAdminException {
Map<String, String> map;
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_LAST_LOG_MARK);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_LAST_LOG_MARK);
map = JacksonService.toRefer(resp.body(), new TypeReference<Map<String, String>>() {
});
} catch (Exception e) {
Expand All @@ -65,7 +66,7 @@
public DiskFile listDiskFile() throws BookkeeperAdminException {
Map<String, String> map;
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_LIST_DISK_FILE);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_LIST_DISK_FILE);
map = JacksonService.toRefer(resp.body(), new TypeReference<Map<String, String>>() {
});
} catch (Exception e) {
Expand All @@ -83,7 +84,7 @@
public void expandStorage() throws BookkeeperAdminException {
try {
innerHttpClient.put(UrlConst.BOOKIE_EXPAND_STORAGE);
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 87 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L87

Added line #L87 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -95,7 +96,7 @@
requestBody.put("forceMinor", forceMinor);
try {
innerHttpClient.put(UrlConst.BOOKIE_GC, JacksonService.toJson(requestBody));
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 99 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L99

Added line #L99 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -104,7 +105,7 @@
public boolean isInForceGc() throws BookkeeperAdminException {
Map<String, String> map;
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_GC);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_GC);
map = JacksonService.toRefer(resp.body(), new TypeReference<Map<String, String>>() {
});
} catch (Exception e) {
Expand All @@ -120,15 +121,15 @@
requestBody.put("suspendMinor", minor);
try {
innerHttpClient.put(UrlConst.BOOKIE_GC_SUSPEND_COMPACTION, JacksonService.toJson(requestBody));
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 124 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L124

Added line #L124 was not covered by tests
throw new BookkeeperAdminException(e);
}
}

@Override
public GcSuspendStatus gcSuspendStatus() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_GC_SUSPEND_COMPACTION);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_GC_SUSPEND_COMPACTION);

Check warning on line 132 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L132

Added line #L132 was not covered by tests
Map<String, Boolean> map = JacksonService.toRefer(resp.body(), new TypeReference<Map<String, Boolean>>() {
});
boolean isMajorGcSuspended = map.get("isMajorGcSuspended");
Expand All @@ -146,7 +147,7 @@
requestBody.put("resumeMinor", minor);
try {
innerHttpClient.put(UrlConst.BOOKIE_GC_RESUME_COMPACTION, JacksonService.toJson(requestBody));
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 150 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L150

Added line #L150 was not covered by tests
throw new BookkeeperAdminException(e);
}
}
Expand All @@ -155,7 +156,7 @@
public List<GarbageCollectionStatus> gcStatusList() throws BookkeeperAdminException {
List<Map<String, Object>> list;
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_GC_DETAILS);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_GC_DETAILS);
list = JacksonService.toRefer(resp.body(), new TypeReference<List<Map<String, Object>>>() {
});
} catch (Exception e) {
Expand All @@ -177,7 +178,7 @@
@Override
public BookieStatus status() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_STATE);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_STATE);
return JacksonService.toObject(resp.body(), BookieStatus.class);
} catch (Exception e) {
throw new BookkeeperAdminException(e);
Expand All @@ -190,15 +191,15 @@
requestBody.put("readOnly", readOnly);
try {
innerHttpClient.put(UrlConst.BOOKIE_STATE_READ_ONLY, JacksonService.toJson(requestBody));
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 194 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/BookiesImpl.java#L194

Added line #L194 was not covered by tests
throw new BookkeeperAdminException(e);
}
}

@Override
public boolean isReadOnly() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_STATE_READ_ONLY);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_STATE_READ_ONLY);
Map<String, Boolean> map = JacksonService.toRefer(resp.body(), new TypeReference<Map<String, Boolean>>() {
});
return map.get("readOnly");
Expand All @@ -210,8 +211,8 @@
@Override
public boolean isReady() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_READY);
return "OK".equals(resp.body());
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_READY);
return "OK".equals(resp.bodyAsString());
} catch (Exception e) {
throw new BookkeeperAdminException(e);
}
Expand All @@ -220,7 +221,7 @@
@Override
public BookieInfo bookieInfo() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.BOOKIE_INFO);
HttpResponse resp = innerHttpClient.get(UrlConst.BOOKIE_INFO);
return JacksonService.toObject(resp.body(), BookieInfo.class);
} catch (Exception e) {
throw new BookkeeperAdminException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.github.protocol.bookkeeper.admin.jdk;


import io.github.openfacade.http.HttpResponse;
import io.github.protocol.bookkeeper.admin.common.JacksonService;

import java.io.IOException;
import java.net.http.HttpResponse;
import java.util.Map;
import java.util.concurrent.ExecutionException;

public class ConfigsImpl implements Configs {

Expand All @@ -18,17 +19,17 @@
@Override
public void putConfig(Map<String, String> config) throws BookkeeperAdminException {
try {
innerHttpClient.put(UrlConst.CONFIG_SERVER_CONFIG, JacksonService.toJson(config));
} catch (IOException | InterruptedException e) {
innerHttpClient.put(UrlConst.CONFIG_SERVER_CONFIG, config);
} catch (IOException | InterruptedException | ExecutionException e) {

Check warning on line 23 in bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/ConfigsImpl.java

View check run for this annotation

Codecov / codecov/patch

bookkeeper-admin/src/main/java/io/github/protocol/bookkeeper/admin/jdk/ConfigsImpl.java#L23

Added line #L23 was not covered by tests
throw new BookkeeperAdminException(e);
}
}

@Override
public Map<String, String> getConfig() throws BookkeeperAdminException {
try {
HttpResponse<String> resp = innerHttpClient.get(UrlConst.CONFIG_SERVER_CONFIG);
return JacksonService.toObject(resp.body(), Map.class);
HttpResponse response = innerHttpClient.get(UrlConst.CONFIG_SERVER_CONFIG);
return JacksonService.toObject(response.body(), Map.class);
} catch (Exception e) {
throw new BookkeeperAdminException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.protocol.bookkeeper.admin.jdk;

import java.net.http.HttpResponse;
import io.github.openfacade.http.HttpResponse;

public class HeartbeatImpl implements Heartbeat {
private final InnerHttpClient innerHttpClient;
Expand All @@ -13,7 +13,7 @@ public HeartbeatImpl(InnerHttpClient innerHttpClient) {
public void heartbeat() throws BookkeeperAdminException {
String url = UrlConst.HEARTBEAT_URL;
try {
HttpResponse<String> httpResponse = innerHttpClient.get(url);
HttpResponse httpResponse = innerHttpClient.get(url);
if (httpResponse.statusCode() != 200) {
throw new BookkeeperAdminException("healthcheck failed, status code: " + httpResponse.statusCode(),
httpResponse.statusCode());
Expand Down
Loading
Loading