/** * 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); } }
namespaces = accumuloClient.namespaceOperations().list(); } catch (Exception e) { log.debug("Unable to obtain list of namespaces", e);
@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; }
if (!shellState.getAccumuloClient().namespaceOperations().testClassLoad(namespace, classname, SortedKeyValueIterator.class.getName())) { throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, shellState.getAccumuloClient().namespaceOperations().attachIterator(namespace, setting, scopes);
assertFalse(ops.exists(namespace)); switch (i) { case 0: ops.addConstraint(namespace, NumericValueConstraint.class.getName()); fail(); break; case 1: ops.attachIterator(namespace, setting); fail(); break; case 2: ops.checkIteratorConflicts(namespace, setting, EnumSet.of(IteratorScope.scan)); fail(); break; case 3: ops.delete(namespace); fail(); break; case 4: ops.getIteratorSetting(namespace, "thing", IteratorScope.scan); fail(); break; case 5: ops.getProperties(namespace); fail(); break; case 6: ops.listConstraints(namespace);
namespace = "__CREATE_NAMESPACE_WITH_PERM_TEST__"; loginAs(testUser); test_user_conn.namespaceOperations().create(namespace); loginAs(rootUser); if (!root_conn.namespaceOperations().list().contains(namespace)) throw new IllegalStateException("Should be able to create a namespace"); break; namespace = "__DROP_NAMESPACE_WITH_PERM_TEST__"; loginAs(rootUser); root_conn.namespaceOperations().create(namespace); loginAs(testUser); test_user_conn.namespaceOperations().delete(namespace); loginAs(rootUser); if (root_conn.namespaceOperations().list().contains(namespace)) throw new IllegalStateException("Should be able to delete a namespace"); break; String namespace2 = namespace + "2"; loginAs(rootUser); root_conn.namespaceOperations().create(namespace); loginAs(testUser); test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%"); loginAs(rootUser); Map<String,String> propies = map(root_conn.namespaceOperations().getProperties(namespace)); if (!propies.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%")) throw new IllegalStateException("Should be able to set a table property"); loginAs(testUser);
assertFalse(c.namespaceOperations().exists(namespace)); assertFalse(c.tableOperations().exists(t1)); assertFalse(c.tableOperations().exists(t2)); c.namespaceOperations().create(namespace); c.tableOperations().create(t1); c.tableOperations().create(t0); assertTrue(c.namespaceOperations().exists(namespace)); assertTrue(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t0)); c.namespaceOperations().setProperty(namespace, k, v); assertTrue(checkNamespaceHasProp(namespace, k, v)); assertTrue(checkTableHasProp(t1, k, v)); c.namespaceOperations().removeProperty(namespace, k); assertFalse(checkNamespaceHasProp(namespace, k, v)); assertFalse(checkTableHasProp(t1, k, v)); c.namespaceOperations().setProperty(Namespaces.DEFAULT_NAMESPACE, k, v); assertFalse(checkNamespaceHasProp(namespace, k, v)); assertFalse(checkTableHasProp(t1, k, v)); c.namespaceOperations().setProperty(namespace, k2, v2); c.tableOperations().setProperty(t2, k2, table_v2); assertTrue(checkNamespaceHasProp(namespace, k2, v2)); c.tableOperations().delete(t2); c.tableOperations().delete(t0); c.namespaceOperations().delete(namespace);
@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); }
@Test public void verifyIteratorInheritance() throws Exception { String t1 = namespace + ".1"; c.namespaceOperations().create(namespace); c.tableOperations().create(t1); String iterName = namespace + "_iter"; assertFalse(c.namespaceOperations().listIterators(namespace).containsKey(iterName)); assertFalse(c.tableOperations().listIterators(t1).containsKey(iterName)); c.namespaceOperations().checkIteratorConflicts(namespace, setting, EnumSet.allOf(IteratorScope.class)); c.namespaceOperations().attachIterator(namespace, setting); sleepUninterruptibly(2, TimeUnit.SECONDS); try { c.namespaceOperations().checkIteratorConflicts(namespace, setting, EnumSet.allOf(IteratorScope.class)); fail(); IteratorSetting setting2 = c.namespaceOperations().getIteratorSetting(namespace, setting.getName(), IteratorScope.scan); assertEquals(setting, setting2); assertTrue(c.namespaceOperations().listIterators(namespace).containsKey(iterName)); assertTrue(c.tableOperations().listIterators(t1).containsKey(iterName)); s = c.createScanner(t1, Authorizations.EMPTY); c.namespaceOperations().removeIterator(namespace, setting.getName(), EnumSet.allOf(IteratorScope.class)); sleepUninterruptibly(2, TimeUnit.SECONDS); assertFalse(c.namespaceOperations().listIterators(namespace).containsKey(iterName));
@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 }
&& !shellState.getAccumuloClient().namespaceOperations().exists(namespace)) { throw new NamespaceNotFoundException(null, namespace, null); + ", still removing from zookeeper if it's there."); shellState.getAccumuloClient().namespaceOperations().removeProperty(namespace, property); Shell.log.debug("Successfully deleted namespace configuration option."); } else { new ColumnVisibility(value); // validate that it is a valid expression shellState.getAccumuloClient().namespaceOperations().setProperty(namespace, property, value); Shell.log.debug("Successfully set table configuration option."); shellState.getContext(), Tables.getTableId(shellState.getContext(), tableName))); for (Entry<String,String> e : shellState.getAccumuloClient().namespaceOperations() .getProperties(n)) { namespaceConfig.put(e.getKey(), e.getValue()); acuconf = shellState.getAccumuloClient().tableOperations().getProperties(tableName); } else if (namespace != null) { acuconf = shellState.getAccumuloClient().namespaceOperations().getProperties(namespace);
@Test public void listNamespaces() throws Exception { SortedSet<String> namespaces = c.namespaceOperations().list(); Map<String,String> map = c.namespaceOperations().namespaceIdMap(); assertEquals(2, namespaces.size()); assertEquals(2, map.size()); assertNull(map.get(namespace)); c.namespaceOperations().create(namespace); namespaces = c.namespaceOperations().list(); map = c.namespaceOperations().namespaceIdMap(); assertEquals(3, namespaces.size()); assertEquals(3, map.size()); assertNotNull(map.get(namespace)); c.namespaceOperations().delete(namespace); namespaces = c.namespaceOperations().list(); map = c.namespaceOperations().namespaceIdMap(); assertEquals(2, namespaces.size()); assertEquals(2, map.size());
@Test public void notInstancePreferredVolumeChooser() throws Exception { log.info("Starting notInstancePreferredVolumeChooser"); // Create namespace Connector connector = getConnector(); connector.namespaceOperations().create(namespace1); // Set properties on the namespace String propertyName = Property.TABLE_VOLUME_CHOOSER.getKey(); String volume = PreferredVolumeChooser.class.getName(); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); propertyName = "table.custom.preferredVolumes"; volume = v3.toString(); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); // Create table1 on namespace1 String tableName = namespace1 + ".1"; connector.tableOperations().create(tableName); String tableID = connector.tableOperations().tableIdMap().get(tableName); // Add 10 splits to the table addSplits(connector, tableName); // Write some data to the table writeAndReadData(connector, tableName); // Verify the new files are written to the Volumes specified verifyVolumes(connector, tableName, TabletsSection.getRange(tableID), v1.toString() + "," + v2.toString() + "," + v4.toString()); }
c.namespaceOperations().create(namespace); c.tableOperations().create(t1); assertTrue(c.tableOperations().exists(t1)); assertFalse(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); assertFalse(c.tableOperations().exists(t3)); c.namespaceOperations().create(namespace2); c.tableOperations().create(t2); c.tableOperations().create(t3); assertTrue(c.namespaceOperations().exists(namespace2)); assertFalse(c.tableOperations().exists(t2)); assertFalse(c.tableOperations().exists(t3)); assertFalse(checkTableHasProp(t1, k2, k2v1)); assertFalse(checkTableHasProp(t1, k2, k2v2)); c.namespaceOperations().setProperty(namespace, k1, k1v1); c.namespaceOperations().setProperty(namespace2, k1, k1v2); c.namespaceOperations().setProperty(namespace, k2, k2v1); c.namespaceOperations().setProperty(namespace2, k2, k2v1); c.tableOperations().setProperty(t1, k2, k2v2); assertTrue(checkNamespaceHasProp(namespace, k1, k1v1)); assertTrue(c.namespaceOperations().exists(namespace2)); assertTrue(c.tableOperations().exists(t1)); assertTrue(c.tableOperations().exists(t2));
@Test public void verifyConstraintInheritance() throws Exception { String t1 = namespace + ".1"; c.namespaceOperations().create(namespace); c.tableOperations().create(t1, new NewTableConfiguration().withoutDefaultIterators()); String constraintClassName = NumericValueConstraint.class.getName(); c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName)); assertFalse(c.tableOperations().listConstraints(t1).containsKey(constraintClassName)); c.namespaceOperations().addConstraint(namespace, constraintClassName); boolean passed = false; for (int i = 0; i < 5; i++) { if (!c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName)) { Thread.sleep(500); continue; Integer namespaceNum = null; for (int i = 0; i < 5; i++) { namespaceNum = c.namespaceOperations().listConstraints(namespace).get(constraintClassName); if (null == namespaceNum) { Thread.sleep(500); c.namespaceOperations().removeConstraint(namespace, namespaceNum); passed = false; for (int i = 0; i < 5; i++) { if (c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName)) { Thread.sleep(500); continue;
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; }
for (String constraint : cl.getArgs()) { if (namespace != null) { if (!shellState.getAccumuloClient().namespaceOperations().testClassLoad(namespace, constraint, Constraint.class.getName())) { throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, + Constraint.class.getName()); i = shellState.getAccumuloClient().namespaceOperations().addConstraint(namespace, constraint); shellState.getReader().println("Added constraint " + constraint + " to namespace " i = Integer.parseInt(constraint); if (namespace != null) { shellState.getAccumuloClient().namespaceOperations().removeConstraint(namespace, i); shellState.getReader() .println("Removed constraint " + i + " from namespace " + namespace); if (namespace != null) { for (Entry<String,Integer> property : shellState.getAccumuloClient().namespaceOperations() .listConstraints(namespace).entrySet()) { shellState.getReader().println(property.toString());
@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 namespace = namespaces.get(rand.nextInt(namespaces.size())); try { conn.namespaceOperations().create(namespace); log.debug("Created namespace " + namespace); } catch (NamespaceExistsException e) { log.debug("Create namespace " + namespace + " failed, it exists"); } } }
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()); try { env.getConnector().namespaceOperations().setProperty(namespace, property.getKey(), property.getDefaultValue()); } catch (AccumuloException ex) {