Search in sources :

Example 16 with ThriftTableOperationException

use of org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException in project accumulo by apache.

the class TableOperationsImpl method testClassLoad.

@Override
public boolean testClassLoad(final String tableName, final String className, final String asTypeName) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    EXISTING_TABLE_NAME.validate(tableName);
    checkArgument(className != null, "className is null");
    checkArgument(asTypeName != null, "asTypeName is null");
    try {
        return ServerClient.executeRaw(context, client -> client.checkTableClass(TraceUtil.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);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) IOException(java.io.IOException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)

Example 17 with ThriftTableOperationException

use of org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException in project accumulo by apache.

the class TableOperationsImpl method getDiskUsage.

@Override
public List<DiskUsage> getDiskUsage(Set<String> tableNames) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    List<TDiskUsage> diskUsages = null;
    while (diskUsages == null) {
        Pair<String, Client> pair = null;
        try {
            // this operation may us a lot of memory... its likely that connections to tabletservers
            // hosting metadata tablets will be cached, so do not use cached
            // connections
            pair = ServerClient.getConnection(context, new ClientService.Client.Factory(), false);
            diskUsages = pair.getSecond().getDiskUsage(tableNames, context.rpcCreds());
        } catch (ThriftTableOperationException e) {
            switch(e.getType()) {
                case NOTFOUND:
                    throw new TableNotFoundException(e);
                case NAMESPACE_NOTFOUND:
                    throw new TableNotFoundException(e.getTableName(), new NamespaceNotFoundException(e));
                default:
                    throw new AccumuloException(e.description, e);
            }
        } catch (ThriftSecurityException e) {
            throw new AccumuloSecurityException(e.getUser(), e.getCode());
        } catch (TTransportException e) {
            // some sort of communication error occurred, retry
            if (pair == null) {
                log.debug("Disk usage request failed.  Pair is null.  Retrying request...", e);
            } else {
                log.debug("Disk usage request failed {}, retrying ... ", pair.getFirst(), e);
            }
            sleepUninterruptibly(100, MILLISECONDS);
        } catch (TException e) {
            // may be a TApplicationException which indicates error on the server side
            throw new AccumuloException(e);
        } finally {
            // must always return thrift connection
            if (pair != null)
                ServerClient.close(pair.getSecond(), context);
        }
    }
    List<DiskUsage> finalUsages = new ArrayList<>();
    for (TDiskUsage diskUsage : diskUsages) {
        finalUsages.add(new DiskUsage(new TreeSet<>(diskUsage.getTables()), diskUsage.getUsage()));
    }
    return finalUsages;
}
Also used : TException(org.apache.thrift.TException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ClientService(org.apache.accumulo.core.clientImpl.thrift.ClientService) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) TTransportException(org.apache.thrift.transport.TTransportException) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) DiskUsage(org.apache.accumulo.core.client.admin.DiskUsage) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TDiskUsage(org.apache.accumulo.core.clientImpl.thrift.TDiskUsage) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client)

Example 18 with ThriftTableOperationException

use of org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException in project accumulo by apache.

the class TableOperationsImpl method _flush.

private void _flush(TableId tableId, Text start, Text end, boolean wait) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    try {
        long flushID;
        while (true) {
            ManagerClientService.Iface client = null;
            try {
                client = ManagerClient.getConnectionWithRetry(context);
                flushID = client.initiateFlush(TraceUtil.traceInfo(), context.rpcCreds(), tableId.canonical());
                break;
            } catch (TTransportException tte) {
                log.debug("Failed to call initiateFlush, retrying ... ", tte);
                sleepUninterruptibly(100, MILLISECONDS);
            } catch (ThriftNotActiveServiceException e) {
                // Let it loop, fetching a new location
                log.debug("Contacted a Manager which is no longer active, retrying");
                sleepUninterruptibly(100, MILLISECONDS);
            } finally {
                ManagerClient.close(client, context);
            }
        }
        while (true) {
            ManagerClientService.Iface client = null;
            try {
                client = ManagerClient.getConnectionWithRetry(context);
                client.waitForFlush(TraceUtil.traceInfo(), context.rpcCreds(), tableId.canonical(), TextUtil.getByteBuffer(start), TextUtil.getByteBuffer(end), flushID, wait ? Long.MAX_VALUE : 1);
                break;
            } catch (TTransportException tte) {
                log.debug("Failed to call initiateFlush, retrying ... ", tte);
                sleepUninterruptibly(100, MILLISECONDS);
            } catch (ThriftNotActiveServiceException e) {
                // Let it loop, fetching a new location
                log.debug("Contacted a Manager which is no longer active, retrying");
                sleepUninterruptibly(100, MILLISECONDS);
            } finally {
                ManagerClient.close(client, context);
            }
        }
    } catch (ThriftSecurityException e) {
        switch(e.getCode()) {
            case TABLE_DOESNT_EXIST:
                throw new TableNotFoundException(tableId.canonical(), null, e.getMessage(), e);
            default:
                log.debug("flush security exception on table id {}", tableId);
                throw new AccumuloSecurityException(e.user, e.code, e);
        }
    } catch (ThriftTableOperationException e) {
        switch(e.getType()) {
            case NOTFOUND:
                throw new TableNotFoundException(e);
            default:
                throw new AccumuloException(e.description, e);
        }
    } catch (Exception e) {
        throw new AccumuloException(e);
    }
}
Also used : ManagerClientService(org.apache.accumulo.core.manager.thrift.ManagerClientService) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) TTransportException(org.apache.thrift.transport.TTransportException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) IOException(java.io.IOException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)

Example 19 with ThriftTableOperationException

use of org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException in project accumulo by apache.

the class FateServiceHandler method executeFateOperation.

@Override
public void executeFateOperation(TInfo tinfo, TCredentials c, long opid, FateOperation op, List<ByteBuffer> arguments, Map<String, String> options, boolean autoCleanup) throws ThriftSecurityException, ThriftTableOperationException {
    authenticate(c);
    String goalMessage = op.toString() + " ";
    switch(op) {
        case NAMESPACE_CREATE:
            {
                TableOperation tableOp = TableOperation.CREATE;
                validateArgumentCount(arguments, tableOp, 1);
                String namespace = validateName(arguments.get(0), tableOp, NEW_NAMESPACE_NAME);
                if (!manager.security.canCreateNamespace(c))
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Create " + namespace + " namespace.";
                manager.fate.seedTransaction(opid, new TraceRepo<>(new CreateNamespace(c.getPrincipal(), namespace, options)), autoCleanup, goalMessage);
                break;
            }
        case NAMESPACE_RENAME:
            {
                TableOperation tableOp = TableOperation.RENAME;
                validateArgumentCount(arguments, tableOp, 2);
                String oldName = validateName(arguments.get(0), tableOp, EXISTING_NAMESPACE_NAME.and(NOT_BUILTIN_NAMESPACE));
                String newName = validateName(arguments.get(1), tableOp, NEW_NAMESPACE_NAME);
                NamespaceId namespaceId = ClientServiceHandler.checkNamespaceId(manager.getContext(), oldName, tableOp);
                if (!manager.security.canRenameNamespace(c, namespaceId))
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Rename " + oldName + " namespace to " + newName;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new RenameNamespace(namespaceId, oldName, newName)), autoCleanup, goalMessage);
                break;
            }
        case NAMESPACE_DELETE:
            {
                TableOperation tableOp = TableOperation.DELETE;
                validateArgumentCount(arguments, tableOp, 1);
                String namespace = validateName(arguments.get(0), tableOp, EXISTING_NAMESPACE_NAME.and(NOT_BUILTIN_NAMESPACE));
                NamespaceId namespaceId = ClientServiceHandler.checkNamespaceId(manager.getContext(), namespace, tableOp);
                if (!manager.security.canDeleteNamespace(c, namespaceId))
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Delete namespace Id: " + namespaceId;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new DeleteNamespace(namespaceId)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_CREATE:
            {
                TableOperation tableOp = TableOperation.CREATE;
                // offset where split data begins in arguments list
                int SPLIT_OFFSET = 4;
                if (arguments.size() < SPLIT_OFFSET) {
                    throw new ThriftTableOperationException(null, null, tableOp, TableOperationExceptionType.OTHER, "Expected at least " + SPLIT_OFFSET + " arguments, saw :" + arguments.size());
                }
                String tableName = validateName(arguments.get(0), tableOp, NEW_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                TimeType timeType = TimeType.valueOf(ByteBufferUtil.toString(arguments.get(1)));
                InitialTableState initialTableState = InitialTableState.valueOf(ByteBufferUtil.toString(arguments.get(2)));
                int splitCount = Integer.parseInt(ByteBufferUtil.toString(arguments.get(3)));
                validateArgumentCount(arguments, tableOp, SPLIT_OFFSET + splitCount);
                Path splitsPath = null;
                Path splitsDirsPath = null;
                if (splitCount > 0) {
                    try {
                        Path tmpDir = mkTempDir(opid);
                        splitsPath = new Path(tmpDir, "splits");
                        splitsDirsPath = new Path(tmpDir, "splitsDirs");
                        writeSplitsToFile(splitsPath, arguments, splitCount, SPLIT_OFFSET);
                    } catch (IOException e) {
                        throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.OTHER, "Exception thrown while writing splits to file system");
                    }
                }
                NamespaceId namespaceId;
                try {
                    namespaceId = Namespaces.getNamespaceId(manager.getContext(), TableNameUtil.qualify(tableName).getFirst());
                } catch (NamespaceNotFoundException e) {
                    throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.NAMESPACE_NOTFOUND, "");
                }
                if (!manager.security.canCreateTable(c, tableName, namespaceId))
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                for (Map.Entry<String, String> entry : options.entrySet()) {
                    if (!Property.isTablePropertyValid(entry.getKey(), entry.getValue())) {
                        throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.OTHER, "Property or value not valid " + entry.getKey() + "=" + entry.getValue());
                    }
                }
                goalMessage += "Create table " + tableName + " " + initialTableState + " with " + splitCount + " splits.";
                manager.fate.seedTransaction(opid, new TraceRepo<>(new CreateTable(c.getPrincipal(), tableName, timeType, options, splitsPath, splitCount, splitsDirsPath, initialTableState, namespaceId)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_RENAME:
            {
                TableOperation tableOp = TableOperation.RENAME;
                validateArgumentCount(arguments, tableOp, 2);
                String oldTableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                String newTableName = validateName(arguments.get(1), tableOp, NEW_TABLE_NAME.and(sameNamespaceAs(oldTableName)));
                TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), oldTableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canRename;
                try {
                    canRename = manager.security.canRenameTable(c, tableId, oldTableName, newTableName, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, oldTableName, TableOperation.RENAME);
                    throw e;
                }
                if (!canRename)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Rename table " + oldTableName + "(" + tableId + ") to " + oldTableName;
                try {
                    manager.fate.seedTransaction(opid, new TraceRepo<>(new RenameTable(namespaceId, tableId, oldTableName, newTableName)), autoCleanup, goalMessage);
                } catch (NamespaceNotFoundException e) {
                    throw new ThriftTableOperationException(null, oldTableName, tableOp, TableOperationExceptionType.NAMESPACE_NOTFOUND, "");
                }
                break;
            }
        case TABLE_CLONE:
            {
                TableOperation tableOp = TableOperation.CLONE;
                validateArgumentCount(arguments, tableOp, 3);
                TableId srcTableId = validateTableIdArgument(arguments.get(0), tableOp, CAN_CLONE_TABLE);
                String tableName = validateName(arguments.get(1), tableOp, NEW_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                boolean keepOffline = false;
                if (arguments.get(2) != null) {
                    keepOffline = Boolean.parseBoolean(ByteBufferUtil.toString(arguments.get(2)));
                }
                NamespaceId namespaceId;
                try {
                    namespaceId = Namespaces.getNamespaceId(manager.getContext(), TableNameUtil.qualify(tableName).getFirst());
                } catch (NamespaceNotFoundException e) {
                    // shouldn't happen, but possible once cloning between namespaces is supported
                    throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.NAMESPACE_NOTFOUND, "");
                }
                final boolean canCloneTable;
                try {
                    canCloneTable = manager.security.canCloneTable(c, srcTableId, tableName, namespaceId, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, srcTableId, null, TableOperation.CLONE);
                    throw e;
                }
                if (!canCloneTable)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                Map<String, String> propertiesToSet = new HashMap<>();
                Set<String> propertiesToExclude = new HashSet<>();
                for (Entry<String, String> entry : options.entrySet()) {
                    if (entry.getKey().startsWith(TableOperationsImpl.CLONE_EXCLUDE_PREFIX)) {
                        propertiesToExclude.add(entry.getKey().substring(TableOperationsImpl.CLONE_EXCLUDE_PREFIX.length()));
                        continue;
                    }
                    if (!Property.isTablePropertyValid(entry.getKey(), entry.getValue())) {
                        throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.OTHER, "Property or value not valid " + entry.getKey() + "=" + entry.getValue());
                    }
                    propertiesToSet.put(entry.getKey(), entry.getValue());
                }
                goalMessage += "Clone table " + srcTableId + " to " + tableName;
                if (keepOffline)
                    goalMessage += " and keep offline.";
                manager.fate.seedTransaction(opid, new TraceRepo<>(new CloneTable(c.getPrincipal(), namespaceId, srcTableId, tableName, propertiesToSet, propertiesToExclude, keepOffline)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_DELETE:
            {
                TableOperation tableOp = TableOperation.DELETE;
                validateArgumentCount(arguments, tableOp, 1);
                String tableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canDeleteTable;
                try {
                    canDeleteTable = manager.security.canDeleteTable(c, tableId, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.DELETE);
                    throw e;
                }
                if (!canDeleteTable)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Delete table " + tableName + "(" + tableId + ")";
                manager.fate.seedTransaction(opid, new TraceRepo<>(new PreDeleteTable(namespaceId, tableId)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_ONLINE:
            {
                TableOperation tableOp = TableOperation.ONLINE;
                validateArgumentCount(arguments, tableOp, 1);
                final var tableId = validateTableIdArgument(arguments.get(0), tableOp, NOT_ROOT_TABLE_ID);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canOnlineOfflineTable;
                try {
                    canOnlineOfflineTable = manager.security.canOnlineOfflineTable(c, tableId, op, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, null, TableOperation.ONLINE);
                    throw e;
                }
                if (!canOnlineOfflineTable)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Online table " + tableId;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new ChangeTableState(namespaceId, tableId, tableOp)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_OFFLINE:
            {
                TableOperation tableOp = TableOperation.OFFLINE;
                validateArgumentCount(arguments, tableOp, 1);
                final var tableId = validateTableIdArgument(arguments.get(0), tableOp, NOT_ROOT_TABLE_ID);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canOnlineOfflineTable;
                try {
                    canOnlineOfflineTable = manager.security.canOnlineOfflineTable(c, tableId, op, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, null, TableOperation.OFFLINE);
                    throw e;
                }
                if (!canOnlineOfflineTable)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Offline table " + tableId;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new ChangeTableState(namespaceId, tableId, tableOp)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_MERGE:
            {
                TableOperation tableOp = TableOperation.MERGE;
                validateArgumentCount(arguments, tableOp, 3);
                String tableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME);
                Text startRow = ByteBufferUtil.toText(arguments.get(1));
                Text endRow = ByteBufferUtil.toText(arguments.get(2));
                final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canMerge;
                try {
                    canMerge = manager.security.canMerge(c, tableId, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.MERGE);
                    throw e;
                }
                if (!canMerge)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                Manager.log.debug("Creating merge op: {} {} {}", tableId, startRow, endRow);
                goalMessage += "Merge table " + tableName + "(" + tableId + ") splits from " + startRow + " to " + endRow;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new TableRangeOp(MergeInfo.Operation.MERGE, namespaceId, tableId, startRow, endRow)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_DELETE_RANGE:
            {
                TableOperation tableOp = TableOperation.DELETE_RANGE;
                validateArgumentCount(arguments, tableOp, 3);
                String tableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME.and(NOT_METADATA_TABLE));
                Text startRow = ByteBufferUtil.toText(arguments.get(1));
                Text endRow = ByteBufferUtil.toText(arguments.get(2));
                final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canDeleteRange;
                try {
                    canDeleteRange = manager.security.canDeleteRange(c, tableId, tableName, startRow, endRow, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.DELETE_RANGE);
                    throw e;
                }
                if (!canDeleteRange)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Delete table " + tableName + "(" + tableId + ") range " + startRow + " to " + endRow;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new TableRangeOp(MergeInfo.Operation.DELETE, namespaceId, tableId, startRow, endRow)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_BULK_IMPORT:
            {
                TableOperation tableOp = TableOperation.BULK_IMPORT;
                validateArgumentCount(arguments, tableOp, 4);
                String tableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                String dir = ByteBufferUtil.toString(arguments.get(1));
                String failDir = ByteBufferUtil.toString(arguments.get(2));
                boolean setTime = Boolean.parseBoolean(ByteBufferUtil.toString(arguments.get(3)));
                final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canBulkImport;
                try {
                    canBulkImport = manager.security.canBulkImport(c, tableId, tableName, dir, failDir, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.BULK_IMPORT);
                    throw e;
                }
                if (!canBulkImport)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                manager.updateBulkImportStatus(dir, BulkImportState.INITIAL);
                goalMessage += "Bulk import " + dir + " to " + tableName + "(" + tableId + ") failing to " + failDir;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new org.apache.accumulo.manager.tableOps.bulkVer1.BulkImport(tableId, dir, failDir, setTime)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_COMPACT:
            {
                TableOperation tableOp = TableOperation.COMPACT;
                validateArgumentCount(arguments, tableOp, 2);
                TableId tableId = validateTableIdArgument(arguments.get(0), tableOp, null);
                CompactionConfig compactionConfig = UserCompactionUtils.decodeCompactionConfig(ByteBufferUtil.toBytes(arguments.get(1)));
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canCompact;
                try {
                    canCompact = manager.security.canCompact(c, tableId, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, null, TableOperation.COMPACT);
                    throw e;
                }
                if (!canCompact)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Compact table (" + tableId + ") with config " + compactionConfig;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new CompactRange(namespaceId, tableId, compactionConfig)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_CANCEL_COMPACT:
            {
                TableOperation tableOp = TableOperation.COMPACT_CANCEL;
                validateArgumentCount(arguments, tableOp, 1);
                TableId tableId = validateTableIdArgument(arguments.get(0), tableOp, null);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canCancelCompact;
                try {
                    canCancelCompact = manager.security.canCompact(c, tableId, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, null, TableOperation.COMPACT_CANCEL);
                    throw e;
                }
                if (!canCancelCompact)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Cancel compaction of table (" + tableId + ")";
                manager.fate.seedTransaction(opid, new TraceRepo<>(new CancelCompactions(namespaceId, tableId)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_IMPORT:
            {
                TableOperation tableOp = TableOperation.IMPORT;
                // offset where table list begins
                int IMPORT_DIR_OFFSET = 2;
                if (arguments.size() < IMPORT_DIR_OFFSET) {
                    throw new ThriftTableOperationException(null, null, tableOp, TableOperationExceptionType.OTHER, "Expected at least " + IMPORT_DIR_OFFSET + "arguments, sar :" + arguments.size());
                }
                String tableName = validateName(arguments.get(0), tableOp, NEW_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                List<ByteBuffer> exportDirArgs = arguments.stream().skip(1).collect(Collectors.toList());
                Set<String> exportDirs = ByteBufferUtil.toStringSet(exportDirArgs);
                NamespaceId namespaceId;
                try {
                    namespaceId = Namespaces.getNamespaceId(manager.getContext(), TableNameUtil.qualify(tableName).getFirst());
                } catch (NamespaceNotFoundException e) {
                    throw new ThriftTableOperationException(null, tableName, tableOp, TableOperationExceptionType.NAMESPACE_NOTFOUND, "");
                }
                final boolean canImport;
                try {
                    canImport = manager.security.canImport(c, tableName, exportDirs, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, null, tableName, TableOperation.IMPORT);
                    throw e;
                }
                if (!canImport)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Import table with new name: " + tableName + " from " + exportDirs;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new ImportTable(c.getPrincipal(), tableName, exportDirs, namespaceId)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_EXPORT:
            {
                TableOperation tableOp = TableOperation.EXPORT;
                validateArgumentCount(arguments, tableOp, 2);
                String tableName = validateName(arguments.get(0), tableOp, EXISTING_TABLE_NAME.and(NOT_BUILTIN_TABLE));
                String exportDir = ByteBufferUtil.toString(arguments.get(1));
                TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, tableOp);
                NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
                final boolean canExport;
                try {
                    canExport = manager.security.canExport(c, tableId, tableName, exportDir, namespaceId);
                } catch (ThriftSecurityException e) {
                    throwIfTableMissingSecurityException(e, tableId, tableName, TableOperation.EXPORT);
                    throw e;
                }
                if (!canExport)
                    throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
                goalMessage += "Export table " + tableName + "(" + tableId + ") to " + exportDir;
                manager.fate.seedTransaction(opid, new TraceRepo<>(new ExportTable(namespaceId, tableName, tableId, exportDir)), autoCleanup, goalMessage);
                break;
            }
        case TABLE_BULK_IMPORT2:
            TableOperation tableOp = TableOperation.BULK_IMPORT;
            validateArgumentCount(arguments, tableOp, 3);
            final var tableId = validateTableIdArgument(arguments.get(0), tableOp, NOT_ROOT_TABLE_ID);
            String dir = ByteBufferUtil.toString(arguments.get(1));
            boolean setTime = Boolean.parseBoolean(ByteBufferUtil.toString(arguments.get(2)));
            NamespaceId namespaceId = getNamespaceIdFromTableId(tableOp, tableId);
            final boolean canBulkImport;
            String tableName;
            try {
                tableName = manager.getContext().getTableName(tableId);
                canBulkImport = manager.security.canBulkImport(c, tableId, tableName, dir, null, namespaceId);
            } catch (ThriftSecurityException e) {
                throwIfTableMissingSecurityException(e, tableId, "", TableOperation.BULK_IMPORT);
                throw e;
            } catch (TableNotFoundException e) {
                throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.BULK_IMPORT, TableOperationExceptionType.NOTFOUND, "Table no longer exists");
            }
            if (!canBulkImport)
                throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
            manager.updateBulkImportStatus(dir, BulkImportState.INITIAL);
            goalMessage += "Bulk import (v2)  " + dir + " to " + tableName + "(" + tableId + ")";
            manager.fate.seedTransaction(opid, new TraceRepo<>(new PrepBulkImport(tableId, dir, setTime)), autoCleanup, goalMessage);
            break;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Set(java.util.Set) HashSet(java.util.HashSet) ChangeTableState(org.apache.accumulo.manager.tableOps.ChangeTableState) DeleteNamespace(org.apache.accumulo.manager.tableOps.namespace.delete.DeleteNamespace) PreDeleteTable(org.apache.accumulo.manager.tableOps.delete.PreDeleteTable) PrepBulkImport(org.apache.accumulo.manager.tableOps.bulkVer2.PrepBulkImport) InitialTableState(org.apache.accumulo.core.client.admin.InitialTableState) CreateTable(org.apache.accumulo.manager.tableOps.create.CreateTable) RenameNamespace(org.apache.accumulo.manager.tableOps.namespace.rename.RenameNamespace) TimeType(org.apache.accumulo.core.client.admin.TimeType) CancelCompactions(org.apache.accumulo.manager.tableOps.compact.cancel.CancelCompactions) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) List(java.util.List) ImportTable(org.apache.accumulo.manager.tableOps.tableImport.ImportTable) CloneTable(org.apache.accumulo.manager.tableOps.clone.CloneTable) Path(org.apache.hadoop.fs.Path) CompactRange(org.apache.accumulo.manager.tableOps.compact.CompactRange) Text(org.apache.hadoop.io.Text) TraceRepo(org.apache.accumulo.manager.tableOps.TraceRepo) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ExportTable(org.apache.accumulo.manager.tableOps.tableExport.ExportTable) RenameTable(org.apache.accumulo.manager.tableOps.rename.RenameTable) TableOperation(org.apache.accumulo.core.clientImpl.thrift.TableOperation) TableRangeOp(org.apache.accumulo.manager.tableOps.merge.TableRangeOp) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Map(java.util.Map) HashMap(java.util.HashMap) CreateNamespace(org.apache.accumulo.manager.tableOps.namespace.create.CreateNamespace)

Example 20 with ThriftTableOperationException

use of org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException 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)

Aggregations

ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)20 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)14 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)12 NamespaceId (org.apache.accumulo.core.data.NamespaceId)10 TException (org.apache.thrift.TException)10 IOException (java.io.IOException)8 TableId (org.apache.accumulo.core.data.TableId)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 TTransportException (org.apache.thrift.transport.TTransportException)5 NamespaceExistsException (org.apache.accumulo.core.client.NamespaceExistsException)4 TableExistsException (org.apache.accumulo.core.client.TableExistsException)4 ThriftNotActiveServiceException (org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException)4 ManagerClientService (org.apache.accumulo.core.manager.thrift.ManagerClientService)4 FileNotFoundException (java.io.FileNotFoundException)3 HashSet (java.util.HashSet)3 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)3 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)3 Text (org.apache.hadoop.io.Text)3