Search in sources :

Example 6 with ThriftTableOperationException

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

the class ClientServiceHandler method checkTableClass.

@Override
public boolean checkTableClass(TInfo tinfo, TCredentials credentials, String tableName, String className, String interfaceMatch) throws TException, ThriftTableOperationException, ThriftSecurityException {
    security.authenticateUser(credentials, credentials);
    TableId tableId = checkTableId(context, tableName, null);
    ClassLoader loader = getClass().getClassLoader();
    Class<?> shouldMatch;
    try {
        shouldMatch = loader.loadClass(interfaceMatch);
        AccumuloConfiguration conf = context.getTableConfiguration(tableId);
        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 : TableId(org.apache.accumulo.core.data.TableId) 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 7 with ThriftTableOperationException

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

the class CompactionCoordinator method cancel.

@Override
public void cancel(TInfo tinfo, TCredentials credentials, String externalCompactionId) throws TException {
    var runningCompaction = RUNNING.get(ExternalCompactionId.of(externalCompactionId));
    var extent = KeyExtent.fromThrift(runningCompaction.getJob().getExtent());
    try {
        NamespaceId nsId = getContext().getNamespaceId(extent.tableId());
        if (!security.canCompact(credentials, extent.tableId(), nsId)) {
            throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
        }
    } catch (TableNotFoundException e) {
        throw new ThriftTableOperationException(extent.tableId().canonical(), null, TableOperation.COMPACT_CANCEL, TableOperationExceptionType.NOTFOUND, e.getMessage());
    }
    HostAndPort address = HostAndPort.fromString(runningCompaction.getCompactorAddress());
    ExternalCompactionUtil.cancelCompaction(getContext(), address, externalCompactionId);
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) HostAndPort(org.apache.accumulo.core.util.HostAndPort) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 8 with ThriftTableOperationException

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

the class FateServiceHandler method waitForFateOperation.

@Override
public String waitForFateOperation(TInfo tinfo, TCredentials credentials, long opid) throws ThriftSecurityException, ThriftTableOperationException {
    authenticate(credentials);
    TStatus status = manager.fate.waitForCompletion(opid);
    if (status == TStatus.FAILED) {
        Exception e = manager.fate.getException(opid);
        if (e instanceof ThriftTableOperationException)
            throw (ThriftTableOperationException) e;
        else if (e instanceof ThriftSecurityException)
            throw (ThriftSecurityException) e;
        else if (e instanceof RuntimeException)
            throw (RuntimeException) e;
        else
            throw new RuntimeException(e);
    }
    String ret = manager.fate.getReturn(opid);
    if (ret == null)
        // thrift does not like returning null
        ret = "";
    return ret;
}
Also used : TStatus(org.apache.accumulo.fate.ReadOnlyTStore.TStatus) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) 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) IOException(java.io.IOException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)

Example 9 with ThriftTableOperationException

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

the class ManagerClientServiceHandler method alterTableProperty.

private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
    final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
    NamespaceId namespaceId = getNamespaceIdFromTableId(op, tableId);
    if (!manager.security.canAlterTable(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    try {
        if (value == null || value.isEmpty()) {
            TablePropUtil.removeTableProperty(manager.getContext(), tableId, property);
        } else if (!TablePropUtil.setTableProperty(manager.getContext(), 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(manager.getContext(), tableName, op);
        log.info("Error altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    } catch (Exception e) {
        log.error("Problem altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) 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) KeeperException(org.apache.zookeeper.KeeperException)

Example 10 with ThriftTableOperationException

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

the class ManagerClientServiceHandler method waitForFlush.

@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) 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);
    Text startRow = ByteBufferUtil.toText(startRowBB);
    Text endRow = ByteBufferUtil.toText(endRowBB);
    if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
        throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
    Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
    for (long l = 0; l < maxLoops; l++) {
        for (TServerInstance instance : serversToFlush) {
            try {
                final TServerConnection server = manager.tserverSet.getConnection(instance);
                if (server != null)
                    server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
            } catch (TException ex) {
                Manager.log.error(ex.toString());
            }
        }
        if (tableId.equals(RootTable.ID))
            // this code does not properly handle the root tablet. See #798
            break;
        if (l == maxLoops - 1)
            break;
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        serversToFlush.clear();
        try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
            int tabletsToWaitFor = 0;
            int tabletCount = 0;
            for (TabletMetadata tablet : tablets) {
                int logs = tablet.getLogs().size();
                // when tablet is not online and has no logs, there is no reason to wait for it
                if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
                    tabletsToWaitFor++;
                    if (tablet.hasCurrent())
                        serversToFlush.add(tablet.getLocation());
                }
                tabletCount++;
            }
            if (tabletsToWaitFor == 0)
                break;
            if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
                throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
        } catch (TabletDeletedException e) {
            Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
        }
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) Text(org.apache.hadoop.io.Text) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) HashSet(java.util.HashSet)

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