@PUT @Path("/namespaces/{namespace-id}/properties") @AuditPolicy(AuditDetail.REQUEST_BODY) public void updateNamespaceProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { NamespaceMeta meta = getNamespaceMeta(request); namespaceAdmin.updateProperties(new NamespaceId(namespaceId), meta); responder.sendString(HttpResponseStatus.OK, String.format("Updated properties for namespace '%s'.", namespaceId)); }
@PUT @Path("/namespaces/{namespace-id}/properties") @AuditPolicy(AuditDetail.REQUEST_BODY) public void updateNamespaceProperties(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId) throws Exception { NamespaceMeta meta = getNamespaceMeta(request); namespaceAdmin.updateProperties(new NamespaceId(namespaceId), meta); responder.sendString(HttpResponseStatus.OK, String.format("Updated properties for namespace '%s'.", namespaceId)); }
@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)); }
namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setRootDirectory("/newloc").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setHBaseNamespace("custns").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setHiveDatabase("newDB").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setRootDirectory("").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setPrincipal("newPrincipal").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setKeytabURI("/new/keytab/uri").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(), new NamespaceMeta.Builder(nsMeta).setGroupName("anotherGroup").build()); Assert.fail(); namespaceAdmin.updateProperties(nsMeta.getNamespaceId(),
@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); }