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