Search in sources :

Example 66 with Connector

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());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 67 with Connector

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;
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) UnknownScanner(org.apache.accumulo.proxy.thrift.UnknownScanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Range(org.apache.accumulo.core.data.Range) 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) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) ScanColumn(org.apache.accumulo.proxy.thrift.ScanColumn) UUID(java.util.UUID)

Example 68 with Connector

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 69 with Connector

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Example 70 with Connector

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) CommandLine(org.apache.commons.cli.CommandLine) Shell(org.apache.accumulo.shell.Shell) Authorizations(org.apache.accumulo.core.security.Authorizations) ConsoleReader(jline.console.ConsoleReader) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) Test(org.junit.Test)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)622 Test (org.junit.Test)415 BatchWriter (org.apache.accumulo.core.client.BatchWriter)171 Value (org.apache.accumulo.core.data.Value)162 Text (org.apache.hadoop.io.Text)160 Scanner (org.apache.accumulo.core.client.Scanner)158 Mutation (org.apache.accumulo.core.data.Mutation)152 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)143 Key (org.apache.accumulo.core.data.Key)139 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)101 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)87 AccumuloException (org.apache.accumulo.core.client.AccumuloException)83 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)75 Range (org.apache.accumulo.core.data.Range)74 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)65 Authorizations (org.apache.accumulo.core.security.Authorizations)60 HashSet (java.util.HashSet)57 Instance (org.apache.accumulo.core.client.Instance)55 ArrayList (java.util.ArrayList)53 Entry (java.util.Map.Entry)53