use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class BackupWorkerRole method establishConnectionToLeader.
/**
* Establishes a connection with the leader backup master.
*/
private void establishConnectionToLeader() {
// Create unending retry policy for establishing connection with the leader backup master.
RetryPolicy infiniteRetryPolicy = new ExponentialBackoffRetry((int) mLeaderConnectionIntervalMin, (int) mLeaderConnectionIntervalMax, Integer.MAX_VALUE);
while (infiniteRetryPolicy.attempt()) {
// Get leader address.
InetSocketAddress leaderAddress;
try {
// Create inquire client to determine leader address.
MasterInquireClient inquireClient = MasterClientContext.newBuilder(ClientContext.create(ServerConfiguration.global())).build().getMasterInquireClient();
leaderAddress = inquireClient.getPrimaryRpcAddress();
} catch (Throwable t) {
LOG.warn("Failed to get backup-leader address. {}. Error:{}. Attempt:{}", t.toString(), infiniteRetryPolicy.getAttemptCount());
continue;
}
// InetSocketAddress acquired. Establish messaging connection with the leader.
try {
// Create messaging client for backup-leader.
GrpcMessagingClient messagingClient = new GrpcMessagingClient(ServerConfiguration.global(), mServerUserState, mExecutorService, "BackupWorker");
// Initiate the connection to backup-leader on catalyst context and wait.
mLeaderConnection = mGrpcMessagingContext.execute(() -> messagingClient.connect(leaderAddress)).get().get();
// Activate the connection.
activateLeaderConnection(mLeaderConnection);
LOG.info("Established connection to backup-leader: {}", leaderAddress);
break;
} catch (Throwable t) {
LOG.warn("Failed to establish connection to backup-leader: {}. Error:{}. Attempt:{}", leaderAddress, t.toString(), infiniteRetryPolicy.getAttemptCount());
}
}
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class MetricsHeartbeatContextTest method testCancelFuture.
@Test
public void testCancelFuture() {
Map<MasterInquireClient.ConnectDetails, MetricsHeartbeatContext> map = getContextMap();
assertTrue(map.isEmpty());
ScheduledFuture<?> future = Mockito.mock(ScheduledFuture.class);
when(future.cancel(any(Boolean.class))).thenReturn(true);
InstancedConfiguration conf = ConfigurationTestUtils.defaults();
conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
ClientContext ctx = ClientContext.create(conf);
MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
MetricsHeartbeatContext.addHeartbeat(ctx, client);
assertFalse(map.isEmpty());
map.forEach((addr, heartbeat) -> {
ScheduledFuture<?> realFuture = Whitebox.getInternalState(heartbeat, "mMetricsMasterHeartbeatTask");
// Should be created and scheduled
assertNotNull(realFuture);
// Scheduled indefinitely
assertFalse(realFuture.isDone());
Whitebox.setInternalState(heartbeat, "mMetricsMasterHeartbeatTask", future);
// Cancel the real one once replaced with a mock.
realFuture.cancel(false);
});
MetricsHeartbeatContext.removeHeartbeat(ctx);
// Make sure the future is canceled afterwards
verify(future).cancel(false);
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class MetricsHeartbeatContextTest method testContextCounter.
@Test
public void testContextCounter() {
Map<MasterInquireClient.ConnectDetails, MetricsHeartbeatContext> map = getContextMap();
assertTrue(map.isEmpty());
InstancedConfiguration conf = ConfigurationTestUtils.defaults();
conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
ClientContext ctx = ClientContext.create(conf);
MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
MetricsHeartbeatContext.addHeartbeat(ctx, client);
assertFalse(map.isEmpty());
map.forEach((details, context) -> assertEquals(1, (int) Whitebox.getInternalState(context, "mCtxCount")));
MetricsHeartbeatContext.addHeartbeat(ctx, client);
map.forEach((details, context) -> assertEquals(2, (int) Whitebox.getInternalState(context, "mCtxCount")));
conf = ConfigurationTestUtils.defaults();
conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
conf.set(PropertyKey.MASTER_RPC_ADDRESSES, "master1:19998,master2:19998,master3:19998");
ClientContext haCtx = ClientContext.create(conf);
MetricsHeartbeatContext.addHeartbeat(haCtx, MasterInquireClient.Factory.create(conf, haCtx.getUserState()));
assertEquals(2, map.size());
MetricsHeartbeatContext.removeHeartbeat(ctx);
assertEquals(2, map.size());
map.forEach((details, context) -> assertEquals(1, (int) Whitebox.getInternalState(context, "mCtxCount")));
assertNotNull(getInternalExecutor());
MetricsHeartbeatContext.removeHeartbeat(ctx);
MetricsHeartbeatContext.removeHeartbeat(haCtx);
assertNull(getInternalExecutor());
assertTrue(map.isEmpty());
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class AlluxioWorker method main.
/**
* Starts the Alluxio worker.
*
* @param args command line arguments, should be empty
*/
public static void main(String[] args) {
if (args.length != 0) {
LOG.info("java -cp {} {}", RuntimeConstants.ALLUXIO_JAR, AlluxioWorker.class.getCanonicalName());
System.exit(-1);
}
if (!ConfigurationUtils.masterHostConfigured(ServerConfiguration.global())) {
ProcessUtils.fatalError(LOG, ConfigurationUtils.getMasterHostNotConfiguredMessage("Alluxio worker"));
}
CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.WORKER);
MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(ServerConfiguration.global(), ServerUserState.global());
try {
RetryUtils.retry("load cluster default configuration with master", () -> {
InetSocketAddress masterAddress = masterInquireClient.getPrimaryRpcAddress();
ServerConfiguration.loadWorkerClusterDefaults(masterAddress);
}, RetryUtils.defaultWorkerMasterClientRetry(ServerConfiguration.getDuration(PropertyKey.WORKER_MASTER_CONNECT_RETRY_TIMEOUT)));
} catch (IOException e) {
ProcessUtils.fatalError(LOG, "Failed to load cluster default configuration for worker. Please make sure that Alluxio " + "master is running: %s", e.toString());
}
WorkerProcess process;
try {
process = WorkerProcess.Factory.create();
} catch (Throwable t) {
ProcessUtils.fatalError(LOG, t, "Failed to create worker process");
// fatalError will exit, so we shouldn't reach here.
throw t;
}
ProcessUtils.stopProcessOnShutdown(process);
ProcessUtils.run(process);
}
use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.
the class AlluxioJobWorker method main.
/**
* Starts the Alluxio job worker.
*
* @param args command line arguments, should be empty
*/
public static void main(String[] args) {
if (args.length != 0) {
LOG.info("java -cp {} {}", RuntimeConstants.ALLUXIO_JAR, AlluxioJobWorker.class.getCanonicalName());
System.exit(-1);
}
if (!ConfigurationUtils.masterHostConfigured(ServerConfiguration.global())) {
System.out.println(ConfigurationUtils.getMasterHostNotConfiguredMessage("Alluxio job worker"));
System.exit(1);
}
if (!ConfigurationUtils.jobMasterHostConfigured(ServerConfiguration.global())) {
System.out.println(ConfigurationUtils.getJobMasterHostNotConfiguredMessage("Alluxio job worker"));
System.exit(1);
}
CommonUtils.PROCESS_TYPE.set(CommonUtils.ProcessType.JOB_WORKER);
MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(ServerConfiguration.global(), ServerUserState.global());
try {
RetryUtils.retry("load cluster default configuration with master", () -> {
InetSocketAddress masterAddress = masterInquireClient.getPrimaryRpcAddress();
ServerConfiguration.loadWorkerClusterDefaults(masterAddress);
}, RetryUtils.defaultWorkerMasterClientRetry(ServerConfiguration.getDuration(PropertyKey.WORKER_MASTER_CONNECT_RETRY_TIMEOUT)));
} catch (IOException e) {
ProcessUtils.fatalError(LOG, "Failed to load cluster default configuration for job worker. Please make sure that " + "Alluxio master is running: %s", e.toString());
}
JobWorkerProcess process;
try {
process = JobWorkerProcess.Factory.create();
} catch (Throwable t) {
ProcessUtils.fatalError(LOG, t, "Failed to create job worker process");
// fatalError will exit, so we shouldn't reach here.
throw t;
}
ProcessUtils.stopProcessOnShutdown(process);
ProcessUtils.run(process);
}
Aggregations