Search in sources :

Example 11 with ClusterInformation

use of org.apache.flink.runtime.entrypoint.ClusterInformation in project flink by apache.

the class TaskExecutorTest method testRegisterWithDefaultSlotResourceProfile.

@Test
public void testRegisterWithDefaultSlotResourceProfile() throws Exception {
    final int numberOfSlots = 2;
    final TaskExecutor taskExecutor = createTaskExecutor(numberOfSlots);
    taskExecutor.start();
    try {
        final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
        final CompletableFuture<ResourceProfile> registeredDefaultSlotResourceProfileFuture = new CompletableFuture<>();
        final ResourceID ownResourceId = testingResourceManagerGateway.getOwnResourceId();
        testingResourceManagerGateway.setRegisterTaskExecutorFunction(taskExecutorRegistration -> {
            registeredDefaultSlotResourceProfileFuture.complete(taskExecutorRegistration.getDefaultSlotResourceProfile());
            return CompletableFuture.completedFuture(new TaskExecutorRegistrationSuccess(new InstanceID(), ownResourceId, new ClusterInformation("localhost", 1234)));
        });
        rpc.registerGateway(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway);
        resourceManagerLeaderRetriever.notifyListener(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway.getFencingToken().toUUID());
        assertThat(registeredDefaultSlotResourceProfileFuture.get(), equalTo(TaskExecutorResourceUtils.generateDefaultSlotResourceProfile(TM_RESOURCE_SPEC, numberOfSlots)));
    } finally {
        RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
    }
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) TaskSlotUtils.createTotalResourceProfile(org.apache.flink.runtime.taskexecutor.slot.TaskSlotUtils.createTotalResourceProfile) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InstanceID(org.apache.flink.runtime.instance.InstanceID) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway) ClusterInformation(org.apache.flink.runtime.entrypoint.ClusterInformation) Test(org.junit.Test)

Example 12 with ClusterInformation

use of org.apache.flink.runtime.entrypoint.ClusterInformation in project flink by apache.

the class TaskExecutorTest method runResourceManagerHeartbeatTest.

private void runResourceManagerHeartbeatTest(HeartbeatServices heartbeatServices, Consumer<TestingResourceManagerGateway> setupResourceManagerGateway, TriConsumerWithException<TaskExecutorGateway, ResourceID, CompletableFuture<ResourceID>, Exception> heartbeatAction) throws Exception {
    final String rmAddress = "rm";
    final ResourceID rmResourceId = new ResourceID(rmAddress);
    final ResourceManagerId rmLeaderId = ResourceManagerId.generate();
    TestingResourceManagerGateway rmGateway = new TestingResourceManagerGateway(rmLeaderId, rmResourceId, rmAddress, rmAddress);
    final TaskExecutorRegistrationSuccess registrationResponse = new TaskExecutorRegistrationSuccess(new InstanceID(), rmResourceId, new ClusterInformation("localhost", 1234));
    final Queue<CompletableFuture<RegistrationResponse>> registrationResponses = new ArrayDeque<>(2);
    registrationResponses.add(CompletableFuture.completedFuture(registrationResponse));
    registrationResponses.add(new CompletableFuture<>());
    final CompletableFuture<ResourceID> taskExecutorRegistrationFuture = new CompletableFuture<>();
    final CountDownLatch registrationAttempts = new CountDownLatch(2);
    rmGateway.setRegisterTaskExecutorFunction(registration -> {
        taskExecutorRegistrationFuture.complete(registration.getResourceId());
        registrationAttempts.countDown();
        return registrationResponses.poll();
    });
    setupResourceManagerGateway.accept(rmGateway);
    final CompletableFuture<ResourceID> taskExecutorDisconnectFuture = new CompletableFuture<>();
    rmGateway.setDisconnectTaskExecutorConsumer(disconnectInfo -> taskExecutorDisconnectFuture.complete(disconnectInfo.f0));
    rpc.registerGateway(rmAddress, rmGateway);
    final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setUnresolvedTaskManagerLocation(unresolvedTaskManagerLocation).build();
    final TaskExecutor taskManager = createTaskExecutor(taskManagerServices, heartbeatServices);
    try {
        taskManager.start();
        final TaskExecutorGateway taskExecutorGateway = taskManager.getSelfGateway(TaskExecutorGateway.class);
        // define a leader and see that a registration happens
        resourceManagerLeaderRetriever.notifyListener(rmAddress, rmLeaderId.toUUID());
        // register resource manager success will trigger monitoring heartbeat target between tm
        // and rm
        assertThat(taskExecutorRegistrationFuture.get(), equalTo(unresolvedTaskManagerLocation.getResourceID()));
        heartbeatAction.accept(taskExecutorGateway, rmGateway.getOwnResourceId(), taskExecutorDisconnectFuture);
        // heartbeat timeout should trigger disconnect TaskManager from ResourceManager
        assertThat(taskExecutorDisconnectFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS), equalTo(unresolvedTaskManagerLocation.getResourceID()));
        assertTrue("The TaskExecutor should try to reconnect to the RM", registrationAttempts.await(timeout.toMilliseconds(), TimeUnit.SECONDS));
    } finally {
        RpcUtils.terminateRpcEndpoint(taskManager, timeout);
    }
}
Also used : InstanceID(org.apache.flink.runtime.instance.InstanceID) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterInformation(org.apache.flink.runtime.entrypoint.ClusterInformation) ArrayDeque(java.util.ArrayDeque) CompletableFuture(java.util.concurrent.CompletableFuture) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) ResourceManagerId(org.apache.flink.runtime.resourcemanager.ResourceManagerId) TestingResourceManagerGateway(org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway)

Aggregations

ClusterInformation (org.apache.flink.runtime.entrypoint.ClusterInformation)12 TestingResourceManagerGateway (org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway)10 InstanceID (org.apache.flink.runtime.instance.InstanceID)9 CompletableFuture (java.util.concurrent.CompletableFuture)7 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)7 Test (org.junit.Test)7 Task (org.apache.flink.runtime.taskmanager.Task)6 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)5 RegistrationResponse (org.apache.flink.runtime.registration.RegistrationResponse)5 FlinkException (org.apache.flink.util.FlinkException)5 ArrayDeque (java.util.ArrayDeque)4 Collection (java.util.Collection)4 UUID (java.util.UUID)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 JobID (org.apache.flink.api.common.JobID)4 File (java.io.File)3 IOException (java.io.IOException)3 InetAddress (java.net.InetAddress)3 Collections (java.util.Collections)3