Java Code Examples for org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup#getTaskAssignment()

The following examples show how to use org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup#getTaskAssignment() . 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: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testImmediateReleaseOneLevel() {
	try {
		JobVertexID vid = new JobVertexID();

		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		Instance instance = SchedulerTestUtils.getRandomInstance(1);
		
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		SimpleSlot sub = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, vid);
		sub.releaseSlot();
		
		assertTrue(sub.isReleased());
		assertTrue(sharedSlot.isReleased());
		
		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 2
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testImmediateReleaseTwoLevel() {
	try {
		JobVertexID vid = new JobVertexID();
		JobVertex vertex = new JobVertex("vertex", vid);
		
		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		CoLocationGroup coLocationGroup = new CoLocationGroup(vertex);
		CoLocationConstraint constraint = coLocationGroup.getLocationConstraint(0);
		
		Instance instance = SchedulerTestUtils.getRandomInstance(1);
		
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		SimpleSlot sub = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, constraint);
		
		assertNull(sub.getGroupID());
		assertEquals(constraint.getSharedSlot(), sub.getParent());
		
		sub.releaseSlot();

		assertTrue(sub.isReleased());
		assertTrue(sharedSlot.isReleased());

		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 3
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void allocateAndReleaseEmptySlot() {
	try {
		JobVertexID vertexId = new JobVertexID();
		
		SlotSharingGroup sharingGroup = new SlotSharingGroup(vertexId);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();
		
		assertEquals(0, assignment.getNumberOfSlots());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vertexId));
		
		Instance instance = SchedulerTestUtils.getRandomInstance(2);
		
		assertEquals(2, instance.getTotalNumberOfSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
		assertEquals(2, instance.getNumberOfAvailableSlots());
		
		// allocate a shared slot
		SharedSlot slot = instance.allocateSharedSlot(assignment);
		assertEquals(2, instance.getTotalNumberOfSlots());
		assertEquals(1, instance.getNumberOfAllocatedSlots());
		assertEquals(1, instance.getNumberOfAvailableSlots());
		
		// check that the new slot is fresh
		assertTrue(slot.isAlive());
		assertFalse(slot.isCanceled());
		assertFalse(slot.isReleased());
		assertEquals(0, slot.getNumberLeaves());
		assertFalse(slot.hasChildren());
		assertTrue(slot.isRootAndEmpty());
		assertNotNull(slot.toString());
		assertTrue(slot.getSubSlots().isEmpty());
		assertEquals(0, slot.getSlotNumber());
		assertEquals(0, slot.getRootSlotNumber());
		
		// release the slot immediately.
		slot.releaseSlot();

		assertTrue(slot.isCanceled());
		assertTrue(slot.isReleased());
		
		// the slot sharing group and instance should not
		assertEquals(2, instance.getTotalNumberOfSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
		assertEquals(2, instance.getNumberOfAvailableSlots());

		assertEquals(0, assignment.getNumberOfSlots());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vertexId));
		
		// we should not be able to allocate any children from this released slot
		assertNull(slot.allocateSharedSlot(new AbstractID()));
		assertNull(slot.allocateSubSlot(new AbstractID()));
		
		// we cannot add this slot to the assignment group
		assertNull(assignment.addSharedSlotAndAllocateSubSlot(slot, Locality.NON_LOCAL, vertexId));
		assertEquals(0, assignment.getNumberOfSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 4
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void allocateSimpleSlotsAndReleaseFromLeaves() {
	try {
		JobVertexID vid1 = new JobVertexID();
		JobVertexID vid2 = new JobVertexID();
		JobVertexID vid3 = new JobVertexID();

		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid1, vid2, vid3);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		Instance instance = SchedulerTestUtils.getRandomInstance(1);

		// allocate a shared slot
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		// allocate a series of sub slots

		SimpleSlot sub1 = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, vid1);
		SimpleSlot sub2 = assignment.getSlotForTask(vid2, NO_LOCATION);
		SimpleSlot sub3 = assignment.getSlotForTask(vid3, NO_LOCATION);
		
		assertNotNull(sub1);
		assertNotNull(sub2);
		assertNotNull(sub3);

		assertEquals(3, sharedSlot.getNumberLeaves());

		assertEquals(1, assignment.getNumberOfSlots());
		
		// release from the leaves.
		
		sub2.releaseSlot();

		assertTrue(sharedSlot.isAlive());
		assertTrue(sub1.isAlive());
		assertTrue(sub2.isReleased());
		assertTrue(sub3.isAlive());
		
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(1, assignment.getNumberOfSlots());
		
		assertEquals(2, sharedSlot.getNumberLeaves());

		
		sub1.releaseSlot();

		assertTrue(sharedSlot.isAlive());
		assertTrue(sub1.isReleased());
		assertTrue(sub2.isReleased());
		assertTrue(sub3.isAlive());
		
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(1, assignment.getNumberOfSlots());
		
		assertEquals(1, sharedSlot.getNumberLeaves());

		sub3.releaseSlot();

		assertTrue(sharedSlot.isReleased());
		assertTrue(sub1.isReleased());
		assertTrue(sub2.isReleased());
		assertTrue(sub3.isReleased());

		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(0, assignment.getNumberOfSlots());
		
		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, assignment.getNumberOfSlots());

		assertNull(sharedSlot.allocateSharedSlot(new AbstractID()));
		assertNull(sharedSlot.allocateSubSlot(new AbstractID()));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 5
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void allocateAndReleaseInMixedOrder() {
	try {
		JobVertexID vid1 = new JobVertexID();
		JobVertexID vid2 = new JobVertexID();
		JobVertexID vid3 = new JobVertexID();

		SlotSharingGroup sharingGroup = new SlotSharingGroup(vid1, vid2, vid3);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();

		Instance instance = SchedulerTestUtils.getRandomInstance(1);

		// allocate a shared slot
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		// allocate a series of sub slots

		SimpleSlot sub1 = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.UNCONSTRAINED, vid1);
		SimpleSlot sub2 = assignment.getSlotForTask(vid2, NO_LOCATION);

		assertNotNull(sub1);
		assertNotNull(sub2);

		assertEquals(2, sharedSlot.getNumberLeaves());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(1, assignment.getNumberOfSlots());
		
		
		sub2.releaseSlot();

		assertEquals(1, sharedSlot.getNumberLeaves());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(1, assignment.getNumberOfSlots());
		
		
		SimpleSlot sub3 = assignment.getSlotForTask(vid3, NO_LOCATION);
		assertNotNull(sub3);
		
		assertEquals(2, sharedSlot.getNumberLeaves());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(1, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(1, assignment.getNumberOfSlots());
		
		sub3.releaseSlot();
		sub1.releaseSlot();

		assertTrue(sharedSlot.isReleased());
		assertEquals(0, sharedSlot.getNumberLeaves());
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid1));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid2));
		assertEquals(0, assignment.getNumberOfAvailableSlotsForGroup(vid3));
		assertEquals(0, assignment.getNumberOfSlots());
		
		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, assignment.getNumberOfSlots());

		assertNull(sharedSlot.allocateSharedSlot(new AbstractID()));
		assertNull(sharedSlot.allocateSubSlot(new AbstractID()));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 6
Source File: SharedSlotsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * We allocate and the structure below and release it from the root.
 *
 * <pre>
 *     Shared(0)(root)
 *        |
 *        +-- Simple(2)(sink)
 *        |
 *        +-- Shared(1)(co-location-group)
 *        |      |
 *        |      +-- Simple(0)(tail)
 *        |      +-- Simple(1)(head)
 *        |
 *        +-- Simple(0)(source)
 * </pre>
 */
@Test
public void testReleaseTwoLevelsFromRoot() {
	try {
		JobVertexID sourceId = new JobVertexID();
		JobVertexID headId = new JobVertexID();
		JobVertexID tailId = new JobVertexID();
		JobVertexID sinkId = new JobVertexID();

		JobVertex headVertex = new JobVertex("head", headId);
		JobVertex tailVertex = new JobVertex("tail", tailId);

		SlotSharingGroup sharingGroup = new SlotSharingGroup(sourceId, headId, tailId, sinkId);
		SlotSharingGroupAssignment assignment = sharingGroup.getTaskAssignment();
		assertEquals(0, assignment.getNumberOfSlots());

		CoLocationGroup coLocationGroup = new CoLocationGroup(headVertex, tailVertex);
		CoLocationConstraint constraint = coLocationGroup.getLocationConstraint(0);
		assertFalse(constraint.isAssigned());

		Instance instance = SchedulerTestUtils.getRandomInstance(1);

		// allocate a shared slot
		SharedSlot sharedSlot = instance.allocateSharedSlot(assignment);

		// get the first simple slot
		SimpleSlot sourceSlot = assignment.addSharedSlotAndAllocateSubSlot(sharedSlot, Locality.LOCAL, sourceId);
		
		SimpleSlot headSlot = assignment.getSlotForTask(constraint, NO_LOCATION);
		constraint.lockLocation();
		SimpleSlot tailSlot = assignment.getSlotForTask(constraint, NO_LOCATION);
		
		SimpleSlot sinkSlot = assignment.getSlotForTask(sinkId, NO_LOCATION);
		
		assertEquals(4, sharedSlot.getNumberLeaves());

		// release all
		sourceSlot.releaseSlot();
		headSlot.releaseSlot();
		tailSlot.releaseSlot();
		sinkSlot.releaseSlot();

		assertTrue(sharedSlot.isReleased());
		assertTrue(sourceSlot.isReleased());
		assertTrue(headSlot.isReleased());
		assertTrue(tailSlot.isReleased());
		assertTrue(sinkSlot.isReleased());
		assertTrue(constraint.getSharedSlot().isReleased());

		assertTrue(constraint.isAssigned());
		assertFalse(constraint.isAssignedAndAlive());

		assertEquals(1, instance.getNumberOfAvailableSlots());
		assertEquals(0, instance.getNumberOfAllocatedSlots());
		
		assertEquals(0, assignment.getNumberOfSlots());
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}