Search in sources :

Example 6 with MasterInquireClient

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.");
    }
}
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)

Example 7 with MasterInquireClient

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

Example 8 with MasterInquireClient

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));
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) CommandLine(org.apache.commons.cli.CommandLine) ZookeeperAuthority(alluxio.uri.ZookeeperAuthority) InetSocketAddress(java.net.InetSocketAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with MasterInquireClient

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));
}
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 10 with MasterInquireClient

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());
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ClientContext(alluxio.ClientContext) Test(org.junit.Test)

Aggregations

MasterInquireClient (alluxio.master.MasterInquireClient)15 InetSocketAddress (java.net.InetSocketAddress)8 Test (org.junit.Test)7 ClientContext (alluxio.ClientContext)6 UnavailableException (alluxio.exception.status.UnavailableException)4 IOException (java.io.IOException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 InstancedConfiguration (alluxio.conf.InstancedConfiguration)3 MasterClientContext (alluxio.master.MasterClientContext)3 PollingMasterInquireClient (alluxio.master.PollingMasterInquireClient)3 ExponentialBackoffRetry (alluxio.retry.ExponentialBackoffRetry)3 FileSystemMasterClient (alluxio.client.file.FileSystemMasterClient)2 CommandLine (org.apache.commons.cli.CommandLine)2 AlluxioURI (alluxio.AlluxioURI)1 FileSystem (alluxio.client.file.FileSystem)1 FileSystemContext (alluxio.client.file.FileSystemContext)1 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)1 SingleMasterInquireClient (alluxio.master.SingleMasterInquireClient)1 ZkMasterInquireClient (alluxio.master.ZkMasterInquireClient)1 GrpcMessagingClient (alluxio.master.transport.GrpcMessagingClient)1