/** * Ensures the given Accumulo namespace exist, creating it if necessary * * @param schema Presto schema (Accumulo namespace) */ public void ensureNamespace(String schema) { try { // If the table schema is not "default" and the namespace does not exist, create it if (!schema.equals(DEFAULT) && !connector.namespaceOperations().exists(schema)) { connector.namespaceOperations().create(schema); } } catch (AccumuloException | AccumuloSecurityException e) { throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Failed to check for existence or create Accumulo namespace", e); } catch (NamespaceExistsException e) { // Suppress race condition between test for existence and creation LOG.warn("NamespaceExistsException suppressed when creating " + schema); } }
public static String getNamespaceOpt(final CommandLine cl, final Shell shellState) throws NamespaceNotFoundException, AccumuloException, AccumuloSecurityException { String namespace = null; if (cl.hasOption(ShellOptions.namespaceOption)) { namespace = cl.getOptionValue(ShellOptions.namespaceOption); if (!shellState.getAccumuloClient().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(namespace, namespace, "specified namespace that doesn't exist"); } } else { throw new NamespaceNotFoundException(null, null, "no namespace specified"); } return namespace; }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceExistsException, NamespaceNotFoundException { if (createNamespaceOptCopyConfig == null) { getOptions(); } String namespace = cl.getArgs()[0]; shellState.getAccumuloClient().namespaceOperations().create(namespace); // Copy options if flag was set Iterable<Entry<String,String>> configuration = null; if (cl.hasOption(createNamespaceOptCopyConfig.getOpt())) { String copy = cl.getOptionValue(createNamespaceOptCopyConfig.getOpt()); if (shellState.getAccumuloClient().namespaceOperations().exists(namespace)) { configuration = shellState.getAccumuloClient().namespaceOperations().getProperties(copy); } } if (configuration != null) { for (Entry<String,String> entry : configuration) { if (Property.isValidTablePropertyKey(entry.getKey())) { shellState.getAccumuloClient().namespaceOperations().setProperty(namespace, entry.getKey(), entry.getValue()); } } } return 0; }
&& !shellState.getAccumuloClient().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(null, namespace, null);
private void createNamespaceIfNecessary(NamespaceOperations namespaceOperations, String table) throws AccumuloException, AccumuloSecurityException { // if the table has a namespace in it that doesn't already exist, create it if (table.contains(".")) { String namespace = table.split("\\.")[0]; try { if (!namespaceOperations.exists(namespace)) { namespaceOperations.create(namespace); } } catch (NamespaceExistsException e) { // in this case, somebody else must have created the namespace after our existence check log.info("Tried to create " + namespace + " but somebody beat us to the punch"); } } }
private void createNamespaceIfNecessary(NamespaceOperations namespaceOperations, String table) throws AccumuloException, AccumuloSecurityException { // if the table has a namespace in it that doesn't already exist, create it if (table.contains(".")) { String namespace = table.split("\\.")[0]; try { if (!namespaceOperations.exists(namespace)) { namespaceOperations.create(namespace); } } catch (NamespaceExistsException e) { // in this case, somebody else must have created the namespace after our existence check log.info("Tried to create Accumulo namespace," + namespace + ", but it already exists"); } } } }
public static String getNamespaceOpt(final CommandLine cl, final Shell shellState) throws NamespaceNotFoundException, AccumuloException, AccumuloSecurityException { String namespace = null; if (cl.hasOption(ShellOptions.namespaceOption)) { namespace = cl.getOptionValue(ShellOptions.namespaceOption); if (!shellState.getConnector().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(namespace, namespace, "specified namespace that doesn't exist"); } } else { throw new NamespaceNotFoundException(null, null, "no namespace specified"); } return namespace; }
@Override public boolean namespaceExists(ByteBuffer login, String namespaceName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException { try { return getConnector(login).namespaceOperations().exists(namespaceName); } catch (Exception e) { handleException(e); return false; } }
@Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException, NamespaceExistsException, NamespaceNotFoundException { if (createNamespaceOptCopyConfig == null) { getOptions(); } String namespace = cl.getArgs()[0]; shellState.getConnector().namespaceOperations().create(namespace); // Copy options if flag was set Iterable<Entry<String,String>> configuration = null; if (cl.hasOption(createNamespaceOptCopyConfig.getOpt())) { String copy = cl.getOptionValue(createNamespaceOptCopyConfig.getOpt()); if (shellState.getConnector().namespaceOperations().exists(namespace)) { configuration = shellState.getConnector().namespaceOperations().getProperties(copy); } } if (configuration != null) { for (Entry<String,String> entry : configuration) { if (Property.isValidTablePropertyKey(entry.getKey())) { shellState.getConnector().namespaceOperations().setProperty(namespace, entry.getKey(), entry.getValue()); } } } return 0; }
@Test public void createTableInMissingNamespace() throws Exception { String t = namespace + ".1"; assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t)); try { c.tableOperations().create(t); fail(); } catch (AccumuloException e) { assertEquals(NamespaceNotFoundException.class.getName(), e.getCause().getClass().getName()); assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t)); } }
String namespace = prefix.substring(0, prefix.indexOf(".")); try { if (!conn.namespaceOperations().exists(namespace)) { conn.namespaceOperations().create(namespace);
@Test(expected = NamespaceNotEmptyException.class) public void deleteNonEmptyNamespace() throws Exception { String tableName1 = namespace + ".1"; assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(tableName1)); c.namespaceOperations().create(namespace); c.tableOperations().create(tableName1); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(tableName1)); c.namespaceOperations().delete(namespace); // should fail }
@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); }
final String[] parts = metricsTable.split("\\.", 2); final String namespace = parts[0]; if (!connector.namespaceOperations().exists(namespace)) { try { LOG.info("Creating namespace " + namespace);
int choice = Integer.parseInt(parts[1]); Property property = tableSettings[choice].property; if (env.getConnector().namespaceOperations().exists(namespace)) { log.debug("Setting " + property.getKey() + " on " + namespace + " back to " + property.getDefaultValue());
String t1 = namespace + ".1"; String t2 = namespace + ".2"; assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); assertTrue(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); c.tableOperations().create(t1); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); c.tableOperations().create(t2); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t2)); c.tableOperations().delete(t1); assertTrue(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t2)); c.tableOperations().delete(t2); assertTrue(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); c.namespaceOperations().delete(namespace); assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2));
c.tableOperations().create(t1); assertTrue(c.tableOperations().exists(t1)); assertFalse(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); assertFalse(c.tableOperations().exists(t3)); assertTrue(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); assertFalse(c.tableOperations().exists(t3)); c.tableOperations().clone(t1, t, false, null, null); assertTrue(c.namespaceOperations().exists(namespace2)); assertTrue(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t2));
String v = "42K"; assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); c.tableOperations().create(t1); c.tableOperations().create(t0); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t0));