use of org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException in project accumulo by apache.
the class MasterClientServiceHandler method alterTableProperty.
private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
final Table.ID tableId = ClientServiceHandler.checkTableId(master.getInstance(), tableName, op);
Namespace.ID namespaceId = getNamespaceIdFromTableId(op, tableId);
if (!master.security.canAlterTable(c, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
try {
if (value == null || value.isEmpty()) {
TablePropUtil.removeTableProperty(tableId, property);
} else if (!TablePropUtil.setTableProperty(tableId, property, value)) {
throw new Exception("Invalid table property.");
}
} catch (KeeperException.NoNodeException e) {
// race condition... table no longer exists? This call will throw an exception if the table was deleted:
ClientServiceHandler.checkTableId(master.getInstance(), tableName, op);
log.info("Error altering table property", e);
throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
} catch (Exception e) {
log.error("Problem altering table property", e);
throw new ThriftTableOperationException(tableId.canonicalID(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
}
}
use of org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException in project accumulo by apache.
the class MasterReplicationCoordinator method getServicerAddress.
@Override
public String getServicerAddress(String remoteTableId, TCredentials creds) throws ReplicationCoordinatorException, TException {
try {
security.authenticateUser(master.rpcCreds(), creds);
} catch (ThriftSecurityException e) {
log.error("{} failed to authenticate for replication to {}", creds.getPrincipal(), remoteTableId);
throw new ReplicationCoordinatorException(ReplicationCoordinatorErrorCode.CANNOT_AUTHENTICATE, "Could not authenticate " + creds.getPrincipal());
}
Set<TServerInstance> tservers = master.onlineTabletServers();
if (tservers.isEmpty()) {
throw new ReplicationCoordinatorException(ReplicationCoordinatorErrorCode.NO_AVAILABLE_SERVERS, "No tservers are available for replication");
}
TServerInstance tserver = getRandomTServer(tservers, rand.nextInt(tservers.size()));
String replServiceAddr;
try {
replServiceAddr = new String(reader.getData(ZooUtil.getRoot(inst) + ReplicationConstants.ZOO_TSERVERS + "/" + tserver.hostPort(), null), UTF_8);
} catch (KeeperException | InterruptedException e) {
log.error("Could not fetch repliation service port for tserver", e);
throw new ReplicationCoordinatorException(ReplicationCoordinatorErrorCode.SERVICE_CONFIGURATION_UNAVAILABLE, "Could not determine port for replication service running at " + tserver.hostPort());
}
return replServiceAddr;
}
use of org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException in project accumulo by apache.
the class Writer method updateServer.
private static void updateServer(ClientContext context, Mutation m, KeyExtent extent, HostAndPort server) throws TException, NotServingTabletException, ConstraintViolationException, AccumuloSecurityException {
checkArgument(m != null, "m is null");
checkArgument(extent != null, "extent is null");
checkArgument(server != null, "server is null");
checkArgument(context != null, "context is null");
TabletClientService.Iface client = null;
try {
client = ThriftUtil.getTServerClient(server, context);
client.update(Tracer.traceInfo(), context.rpcCreds(), extent.toThrift(), m.toThrift(), TDurability.DEFAULT);
return;
} catch (ThriftSecurityException e) {
throw new AccumuloSecurityException(e.user, e.code);
} finally {
ThriftUtil.returnClient((TServiceClient) client);
}
}
use of org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException in project accumulo by apache.
the class MiniAccumuloClusterImpl method getMasterMonitorInfo.
/**
* Get programmatic interface to information available in a normal monitor. XXX the returned structure won't contain information about the metadata table
* until there is data in it. e.g. if you want to see the metadata table you should create a table.
*
* @since 1.6.1
*/
public MasterMonitorInfo getMasterMonitorInfo() throws AccumuloException, AccumuloSecurityException {
MasterClientService.Iface client = null;
while (true) {
try {
Instance instance = new ZooKeeperInstance(getClientConfig());
ClientContext context = new ClientContext(instance, new Credentials("root", new PasswordToken("unchecked")), getClientConfig());
client = MasterClient.getConnectionWithRetry(context);
return client.getMasterStats(Tracer.traceInfo(), context.rpcCreds());
} catch (ThriftSecurityException exception) {
throw new AccumuloSecurityException(exception);
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
log.debug("Contacted a Master which is no longer active, retrying");
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} catch (TException exception) {
throw new AccumuloException(exception);
} finally {
if (client != null) {
MasterClient.close(client);
}
}
}
}
use of org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException in project accumulo by apache.
the class ClientServiceHandler method bulkImportFiles.
@Override
public List<String> bulkImportFiles(TInfo tinfo, final TCredentials credentials, final long tid, final String tableId, final List<String> files, final String errorDir, final boolean setTime) throws ThriftSecurityException, ThriftTableOperationException, TException {
try {
if (!security.canPerformSystemActions(credentials))
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
bulkImportStatus.updateBulkImportStatus(files, BulkImportState.INITIAL);
log.debug("Got request to bulk import files to table({}): {}", tableId, files);
return transactionWatcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
bulkImportStatus.updateBulkImportStatus(files, BulkImportState.PROCESSING);
try {
return BulkImporter.bulkLoad(context, tid, tableId, files, errorDir, setTime);
} finally {
bulkImportStatus.removeBulkImportStatus(files);
}
}
});
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
} catch (Exception ex) {
throw new TException(ex);
}
}
Aggregations