Search in sources :

Example 1 with LeaderRetrievalListener

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener in project flink by apache.

the class SingleLeaderElectionServiceTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    final UUID uuid = UUID.randomUUID();
    final SingleLeaderElectionService service = new SingleLeaderElectionService(executor, uuid);
    // create a leader contender and let it grab leadership
    final LeaderContender contender = mockContender(service);
    service.start(contender);
    verify(contender, times(1)).grantLeadership(uuid);
    // some leader listeners
    final LeaderRetrievalListener listener1 = mock(LeaderRetrievalListener.class);
    final LeaderRetrievalListener listener2 = mock(LeaderRetrievalListener.class);
    LeaderRetrievalService listenerService1 = service.createLeaderRetrievalService();
    LeaderRetrievalService listenerService2 = service.createLeaderRetrievalService();
    listenerService1.start(listener1);
    listenerService2.start(listener2);
    // one listener stops
    listenerService1.stop();
    // shut down the service
    service.shutdown();
    // the leader contender and running listener should get error notifications
    verify(contender, times(1)).handleError(any(Exception.class));
    verify(listener2, times(1)).handleError(any(Exception.class));
    // the stopped listener gets no notification
    verify(listener1, times(0)).handleError(any(Exception.class));
    // should not be possible to start again after shutdown
    try {
        service.start(contender);
        fail("should fail with an exception");
    } catch (IllegalStateException e) {
    // expected
    }
    // no additional leadership grant
    verify(contender, times(1)).grantLeadership(any(UUID.class));
}
Also used : LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) LeaderRetrievalListener(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with LeaderRetrievalListener

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener in project flink by apache.

the class FlinkResourceManager method preStart.

// ------------------------------------------------------------------------
//  Actor Behavior
// ------------------------------------------------------------------------
@Override
public void preStart() {
    try {
        // we start our leader retrieval service to make sure we get informed
        // about JobManager leader changes
        leaderRetriever.start(new LeaderRetrievalListener() {

            @Override
            public void notifyLeaderAddress(String leaderAddress, UUID leaderSessionID) {
                self().tell(new NewLeaderAvailable(leaderAddress, leaderSessionID), ActorRef.noSender());
            }

            @Override
            public void handleError(Exception e) {
                self().tell(new FatalErrorOccurred("Leader retrieval service failed", e), ActorRef.noSender());
            }
        });
        // framework specific initialization
        initialize();
    } catch (Throwable t) {
        self().tell(new FatalErrorOccurred("Error during startup of ResourceManager actor", t), ActorRef.noSender());
    }
}
Also used : NewLeaderAvailable(org.apache.flink.runtime.clusterframework.messages.NewLeaderAvailable) FatalErrorOccurred(org.apache.flink.runtime.clusterframework.messages.FatalErrorOccurred) LeaderRetrievalListener(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener) UUID(java.util.UUID)

Example 3 with LeaderRetrievalListener

use of org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener in project flink by apache.

the class YarnIntraNonHaMasterServicesTest method testClosingReportsToLeader.

@Test
public void testClosingReportsToLeader() throws Exception {
    final Configuration flinkConfig = new Configuration();
    try (YarnHighAvailabilityServices services = new YarnIntraNonHaMasterServices(flinkConfig, hadoopConfig)) {
        final LeaderElectionService elector = services.getResourceManagerLeaderElectionService();
        final LeaderRetrievalService retrieval = services.getResourceManagerLeaderRetriever();
        final LeaderContender contender = mockContender(elector);
        final LeaderRetrievalListener listener = mock(LeaderRetrievalListener.class);
        elector.start(contender);
        retrieval.start(listener);
        // wait until the contender has become the leader
        verify(listener, timeout(1000L).times(1)).notifyLeaderAddress(anyString(), any(UUID.class));
        // now we can close the election service
        services.close();
        verify(contender, timeout(1000L).times(1)).handleError(any(Exception.class));
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) LeaderElectionService(org.apache.flink.runtime.leaderelection.LeaderElectionService) LeaderRetrievalListener(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)3 LeaderRetrievalListener (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener)3 LeaderContender (org.apache.flink.runtime.leaderelection.LeaderContender)2 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)2 Test (org.junit.Test)2 Configuration (org.apache.flink.configuration.Configuration)1 FatalErrorOccurred (org.apache.flink.runtime.clusterframework.messages.FatalErrorOccurred)1 NewLeaderAvailable (org.apache.flink.runtime.clusterframework.messages.NewLeaderAvailable)1 LeaderElectionService (org.apache.flink.runtime.leaderelection.LeaderElectionService)1