use of org.apache.bookkeeper.stream.proto.storage.StatusCode in project bookkeeper by apache.
the class RootRangeStoreImpl method verifyStreamRequest.
StatusCode verifyStreamRequest(String nsName, String streamName) {
StatusCode code = StatusCode.SUCCESS;
if (!validateNamespaceName(nsName)) {
log.error("Invalid namespace name {}", nsName);
code = StatusCode.INVALID_NAMESPACE_NAME;
} else if (!validateStreamName(streamName)) {
log.error("Invalid stream name {}", streamName);
code = StatusCode.INVALID_STREAM_NAME;
}
return code;
}
use of org.apache.bookkeeper.stream.proto.storage.StatusCode in project bookkeeper by apache.
the class RootRangeStoreImpl method getStream.
@Override
public CompletableFuture<GetStreamResponse> getStream(GetStreamRequest request) {
StreamName streamName = request.getStreamName();
StatusCode code = verifyStreamRequest(streamName.getColName(), streamName.getStreamName());
if (StatusCode.SUCCESS != code) {
return FutureUtils.value(GetStreamResponse.newBuilder().setCode(code).build());
}
byte[] nsNameKey = getNamespaceNameKey(streamName.getColName());
GetStreamResponse.Builder respBuilder = GetStreamResponse.newBuilder();
return store.get(nsNameKey).thenCompose(nsIdBytes -> {
if (null == nsIdBytes) {
return FutureUtils.value(respBuilder.setCode(StatusCode.NAMESPACE_NOT_FOUND).build());
}
long nsId = Bytes.toLong(nsIdBytes, 0);
return getStreamProps(nsId, streamName.getStreamName()).thenCompose(streamProps -> {
if (null == streamProps) {
return FutureUtils.value(respBuilder.setCode(StatusCode.STREAM_NOT_FOUND).build());
} else {
return FutureUtils.value(respBuilder.setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build());
}
}).exceptionally(cause -> respBuilder.setCode(StatusCode.INTERNAL_SERVER_ERROR).build());
});
}
use of org.apache.bookkeeper.stream.proto.storage.StatusCode in project bookkeeper by apache.
the class RootRangeStoreImpl method createStream.
//
// Stream API
//
@Override
public CompletableFuture<CreateStreamResponse> createStream(CreateStreamRequest request) {
String streamName = request.getName();
String nsName = request.getColName();
StatusCode code = verifyStreamRequest(nsName, streamName);
if (StatusCode.SUCCESS != code) {
return FutureUtils.value(CreateStreamResponse.newBuilder().setCode(code).build());
}
return createStream(nsName, streamName, request.getStreamConf());
}
use of org.apache.bookkeeper.stream.proto.storage.StatusCode in project bookkeeper by apache.
the class RootRangeClientImpl method processDeleteNamespaceResponse.
private void processDeleteNamespaceResponse(String namespace, DeleteNamespaceResponse response, CompletableFuture<Boolean> deleteFuture) {
StatusCode code = response.getCode();
if (StatusCode.SUCCESS == code) {
deleteFuture.complete(true);
return;
}
deleteFuture.completeExceptionally(createRootRangeException(namespace, code));
}
use of org.apache.bookkeeper.stream.proto.storage.StatusCode in project bookkeeper by apache.
the class RootRangeClientImpl method processGetStreamResponse.
private void processGetStreamResponse(String streamName, GetStreamResponse response, CompletableFuture<StreamProperties> getStreamFuture) {
StatusCode code = response.getCode();
if (StatusCode.SUCCESS == code) {
getStreamFuture.complete(response.getStreamProps());
return;
}
getStreamFuture.completeExceptionally(createRootRangeException(streamName, code));
}
Aggregations