@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; }
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.");
@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); } }
@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()); }
@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 missingVolumePreferredVolumeChooser() throws Exception { log.info("Starting missingVolumePreferredVolumeChooser"); // 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); // 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()); }
private void changeNamespaceSetting(RandomDataGenerator random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, tableSettings.length - 1); Setting setting = tableSettings[choice]; // pick a random table SortedSet<String> namespaces = env.getConnector().namespaceOperations().list().tailSet("nspc") .headSet("nspd"); if (namespaces.isEmpty()) return; String namespace = random.nextSample(namespaces, 1)[0].toString(); // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_NAMESPACE_SETTING, namespace + "," + choice); log.debug( "Setting " + setting.property.getKey() + " on namespace " + namespace + " to " + newValue); try { env.getConnector().namespaceOperations().setProperty(namespace, setting.property.getKey(), "" + newValue); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NAMESPACE_NOTFOUND) return; } throw ex; } }
connector.namespaceOperations().setProperty(namespace1, propertyName, volume); connector.namespaceOperations().setProperty(namespace2, propertyName, volume);
new ColumnVisibility(value); // validate that it is a valid expression shellState.getConnector().namespaceOperations().setProperty(namespace, property, value); Shell.log.debug("Successfully set table configuration option."); } else {
connector.namespaceOperations().setProperty(namespace1, propertyName, volume); connector.namespaceOperations().setProperty(namespace2, propertyName, volume); connector.namespaceOperations().setProperty(namespace2, propertyName, volume);
connector.namespaceOperations().setProperty(namespace1, propertyName, volume); connector.namespaceOperations().setProperty(namespace1, propertyName, volume); connector.namespaceOperations().setProperty(namespace2, propertyName, volume); connector.namespaceOperations().setProperty(namespace2, propertyName, volume);
+ property.getDefaultValue()); try { env.getConnector().namespaceOperations().setProperty(namespace, property.getKey(), property.getDefaultValue()); } catch (AccumuloException ex) {
break; case 12: ops.setProperty(namespace, "k", "v"); fail(); break;
root_conn.namespaceOperations().create(namespace); loginAs(testUser); test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%"); loginAs(rootUser);
try { loginAs(testUser); test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%"); throw new IllegalStateException("Should NOT be able to set a namespace property"); root_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%"); try {
user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "55"); fail(); } catch (AccumuloSecurityException e) { c.securityOperations().grantNamespacePermission(u1, n1, NamespacePermission.ALTER_NAMESPACE); loginAs(user1); user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "42"); user1Con.namespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey()); loginAs(root); user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33"); fail(); } catch (AccumuloSecurityException e) { c.securityOperations().grantSystemPermission(u1, SystemPermission.ALTER_NAMESPACE); loginAs(user1); user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33"); user1Con.namespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey()); loginAs(root);
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));
c.namespaceOperations().setProperty(namespace, k, v); assertTrue(checkNamespaceHasProp(namespace, k, v)); assertTrue(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));