Search in sources :

Example 11 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class DefaultNamespaceAdminTest method testKerberos.

@Test
public void testKerberos() throws Exception {
    // test that the namespace create handler doesn't allow configuring only one of the following two:
    // principal, keytabURI
    NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName("test_ns").setPrincipal("somePrincipal").build();
    try {
        namespaceAdmin.create(namespaceMeta);
        Assert.fail();
    } catch (BadRequestException bre) {
    // expected
    }
    // now check with just key tab uri
    namespaceMeta = new NamespaceMeta.Builder().setName("test_ns").setKeytabURI("/some/path").build();
    try {
        namespaceAdmin.create(namespaceMeta);
        Assert.fail();
    } catch (BadRequestException bre) {
    // expected
    }
    // if set explore as principal is set to false it should be present with both keytab uri and principal
    namespaceMeta = new NamespaceMeta.Builder().setName("test_ns").setKeytabURI("/some/path").setExploreAsPrincipal(false).build();
    try {
        namespaceAdmin.create(namespaceMeta);
        Assert.fail();
    } catch (BadRequestException bre) {
    // expected
    }
    // if set explore as principal is set to false it shoule be present with both keytab uri and principal
    namespaceMeta = new NamespaceMeta.Builder().setName("test_ns").setPrincipal("somePrincipal").setExploreAsPrincipal(false).build();
    try {
        namespaceAdmin.create(namespaceMeta);
        Assert.fail();
    } catch (BadRequestException bre) {
    // expected
    }
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) BadRequestException(co.cask.cdap.common.BadRequestException) Test(org.junit.Test)

Example 12 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class DefaultNamespaceAdminTest method testSameCustomMapping.

@Test
public void testSameCustomMapping() throws Exception {
    String namespace = "custompaceNamespace";
    NamespaceId namespaceId = new NamespaceId(namespace);
    // create the custom directory since the namespace is being created with custom root directory it needs to exist
    String parentPath = "/custom/root";
    String customRootPath = parentPath + "/path";
    Location customlocation = baseLocationFactory.create(customRootPath);
    Assert.assertTrue(customlocation.mkdirs());
    NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId).setRootDirectory(customRootPath).setHBaseNamespace("hbasens").setHiveDatabase("hivedb").build();
    namespaceAdmin.create(nsMeta);
    // creating a new namespace with same location should fail
    verifyAlreadyExist(new NamespaceMeta.Builder(nsMeta).setName("otherNamespace").build(), namespaceId);
    // creating a new namespace with subdir should fail.
    // subdirLocation here looks like: ..../junit/custompaceNamespace/subdir
    verifyAlreadyExist(new NamespaceMeta.Builder().setName("otherNamespace").setRootDirectory(customRootPath + "/subdir").build(), namespaceId);
    // trying to create a namespace one level up should fail
    verifyAlreadyExist(new NamespaceMeta.Builder().setName("otherNamespace").setRootDirectory(parentPath).build(), namespaceId);
    // but we should be able to create namespace in a different directory under same path
    // otherNamespace here looks like: ..../junit/otherNamespace
    String otherRoot = parentPath + "/otherpath";
    Location otherNamespace = baseLocationFactory.create(otherRoot);
    Assert.assertTrue(otherNamespace.mkdirs());
    namespaceAdmin.create(new NamespaceMeta.Builder().setName("otherNamespace").setRootDirectory(otherRoot).build());
    namespaceAdmin.delete(new NamespaceId("otherNamespace"));
    // creating a new namespace with same hive database should fails
    verifyAlreadyExist(new NamespaceMeta.Builder().setName("otherNamespace").setHiveDatabase("hivedb").build(), namespaceId);
    // creating a new namespace with same hbase namespace should fail
    verifyAlreadyExist(new NamespaceMeta.Builder().setName("otherNamespace").setHBaseNamespace("hbasens").build(), namespaceId);
    //clean up
    namespaceAdmin.delete(namespaceId);
    Locations.deleteQuietly(customlocation);
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 13 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class StorageProviderNamespaceAdminTest method test.

@Test
public void test() throws Exception {
    NamespaceId myspace = new NamespaceId("myspace");
    NamespaceMeta myspaceMeta = new NamespaceMeta.Builder().setName(myspace.getNamespace()).build();
    // the create/delete will look up meta so store that too
    namespaceStore.create(myspaceMeta);
    storageProviderNamespaceAdmin.create(myspaceMeta);
    Location namespaceLocation = namespacedLocationFactory.get(myspace);
    Assert.assertTrue(namespaceLocation.exists());
    storageProviderNamespaceAdmin.delete(myspace);
    Assert.assertFalse(namespaceLocation.exists());
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceId(co.cask.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 14 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandlerTest method testProperties.

@Test
public void testProperties() throws Exception {
    // create with no metadata
    HttpResponse response = createNamespace(NAME);
    assertResponseCode(200, response);
    // verify
    response = getNamespace(NAME);
    JsonObject namespace = readGetResponse(response);
    Assert.assertNotNull(namespace);
    Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
    Assert.assertEquals(EMPTY, namespace.get(DESCRIPTION_FIELD).getAsString());
    // Update scheduler queue name.
    String nonexistentName = NAME + "nonexistent";
    NamespaceMeta meta = new NamespaceMeta.Builder().setName(nonexistentName).setSchedulerQueueName("prod").build();
    setProperties(NAME, meta);
    // assert that the name in the metadata is ignored (the name from the url should be used, instead
    HttpResponse nonexistentGet = getNamespace(nonexistentName);
    Assert.assertEquals(404, nonexistentGet.getStatusLine().getStatusCode());
    response = getNamespace(NAME);
    namespace = readGetResponse(response);
    Assert.assertNotNull(namespace);
    NamespaceConfig config = GSON.fromJson(namespace.get(CONFIG_FIELD).getAsJsonObject(), NamespaceConfig.class);
    Assert.assertEquals("prod", config.getSchedulerQueueName());
    Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
    Assert.assertEquals(EMPTY, namespace.get(DESCRIPTION_FIELD).getAsString());
    // Update description
    meta = new NamespaceMeta.Builder().setName(NAME).setDescription("new fancy description").build();
    setProperties(NAME, meta);
    response = getNamespace(NAME);
    namespace = readGetResponse(response);
    Assert.assertNotNull(namespace);
    //verify that the description has changed
    Assert.assertEquals("new fancy description", namespace.get(DESCRIPTION_FIELD).getAsString());
    Assert.assertEquals(NAME, namespace.get(NAME_FIELD).getAsString());
    // verify other properties set earlier has not changed.
    config = GSON.fromJson(namespace.get(CONFIG_FIELD).getAsJsonObject(), NamespaceConfig.class);
    Assert.assertEquals("prod", config.getSchedulerQueueName());
    // cleanup
    response = deleteNamespace(NAME);
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
}
Also used : NamespaceConfig(co.cask.cdap.proto.NamespaceConfig) NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) HttpResponse(org.apache.http.HttpResponse) JsonObject(com.google.gson.JsonObject) AppForUnrecoverableResetTest(co.cask.cdap.AppForUnrecoverableResetTest) Test(org.junit.Test)

Example 15 with NamespaceMeta

use of co.cask.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class NamespaceHttpHandlerTest method testNamespaceClient.

@Test
public void testNamespaceClient() throws Exception {
    // tests the NamespaceClient's ability to interact with Namespace service/handlers.
    NamespaceAdmin namespaceClient = getInjector().getInstance(NamespaceAdmin.class);
    // test setup creates two namespaces in @BeforeClass, apart from the default namespace which always exists.
    List<NamespaceMeta> namespaces = namespaceClient.list();
    Assert.assertEquals(3, namespaces.size());
    Set<NamespaceMeta> expectedNamespaces = ImmutableSet.of(NamespaceMeta.DEFAULT, TEST_NAMESPACE_META1, TEST_NAMESPACE_META2);
    Assert.assertEquals(expectedNamespaces, Sets.newHashSet(namespaces));
    NamespaceMeta namespaceMeta = namespaceClient.get(new NamespaceId(TEST_NAMESPACE1));
    Assert.assertEquals(TEST_NAMESPACE_META1, namespaceMeta);
    try {
        namespaceClient.get(new NamespaceId("nonExistentNamespace"));
        Assert.fail("Did not expect namespace 'nonExistentNamespace' to exist.");
    } catch (NotFoundException expected) {
    // expected
    }
    // test create and get
    NamespaceId fooNamespace = new NamespaceId("fooNamespace");
    NamespaceMeta toCreate = new NamespaceMeta.Builder().setName(fooNamespace).build();
    namespaceClient.create(toCreate);
    NamespaceMeta receivedMeta = namespaceClient.get(fooNamespace);
    Assert.assertNotNull(receivedMeta);
    Assert.assertEquals(toCreate, receivedMeta);
    namespaceClient.delete(fooNamespace);
    try {
        namespaceClient.get(fooNamespace);
        Assert.fail("Did not expect namespace '" + fooNamespace + "' to exist after deleting it.");
    } catch (NotFoundException expected) {
    // expected
    }
}
Also used : NamespaceMeta(co.cask.cdap.proto.NamespaceMeta) NamespaceAdmin(co.cask.cdap.common.namespace.NamespaceAdmin) NotFoundException(co.cask.cdap.common.NotFoundException) NamespaceId(co.cask.cdap.proto.id.NamespaceId) AppForUnrecoverableResetTest(co.cask.cdap.AppForUnrecoverableResetTest) Test(org.junit.Test)

Aggregations

NamespaceMeta (co.cask.cdap.proto.NamespaceMeta)58 NamespaceId (co.cask.cdap.proto.id.NamespaceId)26 Test (org.junit.Test)22 IOException (java.io.IOException)12 Location (org.apache.twill.filesystem.Location)6 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)5 BadRequestException (co.cask.cdap.common.BadRequestException)5 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)5 ApplicationManager (co.cask.cdap.test.ApplicationManager)5 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceConfig (co.cask.cdap.proto.NamespaceConfig)4 UnauthorizedException (co.cask.cdap.security.spi.authorization.UnauthorizedException)4 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 RowMaker (co.cask.cdap.cli.util.RowMaker)3 Table (co.cask.cdap.cli.util.table.Table)3 NotFoundException (co.cask.cdap.common.NotFoundException)3 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)3 Id (co.cask.cdap.proto.Id)3 ApplicationId (co.cask.cdap.proto.id.ApplicationId)3