import VMChargingBehavior.Selectors.Power
import gr.grnet.aquarium.charging.state.UserAgreementHistoryModel
import gr.grnet.aquarium.computation.BillingMonthInfo
-import gr.grnet.aquarium.event.CreditsModel
import gr.grnet.aquarium.event.DetailsModel
import gr.grnet.aquarium.message.MessageConstants
import gr.grnet.aquarium.message.avro.gen.{UserStateMsg, WalletEntryMsg, ResourceTypeMsg, ResourcesChargingStateMsg, ResourceInstanceChargingStateMsg, ResourceEventMsg}
import gr.grnet.aquarium.util.LogHelpers._
import gr.grnet.aquarium.{Aquarium, AquariumInternalError}
import scala.collection.JavaConverters.asScalaBufferConverter
+import gr.grnet.aquarium.Real
+import gr.grnet.aquarium.HrsOfMillis
/**
* The new [[gr.grnet.aquarium.charging.ChargingBehavior]] for VMs usage.
final class VMChargingBehavior extends ChargingBehaviorSkeleton(List(PowerStatus)) {
def computeCreditsToSubtract(
resourceInstanceChargingState: ResourceInstanceChargingStateMsg,
- oldCredits: CreditsModel.Type,
+ oldCredits: Real,
timeDeltaMillis: Long,
- unitPrice: Double
- ): (CreditsModel.Type, String /* explanation */) = {
+ unitPrice: Real
+ ): (Real, String /* explanation */) = {
val credits = HrsOfMillis(timeDeltaMillis) * unitPrice
val explanation = "Hours(%s) * UnitPrice(%s)".format(HrsOfMillis(timeDeltaMillis), unitPrice)
currentResourceEvent: ResourceEventMsg,
referenceFromMillis: Long,
referenceToMillis: Long,
- totalCredits: CreditsModel.Type
+ totalCredits: Real
): List[String] = {
val previousEvents = resourceInstanceChargingState.getPreviousEvents.asScala.toList
(currentResourceEvent.getValue.toInt,previousEvents) match {
resourceInstanceChargingState: ResourceInstanceChargingStateMsg,
eventDetails: DetailsModel.Type
) = {
- CreditsModel.from(resourceInstanceChargingState.getCurrentValue)
+ Real(resourceInstanceChargingState.getCurrentValue)
}
def constructImplicitEndEventFor(resourceEvent: ResourceEventMsg, newOccurredMillis: Long) = {
setDetails(newDetails).
setOccurredMillis(newOccurredMillis).
setReceivedMillis(newOccurredMillis).
- setValue(VMChargingBehaviorValues.OFF.toString).
+ setValue(VMChargingBehaviorValues.OFF).
build()
}
userAgreementHistoryModel: UserAgreementHistoryModel,
userStateMsg: UserStateMsg,
walletEntryRecorder: WalletEntryMsg ⇒ Unit
- ): (Int, CreditsModel.Type) = {
+ ): (Int, Real) = {
// 1. Ensure proper initial state per resource and per instance
ensureInitializedWorkingState(resourcesChargingState,resourceEvent)
val previousEvents = resourceInstanceChargingState.getPreviousEvents
val retVal = previousEvents.size() match {
case 0 ⇒
- (0,0.0D)
+ (0, Real.Zero)
case _ ⇒
val previousEvent = previousEvents.get(0) // head is most recent
resourceEvent,
resourceType,
billingMonthInfo,
- userStateMsg.getTotalCredits,
+ Real(userStateMsg.getTotalCredits),
previousEvent.getOccurredMillis,
resourceEvent.getOccurredMillis,
userAgreementHistoryModel.agreementByTimeslot,