Search in sources :

Example 81 with ColumnVisibility

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

the class MutationTest method test4.

@Test
public void test4() throws Exception {
    Mutation m1 = new Mutation(new Text("r1"));
    m1.put(nt("cf1"), nt("cq1"), nv("v1"));
    m1.put(nt("cf2"), nt("cq2"), new ColumnVisibility("cv2"), nv("v2"));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    m1.write(dos);
    dos.close();
    Mutation m2 = new Mutation(new Text("r2"));
    m2.put(nt("cf3"), nt("cq3"), nv("v3"));
    m2.put(nt("cf4"), nt("cq4"), new ColumnVisibility("cv2"), nv("v4"));
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    DataInputStream dis = new DataInputStream(bis);
    // used to be a bug where puts done before readFields would be seen
    // after readFields
    m2.readFields(dis);
    assertEquals("r1", new String(m2.getRow()));
    assertEquals(2, m2.getUpdates().size());
    assertEquals(2, m2.size());
    verifyColumnUpdate(m2.getUpdates().get(0), "cf1", "cq1", "", 0l, false, false, "v1");
    verifyColumnUpdate(m2.getUpdates().get(1), "cf2", "cq2", "cv2", 0l, false, false, "v2");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Text(org.apache.hadoop.io.Text) TMutation(org.apache.accumulo.core.data.thrift.TMutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 82 with ColumnVisibility

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

the class MutationTest method testPuts.

@Test
public void testPuts() {
    Mutation m = new Mutation(new Text("r1"));
    m.put(nt("cf1"), nt("cq1"), nv("v1"));
    m.put(nt("cf2"), nt("cq2"), new ColumnVisibility("cv2"), nv("v2"));
    m.put(nt("cf3"), nt("cq3"), 3l, nv("v3"));
    m.put(nt("cf4"), nt("cq4"), new ColumnVisibility("cv4"), 4l, nv("v4"));
    m.putDelete(nt("cf5"), nt("cq5"));
    m.putDelete(nt("cf6"), nt("cq6"), new ColumnVisibility("cv6"));
    m.putDelete(nt("cf7"), nt("cq7"), 7l);
    m.putDelete(nt("cf8"), nt("cq8"), new ColumnVisibility("cv8"), 8l);
    assertEquals(8, m.size());
    List<ColumnUpdate> updates = m.getUpdates();
    assertEquals(8, m.size());
    assertEquals(8, updates.size());
    verifyColumnUpdate(updates.get(0), "cf1", "cq1", "", 0l, false, false, "v1");
    verifyColumnUpdate(updates.get(1), "cf2", "cq2", "cv2", 0l, false, false, "v2");
    verifyColumnUpdate(updates.get(2), "cf3", "cq3", "", 3l, true, false, "v3");
    verifyColumnUpdate(updates.get(3), "cf4", "cq4", "cv4", 4l, true, false, "v4");
    verifyColumnUpdate(updates.get(4), "cf5", "cq5", "", 0l, false, true, "");
    verifyColumnUpdate(updates.get(5), "cf6", "cq6", "cv6", 0l, false, true, "");
    verifyColumnUpdate(updates.get(6), "cf7", "cq7", "", 7l, true, true, "");
    verifyColumnUpdate(updates.get(7), "cf8", "cq8", "cv8", 8l, true, true, "");
}
Also used : Text(org.apache.hadoop.io.Text) TMutation(org.apache.accumulo.core.data.thrift.TMutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Test(org.junit.Test)

Example 83 with ColumnVisibility

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

the class StatusFormatter method formatEntry.

public String formatEntry(Key key, Status status, DateFormat timestampFormat) {
    StringBuilder sb = new StringBuilder();
    Text buffer = new Text();
    // append row
    key.getRow(buffer);
    appendText(sb, buffer).append(" ");
    // append column family
    key.getColumnFamily(buffer);
    appendText(sb, buffer).append(":");
    // append column qualifier
    key.getColumnQualifier(buffer);
    appendText(sb, buffer).append(" ");
    // append visibility expression
    key.getColumnVisibility(buffer);
    sb.append(new ColumnVisibility(buffer));
    // append timestamp
    if (timestampFormat != null) {
        tmpDate.get().setTime(key.getTimestamp());
        sb.append(" ").append(timestampFormat.format(tmpDate.get()));
    }
    sb.append("\t");
    // append value
    if (status != null) {
        sb.append(ProtobufUtil.toString(status));
    } else {
        sb.append("Could not deserialize Status protocol buffer");
    }
    return sb.toString();
}
Also used : Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility)

Example 84 with ColumnVisibility

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

the class BatchWriterReplicationReplayer method replicateLog.

@Override
public long replicateLog(ClientContext context, String tableName, WalEdits data) throws RemoteReplicationException, AccumuloException, AccumuloSecurityException {
    final LogFileKey key = new LogFileKey();
    final LogFileValue value = new LogFileValue();
    final long memoryInBytes = context.getConfiguration().getAsBytes(Property.TSERV_REPLICATION_BW_REPLAYER_MEMORY);
    BatchWriter bw = null;
    long mutationsApplied = 0l;
    try {
        for (ByteBuffer edit : data.getEdits()) {
            DataInputStream dis = new DataInputStream(ByteBufferUtil.toByteArrayInputStream(edit));
            try {
                key.readFields(dis);
                // TODO this is brittle because AccumuloReplicaSystem isn't actually calling LogFileValue.write, but we're expecting
                // what we receive to be readable by the LogFileValue.
                value.readFields(dis);
            } catch (IOException e) {
                log.error("Could not deserialize edit from stream", e);
                throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_DESERIALIZE, "Could not deserialize edit from stream");
            }
            // Create the batchScanner if we don't already have one.
            if (null == bw) {
                BatchWriterConfig bwConfig = new BatchWriterConfig();
                bwConfig.setMaxMemory(memoryInBytes);
                try {
                    bw = context.getConnector().createBatchWriter(tableName, bwConfig);
                } catch (TableNotFoundException e) {
                    throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST, "Table " + tableName + " does not exist");
                }
            }
            log.info("Applying {} mutations to table {} as part of batch", value.mutations.size(), tableName);
            // If we got a ServerMutation, we have to make sure that we preserve the systemTimestamp otherwise
            // the local system will assign a new timestamp.
            List<Mutation> mutationsCopy = new ArrayList<>(value.mutations.size());
            long mutationsCopied = 0l;
            for (Mutation orig : value.mutations) {
                if (orig instanceof ServerMutation) {
                    mutationsCopied++;
                    ServerMutation origServer = (ServerMutation) orig;
                    Mutation copy = new Mutation(orig.getRow());
                    for (ColumnUpdate update : orig.getUpdates()) {
                        long timestamp;
                        // If the update doesn't have a timestamp, pull it from the ServerMutation
                        if (!update.hasTimestamp()) {
                            timestamp = origServer.getSystemTimestamp();
                        } else {
                            timestamp = update.getTimestamp();
                        }
                        // TODO ACCUMULO-2937 cache the CVs
                        if (update.isDeleted()) {
                            copy.putDelete(update.getColumnFamily(), update.getColumnQualifier(), new ColumnVisibility(update.getColumnVisibility()), timestamp);
                        } else {
                            copy.put(update.getColumnFamily(), update.getColumnQualifier(), new ColumnVisibility(update.getColumnVisibility()), timestamp, update.getValue());
                        }
                    }
                    // We also need to preserve the replicationSource information to prevent cycles
                    Set<String> replicationSources = orig.getReplicationSources();
                    if (null != replicationSources && !replicationSources.isEmpty()) {
                        for (String replicationSource : replicationSources) {
                            copy.addReplicationSource(replicationSource);
                        }
                    }
                    mutationsCopy.add(copy);
                } else {
                    mutationsCopy.add(orig);
                }
            }
            log.debug("Copied {} mutations to ensure server-assigned timestamps are propagated", mutationsCopied);
            try {
                bw.addMutations(mutationsCopy);
            } catch (MutationsRejectedException e) {
                log.error("Could not apply mutations to {}", tableName);
                throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_APPLY, "Could not apply mutations to " + tableName);
            }
            log.debug("{} mutations added to the BatchScanner", mutationsCopy.size());
            mutationsApplied += mutationsCopy.size();
        }
    } finally {
        if (null != bw) {
            try {
                bw.close();
            } catch (MutationsRejectedException e) {
                log.error("Could not apply mutations to {}", tableName);
                throw new RemoteReplicationException(RemoteReplicationErrorCode.COULD_NOT_APPLY, "Could not apply mutations to " + tableName);
            }
        }
    }
    log.info("Applied {} mutations in total to {}", mutationsApplied, tableName);
    return mutationsApplied;
}
Also used : ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ArrayList(java.util.ArrayList) RemoteReplicationException(org.apache.accumulo.core.replication.thrift.RemoteReplicationException) ServerMutation(org.apache.accumulo.server.data.ServerMutation) LogFileKey(org.apache.accumulo.tserver.logger.LogFileKey) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ByteBuffer(java.nio.ByteBuffer) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) LogFileValue(org.apache.accumulo.tserver.logger.LogFileValue) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ServerMutation(org.apache.accumulo.server.data.ServerMutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 85 with ColumnVisibility

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

the class Tablet method setupDefaultSecurityLabels.

private void setupDefaultSecurityLabels(KeyExtent extent) {
    if (extent.isMeta()) {
        defaultSecurityLabel = new byte[0];
    } else {
        try {
            ColumnVisibility cv = new ColumnVisibility(tableConfiguration.get(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY));
            this.defaultSecurityLabel = cv.getExpression();
        } catch (Exception e) {
            log.error("{}", e.getMessage(), e);
            this.defaultSecurityLabel = new byte[0];
        }
    }
}
Also used : ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) DecoderException(org.apache.commons.codec.DecoderException) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TConstraintViolationException(org.apache.accumulo.tserver.TConstraintViolationException) FileNotFoundException(java.io.FileNotFoundException) CompactionCanceledException(org.apache.accumulo.tserver.tablet.Compactor.CompactionCanceledException) TooManyFilesException(org.apache.accumulo.tserver.TooManyFilesException) KeeperException(org.apache.zookeeper.KeeperException)

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