package gr.grnet.aquarium.charging
-import gr.grnet.aquarium.{Aquarium, AquariumInternalError}
+import gr.grnet.aquarium.{Real, Aquarium, AquariumInternalError}
import gr.grnet.aquarium.computation.{TimeslotComputations, BillingMonthInfo}
-import gr.grnet.aquarium.event.{CreditsModel, DetailsModel}
+import gr.grnet.aquarium.event.DetailsModel
import gr.grnet.aquarium.logic.accounting.dsl.Timeslot
import gr.grnet.aquarium.message.avro.gen.{EffectivePriceTableMsg, FullPriceTableMsg, ResourceTypeMsg, WalletEntryMsg, ResourceInstanceChargingStateMsg, ResourcesChargingStateMsg, ResourceEventMsg}
import gr.grnet.aquarium.message.avro.{MessageHelpers, AvroHelpers, MessageFactory}
final val selectorLabelsHierarchy: List[String]
) extends ChargingBehavior with Loggable {
- final val HourMillis = CreditsModel.from(1000L * 60 * 60)
- final val HourMillisInverse = CreditsModel.inv(HourMillis)
- final val MB = CreditsModel.from(1024L * 1024L)
- final val MBInverse = CreditsModel.inv(MB)
- final val GB = CreditsModel.from(1024L * 1024L * 1024L)
- final val GBInverse = CreditsModel.inv(GB)
-
- @inline final def HrsOfMillis(timeDeltaMillis: Long): CreditsModel.Type = {
- CreditsModel.*(
- HourMillisInverse,
- CreditsModel.from(timeDeltaMillis)
- )
- }
-
- @inline final def MBsOfBytes(bytes: Double): CreditsModel.Type = {
- CreditsModel.*(
- MBInverse,
- CreditsModel.from(bytes)
- )
- }
-
@inline final protected def rcDebugInfo(rcEvent: ResourceEventMsg) = {
AvroHelpers.jsonStringOfSpecificRecord(rcEvent)
}
DetailsModel.make,
new JArrayList[ResourceEventMsg](),
new JArrayList[ResourceEventMsg](),
- 0.0,
- 0.0,
- 0.0,
- 0.0,
+ Real.toMsgField(0.0),
+ Real.toMsgField(0.0),
+ Real.toMsgField(0.0),
+ Real.toMsgField(0.0),
clientID,
resource,
instanceID
resourceEvent: ResourceEventMsg
) {
- resourceInstanceChargingState.setCurrentValue(resourceEvent.getValue.toString.toDouble)
+ resourceInstanceChargingState.setCurrentValue(resourceEvent.getValue)
}
protected def computeWalletEntriesForNewEvent(
resourceEvent: ResourceEventMsg,
resourceType: ResourceTypeMsg,
billingMonthInfo: BillingMonthInfo,
- totalCredits: Double,
+ totalCredits: Real,
referenceStartMillis: Long,
referenceStopMillis: Long,
agreementByTimeslot: immutable.SortedMap[Timeslot, UserAgreementModel],
resourceInstanceChargingState: ResourceInstanceChargingStateMsg,
aquarium: Aquarium,
walletEntryRecorder: WalletEntryMsg ⇒ Unit
- ): (Int, Double) = {
+ ): (Int, Real) = {
val userID = resourceEvent.getUserID
val resourceEventDetails = resourceEvent.getDetails
- var _oldTotalCredits = totalCredits
+ var _oldTotalReal = totalCredits
var _newAccumulatingAmount = computeNewAccumulatingAmount(resourceInstanceChargingState, resourceEventDetails)
// It will also update the old one inside the data structure.
resourceInstanceChargingState.setOldAccumulatingAmount(resourceInstanceChargingState.getAccumulatingAmount)
- resourceInstanceChargingState.setAccumulatingAmount(_newAccumulatingAmount)
+ resourceInstanceChargingState.setAccumulatingAmount(Real.toMsgField(_newAccumulatingAmount))
val policyByTimeslot = aquarium.policyStore.loadSortedPolicyModelsWithin(
referenceStartMillis,
val (creditsToSubtract, explanation) = this.computeCreditsToSubtract(
resourceInstanceChargingState,
- _oldTotalCredits, // FIXME ??? Should recalculate ???
+ _oldTotalReal, // FIXME ??? Should recalculate ???
timeDeltaMillis,
- cs.getUnitPrice
+ Real(cs.getUnitPrice)
)
- cs.setCreditsToSubtract(creditsToSubtract)
+ cs.setCreditsToSubtract(creditsToSubtract.toString())
cs.setExplanation(explanation)
cs
throw new AquariumInternalError("No chargeslots computed for resource event %s".format(resourceEvent.getOriginalID))
}
- val sumOfCreditsToSubtract = fullChargeslots.map(_.getCreditsToSubtract.toDouble).sum
- val newTotalCredits = _oldTotalCredits - sumOfCreditsToSubtract
+ val sumOfRealToSubtract = fullChargeslots.map(x ⇒ Real(x.getCreditsToSubtract)).sum
+ val newTotalReal = _oldTotalReal - sumOfRealToSubtract
val eventsForWallet = new ju.ArrayList[ResourceEventMsg](resourceInstanceChargingState.getPreviousEvents)
eventsForWallet.add(0, resourceEvent)
import scala.collection.JavaConverters.seqAsJavaListConverter
val newWalletEntry = MessageFactory.newWalletEntryMsg(
userID,
- CreditsModel.from(sumOfCreditsToSubtract),
- CreditsModel.from(_oldTotalCredits),
- CreditsModel.from(newTotalCredits),
+ Real.toMsgField(sumOfRealToSubtract),
+ Real.toMsgField(_oldTotalReal),
+ Real.toMsgField(newTotalReal),
TimeHelpers.nowMillis(),
referenceStartMillis,
referenceStopMillis,
walletEntryRecorder.apply(newWalletEntry)
- (1, sumOfCreditsToSubtract)
+ (1, sumOfRealToSubtract)
}
currentResourceEvent: ResourceEventMsg,
referenceStartMillis: Long,
referenceStopMillis: Long,
- totalCredits: Double
+ totalCredits: Real
): EffectivePriceTableModel = {
val selectorPath = computeSelectorPath(