@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NamespaceNotFoundException, NamespaceExistsException { String old = cl.getArgs()[0]; String newer = cl.getArgs()[1]; boolean resetContext = false; Table.ID currentTableId = null; if (!(shellState.getTableName() == null) && !shellState.getTableName().isEmpty()) { Namespace.ID namespaceId = Namespaces.getNamespaceId(shellState.getContext(), old); List<Table.ID> tableIds = Namespaces.getTableIds(shellState.getContext(), namespaceId); currentTableId = Tables.getTableId(shellState.getContext(), shellState.getTableName()); resetContext = tableIds.contains(currentTableId); } shellState.getAccumuloClient().namespaceOperations().rename(old, newer); if (resetContext) { shellState.setTableName(Tables.getTableName(shellState.getContext(), currentTableId)); } return 0; }
@Override public void visit(State state, Environment env, Properties props) throws Exception { Connector conn = env.getConnector(); Random rand = (Random) state.get("rand"); @SuppressWarnings("unchecked") List<String> namespaces = (List<String>) state.get("namespaces"); String srcName = namespaces.get(rand.nextInt(namespaces.size())); String newName = namespaces.get(rand.nextInt(namespaces.size())); try { conn.namespaceOperations().rename(srcName, newName); log.debug("Renamed namespace " + srcName + " " + newName); } catch (NamespaceExistsException e) { log.debug("Rename namespace " + srcName + " failed, " + newName + " exists"); } catch (NamespaceNotFoundException e) { log.debug("Rename namespace " + srcName + " failed, doesn't exist"); } } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NamespaceNotFoundException, NamespaceExistsException { String old = cl.getArgs()[0]; String newer = cl.getArgs()[1]; boolean resetContext = false; String currentTableId = ""; if (!(shellState.getTableName() == null) && !shellState.getTableName().isEmpty()) { String namespaceId = Namespaces.getNamespaceId(shellState.getInstance(), old); List<String> tableIds = Namespaces.getTableIds(shellState.getInstance(), namespaceId); currentTableId = Tables.getTableId(shellState.getInstance(), shellState.getTableName()); resetContext = tableIds.contains(currentTableId); } shellState.getConnector().namespaceOperations().rename(old, newer); if (resetContext) { shellState.setTableName(Tables.getTableName(shellState.getInstance(), currentTableId)); } return 0; }
@Override public void renameNamespace(ByteBuffer login, String oldNamespaceName, String newNamespaceName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, org.apache.accumulo.proxy.thrift.NamespaceExistsException, TException { try { getConnector(login).namespaceOperations().rename(oldNamespaceName, newNamespaceName); } catch (NamespaceNotFoundException e) { throw new org.apache.accumulo.proxy.thrift.NamespaceNotFoundException(e.toString()); } catch (NamespaceExistsException e) { throw new org.apache.accumulo.proxy.thrift.NamespaceExistsException(e.toString()); } catch (Exception e) { handleException(e); } }
break; case 11: ops.rename(namespace, namespace + "2"); fail(); break; ops.create(namespace + i + "_1"); ops.create(namespace + i + "_2"); ops.rename(namespace + i + "_1", namespace + i + "_2"); // should fail here fail(); break; case 4: ops.create(namespace + i + "_1"); ops.rename(namespace + i + "_1", Namespaces.DEFAULT_NAMESPACE); // should fail here fail(); break; case 5: ops.create(namespace + i + "_1"); ops.rename(namespace + i + "_1", Namespaces.ACCUMULO_NAMESPACE); // should fail here fail(); break;
@Test public void renameNamespaceWithTable() throws Exception { String namespace2 = namespace + "_renamed"; String t1 = namespace + ".t"; String t2 = namespace2 + ".t"; c.namespaceOperations().create(namespace); c.tableOperations().create(t1); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertFalse(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); String namespaceId = c.namespaceOperations().namespaceIdMap().get(namespace); String tableId = c.tableOperations().tableIdMap().get(t1); c.namespaceOperations().rename(namespace, namespace2); assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertTrue(c.namespaceOperations().exists(namespace2)); assertTrue(c.tableOperations().exists(t2)); // verify id's didn't change String namespaceId2 = c.namespaceOperations().namespaceIdMap().get(namespace2); String tableId2 = c.tableOperations().tableIdMap().get(t2); assertEquals(namespaceId, namespaceId2); assertEquals(tableId, tableId2); }
throw new IllegalStateException("Should be able to remove a table property"); loginAs(testUser); test_user_conn.namespaceOperations().rename(namespace, namespace2); loginAs(rootUser); if (root_conn.namespaceOperations().list().contains(namespace)
try { loginAs(testUser); test_user_conn.namespaceOperations().rename(namespace, namespace2); throw new IllegalStateException("Should NOT be able to rename a namespace"); } catch (AccumuloSecurityException e) {