Search in sources :

Example 1 with Credentials

use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.

the class CredentialsTest method roundtripThrift.

@Test
public void roundtripThrift() {
    var instanceID = InstanceId.of(testName());
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(instanceID);
    Credentials roundtrip = Credentials.fromThrift(tCreds);
    assertEquals(creds, roundtrip, "Round-trip through thrift changed credentials equality");
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.jupiter.api.Test)

Example 2 with Credentials

use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.

the class BalanceInPresenceOfOfflineTableIT method test.

@Test
public void test() throws Exception {
    log.info("Test that balancing is not stopped by an offline table with outstanding migrations.");
    log.debug("starting test ingestion");
    VerifyParams params = new VerifyParams(getClientProps(), TEST_TABLE, 200_000);
    TestIngest.ingest(accumuloClient, params);
    accumuloClient.tableOperations().flush(TEST_TABLE, null, null, true);
    VerifyIngest.verifyIngest(accumuloClient, params);
    log.debug("waiting for balancing, up to ~5 minutes to allow for migration cleanup.");
    final long startTime = System.currentTimeMillis();
    long currentWait = 10_000;
    boolean balancingWorked = false;
    Credentials creds = new Credentials(getAdminPrincipal(), getAdminToken());
    while (!balancingWorked && (System.currentTimeMillis() - startTime) < ((5 * 60 + 15) * 1000)) {
        Thread.sleep(currentWait);
        currentWait *= 2;
        log.debug("fetch the list of tablets assigned to each tserver.");
        ManagerClientService.Iface client = null;
        ManagerMonitorInfo stats;
        while (true) {
            try {
                client = ManagerClient.getConnectionWithRetry((ClientContext) accumuloClient);
                stats = client.getManagerStats(TraceUtil.traceInfo(), creds.toThrift(accumuloClient.instanceOperations().getInstanceId()));
                break;
            } catch (ThriftSecurityException exception) {
                throw new AccumuloSecurityException(exception);
            } catch (ThriftNotActiveServiceException e) {
                // Let it loop, fetching a new location
                log.debug("Contacted a Manager which is no longer active, retrying");
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            } catch (TException exception) {
                throw new AccumuloException(exception);
            } finally {
                if (client != null) {
                    ManagerClient.close(client, (ClientContext) accumuloClient);
                }
            }
        }
        if (stats.getTServerInfoSize() < 2) {
            log.debug("we need >= 2 servers. sleeping for {}ms", currentWait);
            continue;
        }
        if (stats.getUnassignedTablets() != 0) {
            log.debug("We shouldn't have unassigned tablets. sleeping for {}ms", currentWait);
            continue;
        }
        long[] tabletsPerServer = new long[stats.getTServerInfoSize()];
        Arrays.fill(tabletsPerServer, 0L);
        for (int i = 0; i < stats.getTServerInfoSize(); i++) {
            for (Map.Entry<String, TableInfo> entry : stats.getTServerInfo().get(i).getTableMap().entrySet()) {
                tabletsPerServer[i] += entry.getValue().getTablets();
            }
        }
        if (tabletsPerServer[0] <= 10) {
            log.debug("We should have > 10 tablets. sleeping for {}ms", currentWait);
            continue;
        }
        long min = NumberUtils.min(tabletsPerServer), max = NumberUtils.max(tabletsPerServer);
        log.debug("Min={}, Max={}", min, max);
        if ((min / ((double) max)) < 0.5) {
            log.debug("ratio of min to max tablets per server should be roughly even. sleeping for {}ms", currentWait);
            continue;
        }
        balancingWorked = true;
    }
    assertTrue("did not properly balance", balancingWorked);
}
Also used : ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) VerifyParams(org.apache.accumulo.test.VerifyIngest.VerifyParams) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) Map(java.util.Map) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.Test)

Example 3 with Credentials

use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.

the class TokenFileIT method testMR.

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path provided by test")
@Test
public void testMR() throws Exception {
    String[] tableNames = getUniqueNames(2);
    String table1 = tableNames[0];
    String table2 = tableNames[1];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(table1);
        c.tableOperations().create(table2);
        try (BatchWriter bw = c.createBatchWriter(table1)) {
            for (int i = 0; i < 100; i++) {
                Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
                m.put("", "", String.format("%09x", i));
                bw.addMutation(m);
            }
        }
        File tf = folder.newFile("root_test.pw");
        try (PrintStream out = new PrintStream(tf)) {
            String outString = new Credentials(getAdminPrincipal(), getAdminToken()).serialize();
            out.println(outString);
        }
        Configuration conf = cluster.getServerContext().getHadoopConf();
        conf.set("hadoop.tmp.dir", new File(tf.getAbsolutePath()).getParent());
        conf.set("mapreduce.framework.name", "local");
        conf.set("mapreduce.cluster.local.dir", new File(System.getProperty("user.dir"), "target/mapreduce-tmp").getAbsolutePath());
        assertEquals(0, ToolRunner.run(conf, new MRTokenFileTester(), new String[] { tf.getAbsolutePath(), table1, table2 }));
        if (e1 != null) {
            e1.printStackTrace();
        }
        assertNull(e1);
        try (Scanner scanner = c.createScanner(table2, new Authorizations())) {
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            assertTrue(iter.hasNext());
            Entry<Key, Value> entry = iter.next();
            assertEquals(Integer.parseInt(new String(entry.getValue().get())), 100);
            assertFalse(iter.hasNext());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PrintStream(java.io.PrintStream) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) File(java.io.File) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 4 with Credentials

use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.

the class CredentialsTest method testToThrift.

@Test
public void testToThrift() throws DestroyFailedException {
    var instanceID = InstanceId.of(testName());
    // verify thrift serialization
    Credentials creds = new Credentials("test", new PasswordToken("testing"));
    TCredentials tCreds = creds.toThrift(instanceID);
    assertEquals("test", tCreds.getPrincipal());
    assertEquals(PasswordToken.class.getName(), tCreds.getTokenClassName());
    assertArrayEquals(AuthenticationTokenSerializer.serialize(new PasswordToken("testing")), tCreds.getToken());
    // verify that we can't serialize if it's destroyed
    creds.getToken().destroy();
    Exception e = assertThrows(RuntimeException.class, () -> creds.toThrift(instanceID));
    assertSame(AccumuloSecurityException.class, e.getCause().getClass());
    assertEquals(AccumuloSecurityException.class.cast(e.getCause()).getSecurityErrorCode(), SecurityErrorCode.TOKEN_EXPIRED);
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) Credentials(org.apache.accumulo.core.clientImpl.Credentials) DestroyFailedException(javax.security.auth.DestroyFailedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.jupiter.api.Test)

Example 5 with Credentials

use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.

the class CredentialsTest method testToString.

@Test
public void testToString() {
    Credentials creds = new Credentials(null, null);
    assertEquals(Credentials.class.getName() + ":null:null:<hidden>", creds.toString());
    creds = new Credentials("", new NullToken());
    assertEquals(Credentials.class.getName() + "::" + NullToken.class.getName() + ":<hidden>", creds.toString());
    creds = new Credentials("abc", null);
    assertEquals(Credentials.class.getName() + ":abc:null:<hidden>", creds.toString());
    creds = new Credentials("abc", new PasswordToken(""));
    assertEquals(Credentials.class.getName() + ":abc:" + PasswordToken.class.getName() + ":<hidden>", creds.toString());
}
Also used : NullToken(org.apache.accumulo.core.client.security.tokens.NullToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.jupiter.api.Test)

Aggregations

Credentials (org.apache.accumulo.core.clientImpl.Credentials)19 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)13 TCredentials (org.apache.accumulo.core.securityImpl.thrift.TCredentials)10 Test (org.junit.Test)8 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)7 Text (org.apache.hadoop.io.Text)5 Test (org.junit.jupiter.api.Test)5 BatchWriter (org.apache.accumulo.core.client.BatchWriter)4 Value (org.apache.accumulo.core.data.Value)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 Scanner (org.apache.accumulo.core.client.Scanner)3 SecurityOperations (org.apache.accumulo.core.client.admin.SecurityOperations)3 ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)3 Writer (org.apache.accumulo.core.clientImpl.Writer)3 Key (org.apache.accumulo.core.data.Key)3 Mutation (org.apache.accumulo.core.data.Mutation)3 Authorizations (org.apache.accumulo.core.security.Authorizations)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2