Skip to content

Commit

Permalink
Updating the current cluster state with the latest price instead of t…
Browse files Browse the repository at this point in the history
…he one when the config was created
  • Loading branch information
ashwanthkumar committed May 17, 2016
1 parent 1253364 commit c4ae269
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/main/scala/in/ashwanthkumar/matsya/Matsya.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,22 @@ class Matsya(ec2: AmazonEC2Client,

def checkClusters(): Unit = {
config.clusters.foreach(clusterConfig => {
val state = stateStore.get(clusterConfig.name)
val verifier = new DefaultVerifier(clusterConfig, state)
state match {
val previousState = stateStore.get(clusterConfig.name)
val currentPrice = timeSeriesStore.get(clusterConfig.machineType, previousState.az).maxBy(_.timestamp).price
val verifier = new DefaultVerifier(clusterConfig, previousState)
previousState.copy(price = currentPrice) match {
case s if s.onSpot && verifier.hasViolated =>
moveToCheapestAZOnSpotIfAvailable(clusterConfig, state, fallbackToOD = clusterConfig.fallBackToOnDemand)
moveToCheapestAZOnSpotIfAvailable(clusterConfig, s, fallbackToOD = clusterConfig.fallBackToOnDemand)
case s if s.onSpot && verifier.isPriceViolation =>
logger.info(s"${clusterConfig.name} has crossed the threshold ${state.nrOfTimes + 1} times so far out of ${clusterConfig.maxNrOfTimes} ")
notifier.info(s"${clusterConfig.name} has crossed the threshold ${state.nrOfTimes + 1} times so far out of ${clusterConfig.maxNrOfTimes}")
logger.info(s"Existing price=${state.price} and max bid price=${clusterConfig.maxBidPrice}")
stateStore.save(clusterConfig.name, state.crossedThreshold())
logger.info(s"${clusterConfig.name} has crossed the threshold ${s.nrOfTimes + 1} times so far out of ${clusterConfig.maxNrOfTimes} ")
notifier.info(s"${clusterConfig.name} has crossed the threshold ${s.nrOfTimes + 1} times so far out of ${clusterConfig.maxNrOfTimes}")
logger.info(s"Existing price=${s.price} and max bid price=${clusterConfig.maxBidPrice}")
stateStore.save(clusterConfig.name, s.crossedThreshold())
case s if s.onOD && hasCooledOff(clusterConfig, s) =>
moveToCheapestAZOnSpotIfAvailable(clusterConfig, state, fallbackToOD = false)
moveToCheapestAZOnSpotIfAvailable(clusterConfig, s, fallbackToOD = false)
case s if s.onSpot =>
stateStore.save(clusterConfig.name, state.resetCount())
logger.info(s"CurrentSpotPrice = ${state.price} is within the MaxBidPrice = ${clusterConfig.maxBidPrice} on AZ = ${state.az}")
stateStore.save(clusterConfig.name, s.resetCount())
logger.info(s"CurrentSpotPrice = ${s.price} is within the MaxBidPrice = ${clusterConfig.maxBidPrice} on AZ = ${s.az}")
}
})
}
Expand Down

0 comments on commit c4ae269

Please sign in to comment.