public static <CT extends TServiceClient,RT> RT execute(ClientContext context, TServiceClientFactory<CT> factory, ClientExecReturn<RT,CT> exec) throws AccumuloException, AccumuloSecurityException { try { return executeRaw(context, factory, 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 void executeVoid(ClientContext context, ClientExec<ClientService.Client> exec) throws AccumuloException, AccumuloSecurityException { try { executeRawVoid(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 Pair<String,ClientService.Client> getConnection(ClientContext context) throws TTransportException { return getConnection(context, true); }
public static <CT extends TServiceClient,RT> RT executeRaw(ClientContext context, TServiceClientFactory<CT> factory, ClientExecReturn<RT,CT> exec) throws Exception { while (true) { CT client = null; String server = null; try { Pair<String,CT> pair = ServerClient.getConnection(context, factory); server = pair.getFirst(); client = pair.getSecond(); return exec.execute(client); } catch (TApplicationException tae) { throw new AccumuloServerException(server, tae); } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } finally { if (client != null) ServerClient.close(client); } } }
public static <T> T executeRaw(ClientContext context, ClientExecReturn<T,ClientService.Client> exec) throws Exception { return executeRaw(context, new ClientService.Client.Factory(), exec); }
} finally { if (client != null) { ServerClient.close(client);
@Override public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, client -> client.getConfiguration(Tracer.traceInfo(), context.rpcCreds(), ConfigurationType.SITE)); }
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); }); } }
public static void executeRawVoid(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 (TApplicationException tae) { throw new AccumuloServerException(server, tae); } catch (TTransportException tte) { log.debug("ClientService request failed " + server + ", retrying ... ", tte); sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } 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, client -> 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 boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, client -> client.checkClass(Tracer.traceInfo(), context.rpcCreds(), className, asTypeName)); }
pair = ServerClient.getConnection(context, false); diskUsages = pair.getSecond().getDiskUsage(tableNames, context.rpcCreds()); } catch (ThriftTableOperationException e) { ServerClient.close(pair.getSecond());
@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, client -> 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); } }
@Override public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(context, client -> client.getConfiguration(Tracer.traceInfo(), context.rpcCreds(), ConfigurationType.CURRENT)); }
public static Pair<String,ClientService.Client> getConnection(ClientContext context, boolean preferCachedConnections, long rpcTimeout) throws TTransportException { return getConnection(context, new ClientService.Client.Factory(), preferCachedConnections, rpcTimeout); }
private void executeVoid(ClientExec<ClientService.Client> exec) throws AccumuloException, AccumuloSecurityException { try { ServerClient.executeRawVoid(context, exec); } catch (ThriftTableOperationException ttoe) { // recast missing table if (ttoe.getType() == TableOperationExceptionType.NOTFOUND) throw new AccumuloSecurityException(null, SecurityErrorCode.TABLE_DOESNT_EXIST); else if (ttoe.getType() == TableOperationExceptionType.NAMESPACE_NOTFOUND) throw new AccumuloSecurityException(null, SecurityErrorCode.NAMESPACE_DOESNT_EXIST); else throw new AccumuloException(ttoe); } 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 boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); checkArgument(className != null, "className is null"); checkArgument(asTypeName != null, "asTypeName is null"); try { return ServerClient.executeRaw(context, client -> client.checkTableClass(Tracer.traceInfo(), context.rpcCreds(), tableName, className, asTypeName)); } 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 (ThriftSecurityException e) { throw new AccumuloSecurityException(e.user, e.code, e); } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } }
@Override public SummaryCollection get() { TSummaryRequest req = getRequest(); TSummaries tSums; try { tSums = ServerClient.execute(ctx, new TabletClientService.Client.Factory(), client -> { TSummaries tsr = client.startGetSummariesForPartition(tinfo, ctx.rpcCreds(), req, modulus, remainder); while (!tsr.finished && !cancelFlag.get()) { tsr = client.contiuneGetSummaries(tinfo, tsr.sessionId); } return tsr; }); } catch (AccumuloException | AccumuloSecurityException e) { throw new RuntimeException(e); } if (cancelFlag.get()) { throw new RuntimeException("Operation canceled"); } return new SummaryCollection(tSums); } }
public static Pair<String,ClientService.Client> getConnection(ClientContext context, boolean preferCachedConnections) throws TTransportException { return getConnection(context, preferCachedConnections, context.getClientTimeoutInMillis()); }
@Override public Iterable<Entry<String,String>> getProperties(final String tableName) throws AccumuloException, TableNotFoundException { checkArgument(tableName != null, "tableName is null"); try { return ServerClient.executeRaw(context, client -> 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); } }