Search in sources :

Example 81 with ServiceException

use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.

the class MasterRpcServices method hasUserPermissions.

@Override
public HasUserPermissionsResponse hasUserPermissions(RpcController controller, HasUserPermissionsRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        if (server.cpHost != null && hasAccessControlServiceCoprocessor(server.cpHost)) {
            User caller = RpcServer.getRequestUser().orElse(null);
            String userName = request.hasUserName() ? request.getUserName().toStringUtf8() : caller.getShortName();
            List<Permission> permissions = new ArrayList<>();
            for (int i = 0; i < request.getPermissionCount(); i++) {
                permissions.add(ShadedAccessControlUtil.toPermission(request.getPermission(i)));
            }
            server.getMasterCoprocessorHost().preHasUserPermissions(userName, permissions);
            if (!caller.getShortName().equals(userName)) {
                List<String> groups = AccessChecker.getUserGroups(userName);
                caller = new InputUser(userName, groups.toArray(new String[groups.size()]));
            }
            List<Boolean> hasUserPermissions = new ArrayList<>();
            if (getAccessChecker() != null) {
                for (Permission permission : permissions) {
                    boolean hasUserPermission = getAccessChecker().hasUserPermission(caller, "hasUserPermissions", permission);
                    hasUserPermissions.add(hasUserPermission);
                }
            } else {
                for (int i = 0; i < permissions.size(); i++) {
                    hasUserPermissions.add(true);
                }
            }
            server.getMasterCoprocessorHost().postHasUserPermissions(userName, permissions);
            HasUserPermissionsResponse.Builder builder = HasUserPermissionsResponse.newBuilder().addAllHasUserPermission(hasUserPermissions);
            return builder.build();
        } else {
            throw new DoNotRetryIOException(new UnsupportedOperationException(AccessController.class.getName() + " is not loaded"));
        }
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : HasUserPermissionsResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AccessControlProtos.HasUserPermissionsResponse) InputUser(org.apache.hadoop.hbase.security.access.AccessChecker.InputUser) User(org.apache.hadoop.hbase.security.User) InputUser(org.apache.hadoop.hbase.security.access.AccessChecker.InputUser) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) AccessController(org.apache.hadoop.hbase.security.access.AccessController) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) Permission(org.apache.hadoop.hbase.security.access.Permission) UserPermission(org.apache.hadoop.hbase.security.access.UserPermission)

Example 82 with ServiceException

use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.

the class MasterRpcServices method deleteSnapshot.

/**
 * Execute Delete Snapshot operation.
 * @return DeleteSnapshotResponse (a protobuf wrapped void) if the snapshot existed and was
 *    deleted properly.
 * @throws ServiceException wrapping SnapshotDoesNotExistException if specified snapshot did not
 *    exist.
 */
@Override
public DeleteSnapshotResponse deleteSnapshot(RpcController controller, DeleteSnapshotRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        server.snapshotManager.checkSnapshotSupport();
        LOG.info(server.getClientIdAuditPrefix() + " delete " + request.getSnapshot());
        server.snapshotManager.deleteSnapshot(request.getSnapshot());
        return DeleteSnapshotResponse.newBuilder().build();
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 83 with ServiceException

use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.

the class MasterRpcServices method snapshot.

/**
 * Triggers an asynchronous attempt to take a snapshot.
 * {@inheritDoc}
 */
@Override
public SnapshotResponse snapshot(RpcController controller, SnapshotRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        server.snapshotManager.checkSnapshotSupport();
        LOG.info(server.getClientIdAuditPrefix() + " snapshot request for:" + ClientSnapshotDescriptionUtils.toString(request.getSnapshot()));
        // get the snapshot information
        SnapshotDescription snapshot = SnapshotDescriptionUtils.validate(request.getSnapshot(), server.getConfiguration());
        server.snapshotManager.takeSnapshot(snapshot);
        // send back the max amount of time the client should wait for the snapshot to complete
        long waitTime = SnapshotDescriptionUtils.getMaxMasterTimeout(server.getConfiguration(), snapshot.getType(), SnapshotDescriptionUtils.DEFAULT_MAX_WAIT_TIME);
        return SnapshotResponse.newBuilder().setExpectedTimeout(waitTime).build();
    } catch (ForeignException e) {
        throw new ServiceException(e.getCause());
    } catch (IOException e) {
        throw new ServiceException(e);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) SnapshotDescription(org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos.SnapshotDescription) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException)

Example 84 with ServiceException

use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.

the class MasterRpcServices method listRSGroupInfos.

@Override
public ListRSGroupInfosResponse listRSGroupInfos(RpcController controller, ListRSGroupInfosRequest request) throws ServiceException {
    ListRSGroupInfosResponse.Builder builder = ListRSGroupInfosResponse.newBuilder();
    LOG.info(server.getClientIdAuditPrefix() + " list rsgroup");
    try {
        if (server.getMasterCoprocessorHost() != null) {
            server.getMasterCoprocessorHost().preListRSGroups();
        }
        List<RSGroupInfo> rsGroupInfos = server.getRSGroupInfoManager().listRSGroups().stream().map(RSGroupInfo::new).collect(Collectors.toList());
        Map<String, RSGroupInfo> name2Info = new HashMap<>();
        List<TableDescriptor> needToFill = new ArrayList<>(server.getTableDescriptors().getAll().values());
        for (RSGroupInfo rsGroupInfo : rsGroupInfos) {
            name2Info.put(rsGroupInfo.getName(), rsGroupInfo);
            for (TableDescriptor td : server.getTableDescriptors().getAll().values()) {
                if (rsGroupInfo.containsTable(td.getTableName())) {
                    needToFill.remove(td);
                }
            }
        }
        for (TableDescriptor td : needToFill) {
            String groupName = td.getRegionServerGroup().orElse(RSGroupInfo.DEFAULT_GROUP);
            RSGroupInfo rsGroupInfo = name2Info.get(groupName);
            if (rsGroupInfo != null) {
                rsGroupInfo.addTable(td.getTableName());
            }
        }
        for (RSGroupInfo rsGroupInfo : rsGroupInfos) {
            // TODO: this can be done at once outside this loop, do not need to scan all every time.
            builder.addRSGroupInfo(ProtobufUtil.toProtoGroupInfo(rsGroupInfo));
        }
        if (server.getMasterCoprocessorHost() != null) {
            server.getMasterCoprocessorHost().postListRSGroups();
        }
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    return builder.build();
}
Also used : ListRSGroupInfosResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.RSGroupAdminProtos.ListRSGroupInfosResponse) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) RSGroupInfo(org.apache.hadoop.hbase.rsgroup.RSGroupInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 85 with ServiceException

use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.

the class MasterRpcServices method grant.

@Override
public GrantResponse grant(RpcController controller, GrantRequest request) throws ServiceException {
    try {
        server.checkInitialized();
        if (server.cpHost != null && hasAccessControlServiceCoprocessor(server.cpHost)) {
            final UserPermission perm = ShadedAccessControlUtil.toUserPermission(request.getUserPermission());
            boolean mergeExistingPermissions = request.getMergeExistingPermissions();
            server.cpHost.preGrant(perm, mergeExistingPermissions);
            try (Table table = server.getConnection().getTable(PermissionStorage.ACL_TABLE_NAME)) {
                PermissionStorage.addUserPermission(getConfiguration(), perm, table, mergeExistingPermissions);
            }
            server.cpHost.postGrant(perm, mergeExistingPermissions);
            User caller = RpcServer.getRequestUser().orElse(null);
            if (AUDITLOG.isTraceEnabled()) {
                // audit log should store permission changes in addition to auth results
                String remoteAddress = RpcServer.getRemoteAddress().map(InetAddress::toString).orElse("");
                AUDITLOG.trace("User {} (remote address: {}) granted permission {}", caller, remoteAddress, perm);
            }
            return GrantResponse.getDefaultInstance();
        } else {
            throw new DoNotRetryIOException(new UnsupportedOperationException(AccessController.class.getName() + " is not loaded"));
        }
    } catch (IOException ioe) {
        throw new ServiceException(ioe);
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) InputUser(org.apache.hadoop.hbase.security.access.AccessChecker.InputUser) User(org.apache.hadoop.hbase.security.User) AccessController(org.apache.hadoop.hbase.security.access.AccessController) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UserPermission(org.apache.hadoop.hbase.security.access.UserPermission)

Aggregations

ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)130 IOException (java.io.IOException)112 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)100 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)39 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)28 UncheckedIOException (java.io.UncheckedIOException)27 TableName (org.apache.hadoop.hbase.TableName)22 QosPriority (org.apache.hadoop.hbase.ipc.QosPriority)22 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)19 UnknownRegionException (org.apache.hadoop.hbase.UnknownRegionException)16 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)16 Test (org.junit.Test)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 ArrayList (java.util.ArrayList)15 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)15 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)15 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)15 KeeperException (org.apache.zookeeper.KeeperException)14 Table (org.apache.hadoop.hbase.client.Table)13 User (org.apache.hadoop.hbase.security.User)13