Search in sources :

Example 16 with UnavailableException

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));
}
Also used : SingleMasterInquireClient(alluxio.master.SingleMasterInquireClient) PollingMasterInquireClient(alluxio.master.PollingMasterInquireClient) ZkMasterInquireClient(alluxio.master.ZkMasterInquireClient) MasterInquireClient(alluxio.master.MasterInquireClient) FileSystem(alluxio.client.file.FileSystem) UnavailableException(alluxio.exception.status.UnavailableException) TimeoutException(java.util.concurrent.TimeoutException) UnavailableException(alluxio.exception.status.UnavailableException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI)

Example 17 with UnavailableException

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) StringWriter(java.io.StringWriter) UnavailableException(alluxio.exception.status.UnavailableException) DateTimeFormatter(java.time.format.DateTimeFormatter) File(java.io.File) AlluxioException(alluxio.exception.AlluxioException) IOException(java.io.IOException) UnavailableException(alluxio.exception.status.UnavailableException)

Example 18 with UnavailableException

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;
}
Also used : UnavailableException(alluxio.exception.status.UnavailableException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) RetryPolicy(alluxio.retry.RetryPolicy)

Example 19 with UnavailableException

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;
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InetSocketAddress(java.net.InetSocketAddress) UnavailableException(alluxio.exception.status.UnavailableException)

Example 20 with UnavailableException

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.");
    }
}
Also used : PollingMasterInquireClient(alluxio.master.PollingMasterInquireClient) MasterInquireClient(alluxio.master.MasterInquireClient) FileSystemMasterClient(alluxio.client.file.FileSystemMasterClient) PollingMasterInquireClient(alluxio.master.PollingMasterInquireClient) InetSocketAddress(java.net.InetSocketAddress) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) UnavailableException(alluxio.exception.status.UnavailableException) FileSystemContext(alluxio.client.file.FileSystemContext) IOException(java.io.IOException)

Aggregations

UnavailableException (alluxio.exception.status.UnavailableException)58 IOException (java.io.IOException)25 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioStatusException (alluxio.exception.status.AlluxioStatusException)9 NotFoundException (alluxio.exception.status.NotFoundException)9 InetSocketAddress (java.net.InetSocketAddress)9 BlockInfo (alluxio.wire.BlockInfo)8 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 WorkerNetAddress (alluxio.wire.WorkerNetAddress)7 WorkerInfo (alluxio.wire.WorkerInfo)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Set (java.util.Set)6 RetryPolicy (alluxio.retry.RetryPolicy)5 TimeoutException (java.util.concurrent.TimeoutException)5 BlockInfoException (alluxio.exception.BlockInfoException)4 ExceptionMessage (alluxio.exception.ExceptionMessage)4 InodeFile (alluxio.master.file.meta.InodeFile)4