Search in sources :

Example 16 with NamespaceMeta

use of io.cdap.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(io.cdap.cdap.proto.NamespaceMeta) BadRequestException(io.cdap.cdap.common.BadRequestException) Test(org.junit.Test)

Example 17 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class DefaultNamespaceAdminTest method testConfigUpdate.

@Test
public void testConfigUpdate() throws Exception {
    String namespace = "custompaceNamespace";
    NamespaceId namespaceId = new NamespaceId(namespace);
    // check that root directory for a namespace cannot be updated
    // create the custom directory since the namespace is being created with custom root directory it needs to exist
    String customRoot = "/some/custom/dir";
    Location customlocation = baseLocationFactory.create(customRoot);
    Assert.assertTrue(customlocation.mkdirs());
    NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId).setRootDirectory(customRoot).build();
    namespaceAdmin.create(nsMeta);
    Assert.assertTrue(namespaceAdmin.exists(namespaceId));
    // Updating the root directory for a namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setRootDirectory("/newloc").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // Updating the HBase namespace for a namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setHBaseNamespace("custns").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // Updating the hive database for a namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setHiveDatabase("newDB").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // removing the root directory mapping for a namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setRootDirectory("").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // updating the principal for an existing namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setPrincipal("newPrincipal").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // updating the keytabURI for an existing namespace with no existing principal should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setKeytabURI("/new/keytab/uri").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // updating the groupname for an existing namespace should fail
    try {
        namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setGroupName("anotherGroup").build());
        Assert.fail();
    } catch (BadRequestException e) {
    // expected
    }
    // Although disabling explore impersonation should be allowed
    Assert.assertTrue(namespaceAdmin.get(nsMeta.getNamespaceId()).getConfig().isExploreAsPrincipal());
    namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setExploreAsPrincipal(false).build());
    Assert.assertFalse(namespaceAdmin.get(nsMeta.getNamespaceId()).getConfig().isExploreAsPrincipal());
    // clean up
    namespaceAdmin.delete(namespaceId);
    Locations.deleteQuietly(customlocation);
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) BadRequestException(io.cdap.cdap.common.BadRequestException) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) Location(org.apache.twill.filesystem.Location) Test(org.junit.Test)

Example 18 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class CLITestBase method testNamespacesOutput.

private void testNamespacesOutput(String command, final List<NamespaceMeta> expected) throws Exception {
    CLIMain cliMain = getCliMain();
    CLIConfig cliConfig = getCliConfig();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintStream output = new PrintStream(outputStream);
    Table table = Table.builder().setHeader("name", "description", "config").setRows(expected, new RowMaker<NamespaceMeta>() {

        @Override
        public List<?> makeRow(NamespaceMeta object) {
            return Lists.newArrayList(object.getName(), object.getDescription(), NamespaceCommandUtils.prettyPrintNamespaceConfigCLI(object.getConfig()));
        }
    }).build();
    cliMain.getTableRenderer().render(cliConfig, output, table);
    final String expectedOutput = outputStream.toString();
    testCommand(command, new Function<String, Void>() {

        @Nullable
        @Override
        public Void apply(@Nullable String output) {
            Assert.assertNotNull(output);
            Assert.assertEquals(expectedOutput, output);
            return null;
        }
    });
}
Also used : PrintStream(java.io.PrintStream) Table(io.cdap.cdap.cli.util.table.Table) RowMaker(io.cdap.cdap.cli.util.RowMaker) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Nullable(javax.annotation.Nullable)

Example 19 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class CLITestBase method testNamespaces.

@Test
public void testNamespaces() throws Exception {
    final String name = PREFIX + "testNamespace";
    final String description = "testDescription";
    final String keytab = "keytab";
    final String principal = "principal";
    final String group = "group";
    final String hbaseNamespace = "hbase";
    final String hiveDatabase = "hiveDB";
    final String schedulerQueueName = "queue";
    File rootdir = TEMPORARY_FOLDER.newFolder("rootdir");
    final String rootDirectory = rootdir.getAbsolutePath();
    final String defaultFields = PREFIX + "defaultFields";
    final String doesNotExist = "doesNotExist";
    createHiveDB(hiveDatabase);
    // initially only default namespace should be present
    NamespaceMeta defaultNs = NamespaceMeta.DEFAULT;
    List<NamespaceMeta> expectedNamespaces = Lists.newArrayList(defaultNs);
    testNamespacesOutput("list namespaces", expectedNamespaces);
    // describe non-existing namespace
    testCommandOutputContains(String.format("describe namespace %s", doesNotExist), String.format("Error: 'namespace:%s' was not found", doesNotExist));
    // delete non-existing namespace
    // TODO: uncomment when fixed - this makes build hang since it requires confirmation from user
    // testCommandOutputContains(String.format("delete namespace %s", doesNotExist),
    // String.format("Error: namespace '%s' was not found", doesNotExist));
    // create a namespace
    String command = String.format("create namespace %s description %s principal %s group-name %s keytab-URI %s " + "hbase-namespace %s hive-database %s root-directory %s %s %s %s %s", name, description, principal, group, keytab, hbaseNamespace, hiveDatabase, rootDirectory, ArgumentName.NAMESPACE_SCHEDULER_QUEUENAME, schedulerQueueName, ArgumentName.NAMESPACE_EXPLORE_AS_PRINCIPAL, false);
    testCommandOutputContains(command, String.format("Namespace '%s' created successfully.", name));
    NamespaceMeta expected = new NamespaceMeta.Builder().setName(name).setDescription(description).setPrincipal(principal).setGroupName(group).setKeytabURI(keytab).setHBaseNamespace(hbaseNamespace).setSchedulerQueueName(schedulerQueueName).setHiveDatabase(hiveDatabase).setRootDirectory(rootDirectory).setExploreAsPrincipal(false).build();
    expectedNamespaces = Lists.newArrayList(defaultNs, expected);
    // list namespaces and verify
    testNamespacesOutput("list namespaces", expectedNamespaces);
    // get namespace details and verify
    expectedNamespaces = Lists.newArrayList(expected);
    command = String.format("describe namespace %s", name);
    testNamespacesOutput(command, expectedNamespaces);
    // try creating a namespace with existing id
    command = String.format("create namespace %s", name);
    testCommandOutputContains(command, String.format("Error: 'namespace:%s' already exists\n", name));
    // create a namespace with default name and description
    command = String.format("create namespace %s", defaultFields);
    testCommandOutputContains(command, String.format("Namespace '%s' created successfully.", defaultFields));
    NamespaceMeta namespaceDefaultFields = new NamespaceMeta.Builder().setName(defaultFields).setDescription("").build();
    // test that there are 3 namespaces including default
    expectedNamespaces = Lists.newArrayList(defaultNs, namespaceDefaultFields, expected);
    testNamespacesOutput("list namespaces", expectedNamespaces);
    // describe namespace with default fields
    expectedNamespaces = Lists.newArrayList(namespaceDefaultFields);
    testNamespacesOutput(String.format("describe namespace %s", defaultFields), expectedNamespaces);
    // delete namespace and verify
    // TODO: uncomment when fixed - this makes build hang since it requires confirmation from user
    // command = String.format("delete namespace %s", name);
    // testCommandOutputContains(command, String.format("Namespace '%s' deleted successfully.", name));
    dropHiveDb(hiveDatabase);
}
Also used : NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) File(java.io.File) Test(org.junit.Test)

Example 20 with NamespaceMeta

use of io.cdap.cdap.proto.NamespaceMeta in project cdap by caskdata.

the class AppFabricClient method reset.

public void reset() throws Exception {
    MockResponder responder;
    HttpRequest request;
    // delete all namespaces
    for (NamespaceMeta namespaceMeta : namespaceQueryAdmin.list()) {
        Id.Namespace namespace = Id.Namespace.from(namespaceMeta.getName());
        responder = new MockResponder();
        request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("%s/unrecoverable/namespaces/%s/datasets", Constants.Gateway.API_VERSION_3, namespace.getId()));
        namespaceHttpHandler.deleteDatasets(request, responder, namespaceMeta.getName());
        verifyResponse(HttpResponseStatus.OK, responder.getStatus(), String.format("could not delete datasets in namespace '%s'", namespace.getId()));
        responder = new MockResponder();
        request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, String.format("/v3/unrecoverable/namespaces/%s", namespace.getId()));
        namespaceHttpHandler.delete(request, responder, namespaceMeta.getName());
        verifyResponse(HttpResponseStatus.OK, responder.getStatus(), String.format("could not delete namespace '%s'", namespace.getId()));
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) NamespaceMeta(io.cdap.cdap.proto.NamespaceMeta) NamespaceId(io.cdap.cdap.proto.id.NamespaceId) ScheduleId(io.cdap.cdap.proto.id.ScheduleId) Id(io.cdap.cdap.common.id.Id) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) ProgramId(io.cdap.cdap.proto.id.ProgramId) KerberosPrincipalId(io.cdap.cdap.proto.id.KerberosPrincipalId)

Aggregations

NamespaceMeta (io.cdap.cdap.proto.NamespaceMeta)144 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)76 Test (org.junit.Test)54 IOException (java.io.IOException)30 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)18 BadRequestException (io.cdap.cdap.common.BadRequestException)14 NotFoundException (io.cdap.cdap.common.NotFoundException)14 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)14 DatasetId (io.cdap.cdap.proto.id.DatasetId)14 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)14 EntityId (io.cdap.cdap.proto.id.EntityId)12 GrantedPermission (io.cdap.cdap.proto.security.GrantedPermission)12 Location (org.apache.twill.filesystem.Location)12 Set (java.util.Set)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 KeyValueTable (io.cdap.cdap.api.dataset.lib.KeyValueTable)10 PartitionedFileSet (io.cdap.cdap.api.dataset.lib.PartitionedFileSet)10 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)10 AccessPermission (io.cdap.cdap.proto.security.AccessPermission)10