Search in sources :

Example 21 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class CreateTableCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException, ClassNotFoundException {
    final String testTableName = cl.getArgs()[0];
    final HashMap<String, String> props = new HashMap<>();
    NewTableConfiguration ntc = new NewTableConfiguration();
    if (!testTableName.matches(Tables.VALID_NAME_REGEX)) {
        shellState.getReader().println("Only letters, numbers and underscores are allowed for use in table names.");
        throw new IllegalArgumentException();
    }
    final String tableName = cl.getArgs()[0];
    if (shellState.getConnector().tableOperations().exists(tableName)) {
        throw new TableExistsException(null, tableName, null);
    }
    final SortedSet<Text> partitions = new TreeSet<>();
    final boolean decode = cl.hasOption(base64Opt.getOpt());
    if (cl.hasOption(createTableOptSplit.getOpt())) {
        partitions.addAll(ShellUtil.scanFile(cl.getOptionValue(createTableOptSplit.getOpt()), decode));
    } else if (cl.hasOption(createTableOptCopySplits.getOpt())) {
        final String oldTable = cl.getOptionValue(createTableOptCopySplits.getOpt());
        if (!shellState.getConnector().tableOperations().exists(oldTable)) {
            throw new TableNotFoundException(null, oldTable, null);
        }
        partitions.addAll(shellState.getConnector().tableOperations().listSplits(oldTable));
    }
    if (cl.hasOption(createTableOptCopyConfig.getOpt())) {
        final String oldTable = cl.getOptionValue(createTableOptCopyConfig.getOpt());
        if (!shellState.getConnector().tableOperations().exists(oldTable)) {
            throw new TableNotFoundException(null, oldTable, null);
        }
    }
    TimeType timeType = TimeType.MILLIS;
    if (cl.hasOption(createTableOptTimeLogical.getOpt())) {
        timeType = TimeType.LOGICAL;
    }
    if (cl.hasOption(createTableOptInitProp.getOpt())) {
        String[] keyVals = StringUtils.split(cl.getOptionValue(createTableOptInitProp.getOpt()), ',');
        for (String keyVal : keyVals) {
            String[] sa = StringUtils.split(keyVal, '=');
            props.put(sa[0], sa[1]);
        }
    }
    // Set iterator if supplied
    if (cl.hasOption(createTableOptIteratorProps.getOpt())) {
        ntc = attachIteratorToNewTable(cl, shellState, ntc);
    }
    // Set up locality groups, if supplied
    if (cl.hasOption(createTableOptLocalityProps.getOpt())) {
        ntc = setLocalityForNewTable(cl, ntc);
    }
    // create table
    shellState.getConnector().tableOperations().create(tableName, ntc.setTimeType(timeType).setProperties(props));
    if (partitions.size() > 0) {
        shellState.getConnector().tableOperations().addSplits(tableName, partitions);
    }
    // switch shell to new table context
    shellState.setTableName(tableName);
    if (cl.hasOption(createTableNoDefaultIters.getOpt())) {
        for (String key : IteratorUtil.generateInitialTableProperties(true).keySet()) {
            shellState.getConnector().tableOperations().removeProperty(tableName, key);
        }
    }
    // Copy options if flag was set
    if (cl.hasOption(createTableOptCopyConfig.getOpt())) {
        if (shellState.getConnector().tableOperations().exists(tableName)) {
            final Iterable<Entry<String, String>> configuration = shellState.getConnector().tableOperations().getProperties(cl.getOptionValue(createTableOptCopyConfig.getOpt()));
            for (Entry<String, String> entry : configuration) {
                if (Property.isValidTablePropertyKey(entry.getKey())) {
                    shellState.getConnector().tableOperations().setProperty(tableName, entry.getKey(), entry.getValue());
                }
            }
        }
    }
    if (cl.hasOption(createTableOptEVC.getOpt())) {
        try {
            shellState.getConnector().tableOperations().addConstraint(tableName, VisibilityConstraint.class.getName());
        } catch (AccumuloException e) {
            Shell.log.warn(e.getMessage() + " while setting visibility constraint, but table was created");
        }
    }
    // Load custom formatter if set
    if (cl.hasOption(createTableOptFormatter.getOpt())) {
        final String formatterClass = cl.getOptionValue(createTableOptFormatter.getOpt());
        shellState.getConnector().tableOperations().setProperty(tableName, Property.TABLE_FORMATTER_CLASS.toString(), formatterClass);
    }
    return 0;
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) HashMap(java.util.HashMap) VisibilityConstraint(org.apache.accumulo.core.constraints.VisibilityConstraint) Text(org.apache.hadoop.io.Text) TimeType(org.apache.accumulo.core.client.admin.TimeType) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TreeSet(java.util.TreeSet) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 22 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class ProxyServer method createTable.

@Override
public void createTable(ByteBuffer login, String tableName, boolean versioningIter, org.apache.accumulo.proxy.thrift.TimeType type) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableExistsException, TException {
    try {
        if (type == null)
            type = org.apache.accumulo.proxy.thrift.TimeType.MILLIS;
        NewTableConfiguration tConfig = new NewTableConfiguration().setTimeType(TimeType.valueOf(type.toString()));
        if (!versioningIter)
            tConfig = tConfig.withoutDefaultIterators();
        getConnector(login).tableOperations().create(tableName, tConfig);
    } catch (TableExistsException e) {
        throw new org.apache.accumulo.proxy.thrift.TableExistsException(e.toString());
    } catch (Exception e) {
        handleException(e);
    }
}
Also used : NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) NoMoreEntriesException(org.apache.accumulo.proxy.thrift.NoMoreEntriesException) ThriftTableOperationException(org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotEmptyException(org.apache.accumulo.core.client.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 23 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo-examples by apache.

the class InsertWithBatchWriter method main.

public static void main(String[] args) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    Connector connector = Connector.builder().usingProperties("conf/accumulo-client.properties").build();
    try {
        connector.tableOperations().create("hellotable");
    } catch (TableExistsException e) {
    // ignore
    }
    try (BatchWriter bw = connector.createBatchWriter("hellotable")) {
        log.trace("writing ...");
        for (int i = 0; i < 10000; i++) {
            Mutation m = new Mutation(String.format("row_%d", i));
            for (int j = 0; j < 5; j++) {
                m.put("colfam", String.format("colqual_%d", j), new Value((String.format("value_%d_%d", i, j)).getBytes()));
            }
            bw.addMutation(m);
            if (i % 100 == 0) {
                log.trace(String.valueOf(i));
            }
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation)

Example 24 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableOperationsImpl method importDirectory.

@Override
public void importDirectory(String tableName, String dir, String failureDir, boolean setTime) throws IOException, AccumuloSecurityException, TableNotFoundException, AccumuloException {
    checkArgument(tableName != null, "tableName is null");
    checkArgument(dir != null, "dir is null");
    checkArgument(failureDir != null, "failureDir is null");
    // check for table existance
    Tables.getTableId(context.getInstance(), tableName);
    Path dirPath = checkPath(dir, "Bulk", "");
    Path failPath = checkPath(failureDir, "Bulk", "failure");
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(UTF_8)), ByteBuffer.wrap(dirPath.toString().getBytes(UTF_8)), ByteBuffer.wrap(failPath.toString().getBytes(UTF_8)), ByteBuffer.wrap((setTime + "").getBytes(UTF_8)));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_BULK_IMPORT, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Example 25 with TableExistsException

use of org.apache.accumulo.core.client.TableExistsException in project accumulo by apache.

the class TableOperationsImpl method deleteRows.

@Override
public void deleteRows(String tableName, Text start, Text end) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    checkArgument(tableName != null, "tableName is null");
    ByteBuffer EMPTY = ByteBuffer.allocate(0);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableName.getBytes(UTF_8)), start == null ? EMPTY : TextUtil.getByteBuffer(start), end == null ? EMPTY : TextUtil.getByteBuffer(end));
    Map<String, String> opts = new HashMap<>();
    try {
        doTableFateOperation(tableName, TableNotFoundException.class, FateOperation.TABLE_DELETE_RANGE, args, opts);
    } catch (TableExistsException e) {
        // should not happen
        throw new AssertionError(e);
    }
}
Also used : HashMap(java.util.HashMap) TableExistsException(org.apache.accumulo.core.client.TableExistsException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TableExistsException (org.apache.accumulo.core.client.TableExistsException)32 AccumuloException (org.apache.accumulo.core.client.AccumuloException)21 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)17 Connector (org.apache.accumulo.core.client.Connector)9 IOException (java.io.IOException)8 BatchWriter (org.apache.accumulo.core.client.BatchWriter)8 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 Value (org.apache.accumulo.core.data.Value)7 HashMap (java.util.HashMap)6 Mutation (org.apache.accumulo.core.data.Mutation)6 ByteBuffer (java.nio.ByteBuffer)5 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)4 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)4 Key (org.apache.accumulo.core.data.Key)4 Text (org.apache.hadoop.io.Text)4 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)3 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)3