SchedulingFilterImpl implements SchedulingFilter { @Timed("scheduling_filter") @Override public Set<Veto> filter(UnusedResource resource, ResourceRequest request) { if (!ConfigurationManager.isDedicated(request.getConstraints()) && isDedicated(resource.getAttributes())) { return ImmutableSet.of(Veto.dedicatedHostConstraintMismatch()); } Optional<Veto> maintenanceVeto = getMaintenanceVeto(resource.getAttributes().getMode()); if (maintenanceVeto.isPresent()) { return maintenanceVeto.asSet(); } Optional<Veto> constraintVeto = getConstraintVeto( request.getConstraints(), request.getJobState(), resource.getAttributes().getAttributes()); if (constraintVeto.isPresent()) { return constraintVeto.asSet(); } return getResourceVetoes( resource.getResourceSlot(), ResourceSlot.from(request.getTask()).add(executorSettings.getExecutorOverhead())); } @Inject @VisibleForTesting  SchedulingFilterImpl(ExecutorSettings executorSettings); @Timed("scheduling_filter") @Override Set<Veto> filter(UnusedResource resource, ResourceRequest request);  }
@Test public void testSufficientPorts() { control.replay(); ResourceSlot twoPorts = Resources.from( Offers.createOffer(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK, Pair.of(80, 81))).slot(); ITaskConfig noPortTask = ITaskConfig.build(makeTask(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK) .newBuilder() .setRequestedPorts(ImmutableSet.of())); ITaskConfig onePortTask = ITaskConfig.build(makeTask(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK) .newBuilder() .setRequestedPorts(ImmutableSet.of("one"))); ITaskConfig twoPortTask = ITaskConfig.build(makeTask(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK) .newBuilder() .setRequestedPorts(ImmutableSet.of("one", "two"))); ITaskConfig threePortTask = ITaskConfig.build(makeTask(DEFAULT_CPUS, DEFAULT_RAM, DEFAULT_DISK) .newBuilder() .setRequestedPorts(ImmutableSet.of("one", "two", "three"))); Set<Veto> none = ImmutableSet.of(); IHostAttributes hostA = hostAttributes(HOST_A, host(HOST_A), rack(RACK_A)); assertEquals( none, defaultFilter.filter( new UnusedResource(twoPorts, hostA), new ResourceRequest(noPortTask, EMPTY))); assertEquals( none, defaultFilter.filter( new UnusedResource(twoPorts, hostA), new ResourceRequest(onePortTask, EMPTY))); assertEquals( none, defaultFilter.filter( new UnusedResource(twoPorts, hostA), new ResourceRequest(twoPortTask, EMPTY))); assertEquals( ImmutableSet.of(veto(PORTS, 1)), defaultFilter.filter( new UnusedResource(twoPorts, hostA), new ResourceRequest(threePortTask, EMPTY))); }
@Test public void testAttributes() { control.replay(); IHostAttributes hostA = hostAttributes( HOST_A, valueAttribute("jvm", "1.4", "1.6", "1.7"), valueAttribute("zone", "a", "b", "c")); checkConstraint(hostA, "jvm", true, "1.4"); checkConstraint(hostA, "jvm", false, "1.0"); checkConstraint(hostA, "xxx", false, "1.4"); checkConstraint(hostA, "jvm", true, "1.2", "1.4"); checkConstraint(hostA, "xxx", false, "1.0", "1.4"); Constraint jvmConstraint = makeConstraint("jvm", "1.6"); Constraint zoneConstraint = makeConstraint("zone", "c"); ITaskConfig task = makeTask(JOB_A, jvmConstraint, zoneConstraint); assertEquals( ImmutableSet.of(), defaultFilter.filter( new UnusedResource(DEFAULT_OFFER, hostA), new ResourceRequest(task, EMPTY))); Constraint jvmNegated = jvmConstraint.deepCopy(); jvmNegated.getConstraint().getValue().setNegated(true); Constraint zoneNegated = jvmConstraint.deepCopy(); zoneNegated.getConstraint().getValue().setNegated(true); assertVetoes( makeTask(JOB_A, jvmNegated, zoneNegated), hostA, Veto.constraintMismatch("jvm")); }