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);
}
}
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));
}
}
}
}
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;
}
}
}
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;
}
}
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;
}
Aggregations