Skip to content
Permalink
Browse files
ACCUMULO-4718 Get code working with recent updates
  • Loading branch information
milleruntime committed Oct 5, 2017
1 parent 7495ba6 commit da53bbbfe0c02c53d63ce41dff2337385576111e
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 25 deletions.
@@ -301,7 +301,8 @@ public static void main(String[] args) throws Exception {
bscanner.close();

IngestInfo ingestInfo = new IngestInfo(opts.logDir);
TabletHistory tabletHistory = new TabletHistory(Tables.getTableId(conn.getInstance(), opts.getTableName()), opts.logDir);
String tableId = conn.tableOperations().tableIdMap().get(opts.getTableName());
TabletHistory tabletHistory = new TabletHistory(tableId, opts.logDir);

SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

@@ -36,6 +36,7 @@
import org.apache.accumulo.core.client.impl.TabletServerBatchWriter;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.data.ConstraintViolationSummary;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
@@ -219,7 +220,7 @@ public static void ingest(Connector connector, FileSystem fs, Opts opts, BatchWr
if (opts.outputFile != null) {
Configuration conf = CachedConfiguration.getInstance();
writer = FileOperations.getInstance().newWriterBuilder().forFile(opts.outputFile + "." + RFile.EXTENSION, fs, conf)
.withTableConfiguration(AccumuloConfiguration.getDefaultConfiguration()).build();
.withTableConfiguration(DefaultConfiguration.getInstance()).build();
writer.startDefaultLocalityGroup();
} else {
bw = connector.createBatchWriter(opts.getTableName(), bwOpts.getBatchWriterConfig());
@@ -60,7 +60,7 @@ public class BulkPlusOne extends BulkImportTest {
static void bulkLoadLots(Logger log, State state, RandWalkEnv env, Value value) throws Exception {
final Path dir = new Path("/tmp", "bulk_" + UUID.randomUUID().toString());
final Path fail = new Path(dir.toString() + "_fail");
final DefaultConfiguration defaultConfiguration = AccumuloConfiguration.getDefaultConfiguration();
final DefaultConfiguration defaultConfiguration = DefaultConfiguration.getInstance();
final Random rand = (Random) state.get("rand");
final FileSystem fs = (FileSystem) state.get("fs");
fs.mkdirs(fail);
@@ -30,6 +30,7 @@
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.TableOfflineException;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
@@ -51,7 +52,7 @@ public static class RFileBatchWriter implements BatchWriter {
RFile.Writer writer;

public RFileBatchWriter(Configuration conf, FileSystem fs, String file) throws IOException {
AccumuloConfiguration aconf = AccumuloConfiguration.getDefaultConfiguration();
AccumuloConfiguration aconf = DefaultConfiguration.getInstance();
CachableBlockFile.Writer cbw = new CachableBlockFile.Writer(PositionedOutputs.wrap(fs.create(new Path(file), false,
conf.getInt("io.file.buffer.size", 4096), (short) conf.getInt("dfs.replication", 3), conf.getLong("dfs.block.size", 1 << 26))), "gz", conf, aconf);
writer = new RFile.Writer(cbw, 100000);
@@ -76,7 +76,7 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
return;
}

String tableId = Tables.getNameToIdMap(env.getAccumuloInstance()).get(dstTableName);
String tableId = env.getAccumuloConnector().tableOperations().tableIdMap().get(dstTableName);
log.debug("copied " + srcTableName + " to " + dstTableName + " (id - " + tableId + " )");

tables.add(dstTableName);
@@ -49,7 +49,7 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
conn.tableOperations().create(tableName);
// Add some splits to make the server's life easier
conn.tableOperations().addSplits(tableName, splits);
String tableId = Tables.getNameToIdMap(env.getAccumuloInstance()).get(tableName);
String tableId = conn.tableOperations().tableIdMap().get(tableName);
log.debug("created " + tableName + " (id:" + tableId + ")");
// Add some splits to make the server's life easier
conn.tableOperations().addSplits(tableName, splits);
@@ -24,6 +24,8 @@
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.TableExistsException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Namespace;
import org.apache.accumulo.core.client.impl.Table;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.testing.core.randomwalk.RandWalkEnv;
import org.apache.accumulo.testing.core.randomwalk.State;
@@ -37,9 +39,11 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti

String tableName = WalkingSecurity.get(state, env).getTableName();
String namespaceName = WalkingSecurity.get(state, env).getNamespaceName();
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Namespace.ID namespaceId = Namespace.ID.of(conn.namespaceOperations().namespaceIdMap().get(namespaceName));

boolean exists = WalkingSecurity.get(state, env).getTableExists();
boolean hasPermission = WalkingSecurity.get(state, env).canAlterTable(WalkingSecurity.get(state, env).getSysCredentials(), tableName, namespaceName);
boolean hasPermission = WalkingSecurity.get(state, env).canAlterTable(WalkingSecurity.get(state, env).getSysCredentials(), tableId, namespaceId);
String newTableName = String.format("security_%s_%s_%d", InetAddress.getLocalHost().getHostName().replaceAll("[-.]", "_"), env.getPid(),
System.currentTimeMillis());

@@ -23,6 +23,8 @@
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.impl.Namespace;
import org.apache.accumulo.core.client.impl.Table;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.security.TablePermission;
import org.apache.accumulo.testing.core.randomwalk.RandWalkEnv;
@@ -75,9 +77,11 @@ public static void alter(State state, RandWalkEnv env, Properties props) throws
sourceToken = env.getToken();
}
Connector conn = env.getAccumuloInstance().getConnector(sourceUser, sourceToken);
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Namespace.ID namespaceId = Namespace.ID.of(conn.namespaceOperations().namespaceIdMap().get(WalkingSecurity.get(state, env).getNamespaceName()));

canGive = WalkingSecurity.get(state, env).canGrantTable(new Credentials(sourceUser, sourceToken).toThrift(env.getAccumuloInstance()), target,
WalkingSecurity.get(state, env).getTableName(), WalkingSecurity.get(state, env).getNamespaceName());
canGive = WalkingSecurity.get(state, env).canGrantTable(new Credentials(sourceUser, sourceToken).toThrift(env.getAccumuloInstance()), target, tableId,
namespaceId);

// toggle
if (!"take".equals(action) && !"give".equals(action)) {
@@ -24,6 +24,8 @@
import org.apache.accumulo.core.client.TableExistsException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.impl.Namespace;
import org.apache.accumulo.core.client.impl.Table;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.testing.core.randomwalk.RandWalkEnv;
@@ -52,10 +54,12 @@ public static void dropTable(State state, RandWalkEnv env, Properties props) thr

String tableName = WalkingSecurity.get(state, env).getTableName();
String namespaceName = WalkingSecurity.get(state, env).getNamespaceName();
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Namespace.ID namespaceId = Namespace.ID.of(conn.namespaceOperations().namespaceIdMap().get(namespaceName));

boolean exists = WalkingSecurity.get(state, env).getTableExists();
boolean hasPermission = WalkingSecurity.get(state, env).canDeleteTable(new Credentials(principal, token).toThrift(env.getAccumuloInstance()), tableName,
namespaceName);
boolean hasPermission = WalkingSecurity.get(state, env).canDeleteTable(new Credentials(principal, token).toThrift(env.getAccumuloInstance()), tableId,
namespaceId);

try {
conn.tableOperations().delete(tableName);
@@ -34,8 +34,10 @@
import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Namespace;
import org.apache.accumulo.core.client.impl.Table;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.DefaultConfiguration;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Mutation;
import org.apache.accumulo.core.data.Value;
@@ -70,10 +72,12 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
boolean tableExists = WalkingSecurity.get(state, env).getTableExists();
String tableName = WalkingSecurity.get(state, env).getTableName();
String namespaceName = WalkingSecurity.get(state, env).getNamespaceName();
Table.ID tableId = Table.ID.of(conn.tableOperations().tableIdMap().get(tableName));
Namespace.ID namespaceId = Namespace.ID.of(conn.namespaceOperations().namespaceIdMap().get(namespaceName));

switch (tp) {
case READ: {
boolean canRead = WalkingSecurity.get(state, env).canScan(WalkingSecurity.get(state, env).getTabCredentials(), tableName, namespaceName);
boolean canRead = WalkingSecurity.get(state, env).canScan(WalkingSecurity.get(state, env).getTabCredentials(), tableId, namespaceId);
Authorizations auths = WalkingSecurity.get(state, env).getUserAuthorizations(WalkingSecurity.get(state, env).getTabCredentials());
boolean ambiguousZone = WalkingSecurity.get(state, env).inAmbiguousZone(conn.whoami(), tp);
boolean ambiguousAuths = WalkingSecurity.get(state, env).ambiguousAuthorizations(conn.whoami());
@@ -144,7 +148,7 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
break;
}
case WRITE:
boolean canWrite = WalkingSecurity.get(state, env).canWrite(WalkingSecurity.get(state, env).getTabCredentials(), tableName, namespaceName);
boolean canWrite = WalkingSecurity.get(state, env).canWrite(WalkingSecurity.get(state, env).getTabCredentials(), tableId, namespaceId);
boolean ambiguousZone = WalkingSecurity.get(state, env).inAmbiguousZone(conn.whoami(), tp);

String key = WalkingSecurity.get(state, env).getLastKey() + "1";
@@ -206,7 +210,7 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
Path fail = new Path(dir.toString() + "_fail");
FileSystem fs = WalkingSecurity.get(state, env).getFs();
FileSKVWriter f = FileOperations.getInstance().newWriterBuilder().forFile(dir + "/securityBulk." + RFile.EXTENSION, fs, fs.getConf())
.withTableConfiguration(AccumuloConfiguration.getDefaultConfiguration()).build();
.withTableConfiguration(DefaultConfiguration.getInstance()).build();
f.startDefaultLocalityGroup();
fs.mkdirs(fail);
for (Key k : keys)
@@ -220,7 +224,7 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
return;
} catch (AccumuloSecurityException ae) {
if (ae.getSecurityErrorCode().equals(SecurityErrorCode.PERMISSION_DENIED)) {
if (WalkingSecurity.get(state, env).canBulkImport(WalkingSecurity.get(state, env).getTabCredentials(), tableName, namespaceName))
if (WalkingSecurity.get(state, env).canBulkImport(WalkingSecurity.get(state, env).getTabCredentials(), tableId, namespaceId))
throw new AccumuloException("Bulk Import failed when it should have worked: " + tableName);
return;
} else if (ae.getSecurityErrorCode().equals(SecurityErrorCode.BAD_CREDENTIALS)) {
@@ -234,12 +238,12 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti
fs.delete(dir, true);
fs.delete(fail, true);

if (!WalkingSecurity.get(state, env).canBulkImport(WalkingSecurity.get(state, env).getTabCredentials(), tableName, namespaceName))
if (!WalkingSecurity.get(state, env).canBulkImport(WalkingSecurity.get(state, env).getTabCredentials(), tableId, namespaceId))
throw new AccumuloException("Bulk Import succeeded when it should have failed: " + dir + " table " + tableName);
break;
case ALTER_TABLE:
AlterTable.renameTable(conn, state, env, tableName, tableName + "plus",
WalkingSecurity.get(state, env).canAlterTable(WalkingSecurity.get(state, env).getTabCredentials(), tableName, namespaceName), tableExists);
WalkingSecurity.get(state, env).canAlterTable(WalkingSecurity.get(state, env).getTabCredentials(), tableId, namespaceId), tableExists);
break;

case GRANT:
@@ -30,6 +30,7 @@
import org.apache.accumulo.core.client.NamespaceNotFoundException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.impl.Credentials;
import org.apache.accumulo.core.client.impl.Namespace;
import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
@@ -83,7 +84,7 @@ public WalkingSecurity(AccumuloServerContext context, Authorizor author, Authent
}

public WalkingSecurity(State state2, RandWalkEnv env2) {
super(new AccumuloServerContext(new ServerConfigurationFactory(HdfsZooInstance.getInstance())));
super(new AccumuloServerContext(HdfsZooInstance.getInstance(), new ServerConfigurationFactory(HdfsZooInstance.getInstance())));
this.state = state2;
this.env = env2;
authorizor = this;
@@ -217,13 +218,13 @@ public boolean hasCachedTablePermission(String user, String table, TablePermissi
}

@Override
public boolean hasNamespacePermission(String user, String namespace, NamespacePermission permission) throws AccumuloSecurityException,
public boolean hasNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws AccumuloSecurityException,
NamespaceNotFoundException {
return Boolean.parseBoolean(state.getString("Nsp-" + user + '-' + permission.name()));
}

@Override
public boolean hasCachedNamespacePermission(String user, String namespace, NamespacePermission permission) throws AccumuloSecurityException,
public boolean hasCachedNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws AccumuloSecurityException,
NamespaceNotFoundException {
return hasNamespacePermission(user, namespace, permission);
}
@@ -263,12 +264,12 @@ public void revokeTablePermission(String user, String table, TablePermission per
}

@Override
public void grantNamespacePermission(String user, String namespace, NamespacePermission permission) throws AccumuloSecurityException,
public void grantNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws AccumuloSecurityException,
NamespaceNotFoundException {
setNspPerm(state, user, permission, namespace, true);
}

private void setNspPerm(State state, String userName, NamespacePermission tnp, String namespace, boolean value) {
private void setNspPerm(State state, String userName, NamespacePermission tnp, Namespace.ID namespace, boolean value) {
if (namespace.equals(userName))
throw new RuntimeException("I don't even know");
log.debug((value ? "Gave" : "Took") + " the table permission " + tnp.name() + (value ? " to" : " from") + " user " + userName);
@@ -278,7 +279,7 @@ private void setNspPerm(State state, String userName, NamespacePermission tnp, S
}

@Override
public void revokeNamespacePermission(String user, String namespace, NamespacePermission permission) throws AccumuloSecurityException,
public void revokeNamespacePermission(String user, Namespace.ID namespace, NamespacePermission permission) throws AccumuloSecurityException,
NamespaceNotFoundException {
setNspPerm(state, user, permission, namespace, false);
}
@@ -294,7 +295,7 @@ public void cleanTablePermissions(String table) throws AccumuloSecurityException
}

@Override
public void cleanNamespacePermissions(String namespace) throws AccumuloSecurityException, NamespaceNotFoundException {
public void cleanNamespacePermissions(Namespace.ID namespace) throws AccumuloSecurityException, NamespaceNotFoundException {
for (String user : new String[] {getSysUserName(), getNspUserName()}) {
for (NamespacePermission tnp : NamespacePermission.values()) {
revokeNamespacePermission(user, namespace, tnp);

0 comments on commit da53bbb

Please sign in to comment.