Search in sources :

Example 1 with NamespaceExistsException

use of org.apache.bookkeeper.clients.exceptions.NamespaceExistsException in project bookkeeper by apache.

the class StreamCluster method createDefaultNamespaces.

private void createDefaultNamespaces() throws Exception {
    StorageClientSettings settings = StorageClientSettings.newBuilder().addEndpoints(getRpcEndpoints().toArray(new Endpoint[getRpcEndpoints().size()])).usePlaintext(true).build();
    log.info("RpcEndpoints are : {}", settings.endpoints());
    String namespaceName = "default";
    try (StorageAdminClient admin = StorageClientBuilder.newBuilder().withSettings(settings).buildAdmin()) {
        System.out.println("Creating namespace '" + namespaceName + "' ...");
        try {
            NamespaceProperties nsProps = result(admin.createNamespace(namespaceName, NamespaceConfiguration.newBuilder().setDefaultStreamConf(DEFAULT_STREAM_CONF).build()));
            System.out.println("Successfully created namespace '" + namespaceName + "':");
            System.out.println(nsProps);
        } catch (NamespaceExistsException nee) {
            System.out.println("Namespace '" + namespaceName + "' already exists.");
        }
    }
}
Also used : StorageClientSettings(org.apache.bookkeeper.clients.config.StorageClientSettings) Endpoint(org.apache.bookkeeper.stream.proto.common.Endpoint) NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) StorageAdminClient(org.apache.bookkeeper.clients.admin.StorageAdminClient) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException)

Example 2 with NamespaceExistsException

use of org.apache.bookkeeper.clients.exceptions.NamespaceExistsException in project bookkeeper by apache.

the class TestProtocolInternalUtils method testCreateRootRangeException.

// 
// Test Exceptions related utils
// 
@Test
public void testCreateRootRangeException() {
    String name = "test-create-root-range-exception";
    // stream exists exception
    Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
    assertTrue(cause1 instanceof StreamExistsException);
    StreamExistsException see = (StreamExistsException) cause1;
    // stream not found
    Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
    assertTrue(cause2 instanceof StreamNotFoundException);
    StreamNotFoundException snfe = (StreamNotFoundException) cause2;
    // invalid stream name
    Throwable invalidStreamNameCause = createRootRangeException(name, StatusCode.INVALID_STREAM_NAME);
    assertTrue(invalidStreamNameCause instanceof InvalidStreamNameException);
    InvalidStreamNameException isne = (InvalidStreamNameException) invalidStreamNameCause;
    // failure
    Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
    ClientException se = (ClientException) cause3;
    assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
    // namespace exists exception
    Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
    assertTrue(cause5 instanceof NamespaceExistsException);
    // namespace not-found exception
    Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
    assertTrue(cause6 instanceof NamespaceNotFoundException);
    // invalid namespace name
    Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
    assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
Also used : InvalidStreamNameException(org.apache.bookkeeper.clients.exceptions.InvalidStreamNameException) InvalidNamespaceNameException(org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException) Test(org.junit.Test)

Example 3 with NamespaceExistsException

use of org.apache.bookkeeper.clients.exceptions.NamespaceExistsException in project bookkeeper by apache.

the class RootRangeClientImplTestBase method testCreateRootRangeException.

@Test
public void testCreateRootRangeException() {
    String name = "test-create-root-range-exception";
    // stream exists exception
    Throwable cause1 = createRootRangeException(name, StatusCode.STREAM_EXISTS);
    assertTrue(cause1 instanceof StreamExistsException);
    StreamExistsException see = (StreamExistsException) cause1;
    // stream not found
    Throwable cause2 = createRootRangeException(name, StatusCode.STREAM_NOT_FOUND);
    assertTrue(cause2 instanceof StreamNotFoundException);
    StreamNotFoundException snfe = (StreamNotFoundException) cause2;
    // failure
    Throwable cause3 = createRootRangeException(name, StatusCode.FAILURE);
    assertTrue(cause3 instanceof ClientException);
    ClientException se = (ClientException) cause3;
    assertEquals("fail to access its root range : code = " + StatusCode.FAILURE, se.getMessage());
    // unexpected
    Throwable cause4 = createRootRangeException(name, StatusCode.BAD_VERSION);
    assertTrue(cause4 instanceof ClientException);
    // namespace exists exception
    Throwable cause5 = createRootRangeException(name, StatusCode.NAMESPACE_EXISTS);
    assertTrue(cause5 instanceof NamespaceExistsException);
    // namespace not-found exception
    Throwable cause6 = createRootRangeException(name, StatusCode.NAMESPACE_NOT_FOUND);
    assertTrue(cause6 instanceof NamespaceNotFoundException);
    // invalid namespace name
    Throwable cause7 = createRootRangeException(name, StatusCode.INVALID_NAMESPACE_NAME);
    assertTrue(cause7 instanceof InvalidNamespaceNameException);
}
Also used : InvalidNamespaceNameException(org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException) StreamNotFoundException(org.apache.bookkeeper.clients.exceptions.StreamNotFoundException) StreamExistsException(org.apache.bookkeeper.clients.exceptions.StreamExistsException) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException) Test(org.junit.Test)

Example 4 with NamespaceExistsException

use of org.apache.bookkeeper.clients.exceptions.NamespaceExistsException in project bookkeeper by apache.

the class StorageAdminClientTest method testNamespaceAPI.

@Test
public void testNamespaceAPI() throws Exception {
    // Create a namespace
    String nsName = testName.getMethodName();
    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 duplicated namespace
    try {
        FutureUtils.result(adminClient.createNamespace(nsName, colConf));
        fail("Should fail on creation if namespace " + nsName + " already exists");
    } catch (NamespaceExistsException cee) {
    // expected
    } catch (ClientException ce) {
        // TODO: currently range server throws InternalServerError
        assertTrue(ce.getMessage().endsWith("code = " + StatusCode.INTERNAL_SERVER_ERROR));
    }
    String notFoundColName = testName.getMethodName() + "_notfound";
    // get a not-found namespace
    try {
        FutureUtils.result(adminClient.getNamespace(notFoundColName));
        fail("Should fail on get if namespace " + notFoundColName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
    // delete a not-found namespace
    try {
        FutureUtils.result(adminClient.deleteNamespace(notFoundColName));
        fail("Should fail on delete if namespace " + notFoundColName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
    // get an existing namespace
    NamespaceProperties getColProps = FutureUtils.result(adminClient.getNamespace(nsName));
    assertEquals(colProps, getColProps);
    // delete an existing namespace
    Boolean deleted = FutureUtils.result(adminClient.deleteNamespace(nsName));
    assertTrue(deleted);
    // the namespace should not exist after deleted.
    try {
        FutureUtils.result(adminClient.getNamespace(nsName));
        fail("Should fail on get if namespace " + nsName + " doesn't exist");
    } catch (NamespaceNotFoundException cnfe) {
    // expected
    }
}
Also used : NamespaceProperties(org.apache.bookkeeper.stream.proto.NamespaceProperties) NamespaceConfiguration(org.apache.bookkeeper.stream.proto.NamespaceConfiguration) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) NamespaceExistsException(org.apache.bookkeeper.clients.exceptions.NamespaceExistsException) NamespaceNotFoundException(org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException) Test(org.junit.Test)

Aggregations

NamespaceExistsException (org.apache.bookkeeper.clients.exceptions.NamespaceExistsException)4 ClientException (org.apache.bookkeeper.clients.exceptions.ClientException)3 NamespaceNotFoundException (org.apache.bookkeeper.clients.exceptions.NamespaceNotFoundException)3 Test (org.junit.Test)3 InvalidNamespaceNameException (org.apache.bookkeeper.clients.exceptions.InvalidNamespaceNameException)2 StreamExistsException (org.apache.bookkeeper.clients.exceptions.StreamExistsException)2 StreamNotFoundException (org.apache.bookkeeper.clients.exceptions.StreamNotFoundException)2 NamespaceProperties (org.apache.bookkeeper.stream.proto.NamespaceProperties)2 StorageAdminClient (org.apache.bookkeeper.clients.admin.StorageAdminClient)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 InvalidStreamNameException (org.apache.bookkeeper.clients.exceptions.InvalidStreamNameException)1 NamespaceConfiguration (org.apache.bookkeeper.stream.proto.NamespaceConfiguration)1 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)1