org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor Java Examples

The following examples show how to use org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor. 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: SlotPoolBatchSlotRequestTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a batch slot request does not react to {@link SlotPool#failAllocation(AllocationID, Exception)}
 * signals whose exception is not {@link UnfulfillableSlotRequestException}.
 */
@Test
public void testPendingBatchSlotRequestDoesNotFailIfAllocationFails() throws Exception {
	final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
	final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>();
	testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId()));

	final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread();

	final Time batchSlotTimeout = Time.milliseconds(1000L);
	try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor)
		.setBatchSlotTimeout(batchSlotTimeout)
		.setResourceManagerGateway(testingResourceManagerGateway)
		.build()) {

		final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile);

		SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(), new FlinkException("Failed request"));

		assertThat(slotFuture.isDone(), is(false));
	}
}
 
Example #2
Source File: Execution.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Releases the assigned resource and completes the release future
 * once the assigned resource has been successfully released.
 *
 * @param cause for the resource release, null if none
 */
private void releaseAssignedResource(@Nullable Throwable cause) {

	assertRunningInJobMasterMainThread();

	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		slot.releaseSlot(cause)
			.whenComplete((Object ignored, Throwable throwable) -> {
				jobMasterMainThreadExecutor.assertRunningInMainThread();
				if (throwable != null) {
					releaseFuture.completeExceptionally(throwable);
				} else {
					releaseFuture.complete(null);
				}
			});
	} else {
		// no assigned resource --> we can directly complete the release future
		releaseFuture.complete(null);
	}
}
 
Example #3
Source File: Execution.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Releases the assigned resource and completes the release future
 * once the assigned resource has been successfully released.
 *
 * @param cause for the resource release, null if none
 */
private void releaseAssignedResource(@Nullable Throwable cause) {

	assertRunningInJobMasterMainThread();

	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		slot.releaseSlot(cause)
			.whenComplete((Object ignored, Throwable throwable) -> {
				jobMasterMainThreadExecutor.assertRunningInMainThread();
				if (throwable != null) {
					releaseFuture.completeExceptionally(throwable);
				} else {
					releaseFuture.complete(null);
				}
			});
	} else {
		// no assigned resource --> we can directly complete the release future
		releaseFuture.complete(null);
	}
}
 
Example #4
Source File: SlotPoolImpl.java    From Flink-CEPplus with 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 #5
Source File: SlotPoolPendingRequestFailureTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a pending slot request is failed with a timeout.
 */
@Test
public void testPendingSlotRequestTimeout() throws Exception {
	final ScheduledExecutorService singleThreadExecutor = Executors.newSingleThreadScheduledExecutor();
	final ComponentMainThreadExecutor componentMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(singleThreadExecutor);

	final SlotPoolImpl slotPool = setUpSlotPool(componentMainThreadExecutor);

	try {
		final Time timeout = Time.milliseconds(5L);

		final CompletableFuture<PhysicalSlot> slotFuture = CompletableFuture
			.supplyAsync(() -> requestNewAllocatedSlot(slotPool, new SlotRequestId(), timeout), componentMainThreadExecutor)
			.thenCompose(Function.identity());

		try {
			slotFuture.get();
			fail("Expected that the future completes with a TimeoutException.");
		} catch (ExecutionException ee) {
			assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class));
		}
	} finally {
		CompletableFuture.runAsync(ThrowingRunnable.unchecked(slotPool::close), componentMainThreadExecutor).get();
		singleThreadExecutor.shutdownNow();
	}
}
 
Example #6
Source File: Execution.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method sends a CancelTask message to the instance of the assigned slot.
 *
 * <p>The sending is tried up to NUM_CANCEL_CALL_TRIES times.
 */
private void sendCancelRpcCall(int numberRetries) {
	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
		final ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		CompletableFuture<Acknowledge> cancelResultFuture = FutureUtils.retry(
			() -> taskManagerGateway.cancelTask(attemptId, rpcTimeout),
			numberRetries,
			jobMasterMainThreadExecutor);

		cancelResultFuture.whenComplete(
			(ack, failure) -> {
				if (failure != null) {
					fail(new Exception("Task could not be canceled.", failure));
				}
			});
	}
}
 
Example #7
Source File: Execution.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * This method sends a CancelTask message to the instance of the assigned slot.
 *
 * <p>The sending is tried up to NUM_CANCEL_CALL_TRIES times.
 */
private void sendCancelRpcCall(int numberRetries) {
	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
		final ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		CompletableFuture<Acknowledge> cancelResultFuture = FutureUtils.retry(
			() -> taskManagerGateway.cancelTask(attemptId, rpcTimeout),
			numberRetries,
			jobMasterMainThreadExecutor);

		cancelResultFuture.whenComplete(
			(ack, failure) -> {
				if (failure != null) {
					fail(new Exception("Task could not be canceled.", failure));
				}
			});
	}
}
 
Example #8
Source File: SchedulerTestBase.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	final JobID jobId = new JobID();
	final SlotPool slotPool = new TestingSlotPoolImpl(jobId);
	final TestingScheduler testingScheduler = new TestingScheduler(
		new HashMap<>(16),
		LocationPreferenceSlotSelectionStrategy.INSTANCE,
		slotPool);

	testingSlotProvider = new TestingSlotPoolSlotProvider(slotPool, testingScheduler);

	final JobMasterId jobMasterId = JobMasterId.generate();
	final String jobManagerAddress = "localhost";
	ComponentMainThreadExecutor executor = ComponentMainThreadExecutorServiceAdapter.forMainThread();
	slotPool.start(jobMasterId, jobManagerAddress, executor);
	testingScheduler.start(executor);
}
 
Example #9
Source File: LegacySchedulerBatchSchedulingTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private LegacyScheduler createLegacyScheduler(JobGraph jobGraph, SlotPool slotPool, ComponentMainThreadExecutor mainThreadExecutor, Time slotRequestTimeout) throws Exception {
	final Scheduler scheduler = createScheduler(slotPool, mainThreadExecutor);
	final LegacyScheduler legacyScheduler = new LegacyScheduler(
		LOG,
		jobGraph,
		VoidBackPressureStatsTracker.INSTANCE,
		TestingUtils.defaultExecutor(),
		new Configuration(),
		scheduler,
		TestingUtils.defaultExecutor(),
		getClass().getClassLoader(),
		new StandaloneCheckpointRecoveryFactory(),
		TestingUtils.TIMEOUT(),
		new NoRestartStrategy.NoRestartStrategyFactory(),
		VoidBlobWriter.getInstance(),
		UnregisteredMetricGroups.createUnregisteredJobManagerJobMetricGroup(),
		slotRequestTimeout,
		NettyShuffleMaster.INSTANCE,
		NoOpPartitionTracker.INSTANCE);

	legacyScheduler.setMainThreadExecutor(mainThreadExecutor);

	return legacyScheduler;
}
 
Example #10
Source File: SlotPoolImpl.java    From flink with 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 #11
Source File: SlotPoolBatchSlotRequestTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a batch slot request fails if its resource manager request fails with {@link UnfulfillableSlotRequestException}.
 */
@Test
public void testPendingBatchSlotRequestFailsIfRMRequestFailsUnfulfillably() throws Exception {
	final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
	testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally(
		new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN)));

	final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread();

	try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor)
		.setResourceManagerGateway(testingResourceManagerGateway)
		.build()) {

		final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile);

		assertThat(slotFuture.isCompletedExceptionally(), is(true));
	}
}
 
Example #12
Source File: SlotPoolBatchSlotRequestTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a batch slot request fails if its resource manager request fails with {@link UnfulfillableSlotRequestException}.
 */
@Test
public void testPendingBatchSlotRequestFailsIfRMRequestFailsUnfulfillably() throws Exception {
	final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
	testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally(
		new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN)));

	final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread();

	try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor)
		.setResourceManagerGateway(testingResourceManagerGateway)
		.build()) {

		final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile);

		assertThat(slotFuture.isCompletedExceptionally(), is(true));
	}
}
 
Example #13
Source File: SlotPoolBatchSlotRequestTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a batch slot request won't fail if its resource manager request fails with exceptions other than
 * {@link UnfulfillableSlotRequestException}.
 */
@Test
public void testPendingBatchSlotRequestDoesNotFailIfRMRequestFails() throws Exception {
	final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
	testingResourceManagerGateway.setRequestSlotFuture(FutureUtils.completedExceptionally(new FlinkException("Failed request")));

	final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread();

	final Time batchSlotTimeout = Time.milliseconds(1000L);
	try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor)
		.setBatchSlotTimeout(batchSlotTimeout)
		.setResourceManagerGateway(testingResourceManagerGateway)
		.build()) {

		final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile);

		assertThat(slotFuture.isDone(), is(false));
	}
}
 
Example #14
Source File: Execution.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * This method sends a CancelTask message to the instance of the assigned slot.
 *
 * <p>The sending is tried up to NUM_CANCEL_CALL_TRIES times.
 */
private void sendCancelRpcCall(int numberRetries) {
	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		final TaskManagerGateway taskManagerGateway = slot.getTaskManagerGateway();
		final ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		CompletableFuture<Acknowledge> cancelResultFuture = FutureUtils.retry(
			() -> taskManagerGateway.cancelTask(attemptId, rpcTimeout),
			numberRetries,
			jobMasterMainThreadExecutor);

		cancelResultFuture.whenComplete(
			(ack, failure) -> {
				if (failure != null) {
					fail(new Exception("Task could not be canceled.", failure));
				}
			});
	}
}
 
Example #15
Source File: Execution.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Releases the assigned resource and completes the release future
 * once the assigned resource has been successfully released.
 *
 * @param cause for the resource release, null if none
 */
private void releaseAssignedResource(@Nullable Throwable cause) {

	assertRunningInJobMasterMainThread();

	final LogicalSlot slot = assignedResource;

	if (slot != null) {
		ComponentMainThreadExecutor jobMasterMainThreadExecutor =
			getVertex().getExecutionGraph().getJobMasterMainThreadExecutor();

		slot.releaseSlot(cause)
			.whenComplete((Object ignored, Throwable throwable) -> {
				jobMasterMainThreadExecutor.assertRunningInMainThread();
				if (throwable != null) {
					releaseFuture.completeExceptionally(throwable);
				} else {
					releaseFuture.complete(null);
				}
			});
	} else {
		// no assigned resource --> we can directly complete the release future
		releaseFuture.complete(null);
	}
}
 
Example #16
Source File: SlotPoolBatchSlotRequestTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a batch slot request does react to {@link SlotPool#failAllocation(AllocationID, Exception)}
 * signals whose exception is {@link UnfulfillableSlotRequestException}.
 */
@Test
public void testPendingBatchSlotRequestFailsIfAllocationFailsUnfulfillably() throws Exception {
	final TestingResourceManagerGateway testingResourceManagerGateway = new TestingResourceManagerGateway();
	final CompletableFuture<AllocationID> allocationIdFuture = new CompletableFuture<>();
	testingResourceManagerGateway.setRequestSlotConsumer(slotRequest -> allocationIdFuture.complete(slotRequest.getAllocationId()));

	final ComponentMainThreadExecutor directMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forMainThread();

	try (final SlotPoolImpl slotPool = new SlotPoolBuilder(directMainThreadExecutor)
		.setResourceManagerGateway(testingResourceManagerGateway)
		.build()) {

		final CompletableFuture<PhysicalSlot> slotFuture = SlotPoolUtils.requestNewAllocatedBatchSlot(slotPool, directMainThreadExecutor, resourceProfile);

		SlotPoolUtils.failAllocation(slotPool, directMainThreadExecutor, allocationIdFuture.get(),
			new UnfulfillableSlotRequestException(new AllocationID(), ResourceProfile.UNKNOWN));

		assertThat(slotFuture.isCompletedExceptionally(), is(true));
	}
}
 
Example #17
Source File: SlotPoolPendingRequestFailureTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a pending slot request is failed with a timeout.
 */
@Test
public void testPendingSlotRequestTimeout() throws Exception {
	final ScheduledExecutorService singleThreadExecutor = Executors.newSingleThreadScheduledExecutor();
	final ComponentMainThreadExecutor componentMainThreadExecutor = ComponentMainThreadExecutorServiceAdapter.forSingleThreadExecutor(singleThreadExecutor);

	final SlotPoolImpl slotPool = setUpSlotPool(componentMainThreadExecutor);

	try {
		final Time timeout = Time.milliseconds(5L);

		final CompletableFuture<PhysicalSlot> slotFuture = CompletableFuture
			.supplyAsync(() -> requestNewAllocatedSlot(slotPool, new SlotRequestId(), timeout), componentMainThreadExecutor)
			.thenCompose(Function.identity());

		try {
			slotFuture.get();
			fail("Expected that the future completes with a TimeoutException.");
		} catch (ExecutionException ee) {
			assertThat(ExceptionUtils.stripExecutionException(ee), instanceOf(TimeoutException.class));
		}
	} finally {
		CompletableFuture.runAsync(ThrowingRunnable.unchecked(slotPool::close), componentMainThreadExecutor).get();
		singleThreadExecutor.shutdownNow();
	}
}
 
Example #18
Source File: SchedulerTestBase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
	final JobID jobId = new JobID();
	final SlotPool slotPool = new SlotPoolImpl(jobId);
	final TestingScheduler testingScheduler = new TestingScheduler(
		new HashMap<>(16),
		LocationPreferenceSlotSelectionStrategy.INSTANCE,
		slotPool);

	testingSlotProvider = new TestingSlotPoolSlotProvider(slotPool, testingScheduler);

	final JobMasterId jobMasterId = JobMasterId.generate();
	final String jobManagerAddress = "localhost";
	ComponentMainThreadExecutor executor = TestingComponentMainThreadExecutorServiceAdapter.forMainThread();
	slotPool.start(jobMasterId, jobManagerAddress, executor);
	testingScheduler.start(executor);
}
 
Example #19
Source File: SchedulerImpl.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public SchedulerImpl(
	@Nonnull SlotSelectionStrategy slotSelectionStrategy,
	@Nonnull SlotPool slotPool,
	@Nonnull Map<SlotSharingGroupId, SlotSharingManager> slotSharingManagers) {

	this.slotSelectionStrategy = slotSelectionStrategy;
	this.slotSharingManagers = slotSharingManagers;
	this.slotPool = slotPool;
	this.componentMainThreadExecutor = new ComponentMainThreadExecutor.DummyComponentMainThreadExecutor(
		"Scheduler is not initialized with proper main thread executor. " +
			"Call to Scheduler.start(...) required.");
}
 
Example #20
Source File: DefaultSchedulerBatchSchedulingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private SlotProvider createSlotProvider(SlotPool slotPool, ComponentMainThreadExecutor mainThreadExecutor) {
	final SchedulerImpl scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.createDefault(), slotPool);
	scheduler.start(mainThreadExecutor);

	return scheduler;
}
 
Example #21
Source File: BulkSlotProviderImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
BulkSlotProviderImpl(final SlotSelectionStrategy slotSelectionStrategy, final SlotPool slotPool) {
	this.slotSelectionStrategy = checkNotNull(slotSelectionStrategy);
	this.slotPool = checkNotNull(slotPool);

	this.slotRequestBulkChecker = new PhysicalSlotRequestBulkChecker(
		this::getAllSlotInfos,
		SystemClock.getInstance());

	this.componentMainThreadExecutor = new ComponentMainThreadExecutor.DummyComponentMainThreadExecutor(
		"Scheduler is not initialized with proper main thread executor. " +
			"Call to BulkSlotProvider.start(...) required.");
}
 
Example #22
Source File: OperatorCoordinatorSchedulerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private DefaultScheduler setupTestJobAndScheduler(
		OperatorCoordinator.Provider provider,
		@Nullable TaskExecutorOperatorEventGateway taskExecutorOperatorEventGateway,
		@Nullable Consumer<JobGraph> jobGraphPreProcessing,
		boolean restartAllOnFailover) throws Exception {

	final OperatorIDPair opIds = OperatorIDPair.of(new OperatorID(), provider.getOperatorId());
	final JobVertex vertex = new JobVertex("Vertex with OperatorCoordinator", testVertexId, Collections.singletonList(opIds));
	vertex.setInvokableClass(NoOpInvokable.class);
	vertex.addOperatorCoordinator(new SerializedValue<>(provider));
	vertex.setParallelism(2);

	final JobGraph jobGraph = new JobGraph("test job with OperatorCoordinator", vertex);
	SchedulerTestingUtils.enableCheckpointing(jobGraph);
	if (jobGraphPreProcessing != null) {
		jobGraphPreProcessing.accept(jobGraph);
	}

	final SchedulerTestingUtils.DefaultSchedulerBuilder schedulerBuilder = taskExecutorOperatorEventGateway == null
			? SchedulerTestingUtils.createSchedulerBuilder(jobGraph, executor)
			: SchedulerTestingUtils.createSchedulerBuilder(jobGraph, executor, taskExecutorOperatorEventGateway);
	if (restartAllOnFailover) {
		schedulerBuilder.setFailoverStrategyFactory(new RestartAllFailoverStrategy.Factory());
	}

	final DefaultScheduler scheduler = schedulerBuilder.build();

	final ComponentMainThreadExecutor mainThreadExecutor = new ComponentMainThreadExecutorServiceAdapter(
		(ScheduledExecutorService) executor, Thread.currentThread());
	scheduler.setMainThreadExecutor(mainThreadExecutor);

	this.createdScheduler = scheduler;
	return scheduler;
}
 
Example #23
Source File: SlotPoolImplTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private static Scheduler setupScheduler(
	SlotPool slotPool,
	ComponentMainThreadExecutor mainThreadExecutable) {
	Scheduler scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.INSTANCE, slotPool);
	scheduler.start(mainThreadExecutable);
	return scheduler;
}
 
Example #24
Source File: TaskSlotTableImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void start(SlotActions initialSlotActions, ComponentMainThreadExecutor mainThreadExecutor) {
	Preconditions.checkState(
		state == State.CREATED,
		"The %s has to be just created before starting",
		TaskSlotTableImpl.class.getSimpleName());
	this.slotActions = Preconditions.checkNotNull(initialSlotActions);
	this.mainThreadExecutor = Preconditions.checkNotNull(mainThreadExecutor);

	timerService.start(this);

	state = State.RUNNING;
}
 
Example #25
Source File: SlotPoolUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static ResourceID offerSlots(
		SlotPoolImpl slotPool,
		ComponentMainThreadExecutor mainThreadExecutor,
		List<ResourceProfile> resourceProfiles,
		TaskManagerGateway taskManagerGateway) {
	final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	CompletableFuture.runAsync(
		() -> {
			slotPool.registerTaskManager(taskManagerLocation.getResourceID());

			final Collection<SlotOffer> slotOffers = IntStream
				.range(0, resourceProfiles.size())
				.mapToObj(i -> new SlotOffer(new AllocationID(), i, resourceProfiles.get(i)))
				.collect(Collectors.toList());

			final Collection<SlotOffer> acceptedOffers = slotPool.offerSlots(
				taskManagerLocation,
				taskManagerGateway,
				slotOffers);

			assertThat(acceptedOffers, is(slotOffers));
		},
		mainThreadExecutor
	).join();

	return taskManagerLocation.getResourceID();
}
 
Example #26
Source File: SlotPoolUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static ResourceID offerSlots(
		SlotPoolImpl slotPool,
		ComponentMainThreadExecutor mainThreadExecutor,
		List<ResourceProfile> resourceProfiles,
		TaskManagerGateway taskManagerGateway) {
	final TaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	CompletableFuture.runAsync(
		() -> {
			slotPool.registerTaskManager(taskManagerLocation.getResourceID());

			final Collection<SlotOffer> slotOffers = IntStream
				.range(0, resourceProfiles.size())
				.mapToObj(i -> new SlotOffer(new AllocationID(), i, resourceProfiles.get(i)))
				.collect(Collectors.toList());

			final Collection<SlotOffer> acceptedOffers = slotPool.offerSlots(
				taskManagerLocation,
				taskManagerGateway,
				slotOffers);

			assertThat(acceptedOffers, is(slotOffers));
		},
		mainThreadExecutor
	).join();

	return taskManagerLocation.getResourceID();
}
 
Example #27
Source File: SlotPoolPendingRequestFailureTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private SlotPoolImpl setUpSlotPool(ComponentMainThreadExecutor componentMainThreadExecutor) throws Exception {
	final SlotPoolImpl slotPool = new TestingSlotPoolImpl(jobId);
	slotPool.start(JobMasterId.generate(), "foobar", componentMainThreadExecutor);
	slotPool.connectToResourceManager(resourceManagerGateway);

	return slotPool;
}
 
Example #28
Source File: LegacySchedulerBatchSchedulingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nonnull
private SchedulerImpl createScheduler(SlotPool slotPool, ComponentMainThreadExecutor mainThreadExecutor) {
	final SchedulerImpl scheduler = new SchedulerImpl(LocationPreferenceSlotSelectionStrategy.INSTANCE, slotPool);
	scheduler.start(mainThreadExecutor);

	return scheduler;
}
 
Example #29
Source File: OperatorCoordinatorHolderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private OperatorCoordinatorHolder createCoordinatorHolder(
		final BiFunction<SerializedValue<OperatorEvent>, Integer, CompletableFuture<Acknowledge>> eventSender,
		final Function<OperatorCoordinator.Context, OperatorCoordinator> coordinatorCtor,
		final ComponentMainThreadExecutor mainThreadExecutor) throws Exception {

	final OperatorID opId = new OperatorID();
	final OperatorCoordinator.Provider provider = new OperatorCoordinator.Provider() {
		@Override
		public OperatorID getOperatorId() {
			return opId;
		}

		@Override
		public OperatorCoordinator create(OperatorCoordinator.Context context) {
			return coordinatorCtor.apply(context);
		}
	};

	final OperatorCoordinatorHolder holder = OperatorCoordinatorHolder.create(
			opId,
			provider,
			eventSender,
			"test-coordinator-name",
			3,
			1775);

	holder.lazyInitialize(globalFailureHandler, mainThreadExecutor);
	holder.start();

	return holder;
}
 
Example #30
Source File: SlotPoolUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
public static CompletableFuture<PhysicalSlot> requestNewAllocatedBatchSlot(
	SlotPool slotPool,
	ComponentMainThreadExecutor mainThreadExecutor,
	ResourceProfile resourceProfile) {
	return CompletableFuture
		.supplyAsync(() -> slotPool.requestNewAllocatedBatchSlot(new SlotRequestId(), resourceProfile), mainThreadExecutor)
		.thenCompose(Function.identity());
}