Search in sources :

Example 26 with NamespaceId

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));
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) ManagerMonitorInfo(org.apache.accumulo.core.manager.thrift.ManagerMonitorInfo) LoggerFactory(org.slf4j.LoggerFactory) Status(org.apache.accumulo.server.replication.proto.Replication.Status) Text(org.apache.hadoop.io.Text) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) ByteBuffer(java.nio.ByteBuffer) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) BatchScanner(org.apache.accumulo.core.client.BatchScanner) TInfo(org.apache.accumulo.core.trace.thrift.TInfo) RootTable(org.apache.accumulo.core.metadata.RootTable) Value(org.apache.accumulo.core.data.Value) ReplicationSection(org.apache.accumulo.core.metadata.schema.MetadataSchema.ReplicationSection) PREV_ROW(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.PREV_ROW) TablePropUtil(org.apache.accumulo.server.util.TablePropUtil) Property(org.apache.accumulo.core.conf.Property) TDelegationTokenConfig(org.apache.accumulo.core.securityImpl.thrift.TDelegationTokenConfig) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ClientContext(org.apache.accumulo.core.clientImpl.ClientContext) Set(java.util.Set) DelegationTokenConfigSerializer(org.apache.accumulo.core.clientImpl.DelegationTokenConfigSerializer) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) TabletLoadState(org.apache.accumulo.core.manager.thrift.TabletLoadState) AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) List(java.util.List) DeprecatedPropertyUtil(org.apache.accumulo.core.conf.DeprecatedPropertyUtil) AuthenticationTokenSecretManager(org.apache.accumulo.server.security.delegation.AuthenticationTokenSecretManager) ManagerState(org.apache.accumulo.core.manager.thrift.ManagerState) Entry(java.util.Map.Entry) ShutdownTServer(org.apache.accumulo.manager.tserverOps.ShutdownTServer) NamespaceId(org.apache.accumulo.core.data.NamespaceId) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) TabletSplit(org.apache.accumulo.core.manager.thrift.TabletSplit) ByteBufferUtil(org.apache.accumulo.core.util.ByteBufferUtil) DelegationTokenConfig(org.apache.accumulo.core.client.admin.DelegationTokenConfig) ProtobufUtil(org.apache.accumulo.core.protobuf.ProtobufUtil) FLUSH_ID(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.FLUSH_ID) ArrayList(java.util.ArrayList) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) NamespacePropUtil(org.apache.accumulo.server.util.NamespacePropUtil) HashSet(java.util.HashSet) ManagerGoalState(org.apache.accumulo.core.manager.thrift.ManagerGoalState) Key(org.apache.accumulo.core.data.Key) SystemPropUtil(org.apache.accumulo.server.util.SystemPropUtil) TableOperationExceptionType(org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType) ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) TDelegationToken(org.apache.accumulo.core.securityImpl.thrift.TDelegationToken) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) LOCATION(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION) Logger(org.slf4j.Logger) SecurityErrorCode(org.apache.accumulo.core.clientImpl.thrift.SecurityErrorCode) KeeperException(org.apache.zookeeper.KeeperException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) AuthenticationTokenIdentifier(org.apache.accumulo.core.clientImpl.AuthenticationTokenIdentifier) ClientServiceHandler(org.apache.accumulo.server.client.ClientServiceHandler) TException(org.apache.thrift.TException) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) Token(org.apache.hadoop.security.token.Token) Range(org.apache.accumulo.core.data.Range) TimeUnit(java.util.concurrent.TimeUnit) TableOperation(org.apache.accumulo.core.clientImpl.thrift.TableOperation) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TraceRepo(org.apache.accumulo.manager.tableOps.TraceRepo) Collections(java.util.Collections) LOGS(org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOGS) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) KeeperException(org.apache.zookeeper.KeeperException) TException(org.apache.thrift.TException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException)

Example 27 with NamespaceId

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;
    }
}
Also used : NamespaceId(org.apache.accumulo.core.data.NamespaceId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 28 with NamespaceId

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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 29 with 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));
}
Also used : NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 30 with NamespaceId

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;
}
Also used : ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Aggregations

NamespaceId (org.apache.accumulo.core.data.NamespaceId)32 TableId (org.apache.accumulo.core.data.TableId)20 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)12 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)11 TException (org.apache.thrift.TException)9 IOException (java.io.IOException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 HashSet (java.util.HashSet)6 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)5 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)5 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 Authorizations (org.apache.accumulo.core.security.Authorizations)4 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)4 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)4