@Override public NamespaceMeta get(NamespaceId namespaceId) throws Exception { return namespaceAdmin.get(namespaceId); }
@GET @Path("/namespaces/{namespace-id}") public void getNamespace(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { // return keytab URI without version NamespaceMeta ns = new NamespaceMeta.Builder(namespaceAdmin.get(new NamespaceId(namespaceId))).buildWithoutKeytabURIVersion(); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ns)); }
@GET @Path("/namespaces/{namespace-id}") public void getNamespace(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { // return keytab URI without version NamespaceMeta ns = new NamespaceMeta.Builder(namespaceAdmin.get(new NamespaceId(namespaceId))).buildWithoutKeytabURIVersion(); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(ns)); }
private static void verifyNotFound(NamespaceId namespaceId) throws Exception { try { namespaceAdmin.get(namespaceId); Assert.fail(String.format("Namespace '%s' should not be found since it was just deleted", namespaceId.getNamespace())); } catch (NamespaceNotFoundException e) { Assert.assertEquals(namespaceId, e.getId()); } } }
@Test public void test() throws Exception { try { namespaceAdmin.get(NamespaceId.DEFAULT); Assert.fail("Default namespace should not exist."); } catch (NamespaceNotFoundException e) { // expected } // test that it creates the default namespace BootstrapStepResult result = defaultNamespaceCreator.execute("label", new JsonObject()); BootstrapStepResult expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED); Assert.assertEquals(expected, result); Assert.assertEquals(NamespaceMeta.DEFAULT, namespaceAdmin.get(NamespaceId.DEFAULT)); // test trying to create when it's already there won't error result = defaultNamespaceCreator.execute("label", new JsonObject()); expected = new BootstrapStepResult("label", BootstrapStepResult.Status.SUCCEEDED); Assert.assertEquals(expected, result); Assert.assertEquals(NamespaceMeta.DEFAULT, namespaceAdmin.get(NamespaceId.DEFAULT)); } }
Assert.assertEquals(expectedNamespaces, Sets.newHashSet(namespaces)); NamespaceMeta namespaceMeta = namespaceClient.get(new NamespaceId(TEST_NAMESPACE1)); Assert.assertEquals(TEST_NAMESPACE_META1, namespaceMeta); namespaceClient.get(new NamespaceId("nonExistentNamespace")); Assert.fail("Did not expect namespace 'nonExistentNamespace' to exist."); } catch (NotFoundException expected) { NamespaceMeta toCreate = new NamespaceMeta.Builder().setName(fooNamespace).build(); namespaceClient.create(toCreate); NamespaceMeta receivedMeta = namespaceClient.get(fooNamespace); Assert.assertNotNull(receivedMeta); Assert.assertEquals(toCreate, receivedMeta); namespaceClient.get(fooNamespace); Assert.fail("Did not expect namespace '" + fooNamespace + "' to exist after deleting it."); } catch (NotFoundException expected) {
@Test public void testNamespaces() throws Exception { NamespaceAdmin namespaceAdmin = getNamespaceAdmin(); Authorizer authorizer = getAuthorizer(); try { namespaceAdmin.create(AUTH_NAMESPACE_META); Assert.fail("Namespace create should have failed because alice is not authorized on " + AUTH_NAMESPACE); } catch (UnauthorizedException expected) { // expected } createAuthNamespace(); Assert.assertTrue(namespaceAdmin.list().contains(AUTH_NAMESPACE_META)); namespaceAdmin.get(AUTH_NAMESPACE); // revoke privileges revokeAndAssertSuccess(AUTH_NAMESPACE); try { Assert.assertTrue(namespaceAdmin.list().isEmpty()); namespaceAdmin.exists(AUTH_NAMESPACE); Assert.fail("Namespace existence check should fail since the privilege of alice has been revoked"); } catch (UnauthorizedException expected) { // expected } // grant privileges again grantAndAssertSuccess(AUTH_NAMESPACE, ALICE, ImmutableSet.of(Action.ADMIN)); namespaceAdmin.exists(AUTH_NAMESPACE); Assert.assertEquals(ImmutableSet.of(new Privilege(AUTH_NAMESPACE, Action.ADMIN)), authorizer.listPrivileges(ALICE)); NamespaceMeta updated = new NamespaceMeta.Builder(AUTH_NAMESPACE_META).setDescription("new desc").build(); namespaceAdmin.updateProperties(AUTH_NAMESPACE, updated); Assert.assertEquals(updated, namespaceAdmin.get(AUTH_NAMESPACE)); }
@Test public void testUpdateExistingKeytab() throws Exception { String namespace = "updateNamespace"; NamespaceId namespaceId = new NamespaceId(namespace); NamespaceMeta nsMeta = new NamespaceMeta.Builder().setName(namespaceId) .setPrincipal("alice").setKeytabURI("/alice/keytab").build(); namespaceAdmin.create(nsMeta); Assert.assertTrue(namespaceAdmin.exists(namespaceId)); // update the keytab URI String newKeytab = "/alice/new_keytab"; NamespaceMeta newKeytabMeta = new NamespaceMeta.Builder(nsMeta).setKeytabURI(newKeytab).build(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), newKeytabMeta); // assert the keytab URI is updated and the version remains 0 Assert.assertEquals(newKeytab, namespaceAdmin.get(namespaceId).getConfig().getKeytabURIWithoutVersion()); Assert.assertEquals(0, namespaceAdmin.get(namespaceId).getConfig().getKeytabURIVersion()); // update the namespace with the same keytab URI namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), newKeytabMeta); // assert the keytab URI without version remains the same and the version is incremented to 1 Assert.assertEquals(newKeytab, namespaceAdmin.get(namespaceId).getConfig().getKeytabURIWithoutVersion()); Assert.assertEquals(1, namespaceAdmin.get(namespaceId).getConfig().getKeytabURIVersion()); //clean up namespaceAdmin.delete(namespaceId); }
namespaceAdmin.get(new NamespaceId("random")); Assert.fail("Namespace 'random' should not exist."); } catch (NamespaceNotFoundException e) { NamespaceMeta namespaceMeta = namespaceAdmin.get(namespaceId); Assert.assertEquals(namespaceId.getNamespace(), namespaceMeta.getName()); Assert.assertEquals("", namespaceMeta.getDescription()); NamespaceMeta namespaceMeta = namespaceAdmin.get(namespaceId);
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());