use of org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation in project flink by apache.
the class JobMasterTest method registerSlotsAtJobMaster.
private Collection<SlotOffer> registerSlotsAtJobMaster(int numberSlots, JobMasterGateway jobMasterGateway, JobID jobId, TaskExecutorGateway taskExecutorGateway, UnresolvedTaskManagerLocation unresolvedTaskManagerLocation) throws ExecutionException, InterruptedException {
rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
jobMasterGateway.registerTaskManager(jobId, TaskManagerRegistrationInformation.create(taskExecutorGateway.getAddress(), unresolvedTaskManagerLocation, TestingUtils.zeroUUID()), testingTimeout).get();
Collection<SlotOffer> slotOffers = IntStream.range(0, numberSlots).mapToObj(index -> new SlotOffer(new AllocationID(), index, ResourceProfile.ANY)).collect(Collectors.toList());
return jobMasterGateway.offerSlots(unresolvedTaskManagerLocation.getResourceID(), slotOffers, testingTimeout).get();
}
use of org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation in project flink by apache.
the class JobMasterTest method testTaskManagerRegistrationTriggersHeartbeating.
@Test
public void testTaskManagerRegistrationTriggersHeartbeating() throws Exception {
final CompletableFuture<ResourceID> heartbeatResourceIdFuture = new CompletableFuture<>();
final UnresolvedTaskManagerLocation unresolvedTaskManagerLocation = new LocalUnresolvedTaskManagerLocation();
final TestingTaskExecutorGateway taskExecutorGateway = new TestingTaskExecutorGatewayBuilder().setHeartbeatJobManagerFunction((taskManagerId, ignored) -> {
heartbeatResourceIdFuture.complete(taskManagerId);
return FutureUtils.completedVoidFuture();
}).createTestingTaskExecutorGateway();
rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
final JobMaster jobMaster = new JobMasterBuilder(jobGraph, rpcService).withResourceId(jmResourceId).withConfiguration(configuration).withHighAvailabilityServices(haServices).withHeartbeatServices(new HeartbeatServices(1L, 10000L)).createJobMaster();
jobMaster.start();
try {
final JobMasterGateway jobMasterGateway = jobMaster.getSelfGateway(JobMasterGateway.class);
// register task manager will trigger monitor heartbeat target, schedule heartbeat
// request at interval time
CompletableFuture<RegistrationResponse> registrationResponse = jobMasterGateway.registerTaskManager(jobGraph.getJobID(), TaskManagerRegistrationInformation.create(taskExecutorGateway.getAddress(), unresolvedTaskManagerLocation, TestingUtils.zeroUUID()), testingTimeout);
// wait for the completion of the registration
registrationResponse.get();
assertThat(heartbeatResourceIdFuture.join(), anyOf(nullValue(), equalTo(jmResourceId)));
} finally {
RpcUtils.terminateRpcEndpoint(jobMaster, testingTimeout);
}
}
use of org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation in project flink by apache.
the class JobMasterTestUtils method registerTaskExecutorAndOfferSlots.
public static void registerTaskExecutorAndOfferSlots(TestingRpcService rpcService, JobMasterGateway jobMasterGateway, JobID jobId, int numSlots, TaskExecutorGateway taskExecutorGateway, Time testingTimeout) throws ExecutionException, InterruptedException {
final UnresolvedTaskManagerLocation unresolvedTaskManagerLocation = new LocalUnresolvedTaskManagerLocation();
rpcService.registerGateway(taskExecutorGateway.getAddress(), taskExecutorGateway);
jobMasterGateway.registerTaskManager(jobId, TaskManagerRegistrationInformation.create(taskExecutorGateway.getAddress(), unresolvedTaskManagerLocation, TestingUtils.zeroUUID()), testingTimeout).get();
Collection<SlotOffer> slotOffers = IntStream.range(0, numSlots).mapToObj(index -> new SlotOffer(new AllocationID(), index, ResourceProfile.ANY)).collect(Collectors.toList());
jobMasterGateway.offerSlots(unresolvedTaskManagerLocation.getResourceID(), slotOffers, testingTimeout).get();
}
use of org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation in project flink by apache.
the class TaskExecutorTest method testImmediatelyRegistersIfLeaderIsKnown.
@Test
public void testImmediatelyRegistersIfLeaderIsKnown() throws Exception {
final String resourceManagerAddress = "/resource/manager/address/one";
final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
final CountDownLatch taskManagerRegisteredLatch = new CountDownLatch(1);
testingResourceManagerGateway.setRegisterTaskExecutorFunction(FunctionUtils.uncheckedFunction(ignored -> {
taskManagerRegisteredLatch.countDown();
return CompletableFuture.completedFuture(new TaskExecutorRegistrationSuccess(new InstanceID(), new ResourceID(resourceManagerAddress), new ClusterInformation("localhost", 1234)));
}));
rpc.registerGateway(resourceManagerAddress, testingResourceManagerGateway);
final TaskManagerServices taskManagerServices = new TaskManagerServicesBuilder().setUnresolvedTaskManagerLocation(unresolvedTaskManagerLocation).setTaskSlotTable(TaskSlotUtils.createTaskSlotTable(1)).setTaskStateManager(createTaskExecutorLocalStateStoresManager()).build();
final TaskExecutor taskManager = createTaskExecutor(taskManagerServices);
try {
taskManager.start();
resourceManagerLeaderRetriever.notifyListener(resourceManagerAddress, UUID.randomUUID());
assertTrue(taskManagerRegisteredLatch.await(timeout.toMilliseconds(), TimeUnit.MILLISECONDS));
} finally {
RpcUtils.terminateRpcEndpoint(taskManager, timeout);
}
}
use of org.apache.flink.runtime.taskmanager.UnresolvedTaskManagerLocation in project flink by apache.
the class TaskExecutorTest method testReconnectionAttemptIfExplicitlyDisconnected.
/**
* Tests that the TaskExecutor tries to reconnect to a ResourceManager from which it was
* explicitly disconnected.
*/
@Test
public void testReconnectionAttemptIfExplicitlyDisconnected() throws Exception {
final TaskSlotTable<Task> taskSlotTable = TaskSlotUtils.createTaskSlotTable(1);
final UnresolvedTaskManagerLocation unresolvedTaskManagerLocation = new LocalUnresolvedTaskManagerLocation();
final TaskExecutor taskExecutor = createTaskExecutor(new TaskManagerServicesBuilder().setTaskSlotTable(taskSlotTable).setUnresolvedTaskManagerLocation(unresolvedTaskManagerLocation).build());
taskExecutor.start();
try {
final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
final ClusterInformation clusterInformation = new ClusterInformation("foobar", 1234);
final CompletableFuture<RegistrationResponse> registrationResponseFuture = CompletableFuture.completedFuture(new TaskExecutorRegistrationSuccess(new InstanceID(), ResourceID.generate(), clusterInformation));
final BlockingQueue<ResourceID> registrationQueue = new ArrayBlockingQueue<>(1);
testingResourceManagerGateway.setRegisterTaskExecutorFunction(taskExecutorRegistration -> {
registrationQueue.offer(taskExecutorRegistration.getResourceId());
return registrationResponseFuture;
});
rpc.registerGateway(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway);
resourceManagerLeaderRetriever.notifyListener(testingResourceManagerGateway.getAddress(), testingResourceManagerGateway.getFencingToken().toUUID());
final ResourceID firstRegistrationAttempt = registrationQueue.take();
assertThat(firstRegistrationAttempt, equalTo(unresolvedTaskManagerLocation.getResourceID()));
final TaskExecutorGateway taskExecutorGateway = taskExecutor.getSelfGateway(TaskExecutorGateway.class);
assertThat(registrationQueue, is(empty()));
taskExecutorGateway.disconnectResourceManager(new FlinkException("Test exception"));
final ResourceID secondRegistrationAttempt = registrationQueue.take();
assertThat(secondRegistrationAttempt, equalTo(unresolvedTaskManagerLocation.getResourceID()));
} finally {
RpcUtils.terminateRpcEndpoint(taskExecutor, timeout);
}
}
Aggregations