Java Code Examples for org.apache.flink.runtime.clusterframework.types.SlotProfile#preferredLocality()

The following examples show how to use org.apache.flink.runtime.clusterframework.types.SlotProfile#preferredLocality() . 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: SlotSharingManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the location preferences are honoured when looking for a resolved slot.
 */
@Test
public void testGetResolvedSlotWithLocationPreferences() {
	SlotSharingManager slotSharingManager = createTestingSlotSharingManager();

	SlotSharingManager.MultiTaskSlot rootSlot1 = createRootSlot(new LocalTaskManagerLocation(), slotSharingManager);

	LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	SlotSharingManager.MultiTaskSlot rootSlot2 = createRootSlot(taskManagerLocation, slotSharingManager);

	AbstractID groupId = new AbstractID();

	SlotProfile slotProfile = SlotProfile.preferredLocality(ResourceProfile.UNKNOWN, Collections.singleton(taskManagerLocation));

	Collection<SlotSelectionStrategy.SlotInfoAndResources> slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	final LocationPreferenceSlotSelectionStrategy locationPreferenceSlotSelectionStrategy = LocationPreferenceSlotSelectionStrategy.createDefault();
	SlotSelectionStrategy.SlotInfoAndLocality slotInfoAndLocality =
		locationPreferenceSlotSelectionStrategy.selectBestSlotForProfile(slotInfos, slotProfile).get();
	SlotSharingManager.MultiTaskSlot resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());

	assertNotNull(resolvedRootSlot);
	assertEquals(Locality.LOCAL, slotInfoAndLocality.getLocality());
	assertEquals(rootSlot2.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());

	// occupy the slot
	resolvedRootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		groupId,
		slotInfoAndLocality.getLocality());

	slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	slotInfoAndLocality = locationPreferenceSlotSelectionStrategy.selectBestSlotForProfile(slotInfos, slotProfile).get();
	resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());
	assertNotNull(resolvedRootSlot);
	assertNotSame(Locality.LOCAL, (slotInfoAndLocality.getLocality()));
	assertEquals(rootSlot1.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());
}
 
Example 2
Source File: SlotSharingManagerTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the location preferences are honoured when looking for a resolved slot.
 */
@Test
public void testGetResolvedSlotWithLocationPreferences() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	SlotSharingManager.MultiTaskSlot rootSlot1 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		CompletableFuture.completedFuture(
			new SimpleSlotContext(
				new AllocationID(),
				new LocalTaskManagerLocation(),
				0,
				new SimpleAckingTaskManagerGateway())),
		new SlotRequestId());

	LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	SlotSharingManager.MultiTaskSlot rootSlot2 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		CompletableFuture.completedFuture(
			new SimpleSlotContext(
				new AllocationID(),
				taskManagerLocation,
				0,
				new SimpleAckingTaskManagerGateway())),
		new SlotRequestId());

	AbstractID groupId = new AbstractID();

	SlotProfile slotProfile = SlotProfile.preferredLocality(ResourceProfile.UNKNOWN, Collections.singleton(taskManagerLocation));

	Collection<SlotInfo> slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	SlotSelectionStrategy.SlotInfoAndLocality slotInfoAndLocality =
		LocationPreferenceSlotSelectionStrategy.INSTANCE.selectBestSlotForProfile(slotInfos, slotProfile).get();
	SlotSharingManager.MultiTaskSlot resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());

	assertNotNull(resolvedRootSlot);
	assertEquals(Locality.LOCAL, slotInfoAndLocality.getLocality());
	assertEquals(rootSlot2.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());

	// occupy the slot
	resolvedRootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		groupId,
		slotInfoAndLocality.getLocality());

	slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	slotInfoAndLocality = LocationPreferenceSlotSelectionStrategy.INSTANCE.selectBestSlotForProfile(slotInfos, slotProfile).get();
	resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());
	assertNotNull(resolvedRootSlot);
	assertNotSame(Locality.LOCAL, (slotInfoAndLocality.getLocality()));
	assertEquals(rootSlot1.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());
}
 
Example 3
Source File: SlotSharingManagerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that the location preferences are honoured when looking for a resolved slot.
 */
@Test
public void testGetResolvedSlotWithLocationPreferences() {
	final TestingAllocatedSlotActions allocatedSlotActions = new TestingAllocatedSlotActions();

	SlotSharingManager slotSharingManager = new SlotSharingManager(
		SLOT_SHARING_GROUP_ID,
		allocatedSlotActions,
		SLOT_OWNER);

	SlotSharingManager.MultiTaskSlot rootSlot1 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		CompletableFuture.completedFuture(
			new SimpleSlotContext(
				new AllocationID(),
				new LocalTaskManagerLocation(),
				0,
				new SimpleAckingTaskManagerGateway())),
		new SlotRequestId());

	LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
	SlotSharingManager.MultiTaskSlot rootSlot2 = slotSharingManager.createRootSlot(
		new SlotRequestId(),
		CompletableFuture.completedFuture(
			new SimpleSlotContext(
				new AllocationID(),
				taskManagerLocation,
				0,
				new SimpleAckingTaskManagerGateway())),
		new SlotRequestId());

	AbstractID groupId = new AbstractID();

	SlotProfile slotProfile = SlotProfile.preferredLocality(ResourceProfile.UNKNOWN, Collections.singleton(taskManagerLocation));

	Collection<SlotSelectionStrategy.SlotInfoAndResources> slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	SlotSelectionStrategy.SlotInfoAndLocality slotInfoAndLocality =
		LocationPreferenceSlotSelectionStrategy.INSTANCE.selectBestSlotForProfile(slotInfos, slotProfile).get();
	SlotSharingManager.MultiTaskSlot resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());

	assertNotNull(resolvedRootSlot);
	assertEquals(Locality.LOCAL, slotInfoAndLocality.getLocality());
	assertEquals(rootSlot2.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());

	// occupy the slot
	resolvedRootSlot.allocateSingleTaskSlot(
		new SlotRequestId(),
		ResourceProfile.UNKNOWN,
		groupId,
		slotInfoAndLocality.getLocality());

	slotInfos = slotSharingManager.listResolvedRootSlotInfo(groupId);
	slotInfoAndLocality = LocationPreferenceSlotSelectionStrategy.INSTANCE.selectBestSlotForProfile(slotInfos, slotProfile).get();
	resolvedRootSlot = slotSharingManager.getResolvedRootSlot(slotInfoAndLocality.getSlotInfo());
	assertNotNull(resolvedRootSlot);
	assertNotSame(Locality.LOCAL, (slotInfoAndLocality.getLocality()));
	assertEquals(rootSlot1.getSlotRequestId(), resolvedRootSlot.getSlotRequestId());
}
 
Example 4
Source File: ScheduleWithCoLocationHintTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private static SlotProfile slotProfileForLocation(TaskManagerLocation location) {
	return SlotProfile.preferredLocality(ResourceProfile.UNKNOWN, Collections.singletonList(location));
}
 
Example 5
Source File: SchedulerIsolatedTasksTest.java    From flink with Apache License 2.0 4 votes vote down vote up
private static SlotProfile slotProfileForLocation(TaskManagerLocation... location) {
	return SlotProfile.preferredLocality(ResourceProfile.UNKNOWN, Arrays.asList(location));
}