public static Pair<String,ClientService.Client> getConnection(ClientContext context) throws TTransportException { return getConnection(context, true); }
@Override public boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, new ClientExecReturn<Boolean,ClientService.Client>() { @Override public Boolean execute(ClientService.Client client) throws Exception { return client.checkClass(Tracer.traceInfo(), context.rpcCreds(), className, asTypeName); } }); }
public static <T> T execute(ClientContext context, ClientExecReturn<T,ClientService.Client> exec) throws AccumuloException, AccumuloSecurityException { try { return executeRaw(context, exec); } catch (ThriftSecurityException e) { throw new AccumuloSecurityException(e.user, e.code, e); } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
public static <T> T executeRaw(ClientContext context, ClientExecReturn<T,ClientService.Client> exec) throws Exception { while (true) { ClientService.Client client = null; String server = null; try { Pair<String,Client> pair = ServerClient.getConnection(context); server = pair.getFirst(); client = pair.getSecond(); return exec.execute(client); } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } finally { if (client != null) ServerClient.close(client); } } }
} finally { if (client != null) ServerClient.close(client); locator.invalidateCache();
public static void executeRaw(ClientContext context, ClientExec<ClientService.Client> exec) throws Exception { while (true) { ClientService.Client client = null; String server = null; try { Pair<String,Client> pair = ServerClient.getConnection(context); server = pair.getFirst(); client = pair.getSecond(); exec.execute(client); break; } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } finally { if (client != null) ServerClient.close(client); } } }
} finally { if (client != null) { ServerClient.close(client);
@Override public List<String> call() { List<String> failures = new ArrayList<String>(); ClientService.Client client = null; String server = null; try { // get a connection to a random tablet server, do not prefer cached connections because // this is running on the master and there are lots of connections to tablet servers // serving the !METADATA tablets long timeInMillis = master.getConfiguration().getConfiguration().getTimeInMillis(Property.MASTER_BULK_TIMEOUT); Pair<String,Client> pair = ServerClient.getConnection(master.getInstance(), false, timeInMillis); client = pair.getSecond(); server = pair.getFirst(); List<String> attempt = Collections.singletonList(file); log.debug("Asking " + pair.getFirst() + " to bulk import " + file); List<String> fail = client.bulkImportFiles(Tracer.traceInfo(), SecurityConstants.getSystemCredentials(), tid, tableId, attempt, errorDir, setTime); if (fail.isEmpty()) { loaded.add(file); } else { failures.addAll(fail); } } catch (Exception ex) { log.error("rpc failed server:" + server + ", tid:" + tid + " " + ex); } finally { ServerClient.close(client); } return failures; } }));
public static Pair<String,ClientService.Client> getConnection(ClientContext context, boolean preferCachedConnections) throws TTransportException { return getConnection(context, preferCachedConnections, context.getClientTimeoutInMillis()); }
public static void execute(ClientContext context, ClientExec<ClientService.Client> exec) throws AccumuloException, AccumuloSecurityException { try { executeRaw(context, exec); } catch (ThriftSecurityException e) { throw new AccumuloSecurityException(e.user, e.code, e); } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
@Override public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, new ClientExecReturn<Map<String,String>,ClientService.Client>() { @Override public Map<String,String> execute(ClientService.Client client) throws Exception { return client.getConfiguration(Tracer.traceInfo(), context.rpcCreds(), ConfigurationType.SITE); } }); }
private void checkTabletServerExists(ZooKeeperInstance inst, String userName, String password) throws ResourceException { ClientService.Client client = null; try { Pair<String,Client> pair = ServerClient.getConnection(new ClientContext(inst, new Credentials(userName, new PasswordToken(password)), inst.getConfiguration()), true, 10); client = pair.getSecond(); } catch (TTransportException e) { throw new ResourceException(AccumuloManagedConnectionFactory.UTIL.getString("no_tserver"), e); } finally { if (client != null) { ServerClient.close(client); } } }
@Override public Iterable<Entry<String,String>> getProperties(final String namespace) throws AccumuloException, NamespaceNotFoundException { checkArgument(namespace != null, "namespace is null"); try { return ServerClient .executeRaw(context, new ClientExecReturn<Map<String,String>,ClientService.Client>() { @Override public Map<String,String> execute(ClientService.Client client) throws Exception { return client.getNamespaceConfiguration(Tracer.traceInfo(), context.rpcCreds(), namespace); } }).entrySet(); } catch (ThriftTableOperationException e) { switch (e.getType()) { case NAMESPACE_NOTFOUND: throw new NamespaceNotFoundException(e); case OTHER: default: throw new AccumuloException(e.description, e); } } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
@Override public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, new ClientExecReturn<Map<String,String>,ClientService.Client>() { @Override public Map<String,String> execute(ClientService.Client client) throws Exception { return client.getConfiguration(Tracer.traceInfo(), context.rpcCreds(), ConfigurationType.CURRENT); } }); }
private void checkTabletServerExists(ZooKeeperInstance inst, String userName, String password) throws ResourceException { ClientService.Client client = null; try { Pair<String,Client> pair = ServerClient.getConnection(new ClientContext(inst, new Credentials(userName, new PasswordToken(password)), inst.getConfiguration()), true, 10); client = pair.getSecond(); } catch (TTransportException e) { throw new ResourceException(AccumuloManagedConnectionFactory.UTIL.getString("no_tserver"), e); } finally { if (client != null) { ServerClient.close(client); } } }
@Override public boolean testClassLoad(final String namespace, final String className, final String asTypeName) throws NamespaceNotFoundException, AccumuloException, AccumuloSecurityException { checkArgument(namespace != null, "namespace is null"); checkArgument(className != null, "className is null"); checkArgument(asTypeName != null, "asTypeName is null"); try { return ServerClient.executeRaw(context, new ClientExecReturn<Boolean,ClientService.Client>() { @Override public Boolean execute(ClientService.Client client) throws Exception { return client.checkNamespaceClass(Tracer.traceInfo(), context.rpcCreds(), namespace, className, asTypeName); } }); } catch (ThriftTableOperationException e) { switch (e.getType()) { case NAMESPACE_NOTFOUND: throw new NamespaceNotFoundException(e); default: throw new AccumuloException(e.description, e); } } catch (ThriftSecurityException e) { throw new AccumuloSecurityException(e.user, e.code, e); } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
public ConnectorImpl(final ClientContext context) throws AccumuloException, AccumuloSecurityException { checkArgument(context != null, "Context is null"); checkArgument(context.getCredentials() != null, "Credentials are null"); checkArgument(context.getCredentials().getToken() != null, "Authentication token is null"); if (context.getCredentials().getToken().isDestroyed()) throw new AccumuloSecurityException(context.getCredentials().getPrincipal(), SecurityErrorCode.TOKEN_EXPIRED); this.context = context; // 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.execute(context, new ClientExec<ClientService.Client>() { @Override public void execute(ClientService.Client iface) throws Exception { if (!iface.authenticate(Tracer.traceInfo(), context.rpcCreds())) throw new AccumuloSecurityException("Authentication failed, access denied", SecurityErrorCode.BAD_CREDENTIALS); } }); } this.tableops = new TableOperationsImpl(context); this.namespaceops = new NamespaceOperationsImpl(context, tableops); }
pair = ServerClient.getConnection(context, false); diskUsages = pair.getSecond().getDiskUsage(tableNames, context.rpcCreds()); } catch (ThriftTableOperationException e) { ServerClient.close(pair.getSecond());
@Override public Iterable<Entry<String,String>> getProperties(final String tableName) throws AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); try { return ServerClient .executeRaw(context, new ClientExecReturn<Map<String,String>,ClientService.Client>() { @Override public Map<String,String> execute(ClientService.Client client) throws Exception { return client.getTableConfiguration(Tracer.traceInfo(), context.rpcCreds(), tableName); } }).entrySet(); } catch (ThriftTableOperationException e) { switch (e.getType()) { case NOTFOUND: throw new TableNotFoundException(e); case NAMESPACE_NOTFOUND: throw new TableNotFoundException(tableName, new NamespaceNotFoundException(e)); default: throw new AccumuloException(e.description, e); } } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
return ServerClient.executeRaw(context, new ClientExecReturn<Boolean,ClientService.Client>() { @Override public Boolean execute(ClientService.Client client) throws Exception {