-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support mesos primitives for availability #5435
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
521266f
Support mesos primitives for availability
alanbover 19575f3
Support drainingTime option for maintenance
3bb17cb
use duration instead of long
499441f
fix durations
ee27b68
document draining_time flag
d03cb48
Merge branch 'alan/MARATHON-3216' of https://github.com/alanbover/mar…
unterstein 97713ad
added feature flag
unterstein 5ee67c2
added feature flag
unterstein 599324d
added tests
unterstein 83b6b00
Merge branch 'master' into alan/MARATHON-3216-2
unterstein a716745
addressed feedback
unterstein e623416
addressed feedback
unterstein 33cac4f
reformat
unterstein 49fd7d8
addressed feedback
unterstein b36d207
reformat
unterstein b892d24
adressed feedback of Aleksey and Nikita
unterstein edb678b
added agent and host to log line
unterstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mesosphere.mesos | ||
|
||
import java.time.Clock | ||
|
||
import mesosphere.marathon.RichClock | ||
import mesosphere.marathon.state.Timestamp | ||
import org.apache.mesos.Protos.{ DurationInfo, Offer } | ||
|
||
import scala.concurrent.duration._ | ||
|
||
object Availability { | ||
|
||
def offerAvailable(offer: Offer, drainingTime: FiniteDuration)(implicit clock: Clock): Boolean = { | ||
val now = clock.now() | ||
if (offerHasUnavailability(offer)) { | ||
val start: Timestamp = offer.getUnavailability.getStart | ||
|
||
if (currentlyInDrainingState(now, start, drainingTime)) { | ||
isAgentOutsideUnavailabilityWindow(offer, start, now) | ||
} else true | ||
} else true | ||
} | ||
|
||
private def currentlyInDrainingState(now: Timestamp, start: Timestamp, drainingTime: FiniteDuration) = { | ||
now.after(start - drainingTime) | ||
} | ||
|
||
private def offerHasUnavailability(offer: Offer) = { | ||
offer.hasUnavailability && offer.getUnavailability.hasStart | ||
} | ||
|
||
private def isAgentOutsideUnavailabilityWindow(offer: Offer, start: Timestamp, now: Timestamp) = { | ||
offer.getUnavailability.hasDuration && now.after(start + offer.getUnavailability.getDuration.toDuration) | ||
} | ||
|
||
/** | ||
* Convert Mesos DurationInfo to FiniteDuration. | ||
* | ||
* @return FiniteDuration for DurationInfo | ||
*/ | ||
implicit class DurationInfoHelper(val di: DurationInfo) extends AnyVal { | ||
def toDuration: FiniteDuration = FiniteDuration(di.getNanoseconds, NANOSECONDS) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package mesosphere.mesos | ||
|
||
import org.rogach.scallop.{ ScallopConf, ScallopOption } | ||
|
||
import scala.concurrent.duration._ | ||
|
||
trait MatcherConf { | ||
|
||
def availableFeatures: Set[String] | ||
|
||
def drainingSeconds: ScallopOption[Long] | ||
|
||
def drainingTime: FiniteDuration = FiniteDuration(drainingSeconds(), SECONDS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package mesosphere.mesos | ||
|
||
import java.time.Clock | ||
|
||
import mesosphere.UnitTest | ||
import mesosphere.marathon.RichClock | ||
import mesosphere.marathon.state.Timestamp | ||
import mesosphere.marathon.test.MarathonTestHelper | ||
import org.apache.mesos.Protos.Offer | ||
|
||
import scala.concurrent.duration._ | ||
|
||
class AvailabilityTest extends UnitTest { | ||
|
||
implicit val clock = Clock.systemUTC() | ||
val now = clock.now() | ||
|
||
"Availability" should { | ||
"drop offer from nodes in maintenance" in { | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability().build(), FiniteDuration(0, SECONDS)) shouldBe false | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability(now - Duration(1, HOURS), Duration(1, DAYS)).build(), FiniteDuration(0, SECONDS)) shouldBe false | ||
} | ||
"accept offers from nodes not in maintenance" in { | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability(now + Duration(1, HOURS), Duration(1, DAYS)).build(), FiniteDuration(0, SECONDS)) shouldBe true | ||
Availability.offerAvailable(MarathonTestHelper.makeBasicOffer().build(), Duration(0, SECONDS)) shouldBe true | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability(now - Duration(1, DAYS), Duration(1, HOURS)).build(), FiniteDuration(0, SECONDS)) shouldBe true | ||
} | ||
"drop offers {drainingTime} seconds before node maintenance starts" in { | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability(now + Duration(200, SECONDS), Duration(1, DAYS)).build(), Duration(300, SECONDS)) shouldBe false | ||
} | ||
"drop offer when maintenance with infinite duration" in { | ||
Availability.offerAvailable(makeBasicOfferWithUnavailability(now - Duration(1, HOURS)).build(), FiniteDuration(0, SECONDS)) shouldBe false | ||
} | ||
} | ||
|
||
def makeBasicOfferWithUnavailability(startTime: Timestamp = now, duration: FiniteDuration = Duration(5, DAYS)): Offer.Builder = { | ||
MarathonTestHelper.makeBasicOfferWithUnavailability(startTime, duration) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a remove of an unwanted whitespace to prevent a reformat in the next time.