use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class FileSystemAdminShellUtils method checkMasterClientService.
/**
* Checks if the master client service is available.
* Throws an exception if fails to determine that the master client service is running.
*
* @param alluxioConf Alluxio configuration
*/
public static void checkMasterClientService(AlluxioConfiguration alluxioConf) throws IOException {
try (FileSystemContext context = FileSystemContext.create(ClientContext.create(alluxioConf));
CloseableResource<FileSystemMasterClient> client = context.acquireMasterClientResource()) {
InetSocketAddress address = client.get().getAddress();
List<InetSocketAddress> addresses = Arrays.asList(address);
MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () -> new ExponentialBackoffRetry(50, 100, 2), alluxioConf);
inquireClient.getPrimaryRpcAddress();
} catch (UnavailableException e) {
throw new IOException("Cannot connect to Alluxio leader master.");
}
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class MasterInfoCommand method run.
@Override
public int run(CommandLine cl) {
MasterInquireClient inquireClient = MasterInquireClient.Factory.create(mFsContext.getClusterConf(), mFsContext.getClientContext().getUserState());
try {
InetSocketAddress leaderAddress = inquireClient.getPrimaryRpcAddress();
System.out.println("Current leader master: " + leaderAddress.toString());
} catch (UnavailableException e) {
System.out.println("Failed to find leader master");
}
try {
List<InetSocketAddress> masterAddresses = inquireClient.getMasterRpcAddresses();
System.out.println(String.format("All masters: %s", masterAddresses));
} catch (UnavailableException e) {
System.out.println("Failed to find all master addresses");
}
return 0;
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class LogLevelTest method parseZooKeeperHAMasterTarget.
@Test
public void parseZooKeeperHAMasterTarget() throws Exception {
String masterAddress = "masters-1:2181";
mConf.set(PropertyKey.ZOOKEEPER_ENABLED, true);
mConf.set(PropertyKey.ZOOKEEPER_ADDRESS, masterAddress);
CommandLine mockCommandLine = mock(CommandLine.class);
String[] mockArgs = new String[] { "--target", "master" };
when(mockCommandLine.getArgs()).thenReturn(mockArgs);
when(mockCommandLine.hasOption(LogLevel.TARGET_OPTION_NAME)).thenReturn(true);
when(mockCommandLine.getOptionValue(LogLevel.TARGET_OPTION_NAME)).thenReturn(mockArgs[1]);
PowerMockito.mockStatic(MasterInquireClient.Factory.class);
MasterInquireClient mockInquireClient = mock(MasterInquireClient.class);
when(mockInquireClient.getPrimaryRpcAddress()).thenReturn(new InetSocketAddress("masters-1", mConf.getInt(PropertyKey.MASTER_RPC_PORT)));
when(mockInquireClient.getConnectDetails()).thenReturn(() -> new ZookeeperAuthority(masterAddress));
when(MasterInquireClient.Factory.create(any(), any())).thenReturn(mockInquireClient);
List<LogLevel.TargetInfo> targets = LogLevel.parseOptTarget(mockCommandLine, mConf);
assertEquals(1, targets.size());
assertEquals(new LogLevel.TargetInfo("masters-1", MASTER_WEB_PORT, "master"), targets.get(0));
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class MultiProcessCluster method getPrimaryMasterIndex.
/**
* Gets the index of the primary master.
*
* @param timeoutMs maximum amount of time to wait, in milliseconds
* @return the index of the primary master
*/
public synchronized int getPrimaryMasterIndex(int timeoutMs) throws TimeoutException, InterruptedException {
final FileSystem fs = getFileSystemClient();
final MasterInquireClient inquireClient = getMasterInquireClient();
CommonUtils.waitFor("a primary master to be serving", () -> {
try {
// Make sure the leader is serving.
fs.getStatus(new AlluxioURI("/"));
return true;
} catch (Exception e) {
LOG.error("Failed to get status of root directory:", e);
return false;
}
}, WaitForOptions.defaults().setTimeoutMs(timeoutMs));
int primaryRpcPort;
try {
primaryRpcPort = inquireClient.getPrimaryRpcAddress().getPort();
} catch (UnavailableException e) {
throw new RuntimeException(e);
}
// Returns the master whose RPC port matches the primary RPC port.
for (int i = 0; i < mMasterAddresses.size(); i++) {
if (mMasterAddresses.get(i).getRpcPort() == primaryRpcPort) {
return i;
}
}
throw new RuntimeException(String.format("No master found with RPC port %d. Master addresses: %s", primaryRpcPort, mMasterAddresses));
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class MetricsHeartbeatContextTest method testExecutorInitialized.
@Test
public void testExecutorInitialized() {
InstancedConfiguration conf = ConfigurationTestUtils.defaults();
conf.set(PropertyKey.MASTER_HOSTNAME, "localhost");
conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
ClientContext ctx = ClientContext.create(conf);
MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
// Add and delete a single context, make sure it is non null after adding, and then null after
// removing
MetricsHeartbeatContext.addHeartbeat(ctx, client);
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertNull(getInternalExecutor());
// Add a few, then remove and check for the state in between
MetricsHeartbeatContext.addHeartbeat(ctx, client);
MetricsHeartbeatContext.addHeartbeat(ctx, client);
MetricsHeartbeatContext.addHeartbeat(ctx, client);
MetricsHeartbeatContext.addHeartbeat(ctx, client);
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertNull(getInternalExecutor());
}
Aggregations