Search in sources :

Example 1 with BlockMasterClient

use of alluxio.client.block.BlockMasterClient in project alluxio by Alluxio.

the class FileSystemContext method getWorkerAddresses.

/**
   * @return if there are any local workers, the returned list will ONLY contain the local workers,
   *         otherwise a list of all remote workers will be returned
   * @throws IOException if an error occurs communicating with the master
   */
private List<WorkerNetAddress> getWorkerAddresses() throws IOException {
    List<WorkerInfo> infos;
    BlockMasterClient blockMasterClient = mBlockMasterClientPool.acquire();
    try {
        infos = blockMasterClient.getWorkerInfoList();
    } catch (AlluxioException e) {
        throw new IOException(e);
    } finally {
        mBlockMasterClientPool.release(blockMasterClient);
    }
    if (infos.isEmpty()) {
        throw new IOException(ExceptionMessage.NO_WORKER_AVAILABLE.getMessage());
    }
    // Convert the worker infos into net addresses, if there are local addresses, only keep those
    List<WorkerNetAddress> workerNetAddresses = new ArrayList<>();
    List<WorkerNetAddress> localWorkerNetAddresses = new ArrayList<>();
    String localHostname = NetworkAddressUtils.getClientHostName();
    for (WorkerInfo info : infos) {
        WorkerNetAddress netAddress = info.getAddress();
        if (netAddress.getHost().equals(localHostname)) {
            localWorkerNetAddresses.add(netAddress);
        }
        workerNetAddresses.add(netAddress);
    }
    return localWorkerNetAddresses.isEmpty() ? workerNetAddresses : localWorkerNetAddresses;
}
Also used : BlockMasterClient(alluxio.client.block.BlockMasterClient) WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArrayList(java.util.ArrayList) WorkerInfo(alluxio.wire.WorkerInfo) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 2 with BlockMasterClient

use of alluxio.client.block.BlockMasterClient in project alluxio by Alluxio.

the class AlluxioFrameworkIntegrationTest method testMesosDeploy.

private void testMesosDeploy(Map<PropertyKey, String> properties) throws Exception {
    StringBuilder alluxioJavaOpts = new StringBuilder(System.getProperty("ALLUXIO_JAVA_OPTS", ""));
    for (Entry<PropertyKey, String> entry : properties.entrySet()) {
        alluxioJavaOpts.append(String.format(" -D%s=%s", entry.getKey().toString(), entry.getValue()));
    }
    Map<String, String> env = ImmutableMap.of("ALLUXIO_JAVA_OPTS", alluxioJavaOpts.toString());
    try {
        startAlluxioFramework(env);
        LOG.info("Launched Alluxio cluster, waiting for worker to register with master");
        String masterHostName = NetworkAddressUtils.getLocalHostName();
        int masterPort = Configuration.getInt(PropertyKey.MASTER_RPC_PORT);
        InetSocketAddress masterAddress = new InetSocketAddress(masterHostName, masterPort);
        try (final BlockMasterClient client = BlockMasterClient.Factory.create(masterAddress)) {
            CommonUtils.waitFor("Alluxio worker to register with master", new Function<Void, Boolean>() {

                @Override
                public Boolean apply(Void input) {
                    try {
                        try {
                            return !client.getWorkerInfoList().isEmpty();
                        } catch (ConnectionFailedException e) {
                            // block master isn't up yet, keep waiting
                            return false;
                        }
                    } catch (Exception e) {
                        throw Throwables.propagate(e);
                    }
                }
            }, WaitForOptions.defaults().setTimeout(15 * Constants.MINUTE_MS));
        }
        LOG.info("Worker registered");
        basicAlluxioTests();
    } finally {
        stopAlluxioFramework();
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionFailedException(alluxio.exception.ConnectionFailedException) BlockMasterClient(alluxio.client.block.BlockMasterClient) ConnectionFailedException(alluxio.exception.ConnectionFailedException) PropertyKey(alluxio.PropertyKey)

Aggregations

BlockMasterClient (alluxio.client.block.BlockMasterClient)2 PropertyKey (alluxio.PropertyKey)1 AlluxioException (alluxio.exception.AlluxioException)1 ConnectionFailedException (alluxio.exception.ConnectionFailedException)1 WorkerInfo (alluxio.wire.WorkerInfo)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1