@Override public void changeLocalUserPassword(final String principal, final PasswordToken token) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); checkArgument(token != null, "token is null"); final Credentials toChange = new Credentials(principal, token); executeVoid(client -> client.changeLocalUserPassword(Tracer.traceInfo(), context.rpcCreds(), principal, ByteBuffer.wrap(token.getPassword()))); if (context.getCredentials().getPrincipal().equals(principal)) { context.setCredentials(toChange); } }
ZookeeperLockChecker(ClientContext context) { zc = context.getZooCache(); this.root = context.getZooKeeperRoot() + Constants.ZTSERVERS; }
@Override public BatchScanner createBatchScanner(String tableName) throws TableNotFoundException, AccumuloSecurityException, AccumuloException { Authorizations auths = securityOperations().getUserAuthorizations(getPrincipal()); return createBatchScanner(tableName, auths); }
@Override public Scanner createScanner(String tableName) throws TableNotFoundException, AccumuloSecurityException, AccumuloException { Authorizations auths = securityOperations().getUserAuthorizations(getPrincipal()); return createScanner(tableName, auths); }
@Override public void grantNamespacePermission(final String principal, final String namespace, final NamespacePermission permission) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); checkArgument(namespace != null, "namespace is null"); checkArgument(permission != null, "permission is null"); executeVoid(client -> client.grantNamespacePermission(Tracer.traceInfo(), context.rpcCreds(), principal, namespace, permission.getId())); }
public static ReplicationCoordinator.Client getCoordinatorConnection(ClientContext context) { List<String> locations = context.getMasterLocations(); log.debug("No masters for replication to instance {}", context.getInstanceName()); return null; log.warn("Master found for {} did not have real location {}", context.getInstanceName(), masterThriftService); return null; String zkPath = context.getZooKeeperRoot() + Constants.ZMASTER_REPLICATION_COORDINATOR_ADDR; String replCoordinatorAddr; context.getZooKeepers(), zkPath); ZooReader reader = new ZooReader(context.getZooKeepers(), context.getZooKeepersSessionTimeOut()); replCoordinatorAddr = new String(reader.getData(zkPath, null), UTF_8); } catch (KeeperException | InterruptedException e) {
private static void stopTabletServer(final ClientContext context, List<String> servers, final boolean force) throws AccumuloException, AccumuloSecurityException { if (context.getMasterLocations().size() == 0) { log.info("No masters running. Not attempting safe unload of tserver."); return; } final String zTServerRoot = getTServersZkPath(context); final ZooCache zc = context.getZooCache(); for (String server : servers) { for (int port : context.getConfiguration().getPort(Property.TSERV_CLIENTPORT)) { HostAndPort address = AddressUtil.parseAddress(server, port); final String finalServer = qualifyWithZooKeeperSessionId(zTServerRoot, zc, address.toString()); log.info("Stopping server {}", finalServer); MasterClient.executeVoid(context, client -> client.shutdownTabletServer(Tracer.traceInfo(), context.rpcCreds(), finalServer, force)); } } }
/** * Get the parent ZNode for tservers for the given instance * * @param context * ClientContext * @return The tservers znode for the instance */ static String getTServersZkPath(ClientContext context) { requireNonNull(context); return context.getZooKeeperRoot() + Constants.ZTSERVERS; }
throws AccumuloException, AccumuloSecurityException { try { long timeInMillis = context.getConfiguration().getTimeInMillis(Property.TSERV_BULK_TIMEOUT); TabletClientService.Iface client = ThriftUtil.getTServerClient(location, context, timeInMillis); List<TKeyExtent> failures = client.bulkImport(Tracer.traceInfo(), context.rpcCreds(), tid, Translator.translate(files, Translators.KET), setTime);
log.debug("Created client with user: " + client.whoami()); log.debug("Creating scanner for table: " + table); log.debug("Authorizations are: " + authorizations); scanner = client.createBatchScanner(split.getTableName(), authorizations, scanThreads); setupIterators(attempt, scanner, split.getTableName(), split); if (classLoaderContext != null) {
public ConnectorImpl(ClientContext context) throws AccumuloSecurityException, AccumuloException { this.context = context; SingletonManager.setMode(Mode.CONNECTOR); if (context.getCredentials().getToken().isDestroyed()) throw new AccumuloSecurityException(context.getCredentials().getPrincipal(), SecurityErrorCode.TOKEN_EXPIRED); // Skip fail fast for system services; string literal for class name, to avoid dependency on // server jar final String tokenClassName = context.getCredentials().getToken().getClass().getName(); if (!SYSTEM_TOKEN_NAME.equals(tokenClassName)) { ServerClient.executeVoid(context, iface -> { if (!iface.authenticate(Tracer.traceInfo(), context.rpcCreds())) throw new AccumuloSecurityException("Authentication failed, access denied", SecurityErrorCode.BAD_CREDENTIALS); }); } }
client -> client.getServicerAddress(remoteTableId, peerContext.rpcCreds())); } catch (AccumuloException | AccumuloSecurityException e) { try { finalStatus = replicateLogs(peerContext, peerTserver, target, p, status, sizeLimit, remoteTableId, peerContext.rpcCreds(), helper, accumuloUgi, timeout); } finally { span.stop(); peerContext.getInstanceName(), ProtobufUtil.toString(finalStatus));
@Override public void createLocalUser(final String principal, final PasswordToken password) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); if (context.getSaslParams() == null) { checkArgument(password != null, "password is null"); } executeVoid(client -> { if (context.getSaslParams() == null) { client.createLocalUser(Tracer.traceInfo(), context.rpcCreds(), principal, ByteBuffer.wrap(password.getPassword())); } else { client.createLocalUser(Tracer.traceInfo(), context.rpcCreds(), principal, ByteBuffer.wrap(new byte[0])); } }); }
public ClientContext(SingletonReservation reservation, ClientInfo info, AccumuloConfiguration serverConf) { this.info = info; this.hadoopConf = info.getHadoopConf(); zooCache = new ZooCacheFactory().getZooCache(info.getZooKeepers(), info.getZooKeepersSessionTimeOut()); this.serverConf = serverConf; timeoutSupplier = memoizeWithExpiration( () -> getConfiguration().getTimeInMillis(Property.GENERAL_RPC_TIMEOUT)); sslSupplier = memoizeWithExpiration(() -> SslConnectionParams.forClient(getConfiguration())); saslSupplier = memoizeWithExpiration( () -> SaslConnectionParams.from(getConfiguration(), getCredentials().getToken())); this.singletonReservation = Objects.requireNonNull(reservation); this.tableops = new TableOperationsImpl(this); this.namespaceops = new NamespaceOperationsImpl(this, tableops); }
@Override public boolean authenticateUser(final String principal, final AuthenticationToken token) throws AccumuloException, AccumuloSecurityException { checkArgument(principal != null, "principal is null"); checkArgument(token != null, "token is null"); final Credentials toAuth = new Credentials(principal, token); return execute(client -> client.authenticateUser(Tracer.traceInfo(), context.rpcCreds(), toAuth.toThrift(context.getInstanceID()))); }
/** * Clears the zoo cache from instance/root/{PATH} * * @param context * The Accumulo client context * @param zooPath * A zookeeper path */ public static void clearCacheByPath(ClientContext context, final String zooPath) { String thePath = zooPath.startsWith("/") ? zooPath : "/" + zooPath; getZooCache(context).clear(context.getZooKeeperRoot() + thePath); instanceToMapCache.invalidate(context.getInstanceID()); }
/** * Returns the location(s) of the accumulo master and any redundant servers. * * @return a list of locations in "hostname:port" form */ public List<String> getMasterLocations() { ensureOpen(); String masterLocPath = getZooKeeperRoot() + Constants.ZMASTER_LOCK; OpTimer timer = null; if (log.isTraceEnabled()) { log.trace("tid={} Looking up master location in zookeeper.", Thread.currentThread().getId()); timer = new OpTimer().start(); } byte[] loc = ZooUtil.getLockData(zooCache, masterLocPath); if (timer != null) { timer.stop(); log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), (loc == null ? "null" : new String(loc, UTF_8)), String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); } if (loc == null) { return Collections.emptyList(); } return Collections.singletonList(new String(loc, UTF_8)); }
@Override public BatchScanner createBatchScanner(String tableName, Authorizations authorizations) throws TableNotFoundException { Integer numQueryThreads = ClientProperty.BATCH_SCANNER_NUM_QUERY_THREADS .getInteger(getProperties()); Objects.requireNonNull(numQueryThreads); ensureOpen(); return createBatchScanner(tableName, authorizations, numQueryThreads); }
final LogFileKey key = new LogFileKey(); final LogFileValue value = new LogFileValue(); final long memoryInBytes = context.getConfiguration() .getAsBytes(Property.TSERV_REPLICATION_BW_REPLAYER_MEMORY); bwConfig.setMaxMemory(memoryInBytes); try { bw = context.createBatchWriter(tableName, bwConfig); } catch (TableNotFoundException e) { throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST,
@Override public BatchWriter createBatchWriter(String tableName, BatchWriterConfig config) throws TableNotFoundException { return context.createBatchWriter(tableName, config); }