Search in sources :

Example 11 with MasterInquireClient

use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.

the class FileSystemMasterClientPoolTest method create.

@Test
public void create() throws Exception {
    AlluxioConfiguration conf = ConfigurationTestUtils.defaults();
    FileSystemMasterClient expectedClient = Mockito.mock(FileSystemMasterClient.class);
    PowerMockito.mockStatic(FileSystemMasterClient.Factory.class);
    Mockito.when(FileSystemMasterClient.Factory.create(Mockito.any(MasterClientContext.class))).thenReturn(expectedClient);
    FileSystemMasterClient client;
    ClientContext clientContext = ClientContext.create(conf);
    MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(conf, clientContext.getUserState());
    MasterClientContext masterClientContext = MasterClientContext.newBuilder(clientContext).setMasterInquireClient(masterInquireClient).build();
    try (FileSystemMasterClientPool pool = new FileSystemMasterClientPool(masterClientContext)) {
        client = pool.acquire();
        assertEquals(expectedClient, client);
        pool.release(client);
    }
    Mockito.verify(client).close();
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) MasterClientContext(alluxio.master.MasterClientContext) MasterClientContext(alluxio.master.MasterClientContext) ClientContext(alluxio.ClientContext) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with MasterInquireClient

use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.

the class BlockMasterClientPoolTest method create.

@Test
public void create() throws Exception {
    BlockMasterClient expectedClient = mock(BlockMasterClient.class);
    PowerMockito.mockStatic(BlockMasterClient.Factory.class);
    when(BlockMasterClient.Factory.create(any(MasterClientContext.class))).thenReturn(expectedClient);
    BlockMasterClient client;
    ClientContext clientContext = ClientContext.create(mConf);
    MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(mConf, clientContext.getUserState());
    MasterClientContext masterClientContext = MasterClientContext.newBuilder(clientContext).setMasterInquireClient(masterInquireClient).build();
    try (BlockMasterClientPool pool = new BlockMasterClientPool(masterClientContext)) {
        client = pool.acquire();
        assertEquals(expectedClient, client);
        pool.release(client);
    }
    verify(client).close();
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) MasterClientContext(alluxio.master.MasterClientContext) MasterClientContext(alluxio.master.MasterClientContext) ClientContext(alluxio.ClientContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 13 with MasterInquireClient

use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.

the class LeaderCommand method run.

@Override
public int run(CommandLine cl) {
    System.out.println("This command will be deprecated as of v3.0, please use masterInfo command");
    try (CloseableResource<FileSystemMasterClient> client = mFsContext.acquireMasterClientResource()) {
        try {
            InetSocketAddress address = client.get().getAddress();
            System.out.println(address.getHostName());
            List<InetSocketAddress> addresses = Arrays.asList(address);
            MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses, () -> new ExponentialBackoffRetry(50, 100, 2), mFsContext.getClusterConf());
            try {
                inquireClient.getPrimaryRpcAddress();
            } catch (UnavailableException e) {
                System.err.println("The leader is not currently serving requests.");
            }
        } catch (UnavailableException e) {
            System.err.println("Failed to get the leader master.");
        }
    }
    return 0;
}
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)

Example 14 with MasterInquireClient

use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.

the class FileSystemContext method create.

/**
 * @param subject the parent subject, set to null if not present
 * @param conf Alluxio configuration
 * @param blockWorker block worker
 * @return a context
 */
public static FileSystemContext create(@Nullable Subject subject, @Nullable AlluxioConfiguration conf, @Nullable BlockWorker blockWorker) {
    ClientContext ctx = ClientContext.create(subject, conf);
    MasterInquireClient inquireClient = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
    FileSystemContext context = new FileSystemContext(ctx.getClusterConf(), blockWorker);
    context.init(ctx, inquireClient);
    return context;
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) ClientContext(alluxio.ClientContext) MasterClientContext(alluxio.master.MasterClientContext)

Example 15 with MasterInquireClient

use of alluxio.master.MasterInquireClient in project alluxio by Alluxio.

the class LogLevelTest method parseEmbeddedHAMasterTarget.

@Test
public void parseEmbeddedHAMasterTarget() throws Exception {
    String masterAddresses = "masters-1:19200,masters-2:19200";
    mConf.set(PropertyKey.MASTER_EMBEDDED_JOURNAL_ADDRESSES, masterAddresses);
    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 MultiMasterAuthority(masterAddresses));
    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) MultiMasterAuthority(alluxio.uri.MultiMasterAuthority) InetSocketAddress(java.net.InetSocketAddress) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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