Search in sources :

Example 31 with ClientContext

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

the class ListTabletsCommand method getMetadataInfo.

protected List<TabletRowInfo> getMetadataInfo(Shell shellState, TableInfo tableInfo) throws Exception {
    List<TabletRowInfo> results = new ArrayList<>();
    final ClientContext context = shellState.getContext();
    Set<TServerInstance> liveTserverSet = TabletMetadata.getLiveTServers(context);
    try (var tabletsMetadata = TabletsMetadata.builder(context).forTable(tableInfo.id).build()) {
        for (var md : tabletsMetadata) {
            TabletRowInfo.Factory factory = new TabletRowInfo.Factory(tableInfo.name, md.getExtent());
            var fileMap = md.getFilesMap();
            factory.numFiles(fileMap.size());
            long entries = 0L;
            long size = 0L;
            for (DataFileValue dfv : fileMap.values()) {
                entries += dfv.getNumEntries();
                size += dfv.getSize();
            }
            factory.numEntries(entries);
            factory.size(size);
            factory.numWalLogs(md.getLogs().size());
            factory.dir(md.getDirName());
            factory.location(md.getLocation());
            factory.status(md.getTabletState(liveTserverSet).toString());
            results.add(factory.build());
        }
    }
    return results;
}
Also used : DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

Example 32 with ClientContext

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

the class CreateUserCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException, IOException {
    final String user = cl.getArgs()[0];
    AuthenticationToken userToken = ((ClientContext) shellState.getAccumuloClient()).token();
    PasswordToken passwordToken;
    if (userToken instanceof KerberosToken) {
        passwordToken = new PasswordToken();
    } else {
        final String password = shellState.readMaskedLine("Enter new password for '" + user + "': ", '*');
        if (password == null) {
            shellState.getWriter().println();
            return 0;
        }
        // user canceled
        String passwordConfirm = shellState.readMaskedLine("Please confirm new password for '" + user + "': ", '*');
        if (passwordConfirm == null) {
            shellState.getWriter().println();
            return 0;
        }
        if (!password.equals(passwordConfirm)) {
            throw new IllegalArgumentException("Passwords do not match");
        }
        passwordToken = new PasswordToken(password);
    }
    shellState.getAccumuloClient().securityOperations().createLocalUser(user, passwordToken);
    Shell.log.debug("Created user {}", user);
    return 0;
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext)

Example 33 with ClientContext

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

the class ManagerRepairsDualAssignmentIT method test.

@Test
public void test() throws Exception {
    // make some tablets, spread 'em around
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        ClientContext context = (ClientContext) c;
        ServerContext serverContext = cluster.getServerContext();
        String table = this.getUniqueNames(1)[0];
        c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
        c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
        SortedSet<Text> partitions = new TreeSet<>();
        for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
            partitions.add(new Text(part));
        }
        NewTableConfiguration ntc = new NewTableConfiguration().withSplits(partitions);
        c.tableOperations().create(table, ntc);
        // scan the metadata table and get the two table location states
        Set<TServerInstance> states = new HashSet<>();
        Set<TabletLocationState> oldLocations = new HashSet<>();
        TabletStateStore store = TabletStateStore.getStoreForLevel(DataLevel.USER, context);
        while (states.size() < 2) {
            UtilWaitThread.sleep(250);
            oldLocations.clear();
            for (TabletLocationState tls : store) {
                if (tls.current != null) {
                    states.add(tls.current);
                    oldLocations.add(tls);
                }
            }
        }
        assertEquals(2, states.size());
        // Kill a tablet server... we don't care which one... wait for everything to be reassigned
        cluster.killProcess(ServerType.TABLET_SERVER, cluster.getProcesses().get(ServerType.TABLET_SERVER).iterator().next());
        Set<TServerInstance> replStates = new HashSet<>();
        @SuppressWarnings("deprecation") TableId repTable = org.apache.accumulo.core.replication.ReplicationTable.ID;
        // Find out which tablet server remains
        while (true) {
            UtilWaitThread.sleep(1000);
            states.clear();
            replStates.clear();
            boolean allAssigned = true;
            for (TabletLocationState tls : store) {
                if (tls != null && tls.current != null) {
                    states.add(tls.current);
                } else if (tls != null && tls.extent.equals(new KeyExtent(repTable, null, null))) {
                    replStates.add(tls.current);
                } else {
                    allAssigned = false;
                }
            }
            System.out.println(states + " size " + states.size() + " allAssigned " + allAssigned);
            if (states.size() != 2 && allAssigned)
                break;
        }
        assertEquals(1, replStates.size());
        assertEquals(1, states.size());
        // pick an assigned tablet and assign it to the old tablet
        TabletLocationState moved = null;
        for (TabletLocationState old : oldLocations) {
            if (!states.contains(old.current)) {
                moved = old;
            }
        }
        assertNotEquals(null, moved);
        // throw a mutation in as if we were the dying tablet
        TabletMutator tabletMutator = serverContext.getAmple().mutateTablet(moved.extent);
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        // wait for the manager to fix the problem
        waitForCleanStore(store);
        // now jam up the metadata table
        tabletMutator = serverContext.getAmple().mutateTablet(new KeyExtent(MetadataTable.ID, null, null));
        tabletMutator.putLocation(moved.current, LocationType.CURRENT);
        tabletMutator.mutate();
        waitForCleanStore(TabletStateStore.getStoreForLevel(DataLevel.METADATA, context));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableId(org.apache.accumulo.core.data.TableId) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) TabletMutator(org.apache.accumulo.core.metadata.schema.Ample.TabletMutator) Text(org.apache.hadoop.io.Text) TabletStateStore(org.apache.accumulo.server.manager.state.TabletStateStore) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ServerContext(org.apache.accumulo.server.ServerContext) TreeSet(java.util.TreeSet) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) TabletLocationState(org.apache.accumulo.core.metadata.TabletLocationState) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with ClientContext

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

the class TabletServerResource method getTserverDetails.

/**
 * Generates details for the selected tserver
 *
 * @param tserverAddress
 *          TServer name
 * @return TServer details
 */
@Path("{address}")
@GET
public TabletServerSummary getTserverDetails(@PathParam("address") @NotNull @Pattern(regexp = HOSTNAME_PORT_REGEX) String tserverAddress) throws Exception {
    ManagerMonitorInfo mmi = monitor.getMmi();
    if (mmi == null)
        return new TabletServerSummary();
    boolean tserverExists = false;
    for (TabletServerStatus ts : mmi.getTServerInfo()) {
        if (tserverAddress.equals(ts.getName())) {
            tserverExists = true;
            break;
        }
    }
    if (!tserverExists) {
        return null;
    }
    double splitStdDev = 0;
    double minorStdDev = 0;
    double minorQueueStdDev = 0;
    double majorStdDev = 0;
    double majorQueueStdDev = 0;
    double currentMinorAvg = 0;
    double currentMajorAvg = 0;
    double currentMinorStdDev = 0;
    double currentMajorStdDev = 0;
    total = new TabletStats(null, new ActionStats(), new ActionStats(), new ActionStats(), 0, 0, 0, 0);
    HostAndPort address = HostAndPort.fromString(tserverAddress);
    historical = new TabletStats(null, new ActionStats(), new ActionStats(), new ActionStats(), 0, 0, 0, 0);
    List<TabletStats> tsStats = new ArrayList<>();
    try {
        ClientContext context = monitor.getContext();
        TabletClientService.Client client = ThriftUtil.getClient(new TabletClientService.Client.Factory(), address, context);
        try {
            for (String tableId : mmi.tableMap.keySet()) {
                tsStats.addAll(client.getTabletStats(TraceUtil.traceInfo(), context.rpcCreds(), tableId));
            }
            historical = client.getHistoricalStats(TraceUtil.traceInfo(), context.rpcCreds());
        } finally {
            ThriftUtil.returnClient(client, context);
        }
    } catch (Exception e) {
        return null;
    }
    List<CurrentOperations> currentOps = doCurrentOperations(tsStats);
    if (total.minors.num != 0) {
        currentMinorAvg = (long) (total.minors.elapsed / total.minors.num);
    }
    if (total.minors.elapsed != 0 && total.minors.num != 0) {
        currentMinorStdDev = stddev(total.minors.elapsed, total.minors.num, total.minors.sumDev);
    }
    if (total.majors.num != 0) {
        currentMajorAvg = total.majors.elapsed / total.majors.num;
    }
    if (total.majors.elapsed != 0 && total.majors.num != 0 && total.majors.elapsed > total.majors.num) {
        currentMajorStdDev = stddev(total.majors.elapsed, total.majors.num, total.majors.sumDev);
    }
    ActionStatsUpdator.update(total.minors, historical.minors);
    ActionStatsUpdator.update(total.majors, historical.majors);
    minorStdDev = stddev(total.minors.elapsed, total.minors.num, total.minors.sumDev);
    minorQueueStdDev = stddev(total.minors.queueTime, total.minors.num, total.minors.queueSumDev);
    majorStdDev = stddev(total.majors.elapsed, total.majors.num, total.majors.sumDev);
    majorQueueStdDev = stddev(total.majors.queueTime, total.majors.num, total.majors.queueSumDev);
    splitStdDev = stddev(historical.splits.elapsed, historical.splits.num, historical.splits.sumDev);
    TabletServerDetailInformation details = doDetails(tsStats.size());
    List<AllTimeTabletResults> allTime = doAllTimeResults(majorQueueStdDev, minorQueueStdDev, splitStdDev, majorStdDev, minorStdDev);
    CurrentTabletResults currentRes = doCurrentTabletResults(currentMinorAvg, currentMinorStdDev, currentMajorAvg, currentMajorStdDev);
    return new TabletServerSummary(details, allTime, currentRes, currentOps);
}
Also used : TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) ArrayList(java.util.ArrayList) ActionStats(org.apache.accumulo.core.tabletserver.thrift.ActionStats) HostAndPort(org.apache.accumulo.core.util.HostAndPort) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 35 with ClientContext

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

the class AccumuloReplicaSystem method getContextForPeer.

protected ClientContext getContextForPeer(AccumuloConfiguration localConf, ReplicationTarget target, String principal, AuthenticationToken token) {
    requireNonNull(localConf);
    requireNonNull(target);
    requireNonNull(principal);
    requireNonNull(token);
    Properties properties = new Properties();
    properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), instanceName);
    properties.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers);
    properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal);
    ClientProperty.setAuthenticationToken(properties, token);
    return new ClientContext(SingletonReservation.noop(), ClientInfo.from(properties, token), localConf);
}
Also used : ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Properties(java.util.Properties)

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