use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ManagerClientServiceHandler method initiateFlush.
@Override
public long initiateFlush(TInfo tinfo, TCredentials c, String tableIdStr) throws ThriftSecurityException, ThriftTableOperationException {
TableId tableId = TableId.of(tableIdStr);
NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
if (!manager.security.canFlush(c, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
String zTablePath = Constants.ZROOT + "/" + manager.getInstanceID() + Constants.ZTABLES + "/" + tableId + Constants.ZTABLE_FLUSH_ID;
ZooReaderWriter zoo = manager.getContext().getZooReaderWriter();
byte[] fid;
try {
fid = zoo.mutateExisting(zTablePath, currentValue -> {
long flushID = Long.parseLong(new String(currentValue, UTF_8));
return Long.toString(flushID + 1).getBytes(UTF_8);
});
} catch (NoNodeException nne) {
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
} catch (Exception e) {
Manager.log.warn("{}", e.getMessage(), e);
throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.OTHER, null);
}
return Long.parseLong(new String(fid));
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ClientServiceHandler method checkNamespaceClass.
@Override
public boolean checkNamespaceClass(TInfo tinfo, TCredentials credentials, String ns, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException {
security.authenticateUser(credentials, credentials);
NamespaceId namespaceId = checkNamespaceId(context, ns, null);
ClassLoader loader = getClass().getClassLoader();
Class<?> shouldMatch;
try {
shouldMatch = loader.loadClass(interfaceMatch);
AccumuloConfiguration conf = context.getNamespaceConfiguration(namespaceId);
String context = ClassLoaderUtil.tableContext(conf);
Class<?> test = ClassLoaderUtil.loadClass(context, className, shouldMatch);
test.getDeclaredConstructor().newInstance();
return true;
} catch (Exception e) {
log.warn("Error checking object types", e);
return false;
}
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ClientServiceHandler method grantTablePermission.
@Override
public void grantTablePermission(TInfo tinfo, TCredentials credentials, String user, String tableName, byte permission) throws TException {
TableId tableId = checkTableId(context, tableName, TableOperation.PERMISSION);
NamespaceId namespaceId;
try {
namespaceId = context.getNamespaceId(tableId);
} catch (TableNotFoundException e) {
throw new TException(e);
}
security.grantTablePermission(credentials, user, tableId, TablePermission.getPermissionById(permission), namespaceId);
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ClientServiceHandler method revokeNamespacePermission.
@Override
public void revokeNamespacePermission(TInfo tinfo, TCredentials credentials, String user, String ns, byte permission) throws ThriftSecurityException, ThriftTableOperationException {
NamespaceId namespaceId = checkNamespaceId(context, ns, TableOperation.PERMISSION);
security.revokeNamespacePermission(credentials, user, namespaceId, NamespacePermission.getPermissionById(permission));
}
use of org.apache.accumulo.core.data.NamespaceId in project accumulo by apache.
the class ClientServiceHandler method checkNamespaceId.
public static NamespaceId checkNamespaceId(ClientContext context, String namespaceName, TableOperation operation) throws ThriftTableOperationException {
NamespaceId namespaceId = Namespaces.lookupNamespaceId(context, namespaceName);
if (namespaceId == null) {
// maybe the namespace exists, but the cache was not updated yet... so try to clear the cache
// and check again
context.clearTableListCache();
namespaceId = Namespaces.lookupNamespaceId(context, namespaceName);
if (namespaceId == null)
throw new ThriftTableOperationException(null, namespaceName, operation, TableOperationExceptionType.NAMESPACE_NOTFOUND, null);
}
return namespaceId;
}
Aggregations