/** * 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); } }
@Test(expected = AccumuloSecurityException.class) public void deleteDefaultNamespace() throws Exception { c.namespaceOperations().delete(Namespaces.DEFAULT_NAMESPACE); // should fail }
@Test(expected = AccumuloSecurityException.class) public void deleteAccumuloNamespace() throws Exception { c.namespaceOperations().delete(Namespaces.ACCUMULO_NAMESPACE); // should fail }
@Test public void loadClass() throws Exception { assertTrue(c.namespaceOperations().testClassLoad(Namespaces.DEFAULT_NAMESPACE, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName())); assertFalse(c.namespaceOperations().testClassLoad(Namespaces.DEFAULT_NAMESPACE, "dummy", SortedKeyValueIterator.class.getName())); try { c.namespaceOperations().testClassLoad(namespace, "dummy", "dummy"); fail(); } catch (NamespaceNotFoundException e) { // expected, ignore } }
@Override public List<String> listNamespaces(ByteBuffer login) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException { try { return new LinkedList<>(getConnector(login).namespaceOperations().list()); } catch (Exception e) { handleException(e); return null; } }
@Test public void checkReservedNamespaces() throws Exception { assertEquals(c.namespaceOperations().defaultNamespace(), Namespaces.DEFAULT_NAMESPACE); assertEquals(c.namespaceOperations().systemNamespace(), Namespaces.ACCUMULO_NAMESPACE); }
@Test public void checkBuiltInNamespaces() throws Exception { assertTrue(c.namespaceOperations().exists(Namespaces.DEFAULT_NAMESPACE)); assertTrue(c.namespaceOperations().exists(Namespaces.ACCUMULO_NAMESPACE)); }
@Override public void setNamespaceProperty(ByteBuffer login, String namespaceName, String property, String value) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { getConnector(login).namespaceOperations().setProperty(namespaceName, property, value); } catch (Exception e) { handleExceptionNNF(e); } }
@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 Map<String,Integer> listNamespaceConstraints(ByteBuffer login, String namespaceName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { return getConnector(login).namespaceOperations().listConstraints(namespaceName); } catch (Exception e) { handleExceptionNNF(e); return null; } }
@Override public Map<String,String> namespaceIdMap(ByteBuffer login) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException { try { return getConnector(login).namespaceOperations().namespaceIdMap(); } catch (Exception e) { handleException(e); return null; } }
@Override public int addNamespaceConstraint(ByteBuffer login, String namespaceName, String constraintClassName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { return getConnector(login).namespaceOperations().addConstraint(namespaceName, constraintClassName); } catch (Exception e) { handleExceptionNNF(e); return -1; } }
@Override public boolean testNamespaceClassLoad(ByteBuffer login, String namespaceName, String className, String asTypeName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { return getConnector(login).namespaceOperations().testClassLoad(namespaceName, className, asTypeName); } catch (Exception e) { handleExceptionNNF(e); return false; } }
@Override public void removeNamespaceProperty(ByteBuffer login, String namespaceName, String property) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { getConnector(login).namespaceOperations().removeProperty(namespaceName, property); } catch (Exception e) { handleExceptionNNF(e); } }
@Override public void removeNamespaceConstraint(ByteBuffer login, String namespaceName, int id) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { getConnector(login).namespaceOperations().removeConstraint(namespaceName, id); } catch (Exception e) { handleExceptionNNF(e); } }
@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 }
@Override public void removeNamespaceIterator(ByteBuffer login, String namespaceName, String name, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { getConnector(login).namespaceOperations().removeIterator(namespaceName, name, getIteratorScopes(scopes)); } catch (Exception e) { handleExceptionNNF(e); } }
@Override public void createNamespace(ByteBuffer login, String namespaceName) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceExistsException, TException { try { getConnector(login).namespaceOperations().create(namespaceName); } catch (NamespaceExistsException e) { throw new org.apache.accumulo.proxy.thrift.NamespaceExistsException(e.toString()); } catch (Exception e) { handleException(e); } }
@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)); } }
@Override public void checkNamespaceIteratorConflicts(ByteBuffer login, String namespaceName, org.apache.accumulo.proxy.thrift.IteratorSetting setting, Set<org.apache.accumulo.proxy.thrift.IteratorScope> scopes) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.NamespaceNotFoundException, TException { try { getConnector(login).namespaceOperations().checkIteratorConflicts(namespaceName, getIteratorSetting(setting), getIteratorScopes(scopes)); } catch (Exception e) { handleExceptionNNF(e); } }