@Override public ResourceSlot apply(PreemptionVictim victim) { ResourceSlot slot = victim.getResourceSlot(); if (tierManager.getTier(victim.getConfig()).isRevocable()) { // Revocable task CPU cannot be used for preemption purposes as it's a compressible // resource. We can still use RAM, DISK and PORTS as they are not compressible. slot = new ResourceSlot(0.0, slot.getRam(), slot.getDisk(), slot.getNumPorts()); } return slot.add(executorSettings.getExecutorOverhead()); }
@Test public void testAssignNoVetoes() { expect( filter.filter( new UnusedResource(ResourceSlot.from(MESOS_OFFER), OFFER.getAttributes()), new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY))) .andReturn(ImmutableSet.of()); expect( stateManager.assignTask( storeProvider, Tasks.id(TASK), MESOS_OFFER.getHostname(), MESOS_OFFER.getSlaveId(), ImmutableMap.of(PORT_NAME, PORT))) .andReturn(TASK.getAssignedTask()); expect(taskFactory.createFrom(TASK.getAssignedTask(), MESOS_OFFER.getSlaveId())) .andReturn(TASK_INFO); control.replay(); assertEquals( Assignment.success(TASK_INFO), assigner.maybeAssign( storeProvider, OFFER, new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY), Tasks.id(TASK))); }
public class NotifyingSchedulingFilterTest extends EasyMockTest { private static final ITaskConfig TASK = ITaskConfig.build(new TaskConfig().setNumCpus(1).setRamMb(1024).setDiskMb(1024)); private static final TaskGroupKey GROUP_KEY = TaskGroupKey.from(TASK); private static final UnusedResource RESOURCE = new UnusedResource( ResourceSlot.from(TASK).withOverhead(TaskExecutors.NO_OVERHEAD_EXECUTOR), IHostAttributes.build( new HostAttributes().setHost("host").setMode(MaintenanceMode.NONE))); private static final ResourceRequest REQUEST = new ResourceRequest(TASK, AttributeAggregate.EMPTY); private static final Veto VETO_1 = Veto.insufficientResources("ram", 1); private static final Veto VETO_2 = Veto.insufficientResources("ram", 2); private SchedulingFilter filter; private EventSink eventSink; private SchedulingFilter delegate; @Before public void setUp() { delegate = createMock(SchedulingFilter.class); eventSink = createMock(EventSink.class); filter = new NotifyingSchedulingFilter(delegate, eventSink); } @Test public void testEvents() { Set<Veto> vetoes = ImmutableSet.of(VETO_1, VETO_2); expect(delegate.filter(RESOURCE, REQUEST)).andReturn(vetoes); eventSink.post(new Vetoed(GROUP_KEY, vetoes)); control.replay(); assertEquals(vetoes, filter.filter(RESOURCE, REQUEST)); } @Test public void testNoVetoes() { Set<Veto> vetoes = ImmutableSet.of(); expect(delegate.filter(RESOURCE, REQUEST)).andReturn(vetoes); control.replay(); assertEquals(vetoes, filter.filter(RESOURCE, REQUEST)); } }
@Test public void testAssignVetoes() { expect( filter.filter( new UnusedResource(ResourceSlot.from(MESOS_OFFER), OFFER.getAttributes()), new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY))) .andReturn(ImmutableSet.of(Veto.constraintMismatch("denied"))); control.replay(); assertEquals( Assignment.failure(ImmutableSet.of(Veto.constraintMismatch("denied"))), assigner.maybeAssign( storeProvider, OFFER, new ResourceRequest(TASK.getAssignedTask().getTask(), EMPTY), Tasks.id(TASK))); }