Search in sources :

Example 11 with Credentials

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

the class SystemCredentialsTest method testSystemCredentials.

@Test
public void testSystemCredentials() {
    Credentials a = SystemCredentials.get(instanceId, siteConfig);
    Credentials b = SystemCredentials.get(instanceId, siteConfig);
    assertEquals(a, b);
}
Also used : Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.Test)

Example 12 with Credentials

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

the class ReplicationTableUtilTest method properPathInRow.

@Test
public void properPathInRow() throws Exception {
    Writer writer = EasyMock.createNiceMock(Writer.class);
    writer.update(EasyMock.anyObject(Mutation.class));
    final List<Mutation> mutations = new ArrayList<>();
    // Mock a Writer to just add the mutation to a list
    EasyMock.expectLastCall().andAnswer(() -> {
        mutations.add(((Mutation) EasyMock.getCurrentArguments()[0]));
        return null;
    });
    EasyMock.replay(writer);
    Credentials creds = new Credentials("root", new PasswordToken(""));
    ClientContext context = EasyMock.createMock(ClientContext.class);
    EasyMock.expect(context.getCredentials()).andReturn(creds).anyTimes();
    EasyMock.replay(context);
    // Magic hook to create a Writer
    ReplicationTableUtil.addWriter(creds, writer);
    // Example file seen coming out of LogEntry
    UUID uuid = UUID.randomUUID();
    String myFile = "file:////home/user/accumulo/wal/server+port/" + uuid;
    long createdTime = System.currentTimeMillis();
    ReplicationTableUtil.updateFiles(context, new KeyExtent(TableId.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
    verify(writer);
    assertEquals(1, mutations.size());
    Mutation m = mutations.get(0);
    assertEquals(ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
    List<ColumnUpdate> updates = m.getUpdates();
    assertEquals(1, updates.size());
    ColumnUpdate update = updates.get(0);
    assertEquals(ReplicationSection.COLF, new Text(update.getColumnFamily()));
    assertEquals("1", new Text(update.getColumnQualifier()).toString());
    assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
Also used : ColumnUpdate(org.apache.accumulo.core.data.ColumnUpdate) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) UUID(java.util.UUID) Writer(org.apache.accumulo.core.clientImpl.Writer) Credentials(org.apache.accumulo.core.clientImpl.Credentials) Test(org.junit.Test)

Example 13 with Credentials

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

the class CredentialsTest method testEqualsAndHashCode.

@Test
public void testEqualsAndHashCode() {
    Credentials nullNullCreds = new Credentials(null, null);
    Credentials abcNullCreds = new Credentials("abc", new NullToken());
    Credentials cbaNullCreds = new Credentials("cba", new NullToken());
    Credentials abcBlahCreds = new Credentials("abc", new PasswordToken("blah"));
    // check hash codes
    assertEquals(0, nullNullCreds.hashCode());
    assertEquals("abc".hashCode(), abcNullCreds.hashCode());
    assertEquals(abcNullCreds.hashCode(), abcBlahCreds.hashCode());
    assertNotEquals(abcNullCreds.hashCode(), cbaNullCreds.hashCode());
    // identity
    assertEquals(abcNullCreds, abcNullCreds);
    assertEquals(new Credentials("abc", new NullToken()), abcNullCreds);
    // equal, but different token constructors
    assertEquals(new Credentials("abc", new PasswordToken("abc".getBytes(UTF_8))), new Credentials("abc", new PasswordToken("abc")));
    // test not equals
    assertNotEquals(nullNullCreds, abcBlahCreds);
    assertNotEquals(nullNullCreds, abcNullCreds);
    assertNotEquals(abcNullCreds, abcBlahCreds);
}
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)

Example 14 with Credentials

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

the class CredentialsTest method testCredentialsSerialization.

@Test
public void testCredentialsSerialization() {
    Credentials creds = new Credentials("a:b-c", new PasswordToken("d-e-f".getBytes(UTF_8)));
    String serialized = creds.serialize();
    Credentials result = Credentials.deserialize(serialized);
    assertEquals(creds, result);
    assertEquals("a:b-c", result.getPrincipal());
    assertEquals(new PasswordToken("d-e-f"), result.getToken());
    Credentials nullNullCreds = new Credentials(null, null);
    serialized = nullNullCreds.serialize();
    result = Credentials.deserialize(serialized);
    assertNull(result.getPrincipal());
    assertNull(result.getToken());
}
Also used : 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)

Example 15 with Credentials

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

the class SimpleBalancerFairnessIT method simpleBalancerFairness.

@Test
public void simpleBalancerFairness() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        c.tableOperations().create("test_ingest");
        c.tableOperations().setProperty("test_ingest", Property.TABLE_SPLIT_THRESHOLD.getKey(), "1K");
        c.tableOperations().create("unused");
        TreeSet<Text> splits = TestIngest.getSplitPoints(0, 10000000, NUM_SPLITS);
        log.info("Creating {} splits", splits.size());
        c.tableOperations().addSplits("unused", splits);
        List<String> tservers = c.instanceOperations().getTabletServers();
        TestIngest.IngestParams params = new TestIngest.IngestParams(getClientProperties());
        params.rows = 5000;
        TestIngest.ingest(c, params);
        c.tableOperations().flush("test_ingest", null, null, false);
        sleepUninterruptibly(45, TimeUnit.SECONDS);
        Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
        ManagerMonitorInfo stats = null;
        int unassignedTablets = 1;
        for (int i = 0; unassignedTablets > 0 && i < 20; i++) {
            ManagerClientService.Iface client = null;
            while (true) {
                try {
                    client = ManagerClient.getConnectionWithRetry((ClientContext) c);
                    stats = client.getManagerStats(TraceUtil.traceInfo(), creds.toThrift(c.instanceOperations().getInstanceId()));
                    break;
                } catch (ThriftNotActiveServiceException e) {
                    // Let it loop, fetching a new location
                    sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
                } finally {
                    if (client != null)
                        ManagerClient.close(client, (ClientContext) c);
                }
            }
            unassignedTablets = stats.getUnassignedTablets();
            if (unassignedTablets > 0) {
                log.info("Found {} unassigned tablets, sleeping 3 seconds for tablet assignment", unassignedTablets);
                Thread.sleep(3000);
            }
        }
        assertEquals("Unassigned tablets were not assigned within 60 seconds", 0, unassignedTablets);
        // Compute online tablets per tserver
        List<Integer> counts = new ArrayList<>();
        for (TabletServerStatus server : stats.tServerInfo) {
            int count = 0;
            for (TableInfo table : server.tableMap.values()) {
                count += table.onlineTablets;
            }
            counts.add(count);
        }
        assertTrue("Expected to have at least two TabletServers", counts.size() > 1);
        for (int i = 1; i < counts.size(); i++) {
            int diff = Math.abs(counts.get(0) - counts.get(i));
            assertTrue("Expected difference in tablets to be less than or equal to " + counts.size() + " but was " + diff + ". Counts " + counts, diff <= tservers.size());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TestIngest(org.apache.accumulo.test.TestIngest) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) Credentials(org.apache.accumulo.core.clientImpl.Credentials) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.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