use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.
the class TestHMasterRPCException method testRPCException.
@Test
public void testRPCException() throws IOException, InterruptedException, KeeperException {
ServerName sm = master.getServerName();
boolean fakeZNodeDelete = false;
for (int i = 0; i < 20; i++) {
try {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sm, User.getCurrent(), 0);
MasterProtos.MasterService.BlockingInterface stub = MasterProtos.MasterService.newBlockingStub(channel);
assertTrue(stub.isMasterRunning(null, IsMasterRunningRequest.getDefaultInstance()).getIsMasterRunning());
return;
} catch (ServiceException ex) {
IOException ie = ProtobufUtil.handleRemoteException(ex);
// No SocketTimeoutException here. RpcServer is already started after the construction of
// HMaster.
assertTrue(ie.getMessage().startsWith("org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet"));
LOG.info("Expected exception: ", ie);
if (!fakeZNodeDelete) {
testUtil.getZooKeeperWatcher().getRecoverableZooKeeper().delete(testUtil.getZooKeeperWatcher().getZNodePaths().masterAddressZNode, -1);
fakeZNodeDelete = true;
}
}
Thread.sleep(1000);
}
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.
the class TestCoprocessorEndpoint method testCoprocessorError.
@Test
public void testCoprocessorError() throws Exception {
Configuration configuration = new Configuration(util.getConfiguration());
// Make it not retry forever
configuration.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
Table table = util.getConnection().getTable(TEST_TABLE);
try {
CoprocessorRpcChannel protocol = table.coprocessorService(ROWS[0]);
TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(protocol);
service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
fail("Should have thrown an exception");
} catch (ServiceException e) {
} finally {
table.close();
}
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.
the class TestCoprocessorEndpoint method testMasterCoprocessorError.
@Test
public void testMasterCoprocessorError() throws Throwable {
Admin admin = util.getAdmin();
TestRpcServiceProtos.TestProtobufRpcProto.BlockingInterface service = TestRpcServiceProtos.TestProtobufRpcProto.newBlockingStub(admin.coprocessorService());
try {
service.error(null, TestProtos.EmptyRequestProto.getDefaultInstance());
fail("Should have thrown an exception");
} catch (ServiceException e) {
}
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.
the class TestSecureExport method testAccessCase.
/**
* Test the ExportEndpoint's access levels. The {@link Export} test is ignored
* since the access exceptions cannot be collected from the mappers.
*/
@Test
public void testAccessCase() throws Throwable {
final String exportTable = name.getMethodName();
TableDescriptor exportHtd = TableDescriptorBuilder.newBuilder(TableName.valueOf(exportTable)).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILYA)).build();
User owner = User.createUserForTesting(UTIL.getConfiguration(), USER_OWNER, new String[0]);
SecureTestUtil.createTable(UTIL, owner, exportHtd, new byte[][] { Bytes.toBytes("s") });
SecureTestUtil.grantOnTable(UTIL, USER_RO, TableName.valueOf(exportTable), null, null, Permission.Action.READ);
SecureTestUtil.grantOnTable(UTIL, USER_RX, TableName.valueOf(exportTable), null, null, Permission.Action.READ, Permission.Action.EXEC);
SecureTestUtil.grantOnTable(UTIL, USER_XO, TableName.valueOf(exportTable), null, null, Permission.Action.EXEC);
assertEquals(4, PermissionStorage.getTablePermissions(UTIL.getConfiguration(), TableName.valueOf(exportTable)).size());
AccessTestAction putAction = () -> {
Put p = new Put(ROW1);
p.addColumn(FAMILYA, Bytes.toBytes("qual_0"), NOW, QUAL);
p.addColumn(FAMILYA, Bytes.toBytes("qual_1"), NOW, QUAL);
try (Connection conn = ConnectionFactory.createConnection(UTIL.getConfiguration());
Table t = conn.getTable(TableName.valueOf(exportTable))) {
t.put(p);
}
return null;
};
// no hdfs access.
SecureTestUtil.verifyAllowed(putAction, getUserByLogin(USER_ADMIN), getUserByLogin(USER_OWNER));
SecureTestUtil.verifyDenied(putAction, getUserByLogin(USER_RO), getUserByLogin(USER_XO), getUserByLogin(USER_RX), getUserByLogin(USER_NONE));
final FileSystem fs = UTIL.getDFSCluster().getFileSystem();
final Path openDir = fs.makeQualified(new Path("testAccessCase"));
fs.mkdirs(openDir);
fs.setPermission(openDir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL));
final Path output = fs.makeQualified(new Path(openDir, "output"));
AccessTestAction exportAction = () -> {
try {
String[] args = new String[] { exportTable, output.toString() };
Map<byte[], Export.Response> result = Export.run(new Configuration(UTIL.getConfiguration()), args);
long rowCount = 0;
long cellCount = 0;
for (Export.Response r : result.values()) {
rowCount += r.getRowCount();
cellCount += r.getCellCount();
}
assertEquals(1, rowCount);
assertEquals(2, cellCount);
return null;
} catch (ServiceException | IOException ex) {
throw ex;
} catch (Throwable ex) {
LOG.error(ex.toString(), ex);
throw new Exception(ex);
} finally {
if (fs.exists(new Path(openDir, "output"))) {
// if export completes successfully, every file under the output directory should be
// owned by the current user, not the hbase service user.
FileStatus outputDirFileStatus = fs.getFileStatus(new Path(openDir, "output"));
String currentUserName = User.getCurrent().getShortName();
assertEquals("Unexpected file owner", currentUserName, outputDirFileStatus.getOwner());
FileStatus[] outputFileStatus = fs.listStatus(new Path(openDir, "output"));
for (FileStatus fileStatus : outputFileStatus) {
assertEquals("Unexpected file owner", currentUserName, fileStatus.getOwner());
}
} else {
LOG.info("output directory doesn't exist. Skip check");
}
clearOutput(output);
}
};
SecureTestUtil.verifyDenied(exportAction, getUserByLogin(USER_RO), getUserByLogin(USER_XO), getUserByLogin(USER_NONE));
SecureTestUtil.verifyAllowed(exportAction, getUserByLogin(USER_ADMIN), getUserByLogin(USER_OWNER), getUserByLogin(USER_RX));
AccessTestAction deleteAction = () -> {
UTIL.deleteTable(TableName.valueOf(exportTable));
return null;
};
SecureTestUtil.verifyAllowed(deleteAction, getUserByLogin(USER_OWNER));
fs.delete(openDir, true);
}
use of org.apache.hbase.thirdparty.com.google.protobuf.ServiceException in project hbase by apache.
the class HBaseRpcServicesBase method clearSlowLogsResponses.
@Override
@QosPriority(priority = HConstants.ADMIN_QOS)
public ClearSlowLogResponses clearSlowLogsResponses(final RpcController controller, final ClearSlowLogResponseRequest request) throws ServiceException {
try {
requirePermission("clearSlowLogsResponses", Permission.Action.ADMIN);
} catch (IOException e) {
throw new ServiceException(e);
}
final NamedQueueRecorder namedQueueRecorder = this.server.getNamedQueueRecorder();
boolean slowLogsCleaned = Optional.ofNullable(namedQueueRecorder).map(queueRecorder -> queueRecorder.clearNamedQueue(NamedQueuePayload.NamedQueueEvent.SLOW_LOG)).orElse(false);
ClearSlowLogResponses clearSlowLogResponses = ClearSlowLogResponses.newBuilder().setIsCleaned(slowLogsCleaned).build();
return clearSlowLogResponses;
}
Aggregations