Skip to content

Commit 2facb7a

Browse files
zmalikZain Malik
authored andcommitted
Add mesos primitives, Unavailability support
1 parent f47aa98 commit 2facb7a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.apache.mesos.chronos.scheduler.mesos
2+
3+
import java.util.logging.Logger
4+
5+
import org.apache.mesos.Protos
6+
7+
/**
8+
* Helper for checking availability using mesos primitives
9+
*/
10+
object AvailabilityChecker {
11+
12+
private[this] val log = Logger.getLogger(getClass.getName)
13+
14+
def checkAvailability(offer: Protos.Offer): Boolean = {
15+
var unavailability = offer.hasUnavailability
16+
var now = System.nanoTime()
17+
if (offer.hasUnavailability && offer.getUnavailability.hasStart) {
18+
val start = offer.getUnavailability.getStart.getNanoseconds
19+
if (now.>=(start)) {
20+
if (offer.getUnavailability.hasDuration) {
21+
return start.+(offer.getUnavailability.getDuration.getNanoseconds).>(now)
22+
} else {
23+
return false;
24+
}
25+
26+
}
27+
}
28+
return true
29+
}
30+
31+
}

src/main/scala/org/apache/mesos/chronos/scheduler/mesos/MesosJobFramework.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class MesosJobFramework @Inject()(
131131
case None =>
132132
val neededResources = new Resources(job)
133133
offerResources.toIterator.find { ors =>
134-
ors._2.canSatisfy(neededResources) && ConstraintChecker.checkConstraints(ors._1, job.constraints)
134+
ors._2.canSatisfy(neededResources) && ConstraintChecker.checkConstraints(ors._1, job.constraints) && AvailabilityChecker.checkAvailability(ors._1)
135135
} match {
136136
case Some((offer, resources)) =>
137137
// Subtract this job's resource requirements from the remaining available resources in this offer.

0 commit comments

Comments
 (0)