private void decodeRows(TreeMap<Key,Value> encodedResults, TreeMap<Key,Value> results) throws AccumuloException { for (Entry<Key,Value> entry : encodedResults.entrySet()) { try { results.putAll(WholeRowIterator.decodeRow(entry.getKey(), entry.getValue())); } catch (IOException e) { throw new AccumuloException(e); } } }
@Override public void setProperty(final String tableName, final String property, final String value) throws AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); checkArgument(property != null, "property is null"); checkArgument(value != null, "value is null"); try { setPropertyNoChecks(tableName, property, value); checkLocalityGroups(tableName, property); } catch (TableNotFoundException e) { throw new AccumuloException(e); } }
@Override public void removeProperty(final String tableName, final String property) throws AccumuloException, AccumuloSecurityException { checkArgument(tableName != null, "tableName is null"); checkArgument(property != null, "property is null"); try { removePropertyNoChecks(tableName, property); checkLocalityGroups(tableName, property); } catch (TableNotFoundException e) { throw new AccumuloException(e); } }
@Override public Map<String,Integer> listConstraints(String namespace) throws AccumuloException, NamespaceNotFoundException, AccumuloSecurityException { Map<String,Integer> constraints = new TreeMap<>(); for (Entry<String,String> property : this.getProperties(namespace)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { if (constraints.containsKey(property.getValue())) throw new AccumuloException("Same constraint configured twice: " + property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX + constraints.get(property.getValue()) + "=" + property.getKey()); try { constraints.put(property.getValue(), Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()))); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } } } return constraints; } }
public static byte[] createPass(byte[] password) throws AccumuloException { byte[] salt = generateSalt(); try { return convertPass(password, salt); } catch (NoSuchAlgorithmException e) { log.error("Count not create hashed password", e); throw new AccumuloException("Count not create hashed password", e); } }
@Override public Map<String,Integer> listConstraints(String tableName) throws AccumuloException, TableNotFoundException { Map<String,Integer> constraints = new TreeMap<>(); for (Entry<String,String> property : this.getProperties(tableName)) { if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) { if (constraints.containsKey(property.getValue())) throw new AccumuloException("Same constraint configured twice: " + property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX + constraints.get(property.getValue()) + "=" + property.getKey()); try { constraints.put(property.getValue(), Integer.parseInt( property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()))); } catch (NumberFormatException e) { throw new AccumuloException("Bad key for existing constraint: " + property); } } } return constraints; } }
@Override public void flush(String tableName) throws AccumuloException, AccumuloSecurityException { try { flush(tableName, null, null, false); } catch (TableNotFoundException e) { throw new AccumuloException(e.getMessage(), 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); } }
private void doTableFateOperation(String tableOrNamespaceName, Class<? extends Exception> namespaceNotFoundExceptionClass, FateOperation op, List<ByteBuffer> args, Map<String,String> opts) throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException { try { doFateOperation(op, args, opts, tableOrNamespaceName); } catch (NamespaceExistsException e) { // should not happen throw new AssertionError(e); } catch (NamespaceNotFoundException e) { if (namespaceNotFoundExceptionClass == null) { // should not happen throw new AssertionError(e); } else if (AccumuloException.class.isAssignableFrom(namespaceNotFoundExceptionClass)) { throw new AccumuloException("Cannot create table in non-existent namespace", e); } else if (TableNotFoundException.class.isAssignableFrom(namespaceNotFoundExceptionClass)) { throw new TableNotFoundException(null, tableOrNamespaceName, "Namespace not found", e); } else { // should not happen throw new AssertionError(e); } } }
/** * @param context * the client session for the peer replicant * @return Client to the ReplicationCoordinator service */ public static ReplicationCoordinator.Client getCoordinatorConnectionWithRetry( ClientContext context) throws AccumuloException { requireNonNull(context); for (int attempts = 1; attempts <= 10; attempts++) { ReplicationCoordinator.Client result = getCoordinatorConnection(context); if (result != null) return result; log.debug("Could not get ReplicationCoordinator connection to {}, will retry", context.getInstanceName()); try { Thread.sleep(attempts * 250); } catch (InterruptedException e) { throw new AccumuloException(e); } } throw new AccumuloException( "Timed out trying to communicate with master from " + context.getInstanceName()); }
private static Pair<Text,KeyExtent> verifyRootTablet(ServerContext context, TServerInstance instance) throws AccumuloException { ZooTabletStateStore store = new ZooTabletStateStore(context); if (!store.iterator().hasNext()) { throw new AccumuloException("Illegal state: location is not set in zookeeper"); } TabletLocationState next = store.iterator().next(); if (!instance.equals(next.future)) { throw new AccumuloException("Future location is not to this server for the root tablet"); } if (next.current != null) { throw new AccumuloException("Root tablet already has a location set"); } try { return new Pair<>(new Text(MetadataTableUtil.getRootTabletDir(context)), null); } catch (IOException e) { throw new AccumuloException(e); } }
@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); } }
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); } }
private <T> T execute(ClientExecReturn<T,ClientService.Client> exec) throws AccumuloException, AccumuloSecurityException { try { return ServerClient.executeRaw(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); } }
/** * If this method throws an exception, then its possible the mutation is still being actively * processed. Therefore if code chooses to continue after seeing an exception it should take * this into consideration. * * @return status of a conditional mutation */ public Status getStatus() throws AccumuloException, AccumuloSecurityException { if (status == null) { if (exception instanceof AccumuloException) throw new AccumuloException(exception); if (exception instanceof AccumuloSecurityException) { AccumuloSecurityException ase = (AccumuloSecurityException) exception; throw new AccumuloSecurityException(ase.getUser(), SecurityErrorCode.valueOf(ase.getSecurityErrorCode().name()), ase.getTableInfo(), ase); } else throw new AccumuloException(exception); } return status; }
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); } }
private void doDropUser(final Shell shellState, final String user, final boolean force) throws AccumuloException, AccumuloSecurityException { boolean operate = true; try { if (!force) { shellState.getReader().flush(); String line = shellState.getReader().readLine(getName() + " { " + user + " } (yes|no)? "); operate = line != null && (line.equalsIgnoreCase("y") || line.equalsIgnoreCase("yes")); } if (operate) { shellState.getAccumuloClient().securityOperations().dropLocalUser(user); Shell.log.debug("Deleted user " + user); } } catch (IOException e) { throw new AccumuloException(e); } }
@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); } }
public static <T> T executeServicerWithReturn(ClientContext context, HostAndPort tserver, ClientExecReturn<T,ReplicationServicer.Client> exec, long timeout) throws AccumuloException, AccumuloSecurityException { ReplicationServicer.Client client = null; while (true) { try { client = getServicerConnection(context, tserver, timeout); return exec.execute(client); } catch (ThriftSecurityException e) { throw new AccumuloSecurityException(e.user, e.code, e); } catch (AccumuloException e) { throw e; } catch (Exception e) { throw new AccumuloException(e); } finally { if (client != null) close(client); } } }
@Override public void ping(String tserver) throws AccumuloException { TTransport transport = null; try { transport = ThriftUtil.createTransport(AddressUtil.parseAddress(tserver, false), context); TabletClientService.Client client = ThriftUtil .createClient(new TabletClientService.Client.Factory(), transport); client.getTabletServerStatus(Tracer.traceInfo(), context.rpcCreds()); } catch (TException e) { throw new AccumuloException(e); } finally { if (transport != null) { transport.close(); } } }