Search in sources :

Example 1 with StreamProperties

use of org.apache.bookkeeper.stream.proto.StreamProperties in project bookkeeper by apache.

the class TestStorageServerClientManagerImpl method testGetMetaRangeClient.

@Test
public void testGetMetaRangeClient() throws Exception {
    long streamId = 3456L;
    StreamProperties props = StreamProperties.newBuilder().setStorageContainerId(1234L).setStreamId(streamId).setStreamName("metaclient-stream").setStreamConf(StreamConfiguration.newBuilder().build()).build();
    MetaRangeClientImpl metaRangeClient = serverManager.openMetaRangeClient(props);
    assertEquals(1234L, metaRangeClient.getStorageContainerClient().getStorageContainerId());
    assertTrue(props == metaRangeClient.getStreamProps());
    // the stream properties will be cached here
    assertEquals(props, FutureUtils.result(serverManager.getStreamProperties(streamId)));
    // the metadata range client is cached as well
    assertEquals(metaRangeClient, FutureUtils.result(serverManager.openMetaRangeClient(streamId)));
}
Also used : StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) Test(org.junit.Test)

Example 2 with StreamProperties

use of org.apache.bookkeeper.stream.proto.StreamProperties in project bookkeeper by apache.

the class CreateStreamCommand method run.

@Override
protected void run(String defaultNamespace, StorageAdminClient admin) throws Exception {
    checkNotNull(streamName, "Stream name is not provided");
    System.out.println("Creating stream '" + streamName + "' ...");
    StreamProperties nsProps = result(admin.createStream(null == namespaceName ? defaultNamespace : namespaceName, streamName, DEFAULT_STREAM_CONF));
    System.out.println("Successfully created stream '" + streamName + "':");
    System.out.println(nsProps);
}
Also used : StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties)

Example 3 with StreamProperties

use of org.apache.bookkeeper.stream.proto.StreamProperties in project bookkeeper by apache.

the class TestRangeStoreImpl method testGetActiveRangesMockManager.

@Test
public void testGetActiveRangesMockManager() throws Exception {
    long scId = System.currentTimeMillis();
    StreamProperties props = StreamProperties.newBuilder(streamProps).setStorageContainerId(scId).build();
    StorageContainer scStore = mock(StorageContainer.class);
    when(scStore.stop()).thenReturn(FutureUtils.value(null));
    rangeStore.getRegistry().setStorageContainer(scId, scStore);
    StorageContainerResponse resp = StorageContainerResponse.newBuilder().setCode(StatusCode.STREAM_NOT_FOUND).build();
    StorageContainerRequest request = createGetActiveRangesRequest(scId, 34L);
    when(scStore.getActiveRanges(request)).thenReturn(CompletableFuture.completedFuture(resp));
    CompletableFuture<StorageContainerResponse> future = rangeStore.getActiveRanges(request);
    verify(scStore, times(1)).getActiveRanges(request);
    assertTrue(resp == future.get());
}
Also used : StorageContainerRequest(org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) StorageContainer(org.apache.bookkeeper.stream.storage.api.sc.StorageContainer) StorageContainerResponse(org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse) Test(org.junit.Test)

Example 4 with StreamProperties

use of org.apache.bookkeeper.stream.proto.StreamProperties in project bookkeeper by apache.

the class StorageAdminClientTest method testStreamAPI.

@Test
public void testStreamAPI() throws Exception {
    // Create a namespace
    String nsName = testName.getMethodName() + "_ns";
    NamespaceConfiguration colConf = NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build();
    NamespaceProperties colProps = FutureUtils.result(adminClient.createNamespace(nsName, colConf));
    assertEquals(nsName, colProps.getNamespaceName());
    assertEquals(colConf.getDefaultStreamConf(), colProps.getDefaultStreamConf());
    // Create a stream
    String streamName = testName.getMethodName() + "_stream";
    StreamConfiguration streamConf = StreamConfiguration.newBuilder(DEFAULT_STREAM_CONF).build();
    StreamProperties streamProps = FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
    assertEquals(streamName, streamProps.getStreamName());
    assertEquals(StreamConfiguration.newBuilder(streamConf).setBackendServiceUrl(defaultBackendUri.toString()).build(), streamProps.getStreamConf());
    // create a duplicated stream
    try {
        FutureUtils.result(adminClient.createStream(nsName, streamName, streamConf));
        fail("Should fail on creation if stream " + streamName + " already exists");
    } catch (StreamExistsException cee) {
    // expected
    } catch (ClientException ce) {
        // TODO: currently it throws InternalServerError for stream exists case
        assertTrue(ce.getMessage().endsWith("code = " + StatusCode.INTERNAL_SERVER_ERROR));
    }
    String notFoundStreamName = testName.getMethodName() + "_notfound";
    // get a not-found stream
    try {
        FutureUtils.result(adminClient.getStream(nsName, notFoundStreamName));
        fail("Should fail on get if stream " + notFoundStreamName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
    // delete a not-found stream
    try {
        FutureUtils.result(adminClient.deleteStream(nsName, notFoundStreamName));
        fail("Should fail on delete if stream " + notFoundStreamName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
    // get an existing stream
    StreamProperties getStreamProps = FutureUtils.result(adminClient.getStream(nsName, streamName));
    assertEquals(streamProps, getStreamProps);
    // delete an existing stream
    Boolean deleted = FutureUtils.result(adminClient.deleteStream(nsName, streamName));
    assertTrue(deleted);
    // the stream should not exist after deleted.
    try {
        FutureUtils.result(adminClient.getStream(nsName, streamName));
        fail("Should fail on get if stream " + nsName + " doesn't exist");
    } catch (StreamNotFoundException cnfe) {
    // expected
    }
}
Also used : NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) StreamConfiguration(org.apache.bookkeeper.stream.proto.StreamConfiguration) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) Test(org.junit.Test)

Example 5 with StreamProperties

use of org.apache.bookkeeper.stream.proto.StreamProperties in project bookkeeper by apache.

the class RootRangeStoreImpl method executeCreateStreamTxn.

private CompletableFuture<CreateStreamResponse> executeCreateStreamTxn(long nsId, String streamName, StreamConfiguration streamConf, long currentStreamId, long currentStreamIdRev) {
    long streamId;
    if (currentStreamId < 0) {
        streamId = MIN_DATA_STREAM_ID;
    } else {
        streamId = currentStreamId + 1;
    }
    long scId = placementPolicy.placeStreamRange(streamId, 0L);
    StreamConfiguration newStreamConf = streamConf;
    // no backend service url is provided, use the default service url
    if (isBlank(streamConf.getBackendServiceUrl())) {
        newStreamConf = StreamConfiguration.newBuilder(streamConf).setBackendServiceUrl(defaultServiceUri.toString()).build();
    }
    StreamProperties streamProps = StreamProperties.newBuilder().setStreamId(streamId).setStreamName(streamName).setStorageContainerId(scId).setStreamConf(newStreamConf).build();
    byte[] nsIdKey = getNamespaceIdKey(nsId);
    byte[] streamNameKey = getStreamNameKey(nsId, streamName);
    byte[] streamNameVal = Bytes.toBytes(streamId);
    byte[] streamIdKey = getStreamIdKey(nsId, streamId);
    byte[] streamIdVal = streamProps.toByteArray();
    TxnOp<byte[], byte[]> txn = store.newTxn().If(store.newCompareValue(CompareResult.NOT_EQUAL, nsIdKey, null), currentStreamIdRev < 0 ? store.newCompareValue(CompareResult.EQUAL, STREAM_ID_KEY, null) : store.newCompareModRevision(CompareResult.EQUAL, STREAM_ID_KEY, currentStreamIdRev), store.newCompareValue(CompareResult.EQUAL, streamNameKey, null)).Then(store.newPut(streamNameKey, streamNameVal), store.newPut(streamIdKey, streamIdVal), store.newPut(STREAM_ID_KEY, Bytes.toBytes(streamId))).build();
    return store.txn(txn).thenApply(txnResult -> {
        try {
            CreateStreamResponse.Builder respBuilder = CreateStreamResponse.newBuilder();
            if (txnResult.isSuccess()) {
                respBuilder.setCode(StatusCode.SUCCESS);
                respBuilder.setStreamProps(streamProps);
            } else {
                // TODO: differentiate the error codes
                respBuilder.setCode(StatusCode.INTERNAL_SERVER_ERROR);
            }
            return respBuilder.build();
        } finally {
            txnResult.close();
            txn.close();
        }
    }).exceptionally(cause -> {
        txn.close();
        return CreateStreamResponse.newBuilder().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) StreamConfiguration(org.apache.bookkeeper.stream.proto.StreamConfiguration) StreamProperties(org.apache.bookkeeper.stream.proto.StreamProperties)

Aggregations

StreamProperties (org.apache.bookkeeper.stream.proto.StreamProperties)11 Test (org.junit.Test)7 StreamConfiguration (org.apache.bookkeeper.stream.proto.StreamConfiguration)5 NamespaceProperties (org.apache.bookkeeper.stream.proto.NamespaceProperties)4 KeyValue (org.apache.bookkeeper.api.kv.result.KeyValue)3 NamespaceConfiguration (org.apache.bookkeeper.stream.proto.NamespaceConfiguration)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBuf (io.netty.buffer.ByteBuf)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Slf4j (lombok.extern.slf4j.Slf4j)2 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)2 TxnOp (org.apache.bookkeeper.api.kv.op.TxnOp)2 FutureUtils (org.apache.bookkeeper.common.concurrent.FutureUtils)2 Bytes (org.apache.bookkeeper.common.util.Bytes)2 MVCCAsyncStore (org.apache.bookkeeper.statelib.api.mvcc.MVCCAsyncStore)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 UTF_8 (com.google.common.base.Charsets.UTF_8)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1