Search in sources :

Example 81 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project apex-malhar by apache.

the class AccumuloTestHelper method populateAccumulo.

public static void populateAccumulo() throws IOException {
    BatchWriterConfig config = new BatchWriterConfig();
    BatchWriter batchwriter = null;
    try {
        batchwriter = con.createBatchWriter("tab1", config);
    } catch (TableNotFoundException e) {
        logger.error("error in test helper");
        DTThrowable.rethrow(e);
    }
    try {
        for (int i = 0; i < 500; ++i) {
            String rowstr = "row" + i;
            Mutation mutation = new Mutation(rowstr.getBytes());
            for (int j = 0; j < 500; ++j) {
                String colstr = "col" + "-" + j;
                String valstr = "val" + "-" + i + "-" + j;
                mutation.put(colfam0_bytes, colstr.getBytes(), System.currentTimeMillis(), valstr.getBytes());
            }
            batchwriter.addMutation(mutation);
        }
        batchwriter.close();
    } catch (MutationsRejectedException e) {
        logger.error("error in test helper");
        DTThrowable.rethrow(e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 82 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project apex-malhar by apache.

the class AccumuloTestHelper method getAccumuloTuple.

public static AccumuloTuple getAccumuloTuple(String row, String colFam, String colName) {
    Authorizations auths = new Authorizations();
    Scanner scan = null;
    try {
        scan = con.createScanner("tab1", auths);
    } catch (TableNotFoundException e) {
        logger.error("error in test helper");
        DTThrowable.rethrow(e);
    }
    scan.setRange(new Range(new Text(row)));
    scan.fetchColumn(new Text(colFam), new Text(colName));
    // assuming only one row
    for (Entry<Key, Value> entry : scan) {
        AccumuloTuple tuple = new AccumuloTuple();
        tuple.setRow(entry.getKey().getRow().toString());
        tuple.setColFamily(entry.getKey().getColumnFamily().toString());
        tuple.setColName(entry.getKey().getColumnQualifier().toString());
        tuple.setColValue(entry.getValue().toString());
        return tuple;
    }
    return null;
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Authorizations(org.apache.accumulo.core.security.Authorizations) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 83 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project YCSB by brianfrankcooper.

the class AccumuloClient method scan.

@Override
public Status scan(String t, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        checkTable(t);
    } catch (TableNotFoundException e) {
        System.err.println("Error trying to connect to Accumulo table." + e);
        return Status.ERROR;
    }
    // There doesn't appear to be a way to create a range for a given
    // LENGTH. Just start and end keys. So we'll do this the hard way for
    // now:
    // Just make the end 'infinity' and only read as much as we need.
    scanScanner.clearColumns();
    scanScanner.setRange(new Range(new Text(startkey), null));
    // If no fields are provided, we assume one column/row.
    if (fields != null) {
        // And add each of them as fields we want.
        for (String field : fields) {
            scanScanner.fetchColumn(colFam, new Text(field));
        }
    }
    String rowKey = "";
    HashMap<String, ByteIterator> currentHM = null;
    int count = 0;
    // Begin the iteration.
    for (Entry<Key, Value> entry : scanScanner) {
        // Check for a new row.
        if (!rowKey.equals(entry.getKey().getRow().toString())) {
            if (count++ == recordcount) {
                // Done reading the last row.
                break;
            }
            rowKey = entry.getKey().getRow().toString();
            if (fields != null) {
                // Initial Capacity for all keys.
                currentHM = new HashMap<String, ByteIterator>(fields.size());
            } else {
                // An empty result map.
                currentHM = new HashMap<String, ByteIterator>();
            }
            result.add(currentHM);
        }
        // Now add the key to the hashmap.
        Value v = entry.getValue();
        byte[] buf = v.get();
        currentHM.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
    }
    return Status.OK;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Key(org.apache.accumulo.core.data.Key)

Example 84 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project YCSB by brianfrankcooper.

the class AccumuloClient method read.

@Override
public Status read(String t, String key, Set<String> fields, HashMap<String, ByteIterator> result) {
    try {
        checkTable(t);
    } catch (TableNotFoundException e) {
        System.err.println("Error trying to connect to Accumulo table." + e);
        return Status.ERROR;
    }
    try {
        // Pick out the results we care about.
        for (Entry<Key, Value> entry : getRow(new Text(key), null)) {
            Value v = entry.getValue();
            byte[] buf = v.get();
            result.put(entry.getKey().getColumnQualifier().toString(), new ByteArrayByteIterator(buf));
        }
    } catch (Exception e) {
        System.err.println("Error trying to reading Accumulo table" + key + e);
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Key(org.apache.accumulo.core.data.Key) DBException(com.yahoo.ycsb.DBException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloException(org.apache.accumulo.core.client.AccumuloException)

Example 85 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project Gaffer by gchq.

the class SplitTableTool method run.

@Override
public int run(final String[] arg0) throws OperationException {
    LOGGER.info("Running SplitTableTool");
    final Configuration conf = getConf();
    FileSystem fs;
    try {
        fs = FileSystem.get(conf);
    } catch (final IOException e) {
        throw new OperationException("Failed to get Filesystem from configuration: " + e.getMessage(), e);
    }
    final SortedSet<Text> splits = new TreeSet<>();
    try (final BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(new Path(operation.getInputPath())), CommonConstants.UTF_8))) {
        String line = br.readLine();
        while (line != null) {
            splits.add(new Text(line));
            line = br.readLine();
        }
    } catch (final IOException e) {
        throw new OperationException(e.getMessage(), e);
    }
    try {
        store.getConnection().tableOperations().addSplits(store.getProperties().getTable(), splits);
        LOGGER.info("Added {} splits to table {}", splits.size(), store.getProperties().getTable());
    } catch (final TableNotFoundException | AccumuloException | AccumuloSecurityException | StoreException e) {
        LOGGER.error("Failed to add {} split points to table {}", splits.size(), store.getProperties().getTable());
        throw new OperationException("Failed to add split points to the table specified: " + e.getMessage(), e);
    }
    return SUCCESS_RESPONSE;
}
Also used : Path(org.apache.hadoop.fs.Path) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Configuration(org.apache.hadoop.conf.Configuration) InputStreamReader(java.io.InputStreamReader) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) StoreException(uk.gov.gchq.gaffer.store.StoreException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) FileSystem(org.apache.hadoop.fs.FileSystem) BufferedReader(java.io.BufferedReader) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)160 AccumuloException (org.apache.accumulo.core.client.AccumuloException)100 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)89 Text (org.apache.hadoop.io.Text)51 Value (org.apache.accumulo.core.data.Value)46 Key (org.apache.accumulo.core.data.Key)42 Scanner (org.apache.accumulo.core.client.Scanner)36 IOException (java.io.IOException)34 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 Connector (org.apache.accumulo.core.client.Connector)30 Mutation (org.apache.accumulo.core.data.Mutation)29 Range (org.apache.accumulo.core.data.Range)28 Authorizations (org.apache.accumulo.core.security.Authorizations)26 ArrayList (java.util.ArrayList)25 Entry (java.util.Map.Entry)25 TableExistsException (org.apache.accumulo.core.client.TableExistsException)25 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)23 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)23 HashMap (java.util.HashMap)19