use of alluxio.exception.status.UnavailableException 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.exception.status.UnavailableException in project alluxio by Alluxio.
the class CollectMetricsCommand method run.
@Override
public int run(CommandLine cl) throws AlluxioException, IOException {
// Determine the working dir path
mWorkingDirPath = getWorkingDirectory(cl);
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
StringWriter outputBuffer = new StringWriter();
for (int i = 0; i < COLLECT_METRICS_TIMES; i++) {
LocalDateTime now = LocalDateTime.now();
String timeMsg = String.format("Collecting metrics at %s", dtf.format(now));
LOG.info(timeMsg);
outputBuffer.write(timeMsg);
// Generate URL from config properties
String masterAddr;
try {
masterAddr = mFsContext.getMasterAddress().getHostName();
} catch (UnavailableException e) {
String noMasterMsg = "No Alluxio master available. Skip metrics collection.";
LOG.warn(noMasterMsg);
outputBuffer.write(noMasterMsg);
break;
}
String url = String.format("http://%s:%s%s", masterAddr, mFsContext.getClusterConf().get(PropertyKey.MASTER_WEB_PORT), METRICS_SERVLET_PATH);
LOG.info(String.format("Metric address URL: %s", url));
// Get metrics
String metricsResponse;
try {
metricsResponse = getMetricsJson(url);
} catch (Exception e) {
// Do not break the loop since the HTTP failure can be due to many reasons
// Return the error message instead
LOG.error("Failed to get Alluxio metrics from URL %s. Exception is %s", url, e);
metricsResponse = String.format("Url: %s%nError: %s", url, e.getMessage());
}
outputBuffer.write(metricsResponse);
// Write to file
File outputFile = generateOutputFile(mWorkingDirPath, String.format("%s-%s", getCommandName(), i));
FileUtils.writeStringToFile(outputFile, metricsResponse);
// Wait for an interval
SleepUtils.sleepMs(LOG, COLLECT_METRICS_INTERVAL);
}
// TODO(jiacheng): phase 2 consider outputting partial results in a finally block
File outputFile = generateOutputFile(mWorkingDirPath, String.format("%s.txt", getCommandName()));
FileUtils.writeStringToFile(outputFile, outputBuffer.toString());
return 0;
}
use of alluxio.exception.status.UnavailableException in project alluxio by Alluxio.
the class RpcPortHealthCheckClient method isServing.
@Override
public boolean isServing() {
RetryPolicy retry = mRetryPolicySupplier.get();
while (retry.attempt()) {
try {
LOG.debug("Checking whether {} is listening for RPCs", mNodeAddress);
NetworkAddressUtils.pingService(mNodeAddress, mServiceType, mConf, mUserState);
LOG.debug("Successfully connected to {}", mNodeAddress);
return true;
} catch (UnavailableException e) {
LOG.debug("Failed to connect to {} on attempt #{}", mNodeAddress, retry.getAttemptCount());
} catch (AlluxioStatusException e) {
throw new RuntimeException(e);
}
}
return false;
}
use of alluxio.exception.status.UnavailableException 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.exception.status.UnavailableException 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.");
}
}
Aggregations