public boolean balanceSwitch(final boolean b) throws IOException { return getMasterRpcServices().switchBalancer(b, BalanceSwitchMode.ASYNC); }
/** * Returns the current active master, if available. * @return the active HMaster, null if none is active. */ @Override public MasterService.BlockingInterface getMasterAdminService() { return this.hbaseCluster.getActiveMaster().getMasterRpcServices(); }
intRssStub = ((HMaster)this).getMasterRpcServices(); intLockStub = ((HMaster)this).getMasterRpcServices(); break;
@Test public void testMasterRpcScheduler() { HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); MasterRpcServices masterRpcServices = master.getMasterRpcServices(); RpcScheduler masterRpcScheduler = masterRpcServices.getRpcScheduler(); Assert.assertTrue(masterRpcScheduler instanceof MasterFifoRpcScheduler); }
@Test public void testFlushedSequenceIdsSentToHMaster() throws IOException, InterruptedException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException, ServiceException { SortedMap<byte[], Long> allFlushedSequenceIds = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (int i = 0; i < NUM_RS; ++i) { flushAllRegions(i); } Thread.sleep(10000); HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster(); for (int i = 0; i < NUM_RS; ++i) { for (byte[] regionName : getRegionsByServer(i)) { if (allFlushedSequenceIds.containsKey(regionName)) { GetLastFlushedSequenceIdRequest req = RequestConverter.buildGetLastFlushedSequenceIdRequest(regionName); assertEquals((long)allFlushedSequenceIds.get(regionName), master.getMasterRpcServices().getLastFlushedSequenceId( null, req).getLastFlushedSequenceId()); } } } }
/** * Expect the snapshot to throw an error when checking if the snapshot is * complete * * @param master master to check * @param snapshot the {@link SnapshotDescription} request to pass to the master * @param clazz expected exception from the master */ public static void expectSnapshotDoneException(HMaster master, IsSnapshotDoneRequest snapshot, Class<? extends HBaseSnapshotException> clazz) { try { master.getMasterRpcServices().isSnapshotDone(null, snapshot); Assert.fail("didn't fail to lookup a snapshot"); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException se) { try { throw ProtobufUtil.handleRemoteException(se); } catch (HBaseSnapshotException e) { assertEquals("Threw wrong snapshot exception!", clazz, e.getClass()); } catch (Throwable t) { Assert.fail("Threw an unexpected exception:" + t); } } }
@BeforeClass public static void setupCluster() throws Exception { setupConf(UTIL.getConfiguration()); UTIL.startMiniCluster(1); UTIL.getAdmin().createNamespace(NamespaceDescriptor.create(namespace).build()); UTIL.createTable(tableName1, new byte[][]{ Bytes.toBytes("fam")}, new byte[][] {Bytes.toBytes("1")}); UTIL.createTable(tableName2, new byte[][]{Bytes.toBytes("fam")}, new byte[][] {Bytes.toBytes("1")}); masterRpcService = UTIL.getHBaseCluster().getMaster().getMasterRpcServices(); procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor(); tableRegions1 = UTIL.getAdmin().getRegions(tableName1); tableRegions2 = UTIL.getAdmin().getRegions(tableName2); assert tableRegions1.size() > 0; assert tableRegions2.size() > 0; }
@Test public void testDeleteSnapshot() throws Exception { String snapshotName = "completed"; SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName(snapshotName).build(); DeleteSnapshotRequest request = DeleteSnapshotRequest.newBuilder().setSnapshot(snapshot) .build(); try { master.getMasterRpcServices().deleteSnapshot(null, request); fail("Master didn't throw exception when attempting to delete snapshot that doesn't exist"); } catch (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException e) { // Expected } // write one snapshot to the fs createSnapshot(snapshotName); // then delete the existing snapshot,which shouldn't cause an exception to be thrown master.getMasterRpcServices().deleteSnapshot(null, request); }
/** * Ignore this test, see HBASE-21421 */ @Test @Ignore public void testReportRSWithWrongRegion() throws Exception { final TableName tableName = TableName.valueOf(this.name.getMethodName()); List<HRegionInfo> tableRegions = createTable(tableName); final ServerName sn = ServerName.parseVersionedServerName( ServerName.valueOf("1.example.org", 1, System.currentTimeMillis()).getVersionedBytes()); // make fake request with a region assigned to different RS RegionServerStatusProtos.RegionServerReportRequest.Builder request = makeRSReportRequestWithRegions(sn, tableRegions.get(1)); // sending fake request to master // TODO: replace YouAreDeadException with appropriate exception as and when necessary exception.expect(ServiceException.class); exception.expectCause(isA(YouAreDeadException.class)); RegionServerStatusProtos.RegionServerReportResponse response = master.getMasterRpcServices().regionServerReport(null, request.build()); }
@Test public void testGetCompletedSnapshots() throws Exception { // first check when there are no snapshots GetCompletedSnapshotsRequest request = GetCompletedSnapshotsRequest.newBuilder().build(); GetCompletedSnapshotsResponse response = master.getMasterRpcServices().getCompletedSnapshots(null, request); assertEquals("Found unexpected number of snapshots", 0, response.getSnapshotsCount()); // write one snapshot to the fs String snapshotName = "completed"; SnapshotDescription snapshot = createSnapshot(snapshotName); // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); assertEquals("Found unexpected number of snapshots", 1, response.getSnapshotsCount()); List<SnapshotDescription> snapshots = response.getSnapshotsList(); List<SnapshotDescription> expected = Lists.newArrayList(snapshot); assertEquals("Returned snapshots don't match created snapshots", expected, snapshots); // write a second snapshot snapshotName = "completed_two"; snapshot = createSnapshot(snapshotName); expected.add(snapshot); // check that we get one snapshot response = master.getMasterRpcServices().getCompletedSnapshots(null, request); assertEquals("Found unexpected number of snapshots", 2, response.getSnapshotsCount()); snapshots = response.getSnapshotsList(); assertEquals("Returned snapshots don't match created snapshots", expected, snapshots); }
/** * Helper method for testing async snapshot operations. Just waits for the * given snapshot to complete on the server by repeatedly checking the master. * * @param master the master running the snapshot * @param snapshot the snapshot to check * @param sleep amount to sleep between checks to see if the snapshot is done * @throws ServiceException if the snapshot fails * @throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException */ public static void waitForSnapshotToComplete(HMaster master, SnapshotProtos.SnapshotDescription snapshot, long sleep) throws org.apache.hbase.thirdparty.com.google.protobuf.ServiceException { final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder() .buildPartial(); while (!done.getDone()) { done = master.getMasterRpcServices().isSnapshotDone(null, request); try { Thread.sleep(sleep); } catch (InterruptedException e) { throw new org.apache.hbase.thirdparty.com.google.protobuf.ServiceException(e); } } }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null); master.getMasterRpcServices().getTableDescriptors(null, req); assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled()); }
UTIL.startMiniCluster(2); UTIL.getMiniHBaseCluster().getMaster().getMasterRpcServices().synchronousBalanceSwitch(false); LOG.info("\n\nCreating tables"); for (TableName TABLE : TABLES) {
@Test public void testTableNamesEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.getMasterRpcServices().getTableNames(null, GetTableNamesRequest.newBuilder().build()); assertTrue("Coprocessor should be called on table names request", cp.wasGetTableNamesCalled()); }
master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone());
@Test public void testClusterRequests() throws Exception { // sending fake request to master to see how metric value has changed RegionServerStatusProtos.RegionServerReportRequest.Builder request = RegionServerStatusProtos.RegionServerReportRequest.newBuilder(); ServerName serverName = cluster.getMaster(0).getServerName(); request.setServer(ProtobufUtil.toServerName(serverName)); long expectedRequestNumber = 10000; MetricsMasterSource masterSource = master.getMasterMetrics().getMetricsSource(); ClusterStatusProtos.ServerLoad sl = ClusterStatusProtos.ServerLoad.newBuilder() .setTotalNumberOfRequests(expectedRequestNumber).build(); request.setLoad(sl); master.getMasterRpcServices().regionServerReport(null, request.build()); metricsHelper.assertCounter("cluster_requests", expectedRequestNumber, masterSource); expectedRequestNumber = 15000; sl = ClusterStatusProtos.ServerLoad.newBuilder().setTotalNumberOfRequests(expectedRequestNumber) .build(); request.setLoad(sl); master.getMasterRpcServices().regionServerReport(null, request.build()); metricsHelper.assertCounter("cluster_requests", expectedRequestNumber, masterSource); }
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest( firstGoodPair.getRegionInfo().getEncodedNameAsBytes(), ServerName.valueOf(destName))); assertTrue("Coprocessor should have been called on region move", RegionInfo info = openRegions.get(i); if (!info.isMetaRegion()) { master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(openRegions.get(i).getEncodedNameAsBytes(), ServerName.valueOf(Bytes.toString(destRS))));
master.getReplicationPeerManager().addPeer(peer2, ReplicationPeerConfig.newBuilder().setClusterKey("test").build(), true); master.getMasterRpcServices().regionServerReport(null, request.build()); HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoad = master.getReplicationLoad(new ServerName[] { serverName });
request.setServer(ProtobufUtil.toServerName(sn)); request.setLoad(ServerMetricsBuilder.toServerLoad(ServerMetricsBuilder.of(sn))); master.getMasterRpcServices().regionServerReport(null, request.build());
@Test public void testMasterRpcScheduler() { HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); MasterRpcServices masterRpcServices = master.getMasterRpcServices(); RpcScheduler masterRpcScheduler = masterRpcServices.getRpcScheduler(); Assert.assertTrue(masterRpcScheduler instanceof MasterFifoRpcScheduler); }