Search in sources :

Example 6 with StatusCode

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;
}
Also used : StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Example 7 with StatusCode

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());
    });
}
Also used : ProtoUtils.validateStreamName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateStreamName) GetStreamRequest(org.apache.bookkeeper.stream.proto.storage.GetStreamRequest) Options(org.apache.bookkeeper.api.kv.options.Options) DeleteNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceRequest) CompletableFuture(java.util.concurrent.CompletableFuture) CreateStreamRequest(org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) DeleteStreamRequest(org.apache.bookkeeper.stream.proto.storage.DeleteStreamRequest) UTF_8(com.google.common.base.Charsets.UTF_8) MIN_DATA_STREAM_ID(org.apache.bookkeeper.stream.protocol.ProtocolConstants.MIN_DATA_STREAM_ID) StreamName(org.apache.bookkeeper.stream.proto.StreamName) CreateStreamResponse(org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse) DeleteStreamResponse(org.apache.bookkeeper.stream.proto.storage.DeleteStreamResponse) MVCCAsyncStore(org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore) TxnOp(org.apache.bookkeeper.api.kv.op.TxnOp) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) NamespaceMetadata(org.apache.bookkeeper.stream.proto.NamespaceMetadata) DeleteNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.DeleteNamespaceResponse) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) KeyValue(org.apache.bookkeeper.api.kv.result.KeyValue) URI(java.net.URI) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) StorageContainerPlacementPolicy(org.apache.bookkeeper.stream.protocol.util.StorageContainerPlacementPolicy) CreateNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceResponse) RangeOp(org.apache.bookkeeper.api.kv.op.RangeOp) RootRangeStore(org.apache.bookkeeper.stream.storage.api.metadata.RootRangeStore) StreamConfiguration(org.apache.bookkeeper.stream.proto.StreamConfiguration) Bytes(org.apache.bookkeeper.common.util.Bytes) FutureUtils(org.apache.bookkeeper.common.concurrent.FutureUtils) Slf4j(lombok.extern.slf4j.Slf4j) CreateNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.CreateNamespaceRequest) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) CompareResult(org.apache.bookkeeper.api.kv.op.CompareResult) ProtoUtils.validateNamespaceName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateNamespaceName) GetNamespaceRequest(org.apache.bookkeeper.stream.proto.storage.GetNamespaceRequest) GetNamespaceResponse(org.apache.bookkeeper.stream.proto.storage.GetNamespaceResponse) ProtoUtils.validateStreamName(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.validateStreamName) StreamName(org.apache.bookkeeper.stream.proto.StreamName) GetStreamResponse(org.apache.bookkeeper.stream.proto.storage.GetStreamResponse) StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Example 8 with StatusCode

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());
}
Also used : StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Example 9 with StatusCode

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));
}
Also used : StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Example 10 with StatusCode

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));
}
Also used : StatusCode(org.apache.bookkeeper.stream.proto.storage.StatusCode)

Aggregations

StatusCode (org.apache.bookkeeper.stream.proto.storage.StatusCode)13 UTF_8 (com.google.common.base.Charsets.UTF_8)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 URI (java.net.URI)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)1 RangeOp (org.apache.bookkeeper.api.kv.op.RangeOp)1 TxnOp (org.apache.bookkeeper.api.kv.op.TxnOp)1 Options (org.apache.bookkeeper.api.kv.options.Options)1 Code (org.apache.bookkeeper.api.kv.result.Code)1 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)1 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)1 Bytes (org.apache.bookkeeper.common.util.Bytes)1 MVCCStoreException (org.apache.bookkeeper.statelib.api.exceptions.MVCCStoreException)1 MVCCAsyncStore (org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore)1 NamespaceMetadata (org.apache.bookkeeper.stream.proto.NamespaceMetadata)1 NamespaceProperties (org.apache.bookkeeper.stream.proto.NamespaceProperties)1 StreamConfiguration (org.apache.bookkeeper.stream.proto.StreamConfiguration)1