Java Code Examples for org.apache.flink.runtime.jobmaster.JobMasterId

The following examples show how to use org.apache.flink.runtime.jobmaster.JobMasterId. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: SlotPoolImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Start the slot pool to accept RPC calls.
 *
 * @param jobMasterId The necessary leader id for running the job.
 * @param newJobManagerAddress for the slot requests which are sent to the resource manager
 * @param componentMainThreadExecutor The main thread executor for the job master's main thread.
 */
public void start(
	@Nonnull JobMasterId jobMasterId,
	@Nonnull String newJobManagerAddress,
	@Nonnull ComponentMainThreadExecutor componentMainThreadExecutor) throws Exception {

	this.jobMasterId = jobMasterId;
	this.jobManagerAddress = newJobManagerAddress;
	this.componentMainThreadExecutor = componentMainThreadExecutor;

	scheduleRunAsync(this::checkIdleSlot, idleSlotTimeout);

	if (log.isDebugEnabled()) {
		scheduleRunAsync(this::scheduledLogStatus, STATUS_LOG_INTERVAL_MS, TimeUnit.MILLISECONDS);
	}
}
 
Example 2
Source Project: Flink-CEPplus   Source File: ResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method should be called by the framework once it detects that a currently registered
 * job manager has failed.
 *
 * @param jobId identifying the job whose leader shall be disconnected.
 * @param cause The exception which cause the JobManager failed.
 */
protected void closeJobManagerConnection(JobID jobId, Exception cause) {
	JobManagerRegistration jobManagerRegistration = jobManagerRegistrations.remove(jobId);

	if (jobManagerRegistration != null) {
		final ResourceID jobManagerResourceId = jobManagerRegistration.getJobManagerResourceID();
		final JobMasterGateway jobMasterGateway = jobManagerRegistration.getJobManagerGateway();
		final JobMasterId jobMasterId = jobManagerRegistration.getJobMasterId();

		log.info("Disconnect job manager {}@{} for job {} from the resource manager.",
			jobMasterId,
			jobMasterGateway.getAddress(),
			jobId);

		jobManagerHeartbeatManager.unmonitorTarget(jobManagerResourceId);

		jmResourceIdRegistrations.remove(jobManagerResourceId);

		// tell the job manager about the disconnect
		jobMasterGateway.disconnectResourceManager(getFencingToken(), cause);
	} else {
		log.debug("There was no registered job manager for job {}.", jobId);
	}
}
 
Example 3
Source Project: flink   Source File: ResourceManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method should be called by the framework once it detects that a currently registered
 * job manager has failed.
 *
 * @param jobId identifying the job whose leader shall be disconnected.
 * @param cause The exception which cause the JobManager failed.
 */
protected void closeJobManagerConnection(JobID jobId, Exception cause) {
	JobManagerRegistration jobManagerRegistration = jobManagerRegistrations.remove(jobId);

	if (jobManagerRegistration != null) {
		final ResourceID jobManagerResourceId = jobManagerRegistration.getJobManagerResourceID();
		final JobMasterGateway jobMasterGateway = jobManagerRegistration.getJobManagerGateway();
		final JobMasterId jobMasterId = jobManagerRegistration.getJobMasterId();

		log.info("Disconnect job manager {}@{} for job {} from the resource manager.",
			jobMasterId,
			jobMasterGateway.getAddress(),
			jobId);

		jobManagerHeartbeatManager.unmonitorTarget(jobManagerResourceId);

		jmResourceIdRegistrations.remove(jobManagerResourceId);

		// tell the job manager about the disconnect
		jobMasterGateway.disconnectResourceManager(getFencingToken(), cause);
	} else {
		log.debug("There was no registered job manager for job {}.", jobId);
	}
}
 
Example 4
Source Project: Flink-CEPplus   Source File: TestingTaskExecutorGateway.java    License: Apache License 2.0 6 votes vote down vote up
TestingTaskExecutorGateway(
		String address,
		String hostname,
		BiConsumer<ResourceID, AllocatedSlotReport> heartbeatJobManagerConsumer,
		BiConsumer<JobID, Throwable> disconnectJobManagerConsumer,
		BiFunction<TaskDeploymentDescriptor, JobMasterId, CompletableFuture<Acknowledge>> submitTaskConsumer,
		Function<Tuple5<SlotID, JobID, AllocationID, String, ResourceManagerId>, CompletableFuture<Acknowledge>> requestSlotFunction,
		BiFunction<AllocationID, Throwable, CompletableFuture<Acknowledge>> freeSlotFunction,
		Consumer<ResourceID> heartbeatResourceManagerConsumer,
		Consumer<Exception> disconnectResourceManagerConsumer,
		Function<ExecutionAttemptID, CompletableFuture<Acknowledge>> cancelTaskFunction,
		Supplier<Boolean> canBeReleasedSupplier) {
	this.address = Preconditions.checkNotNull(address);
	this.hostname = Preconditions.checkNotNull(hostname);
	this.heartbeatJobManagerConsumer = Preconditions.checkNotNull(heartbeatJobManagerConsumer);
	this.disconnectJobManagerConsumer = Preconditions.checkNotNull(disconnectJobManagerConsumer);
	this.submitTaskConsumer = Preconditions.checkNotNull(submitTaskConsumer);
	this.requestSlotFunction = Preconditions.checkNotNull(requestSlotFunction);
	this.freeSlotFunction = Preconditions.checkNotNull(freeSlotFunction);
	this.heartbeatResourceManagerConsumer = heartbeatResourceManagerConsumer;
	this.disconnectResourceManagerConsumer = disconnectResourceManagerConsumer;
	this.cancelTaskFunction = cancelTaskFunction;
	this.canBeReleasedSupplier = canBeReleasedSupplier;
}
 
Example 5
Source Project: flink   Source File: DefaultJobLeaderService.java    License: Apache License 2.0 6 votes vote down vote up
@GuardedBy("lock")
private void openRpcConnectionTo(String leaderAddress, JobMasterId jobMasterId) {
	Preconditions.checkState(
		currentJobMasterId == null && rpcConnection == null,
		"Cannot open a new rpc connection if the previous connection has not been closed.");

	currentJobMasterId = jobMasterId;
	rpcConnection = new JobManagerRegisteredRpcConnection(
		LOG,
		leaderAddress,
		jobMasterId,
		rpcService.getExecutor());

	LOG.info("Try to register at job manager {} with leader id {}.", leaderAddress, jobMasterId.toUUID());
	rpcConnection.start();
}
 
Example 6
Source Project: flink   Source File: JobLeaderService.java    License: Apache License 2.0 6 votes vote down vote up
public void reconnect() {
	if (stopped) {
		LOG.debug("Cannot reconnect because the JobManagerLeaderListener has already been stopped.");
	} else {
		final RegisteredRpcConnection<JobMasterId, JobMasterGateway, JMTMRegistrationSuccess> currentRpcConnection = rpcConnection;

		if (currentRpcConnection != null) {
			if (currentRpcConnection.isConnected()) {

				if (currentRpcConnection.tryReconnect()) {
					// double check for concurrent stop operation
					if (stopped) {
						currentRpcConnection.close();
					}
				} else {
					LOG.debug("Could not reconnect to the JobMaster {}.", currentRpcConnection.getTargetAddress());
				}
			} else {
				LOG.debug("Ongoing registration to JobMaster {}.", currentRpcConnection.getTargetAddress());
			}
		} else {
			LOG.debug("Cannot reconnect to an unknown JobMaster.");
		}
	}
}
 
Example 7
Source Project: flink   Source File: SlotPoolImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Start the slot pool to accept RPC calls.
 *
 * @param jobMasterId The necessary leader id for running the job.
 * @param newJobManagerAddress for the slot requests which are sent to the resource manager
 * @param componentMainThreadExecutor The main thread executor for the job master's main thread.
 */
public void start(
	@Nonnull JobMasterId jobMasterId,
	@Nonnull String newJobManagerAddress,
	@Nonnull ComponentMainThreadExecutor componentMainThreadExecutor) throws Exception {

	this.jobMasterId = jobMasterId;
	this.jobManagerAddress = newJobManagerAddress;
	this.componentMainThreadExecutor = componentMainThreadExecutor;

	scheduleRunAsync(this::checkIdleSlot, idleSlotTimeout);
	scheduleRunAsync(this::checkBatchSlotTimeout, batchSlotTimeout);

	if (log.isDebugEnabled()) {
		scheduleRunAsync(this::scheduledLogStatus, STATUS_LOG_INTERVAL_MS, TimeUnit.MILLISECONDS);
	}
}
 
Example 8
Source Project: flink   Source File: TestingTaskExecutorGateway.java    License: Apache License 2.0 6 votes vote down vote up
TestingTaskExecutorGateway(
		String address,
		String hostname,
		BiConsumer<ResourceID, AllocatedSlotReport> heartbeatJobManagerConsumer,
		BiConsumer<JobID, Throwable> disconnectJobManagerConsumer,
		BiFunction<TaskDeploymentDescriptor, JobMasterId, CompletableFuture<Acknowledge>> submitTaskConsumer,
		Function<Tuple5<SlotID, JobID, AllocationID, String, ResourceManagerId>, CompletableFuture<Acknowledge>> requestSlotFunction,
		BiFunction<AllocationID, Throwable, CompletableFuture<Acknowledge>> freeSlotFunction,
		Consumer<ResourceID> heartbeatResourceManagerConsumer,
		Consumer<Exception> disconnectResourceManagerConsumer,
		Function<ExecutionAttemptID, CompletableFuture<Acknowledge>> cancelTaskFunction,
		Supplier<CompletableFuture<Boolean>> canBeReleasedSupplier,
		BiConsumer<JobID, Collection<ResultPartitionID>> releasePartitionsConsumer) {
	this.address = Preconditions.checkNotNull(address);
	this.hostname = Preconditions.checkNotNull(hostname);
	this.heartbeatJobManagerConsumer = Preconditions.checkNotNull(heartbeatJobManagerConsumer);
	this.disconnectJobManagerConsumer = Preconditions.checkNotNull(disconnectJobManagerConsumer);
	this.submitTaskConsumer = Preconditions.checkNotNull(submitTaskConsumer);
	this.requestSlotFunction = Preconditions.checkNotNull(requestSlotFunction);
	this.freeSlotFunction = Preconditions.checkNotNull(freeSlotFunction);
	this.heartbeatResourceManagerConsumer = heartbeatResourceManagerConsumer;
	this.disconnectResourceManagerConsumer = disconnectResourceManagerConsumer;
	this.cancelTaskFunction = cancelTaskFunction;
	this.canBeReleasedSupplier = canBeReleasedSupplier;
	this.releasePartitionsConsumer = releasePartitionsConsumer;
}
 
Example 9
Source Project: flink   Source File: TestingResourceManagerGateway.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public CompletableFuture<Acknowledge> requestSlot(JobMasterId jobMasterId, SlotRequest slotRequest, Time timeout) {
	Consumer<SlotRequest> currentRequestSlotConsumer = requestSlotConsumer;

	if (currentRequestSlotConsumer != null) {
		currentRequestSlotConsumer.accept(slotRequest);
	}

	CompletableFuture<Acknowledge> slotFuture = slotFutureReference.getAndSet(null);

	if (slotFuture != null) {
		return slotFuture;
	} else {
		return CompletableFuture.completedFuture(Acknowledge.get());
	}
}
 
Example 10
Source Project: flink   Source File: DefaultJobLeaderService.java    License: Apache License 2.0 6 votes vote down vote up
JobManagerRetryingRegistration(
		Logger log,
		RpcService rpcService,
		String targetName,
		Class<JobMasterGateway> targetType,
		String targetAddress,
		JobMasterId jobMasterId,
		RetryingRegistrationConfiguration retryingRegistrationConfiguration,
		String taskManagerRpcAddress,
		UnresolvedTaskManagerLocation unresolvedTaskManagerLocation) {
	super(
		log,
		rpcService,
		targetName,
		targetType,
		targetAddress,
		jobMasterId,
		retryingRegistrationConfiguration);

	this.taskManagerRpcAddress = taskManagerRpcAddress;
	this.unresolvedTaskManagerLocation = Preconditions.checkNotNull(unresolvedTaskManagerLocation);
}
 
Example 11
Source Project: Flink-CEPplus   Source File: MesosResourceManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
MockJobMaster(JobID jobID) {
	this.jobID = jobID;
	this.resourceID = new ResourceID(jobID.toString());
	this.address = "/" + jobID;
	this.gateway = mock(JobMasterGateway.class);
	this.jobMasterId = JobMasterId.generate();
	this.leaderRetrievalService = new SettableLeaderRetrievalService(this.address, this.jobMasterId.toUUID());
}
 
Example 12
Source Project: Flink-CEPplus   Source File: TaskExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void jobManagerLostLeadership(final JobID jobId, final JobMasterId jobMasterId) {
	log.info("JobManager for job {} with leader id {} lost leadership.", jobId, jobMasterId);

	runAsync(() ->
		closeJobManagerConnection(
			jobId,
			new Exception("Job leader for job id " + jobId + " lost leadership.")));
}
 
Example 13
Source Project: flink   Source File: ResourceManagerJobMasterTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test receive registration with unmatched leadershipId from job master.
 */
@Test
public void testRegisterJobMasterWithUnmatchedLeaderSessionId2() throws Exception {
			// test throw exception when receive a registration from job master which takes unmatched leaderSessionId
	JobMasterId differentJobMasterId = JobMasterId.generate();
	CompletableFuture<RegistrationResponse> unMatchedLeaderFuture = resourceManagerGateway.registerJobManager(
		differentJobMasterId,
		jobMasterResourceId,
		jobMasterGateway.getAddress(),
		jobId,
		TIMEOUT);
	assertTrue(unMatchedLeaderFuture.get() instanceof RegistrationResponse.Decline);
}
 
Example 14
Source Project: Flink-CEPplus   Source File: JobLeaderService.java    License: Apache License 2.0 5 votes vote down vote up
JobManagerRegisteredRpcConnection(
		Logger log,
		String targetAddress,
		JobMasterId jobMasterId,
		Executor executor) {
	super(log, targetAddress, jobMasterId, executor);
}
 
Example 15
Source Project: Flink-CEPplus   Source File: JobLeaderService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected RetryingRegistration<JobMasterId, JobMasterGateway, JMTMRegistrationSuccess> generateRegistration() {
	return new JobLeaderService.JobManagerRetryingRegistration(
			LOG,
			rpcService,
			"JobManager",
			JobMasterGateway.class,
			getTargetAddress(),
			getTargetLeaderId(),
			retryingRegistrationConfiguration,
			ownerAddress,
			ownLocation);
}
 
Example 16
Source Project: Flink-CEPplus   Source File: JobLeaderService.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected CompletableFuture<RegistrationResponse> invokeRegistration(
		JobMasterGateway gateway,
		JobMasterId jobMasterId,
		long timeoutMillis) throws Exception {
	return gateway.registerTaskManager(taskManagerRpcAddress, taskManagerLocation, Time.milliseconds(timeoutMillis));
}
 
Example 17
Source Project: flink   Source File: TaskExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void jobManagerLostLeadership(final JobID jobId, final JobMasterId jobMasterId) {
	log.info("JobManager for job {} with leader id {} lost leadership.", jobId, jobMasterId);

	runAsync(() ->
		jobTable
			.getConnection(jobId)
			.ifPresent(
				jobManagerConnection -> disconnectJobManagerConnection(
					jobManagerConnection,
					new Exception("Job leader for job id " + jobId + " lost leadership."))));
}
 
Example 18
Source Project: Flink-CEPplus   Source File: JobLeaderIdService.java    License: Apache License 2.0 5 votes vote down vote up
public CompletableFuture<JobMasterId> getLeaderId(JobID jobId) throws Exception {
	if (!jobLeaderIdListeners.containsKey(jobId)) {
		addJob(jobId);
	}

	JobLeaderIdListener listener = jobLeaderIdListeners.get(jobId);

	return listener.getLeaderIdFuture().thenApply(JobMasterId::fromUuidOrNull);
}
 
Example 19
Source Project: Flink-CEPplus   Source File: ResourceManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public CompletableFuture<Acknowledge> requestSlot(
		JobMasterId jobMasterId,
		SlotRequest slotRequest,
		final Time timeout) {

	JobID jobId = slotRequest.getJobId();
	JobManagerRegistration jobManagerRegistration = jobManagerRegistrations.get(jobId);

	if (null != jobManagerRegistration) {
		if (Objects.equals(jobMasterId, jobManagerRegistration.getJobMasterId())) {
			log.info("Request slot with profile {} for job {} with allocation id {}.",
				slotRequest.getResourceProfile(),
				slotRequest.getJobId(),
				slotRequest.getAllocationId());

			try {
				slotManager.registerSlotRequest(slotRequest);
			} catch (SlotManagerException e) {
				return FutureUtils.completedExceptionally(e);
			}

			return CompletableFuture.completedFuture(Acknowledge.get());
		} else {
			return FutureUtils.completedExceptionally(new ResourceManagerException("The job leader's id " +
				jobManagerRegistration.getJobMasterId() + " does not match the received id " + jobMasterId + '.'));
		}

	} else {
		return FutureUtils.completedExceptionally(new ResourceManagerException("Could not find registered job manager for job " + jobId + '.'));
	}
}
 
Example 20
Source Project: Flink-CEPplus   Source File: ResourceManager.java    License: Apache License 2.0 5 votes vote down vote up
protected void jobLeaderLostLeadership(JobID jobId, JobMasterId oldJobMasterId) {
	if (jobManagerRegistrations.containsKey(jobId)) {
		JobManagerRegistration jobManagerRegistration = jobManagerRegistrations.get(jobId);

		if (Objects.equals(jobManagerRegistration.getJobMasterId(), oldJobMasterId)) {
			disconnectJobManager(jobId, new Exception("Job leader lost leadership."));
		} else {
			log.debug("Discarding job leader lost leadership, because a new job leader was found for job {}. ", jobId);
		}
	} else {
		log.debug("Discard job leader lost leadership for outdated leader {} for job {}.", oldJobMasterId, jobId);
	}
}
 
Example 21
private TaskSubmissionTestEnvironment createExecutorWithRunningTask(
		JobID jobId,
		ExecutionAttemptID executionAttemptId,
		Class<? extends AbstractInvokable> invokableClass) throws Exception {

	final TaskDeploymentDescriptor tdd = createTaskDeploymentDescriptor(
			jobId, executionAttemptId, invokableClass);

	final CompletableFuture<Void> taskRunningFuture = new CompletableFuture<>();

	final JobMasterId token = JobMasterId.generate();
	final TaskSubmissionTestEnvironment env = new TaskSubmissionTestEnvironment.Builder(jobId)
			.setJobMasterId(token)
			.setSlotSize(1)
			.addTaskManagerActionListener(executionAttemptId, ExecutionState.RUNNING, taskRunningFuture)
			.setMetricQueryServiceAddress(metricRegistry.getMetricQueryServiceGatewayRpcAddress())
			.setJobMasterGateway(new TestingJobMasterGatewayBuilder()
				.setFencingTokenSupplier(() -> token)
				.setOperatorEventSender((eio, oid, value) -> {
					throw new RuntimeException();
				})
				.build())
			.build();

	env.getTaskSlotTable().allocateSlot(0, jobId, tdd.getAllocationId(), Time.seconds(60));

	final TaskExecutorGateway tmGateway = env.getTaskExecutorGateway();
	tmGateway.submitTask(tdd, env.getJobMasterId(), Time.seconds(10)).get();
	taskRunningFuture.get();

	return env;
}
 
Example 22
Source Project: Flink-CEPplus   Source File: SlotPoolImplTest.java    License: Apache License 2.0 5 votes vote down vote up
private static void setupSlotPool(
	SlotPoolImpl slotPool,
	ResourceManagerGateway resourceManagerGateway,
	ComponentMainThreadExecutor mainThreadExecutable) throws Exception {
	final String jobManagerAddress = "foobar";

	slotPool.start(JobMasterId.generate(), jobManagerAddress, mainThreadExecutable);

	slotPool.connectToResourceManager(resourceManagerGateway);
}
 
Example 23
Source Project: Flink-CEPplus   Source File: SlotPoolInteractionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSlotAllocationNoResourceManager() throws Exception {
	final JobID jid = new JobID();

	try (SlotPool pool = new SlotPoolImpl(
		jid,
		SystemClock.getInstance(),
		TestingUtils.infiniteTime(),
		TestingUtils.infiniteTime()
	)) {

		pool.start(JobMasterId.generate(), "foobar", testMainThreadExecutor.getMainThreadExecutor());
		Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.INSTANCE, pool);
		scheduler.start(testMainThreadExecutor.getMainThreadExecutor());

		CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot(
			new SlotRequestId(),
			new ScheduledUnit(SchedulerTestUtils.getDummyTask()),
			SlotProfile.noLocality(DEFAULT_TESTING_PROFILE),
			true,
			fastTimeout));

		try {
			future.get();
			fail("We expected an ExecutionException.");
		} catch (ExecutionException e) {
			assertTrue(ExceptionUtils.stripExecutionException(e) instanceof TimeoutException);
		}
	}
}
 
Example 24
Source Project: Flink-CEPplus   Source File: SlotPoolInteractionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCancelSlotAllocationWithoutResourceManager() throws Exception {
	final JobID jid = new JobID();

	try (TestingSlotPool pool = new TestingSlotPool(
		jid,
		SystemClock.getInstance(),
		TestingUtils.infiniteTime(),
		TestingUtils.infiniteTime())) {

		final CompletableFuture<SlotRequestId> timeoutFuture = new CompletableFuture<>();
		pool.setTimeoutPendingSlotRequestConsumer(timeoutFuture::complete);
		pool.start(JobMasterId.generate(), "foobar", testMainThreadExecutor.getMainThreadExecutor());
		Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.INSTANCE, pool);
		scheduler.start(testMainThreadExecutor.getMainThreadExecutor());

		SlotRequestId requestId = new SlotRequestId();
		CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot(
			requestId,
			new ScheduledUnit(SchedulerTestUtils.getDummyTask()),
			SlotProfile.noLocality(DEFAULT_TESTING_PROFILE),
			true,
			fastTimeout));

		try {
			future.get();
			fail("We expected a TimeoutException.");
		} catch (ExecutionException e) {
			assertTrue(ExceptionUtils.stripExecutionException(e) instanceof TimeoutException);
		}

		// wait for the timeout of the pending slot request
		timeoutFuture.get();

		assertEquals(0L, pool.getNumberOfWaitingForResourceRequests());
	}
}
 
Example 25
@Override
public CompletableFuture<RegistrationResponse> registerJobManager(JobMasterId jobMasterId, ResourceID jobMasterResourceId, String jobMasterAddress, JobID jobId, Time timeout) {
	final Consumer<Tuple4<JobMasterId, ResourceID, String, JobID>> currentConsumer = registerJobManagerConsumer;

	if (currentConsumer != null) {
		currentConsumer.accept(Tuple4.of(jobMasterId, jobMasterResourceId, jobMasterAddress, jobId));
	}

	return CompletableFuture.completedFuture(
		new JobMasterRegistrationSuccess(
			resourceManagerId,
			ownResourceId));
}
 
Example 26
Source Project: flink   Source File: SlotPoolResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void before() throws Throwable {
	if (slotPool != null) {
		terminateSlotPool();
	}

	testingResourceManagerGateway = new TestingResourceManagerGateway();

	slotPool = new TestingSlotPoolImpl(new JobID());
	scheduler = new SchedulerImpl(schedulingStrategy, slotPool);
	slotPool.start(JobMasterId.generate(), "foobar", mainThreadExecutor);
	scheduler.start(mainThreadExecutor);
	slotPool.connectToResourceManager(testingResourceManagerGateway);
}
 
Example 27
/**
 * Test receive registration with unmatched leadershipId from job master.
 */
@Test
public void testRegisterJobMasterWithUnmatchedLeaderSessionId2() throws Exception {
			// test throw exception when receive a registration from job master which takes unmatched leaderSessionId
	JobMasterId differentJobMasterId = JobMasterId.generate();
	CompletableFuture<RegistrationResponse> unMatchedLeaderFuture = resourceManagerGateway.registerJobManager(
		differentJobMasterId,
		jobMasterResourceId,
		jobMasterGateway.getAddress(),
		jobId,
		TIMEOUT);
	assertTrue(unMatchedLeaderFuture.get() instanceof RegistrationResponse.Decline);
}
 
Example 28
/**
 * Test receive registration with invalid address from job master.
 */
@Test
public void testRegisterJobMasterFromInvalidAddress() throws Exception {
	// test throw exception when receive a registration from job master which takes invalid address
	String invalidAddress = "/jobMasterAddress2";
	CompletableFuture<RegistrationResponse> invalidAddressFuture = resourceManagerGateway.registerJobManager(
		new JobMasterId(HighAvailabilityServices.DEFAULT_LEADER_ID),
		jobMasterResourceId,
		invalidAddress,
		jobId,
		TIMEOUT);
	assertTrue(invalidAddressFuture.get(5, TimeUnit.SECONDS) instanceof RegistrationResponse.Decline);
}
 
Example 29
Source Project: flink   Source File: SlotPoolInteractionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSlotAllocationNoResourceManager() throws Exception {
	final JobID jid = new JobID();

	try (SlotPool pool = new SlotPoolImpl(
		jid,
		SystemClock.getInstance(),
		TestingUtils.infiniteTime(),
		TestingUtils.infiniteTime(),
		TestingUtils.infiniteTime()
	)) {

		pool.start(JobMasterId.generate(), "foobar", testMainThreadExecutor.getMainThreadExecutor());
		Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), pool);
		scheduler.start(testMainThreadExecutor.getMainThreadExecutor());

		CompletableFuture<LogicalSlot> future = testMainThreadExecutor.execute(() -> scheduler.allocateSlot(
			new SlotRequestId(),
			new ScheduledUnit(getExecution()),
			SlotProfile.noLocality(DEFAULT_TESTING_PROFILE),
			fastTimeout));

		try {
			future.get();
			fail("We expected an ExecutionException.");
		} catch (ExecutionException e) {
			assertTrue(ExceptionUtils.stripExecutionException(e) instanceof TimeoutException);
		}
	}
}
 
Example 30
Source Project: flink   Source File: JobLeaderIdService.java    License: Apache License 2.0 5 votes vote down vote up
public CompletableFuture<JobMasterId> getLeaderId(JobID jobId) throws Exception {
	if (!jobLeaderIdListeners.containsKey(jobId)) {
		addJob(jobId);
	}

	JobLeaderIdListener listener = jobLeaderIdListeners.get(jobId);

	return listener.getLeaderIdFuture().thenApply(JobMasterId::fromUuidOrNull);
}