Search in sources :

Example 1 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project Gaffer by gchq.

the class AccumuloStore method insertGraphElements.

protected void insertGraphElements(final Iterable<Element> elements) throws StoreException {
    // Create BatchWriter
    final BatchWriter writer = TableUtils.createBatchWriter(this);
    // too high a latency, etc.
    if (elements != null) {
        for (final Element element : elements) {
            final Pair<Key> keys;
            try {
                keys = keyPackage.getKeyConverter().getKeysFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error("Failed to create an accumulo key from element of type " + element.getGroup() + " when trying to insert elements");
                continue;
            }
            final Value value;
            try {
                value = keyPackage.getKeyConverter().getValueFromElement(element);
            } catch (final AccumuloElementConversionException e) {
                LOGGER.error("Failed to create an accumulo value from element of type " + element.getGroup() + " when trying to insert elements");
                continue;
            }
            final Mutation m = new Mutation(keys.getFirst().getRow());
            m.put(keys.getFirst().getColumnFamily(), keys.getFirst().getColumnQualifier(), new ColumnVisibility(keys.getFirst().getColumnVisibility()), keys.getFirst().getTimestamp(), value);
            try {
                writer.addMutation(m);
            } catch (final MutationsRejectedException e) {
                LOGGER.error("Failed to create an accumulo key mutation");
                continue;
            }
            // If the GraphElement is an Edge then there will be 2 keys.
            if (keys.getSecond() != null) {
                final Mutation m2 = new Mutation(keys.getSecond().getRow());
                m2.put(keys.getSecond().getColumnFamily(), keys.getSecond().getColumnQualifier(), new ColumnVisibility(keys.getSecond().getColumnVisibility()), keys.getSecond().getTimestamp(), value);
                try {
                    writer.addMutation(m2);
                } catch (final MutationsRejectedException e) {
                    LOGGER.error("Failed to create an accumulo key mutation");
                }
            }
        }
    } else {
        throw new GafferRuntimeException("Could not find any elements to add to graph.", Status.BAD_REQUEST);
    }
    try {
        writer.close();
    } catch (final MutationsRejectedException e) {
        LOGGER.warn("Accumulo batch writer failed to close", e);
    }
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) GafferRuntimeException(uk.gov.gchq.gaffer.core.exception.GafferRuntimeException)

Example 2 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class ProxyServer method addUpdatesToMutation.

private void addUpdatesToMutation(HashMap<Text, ColumnVisibility> vizMap, Mutation m, List<ColumnUpdate> cu) {
    for (ColumnUpdate update : cu) {
        ColumnVisibility viz = EMPTY_VIS;
        if (update.isSetColVisibility()) {
            viz = getCahcedCV(vizMap, update.getColVisibility());
        }
        byte[] value = new byte[0];
        if (update.isSetValue())
            value = update.getValue();
        if (update.isSetTimestamp()) {
            if (update.isSetDeleteCell() && update.isDeleteCell()) {
                m.putDelete(update.getColFamily(), update.getColQualifier(), viz, update.getTimestamp());
            } else {
                m.put(update.getColFamily(), update.getColQualifier(), viz, update.getTimestamp(), value);
            }
        } else {
            if (update.isSetDeleteCell() && update.isDeleteCell()) {
                m.putDelete(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz);
            } else {
                m.put(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz, new Value(value));
            }
        }
    }
}
Also used : ColumnUpdate(org.apache.accumulo.proxy.thrift.ColumnUpdate) Value(org.apache.accumulo.core.data.Value) KeyValue(org.apache.accumulo.proxy.thrift.KeyValue) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility)

Example 3 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class ProxyServer method addCellsToWriter.

void addCellsToWriter(Map<ByteBuffer, List<ColumnUpdate>> cells, BatchWriterPlusProblem bwpe) {
    if (bwpe.exception != null)
        return;
    HashMap<Text, ColumnVisibility> vizMap = new HashMap<>();
    for (Map.Entry<ByteBuffer, List<ColumnUpdate>> entry : cells.entrySet()) {
        Mutation m = new Mutation(ByteBufferUtil.toBytes(entry.getKey()));
        addUpdatesToMutation(vizMap, m, entry.getValue());
        try {
            bwpe.writer.addMutation(m);
        } catch (MutationsRejectedException mre) {
            bwpe.exception = mre;
        }
    }
}
Also used : HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Mutation(org.apache.accumulo.core.data.Mutation) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Map(java.util.Map) HashMap(java.util.HashMap) ByteBuffer(java.nio.ByteBuffer) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 4 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class ProxyServer method updateRowsConditionally.

@Override
public Map<ByteBuffer, ConditionalStatus> updateRowsConditionally(String conditionalWriter, Map<ByteBuffer, ConditionalUpdates> updates) throws UnknownWriter, org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, TException {
    ConditionalWriter cw = conditionalWriterCache.getIfPresent(UUID.fromString(conditionalWriter));
    if (cw == null) {
        throw new UnknownWriter();
    }
    try {
        HashMap<Text, ColumnVisibility> vizMap = new HashMap<>();
        ArrayList<ConditionalMutation> cmuts = new ArrayList<>(updates.size());
        for (Entry<ByteBuffer, ConditionalUpdates> cu : updates.entrySet()) {
            ConditionalMutation cmut = new ConditionalMutation(ByteBufferUtil.toBytes(cu.getKey()));
            for (Condition tcond : cu.getValue().conditions) {
                org.apache.accumulo.core.data.Condition cond = new org.apache.accumulo.core.data.Condition(tcond.column.getColFamily(), tcond.column.getColQualifier());
                if (tcond.getColumn().getColVisibility() != null && tcond.getColumn().getColVisibility().length > 0) {
                    cond.setVisibility(getCahcedCV(vizMap, tcond.getColumn().getColVisibility()));
                }
                if (tcond.isSetValue())
                    cond.setValue(tcond.getValue());
                if (tcond.isSetTimestamp())
                    cond.setTimestamp(tcond.getTimestamp());
                if (tcond.isSetIterators()) {
                    cond.setIterators(getIteratorSettings(tcond.getIterators()).toArray(new IteratorSetting[tcond.getIterators().size()]));
                }
                cmut.addCondition(cond);
            }
            addUpdatesToMutation(vizMap, cmut, cu.getValue().updates);
            cmuts.add(cmut);
        }
        Iterator<Result> results = cw.write(cmuts.iterator());
        HashMap<ByteBuffer, ConditionalStatus> resultMap = new HashMap<>();
        while (results.hasNext()) {
            Result result = results.next();
            ByteBuffer row = ByteBuffer.wrap(result.getMutation().getRow());
            ConditionalStatus status = ConditionalStatus.valueOf(result.getStatus().name());
            resultMap.put(row, status);
        }
        return resultMap;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScanResult(org.apache.accumulo.proxy.thrift.ScanResult) Result(org.apache.accumulo.core.client.ConditionalWriter.Result) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) UnknownWriter(org.apache.accumulo.proxy.thrift.UnknownWriter) ConditionalUpdates(org.apache.accumulo.proxy.thrift.ConditionalUpdates) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Condition(org.apache.accumulo.proxy.thrift.Condition) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) 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) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ConditionalStatus(org.apache.accumulo.proxy.thrift.ConditionalStatus)

Example 5 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class DeleterFormatter method next.

/**
 * @return null, because the iteration will provide prompts and handle deletes internally.
 */
@Override
public String next() {
    Entry<Key, Value> next = getScannerIterator().next();
    Key key = next.getKey();
    Mutation m = new Mutation(key.getRow());
    String entryStr = formatEntry(next, isDoTimestamps());
    boolean delete = force;
    try {
        if (!force) {
            shellState.getReader().flush();
            String line = shellState.getReader().readLine("Delete { " + entryStr + " } ? ");
            more = line != null;
            delete = line != null && (line.equalsIgnoreCase("y") || line.equalsIgnoreCase("yes"));
        }
        if (delete) {
            m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
            try {
                writer.addMutation(m);
            } catch (MutationsRejectedException e) {
                log.error(e.toString());
                if (Shell.isDebuggingEnabled())
                    for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) log.trace(cvs.toString());
            }
        }
        shellState.getReader().print(String.format("[%s] %s%n", delete ? "DELETED" : "SKIPPED", entryStr));
    } catch (IOException e) {
        log.error("Cannot write to console", e);
        throw new RuntimeException(e);
    }
    return null;
}
Also used : Value(org.apache.accumulo.core.data.Value) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) IOException(java.io.IOException) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Aggregations

ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)131 Mutation (org.apache.accumulo.core.data.Mutation)57 Text (org.apache.hadoop.io.Text)57 Value (org.apache.accumulo.core.data.Value)52 Key (org.apache.accumulo.core.data.Key)39 Test (org.junit.Test)37 BatchWriter (org.apache.accumulo.core.client.BatchWriter)28 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)20 Authorizations (org.apache.accumulo.core.security.Authorizations)17 ArrayList (java.util.ArrayList)16 Entry (java.util.Map.Entry)16 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 Scanner (org.apache.accumulo.core.client.Scanner)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)12 Configuration (org.apache.hadoop.conf.Configuration)12 Connector (org.apache.accumulo.core.client.Connector)10 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10 TMutation (org.apache.accumulo.core.data.thrift.TMutation)10 Element (uk.gov.gchq.gaffer.data.element.Element)9