use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class MiniAccumuloClusterImplTest method setupMiniCluster.
@BeforeClass
public static void setupMiniCluster() throws Exception {
Logger.getLogger("org.apache.zookeeper").setLevel(Level.ERROR);
File baseDir = new File(System.getProperty("user.dir") + "/target/mini-tests");
assertTrue(baseDir.mkdirs() || baseDir.isDirectory());
testDir = new File(baseDir, MiniAccumuloClusterImplTest.class.getName());
FileUtils.deleteQuietly(testDir);
assertTrue(testDir.mkdir());
MiniAccumuloConfigImpl config = new MiniAccumuloConfigImpl(testDir, "superSecret").setJDWPEnabled(true);
// expressly set number of tservers since we assert it later, in case the default changes
config.setNumTservers(NUM_TSERVERS);
accumulo = new MiniAccumuloClusterImpl(config);
accumulo.start();
// create a table to ensure there are some entries in the !0 table
Connector conn = accumulo.getConnector("root", new PasswordToken("superSecret"));
TableOperations tableops = conn.tableOperations();
tableops.create(TEST_TABLE);
testTableID = tableops.tableIdMap().get(TEST_TABLE);
Scanner s = conn.createScanner(TEST_TABLE, Authorizations.EMPTY);
Iterators.size(s.iterator());
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class ProxyServer method createScanner.
@Override
public String createScanner(ByteBuffer login, String tableName, ScanOptions opts) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableNotFoundException, TException {
try {
Connector connector = getConnector(login);
Authorizations auth;
if (opts != null && opts.isSetAuthorizations()) {
auth = getAuthorizations(opts.authorizations);
} else {
auth = connector.securityOperations().getUserAuthorizations(connector.whoami());
}
Scanner scanner = connector.createScanner(tableName, auth);
if (opts != null) {
if (opts.iterators != null) {
for (org.apache.accumulo.proxy.thrift.IteratorSetting iter : opts.iterators) {
IteratorSetting is = new IteratorSetting(iter.getPriority(), iter.getName(), iter.getIteratorClass(), iter.getProperties());
scanner.addScanIterator(is);
}
}
org.apache.accumulo.proxy.thrift.Range prange = opts.range;
if (prange != null) {
Range range = new Range(Util.fromThrift(prange.getStart()), prange.startInclusive, Util.fromThrift(prange.getStop()), prange.stopInclusive);
scanner.setRange(range);
}
if (opts.columns != null) {
for (ScanColumn col : opts.columns) {
if (col.isSetColQualifier())
scanner.fetchColumn(ByteBufferUtil.toText(col.colFamily), ByteBufferUtil.toText(col.colQualifier));
else
scanner.fetchColumnFamily(ByteBufferUtil.toText(col.colFamily));
}
}
}
UUID uuid = UUID.randomUUID();
ScannerPlusIterator spi = new ScannerPlusIterator();
spi.scanner = scanner;
spi.iterator = scanner.iterator();
scannerCache.put(uuid, spi);
return uuid.toString();
} catch (Exception e) {
handleExceptionTNF(e);
return null;
}
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteAllAuth.
@Test
public void deleteAllAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("abc,123");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations());
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s abc,123", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteExistingAuth.
@Test
public void deleteExistingAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("abc");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations("123"));
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s abc", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
use of org.apache.accumulo.core.client.Connector in project accumulo by apache.
the class DeleteAuthsCommandTest method deleteNonExistingAuth.
@Test
public void deleteNonExistingAuth() throws Exception {
Connector conn = EasyMock.createMock(Connector.class);
CommandLine cli = EasyMock.createMock(CommandLine.class);
Shell shellState = EasyMock.createMock(Shell.class);
ConsoleReader reader = EasyMock.createMock(ConsoleReader.class);
SecurityOperations secOps = EasyMock.createMock(SecurityOperations.class);
EasyMock.expect(shellState.getConnector()).andReturn(conn);
// We're the root user
EasyMock.expect(conn.whoami()).andReturn("root");
EasyMock.expect(cli.getOptionValue("u", "root")).andReturn("foo");
EasyMock.expect(cli.getOptionValue("s")).andReturn("def");
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(conn.securityOperations()).andReturn(secOps);
EasyMock.expect(secOps.getUserAuthorizations("foo")).andReturn(new Authorizations("abc", "123"));
secOps.changeUserAuthorizations("foo", new Authorizations("abc", "123"));
EasyMock.expectLastCall();
EasyMock.replay(conn, cli, shellState, reader, secOps);
cmd.execute("deleteauths -u foo -s def", cli, shellState);
EasyMock.verify(conn, cli, shellState, reader, secOps);
}
Aggregations