org.apache.flink.runtime.util.LeaderConnectionInfo Java Examples
The following examples show how to use
org.apache.flink.runtime.util.LeaderConnectionInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultDispatcherRunnerTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void grantLeadership_oldLeader_doesNotConfirmLeaderSession() throws Exception { final UUID leaderSessionId = UUID.randomUUID(); final CompletableFuture<String> contenderConfirmationFuture = new CompletableFuture<>(); final TestingDispatcherLeaderProcess testingDispatcherLeaderProcess = TestingDispatcherLeaderProcess.newBuilder(leaderSessionId) .setConfirmLeaderSessionFuture(contenderConfirmationFuture) .build(); testingDispatcherLeaderProcessFactory = TestingDispatcherLeaderProcessFactory.from(testingDispatcherLeaderProcess); try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) { testingLeaderElectionService.isLeader(leaderSessionId); testingLeaderElectionService.notLeader(); // complete the confirmation future after losing the leadership contenderConfirmationFuture.complete("leader address"); final CompletableFuture<LeaderConnectionInfo> leaderElectionConfirmationFuture = testingLeaderElectionService.getConfirmationFuture(); try { leaderElectionConfirmationFuture.get(5L, TimeUnit.MILLISECONDS); fail("No valid leader should exist."); } catch (TimeoutException expected) {} } }
Example #2
Source File: ProcessFailureCancelingITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Helper method to wait until the {@link Dispatcher} has set its fencing token. * * @param rpcService to use to connect to the dispatcher * @param haServices high availability services to connect to the dispatcher * @return {@link DispatcherGateway} * @throws Exception if something goes wrong */ static DispatcherGateway retrieveDispatcherGateway(RpcService rpcService, HighAvailabilityServices haServices) throws Exception { final LeaderConnectionInfo leaderConnectionInfo = LeaderRetrievalUtils.retrieveLeaderConnectionInfo(haServices.getDispatcherLeaderRetriever(), Time.seconds(10L)); return rpcService.connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderConnectionInfo.getLeaderSessionID()), DispatcherGateway.class).get(); }
Example #3
Source File: DefaultDispatcherRunnerTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void grantLeadership_validLeader_confirmsLeaderSession() throws Exception { final UUID leaderSessionId = UUID.randomUUID(); try (final DispatcherRunner dispatcherRunner = createDispatcherRunner()) { testingLeaderElectionService.isLeader(leaderSessionId); final CompletableFuture<LeaderConnectionInfo> confirmationFuture = testingLeaderElectionService.getConfirmationFuture(); final LeaderConnectionInfo leaderConnectionInfo = confirmationFuture.get(); assertThat(leaderConnectionInfo.getLeaderSessionId(), is(leaderSessionId)); } }
Example #4
Source File: DefaultCLITest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that the configuration is properly passed via the DefaultCLI to the * created ClusterDescriptor. */ @Test public void testConfigurationPassing() throws Exception { final Configuration configuration = getConfiguration(); final String localhost = "localhost"; final int port = 1234; configuration.setString(JobManagerOptions.ADDRESS, localhost); configuration.setInteger(JobManagerOptions.PORT, port); @SuppressWarnings("unchecked") final AbstractCustomCommandLine<StandaloneClusterId> defaultCLI = (AbstractCustomCommandLine<StandaloneClusterId>) getCli(configuration); final String[] args = {}; CommandLine commandLine = defaultCLI.parseCommandLineOptions(args, false); final ClusterDescriptor<StandaloneClusterId> clusterDescriptor = defaultCLI.createClusterDescriptor(commandLine); final ClusterClient<?> clusterClient = clusterDescriptor.retrieve(defaultCLI.getClusterId(commandLine)); final LeaderConnectionInfo clusterConnectionInfo = clusterClient.getClusterConnectionInfo(); assertThat(clusterConnectionInfo.getHostname(), Matchers.equalTo(localhost)); assertThat(clusterConnectionInfo.getPort(), Matchers.equalTo(port)); }
Example #5
Source File: DefaultCLITest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Tests that command line options override the configuration settings. */ @Test public void testManualConfigurationOverride() throws Exception { final String localhost = "localhost"; final int port = 1234; final Configuration configuration = getConfiguration(); configuration.setString(JobManagerOptions.ADDRESS, localhost); configuration.setInteger(JobManagerOptions.PORT, port); @SuppressWarnings("unchecked") final AbstractCustomCommandLine<StandaloneClusterId> defaultCLI = (AbstractCustomCommandLine<StandaloneClusterId>) getCli(configuration); final String manualHostname = "123.123.123.123"; final int manualPort = 4321; final String[] args = {"-m", manualHostname + ':' + manualPort}; CommandLine commandLine = defaultCLI.parseCommandLineOptions(args, false); final ClusterDescriptor<StandaloneClusterId> clusterDescriptor = defaultCLI.createClusterDescriptor(commandLine); final ClusterClient<?> clusterClient = clusterDescriptor.retrieve(defaultCLI.getClusterId(commandLine)); final LeaderConnectionInfo clusterConnectionInfo = clusterClient.getClusterConnectionInfo(); assertThat(clusterConnectionInfo.getHostname(), Matchers.equalTo(manualHostname)); assertThat(clusterConnectionInfo.getPort(), Matchers.equalTo(manualPort)); }
Example #6
Source File: ProcessFailureCancelingITCase.java From flink with Apache License 2.0 | 5 votes |
/** * Helper method to wait until the {@link Dispatcher} has set its fencing token. * * @param rpcService to use to connect to the dispatcher * @param haServices high availability services to connect to the dispatcher * @return {@link DispatcherGateway} * @throws Exception if something goes wrong */ static DispatcherGateway retrieveDispatcherGateway(RpcService rpcService, HighAvailabilityServices haServices) throws Exception { final LeaderConnectionInfo leaderConnectionInfo = LeaderRetrievalUtils.retrieveLeaderConnectionInfo(haServices.getDispatcherLeaderRetriever(), Time.seconds(10L)); return rpcService.connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderConnectionInfo.getLeaderSessionID()), DispatcherGateway.class).get(); }
Example #7
Source File: ZooKeeperDefaultDispatcherRunnerTest.java From flink with Apache License 2.0 | 5 votes |
private DispatcherGateway grantLeadership(TestingLeaderElectionService dispatcherLeaderElectionService) throws InterruptedException, java.util.concurrent.ExecutionException { final UUID leaderSessionId = UUID.randomUUID(); dispatcherLeaderElectionService.isLeader(leaderSessionId); final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get(); return testingRpcServiceResource.getTestingRpcService().connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderSessionId), DispatcherGateway.class).get(); }
Example #8
Source File: DefaultCLITest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that the configuration is properly passed via the DefaultCLI to the * created ClusterDescriptor. */ @Test public void testConfigurationPassing() throws Exception { final Configuration configuration = getConfiguration(); final String localhost = "localhost"; final int port = 1234; configuration.setString(JobManagerOptions.ADDRESS, localhost); configuration.setInteger(JobManagerOptions.PORT, port); @SuppressWarnings("unchecked") final AbstractCustomCommandLine<StandaloneClusterId> defaultCLI = (AbstractCustomCommandLine<StandaloneClusterId>) getCli(configuration); final String[] args = {}; CommandLine commandLine = defaultCLI.parseCommandLineOptions(args, false); final ClusterDescriptor<StandaloneClusterId> clusterDescriptor = defaultCLI.createClusterDescriptor(commandLine); final ClusterClient<?> clusterClient = clusterDescriptor.retrieve(defaultCLI.getClusterId(commandLine)); final LeaderConnectionInfo clusterConnectionInfo = clusterClient.getClusterConnectionInfo(); assertThat(clusterConnectionInfo.getHostname(), Matchers.equalTo(localhost)); assertThat(clusterConnectionInfo.getPort(), Matchers.equalTo(port)); }
Example #9
Source File: DefaultCLITest.java From flink with Apache License 2.0 | 5 votes |
/** * Tests that command line options override the configuration settings. */ @Test public void testManualConfigurationOverride() throws Exception { final String localhost = "localhost"; final int port = 1234; final Configuration configuration = getConfiguration(); configuration.setString(JobManagerOptions.ADDRESS, localhost); configuration.setInteger(JobManagerOptions.PORT, port); @SuppressWarnings("unchecked") final AbstractCustomCommandLine<StandaloneClusterId> defaultCLI = (AbstractCustomCommandLine<StandaloneClusterId>) getCli(configuration); final String manualHostname = "123.123.123.123"; final int manualPort = 4321; final String[] args = {"-m", manualHostname + ':' + manualPort}; CommandLine commandLine = defaultCLI.parseCommandLineOptions(args, false); final ClusterDescriptor<StandaloneClusterId> clusterDescriptor = defaultCLI.createClusterDescriptor(commandLine); final ClusterClient<?> clusterClient = clusterDescriptor.retrieve(defaultCLI.getClusterId(commandLine)); final LeaderConnectionInfo clusterConnectionInfo = clusterClient.getClusterConnectionInfo(); assertThat(clusterConnectionInfo.getHostname(), Matchers.equalTo(manualHostname)); assertThat(clusterConnectionInfo.getPort(), Matchers.equalTo(manualPort)); }
Example #10
Source File: ProcessFailureCancelingITCase.java From flink with Apache License 2.0 | 5 votes |
/** * Helper method to wait until the {@link Dispatcher} has set its fencing token. * * @param rpcService to use to connect to the dispatcher * @param haServices high availability services to connect to the dispatcher * @return {@link DispatcherGateway} * @throws Exception if something goes wrong */ static DispatcherGateway retrieveDispatcherGateway(RpcService rpcService, HighAvailabilityServices haServices) throws Exception { final LeaderConnectionInfo leaderConnectionInfo = LeaderRetrievalUtils.retrieveLeaderConnectionInfo( haServices.getDispatcherLeaderRetriever(), Duration.ofSeconds(10L)); return rpcService.connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderConnectionInfo.getLeaderSessionId()), DispatcherGateway.class).get(); }
Example #11
Source File: DefaultDispatcherRunnerITCase.java From flink with Apache License 2.0 | 5 votes |
private DispatcherGateway electLeaderAndRetrieveGateway(UUID firstLeaderSessionId) throws InterruptedException, java.util.concurrent.ExecutionException { dispatcherLeaderElectionService.isLeader(firstLeaderSessionId); final LeaderConnectionInfo leaderConnectionInfo = dispatcherLeaderElectionService.getConfirmationFuture().get(); return rpcServiceResource.getTestingRpcService().connect( leaderConnectionInfo.getAddress(), DispatcherId.fromUuid(leaderConnectionInfo.getLeaderSessionId()), DispatcherGateway.class).get(); }
Example #12
Source File: TestingLeaderElectionService.java From flink with Apache License 2.0 | 5 votes |
public synchronized CompletableFuture<UUID> isLeader(UUID leaderSessionID) { if (confirmationFuture != null) { confirmationFuture.cancel(false); } confirmationFuture = new CompletableFuture<>(); hasLeadership = true; issuedLeaderSessionId = leaderSessionID; if (contender != null) { contender.grantLeadership(leaderSessionID); } return confirmationFuture.thenApply(LeaderConnectionInfo::getLeaderSessionId); }
Example #13
Source File: EmbeddedHaServicesTest.java From flink with Apache License 2.0 | 4 votes |
private void runLeaderRetrievalTest(LeaderElectionService leaderElectionService, LeaderRetrievalService leaderRetrievalService) throws Exception { LeaderRetrievalUtils.LeaderConnectionInfoListener leaderRetrievalListener = new LeaderRetrievalUtils.LeaderConnectionInfoListener(); TestingLeaderContender leaderContender = new TestingLeaderContender(); leaderRetrievalService.start(leaderRetrievalListener); leaderElectionService.start(leaderContender); final UUID leaderId = leaderContender.getLeaderSessionFuture().get(); leaderElectionService.confirmLeadership(leaderId, ADDRESS); final LeaderConnectionInfo leaderConnectionInfo = leaderRetrievalListener.getLeaderConnectionInfoFuture().get(); assertThat(leaderConnectionInfo.getAddress(), is(ADDRESS)); assertThat(leaderConnectionInfo.getLeaderSessionId(), is(leaderId)); }
Example #14
Source File: TestingLeaderElectionService.java From flink with Apache License 2.0 | 4 votes |
@Override public synchronized void confirmLeadership(UUID leaderSessionID, String leaderAddress) { if (confirmationFuture != null) { confirmationFuture.complete(new LeaderConnectionInfo(leaderSessionID, leaderAddress)); } }
Example #15
Source File: MiniClusterClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public LeaderConnectionInfo getClusterConnectionInfo() throws LeaderRetrievalException { return LeaderRetrievalUtils.retrieveLeaderConnectionInfo( highAvailabilityServices.getDispatcherLeaderRetriever(), timeout); }
Example #16
Source File: RestClusterClient.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public LeaderConnectionInfo getClusterConnectionInfo() throws LeaderRetrievalException { return LeaderRetrievalUtils.retrieveLeaderConnectionInfo( highAvailabilityServices.getDispatcherLeaderRetriever(), timeout); }
Example #17
Source File: TestingLeaderElectionService.java From flink with Apache License 2.0 | 2 votes |
/** * Gets a future that completes when leadership is confirmed. * * <p>Note: the future is created upon calling {@link #isLeader(UUID)}. */ public synchronized CompletableFuture<LeaderConnectionInfo> getConfirmationFuture() { return confirmationFuture; }
Example #18
Source File: ClusterClient.java From flink with Apache License 2.0 | 2 votes |
/** * Gets the current cluster connection info (may change in case of a HA setup). * * @return The the connection info to the leader component of the cluster * @throws LeaderRetrievalException if the leader could not be retrieved */ public LeaderConnectionInfo getClusterConnectionInfo() throws LeaderRetrievalException { return LeaderRetrievalUtils.retrieveLeaderConnectionInfo( highAvailabilityServices.getDispatcherLeaderRetriever(), timeout); }
Example #19
Source File: ClusterClient.java From Flink-CEPplus with Apache License 2.0 | 2 votes |
/** * Gets the current cluster connection info (may change in case of a HA setup). * * @return The the connection info to the leader component of the cluster * @throws LeaderRetrievalException if the leader could not be retrieved */ public LeaderConnectionInfo getClusterConnectionInfo() throws LeaderRetrievalException { return LeaderRetrievalUtils.retrieveLeaderConnectionInfo( highAvailabilityServices.getJobManagerLeaderRetriever(HighAvailabilityServices.DEFAULT_JOB_ID), timeout); }