Search in sources :

Example 41 with ClientContext

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

the class MetadataMaxFilesIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        SortedSet<Text> splits = new TreeSet<>();
        for (int i = 0; i < 1000; i++) {
            splits.add(new Text(String.format("%03d", i)));
        }
        c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "10000");
        // propagation time
        sleepUninterruptibly(5, TimeUnit.SECONDS);
        for (int i = 0; i < 2; i++) {
            String tableName = "table" + i;
            log.info("Creating {} with splits", tableName);
            NewTableConfiguration ntc = new NewTableConfiguration().withSplits(splits);
            c.tableOperations().create(tableName, ntc);
            log.info("flushing");
            c.tableOperations().flush(MetadataTable.NAME, null, null, true);
            c.tableOperations().flush(RootTable.NAME, null, null, true);
        }
        while (true) {
            ManagerMonitorInfo stats;
            Client client = null;
            try {
                ClientContext context = (ClientContext) c;
                client = ManagerClient.getConnectionWithRetry(context);
                log.info("Fetching stats");
                stats = client.getManagerStats(TraceUtil.traceInfo(), context.rpcCreds());
            } catch (ThriftNotActiveServiceException e) {
                // Let it loop, fetching a new location
                sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
                continue;
            } finally {
                if (client != null)
                    ManagerClient.close(client, (ClientContext) c);
            }
            int tablets = 0;
            for (TabletServerStatus tserver : stats.tServerInfo) {
                for (Entry<String, TableInfo> entry : tserver.tableMap.entrySet()) {
                    if (entry.getKey().startsWith("!") || entry.getKey().startsWith("+"))
                        continue;
                    tablets += entry.getValue().onlineTablets;
                }
            }
            log.info("Online tablets " + tablets);
            if (tablets == 2002)
                break;
            sleepUninterruptibly(1, TimeUnit.SECONDS);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Text(org.apache.hadoop.io.Text) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ManagerClient(org.apache.accumulo.core.clientImpl.ManagerClient) Client(org.apache.accumulo.core.manager.thrift.ManagerClientService.Client) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Test(org.junit.Test)

Example 42 with ClientContext

use of org.apache.accumulo.core.clientImpl.ClientContext 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)

Example 43 with ClientContext

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

the class TabletMetadataIT method getLiveTServersTest.

@Test
public void getLiveTServersTest() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        while (c.instanceOperations().getTabletServers().size() != NUM_TSERVERS) {
            log.info("Waiting for tservers to start up...");
            sleepUninterruptibly(5, TimeUnit.SECONDS);
        }
        Set<TServerInstance> servers = TabletMetadata.getLiveTServers((ClientContext) c);
        assertEquals(NUM_TSERVERS, servers.size());
        // kill a tserver and see if its gone from the list
        getCluster().killProcess(TABLET_SERVER, getCluster().getProcesses().get(TABLET_SERVER).iterator().next());
        while (c.instanceOperations().getTabletServers().size() == NUM_TSERVERS) {
            log.info("Waiting for a tserver to die...");
            sleepUninterruptibly(5, TimeUnit.SECONDS);
        }
        servers = TabletMetadata.getLiveTServers((ClientContext) c);
        assertEquals(NUM_TSERVERS - 1, servers.size());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Example 44 with ClientContext

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

the class ManagerApiIT method expectPermissionSuccess.

private static void expectPermissionSuccess(Function<TCredentials, ClientExec<ManagerClientService.Client>> op, Credentials user) throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).as(user.getPrincipal(), user.getToken()).build()) {
        ClientContext context = (ClientContext) client;
        ManagerClient.executeVoid(context, op.apply(context.rpcCreds()));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext)

Example 45 with ClientContext

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

the class TableDiskUsage method printDiskUsage.

public static void printDiskUsage(Collection<String> tableNames, VolumeManager fs, AccumuloClient client, Printer printer, boolean humanReadable) throws TableNotFoundException, IOException {
    HashSet<TableId> tableIds = new HashSet<>();
    // Get table IDs for all tables requested to be 'du'
    for (String tableName : tableNames) {
        TableId tableId = ((ClientContext) client).getTableId(tableName);
        if (tableId == null)
            throw new TableNotFoundException(null, tableName, "Table " + tableName + " not found");
        tableIds.add(tableId);
    }
    Map<TreeSet<String>, Long> usage = getDiskUsage(tableIds, fs, client);
    String valueFormat = humanReadable ? "%9s" : "%,24d";
    for (Entry<TreeSet<String>, Long> entry : usage.entrySet()) {
        Object value = humanReadable ? NumUtil.bigNumberForSize(entry.getValue()) : entry.getValue();
        printer.print(String.format(valueFormat + " %s", value, entry.getKey()));
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) HashSet(java.util.HashSet)

Aggregations

ClientContext (org.apache.accumulo.core.clientImpl.ClientContext)53 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)22 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)14 Text (org.apache.hadoop.io.Text)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)12 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)11 List (java.util.List)10 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)10 TableId (org.apache.accumulo.core.data.TableId)9 HashSet (java.util.HashSet)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)7 HostAndPort (org.apache.accumulo.core.util.HostAndPort)7 HashMap (java.util.HashMap)6 Scanner (org.apache.accumulo.core.client.Scanner)6