-import gr.grnet.aquarium.message.avro.gen.{ResourcesChargingStateMsg, UserStateMsg, ResourceEventMsg}
-import gr.grnet.aquarium.message.avro.{ModelFactory, MessageFactory, AvroHelpers}
-import gr.grnet.aquarium.policy.ResourceType
+import gr.grnet.aquarium.message.avro.gen.{ResourceTypeMsg, UserStateMsg, ResourceEventMsg}
+import gr.grnet.aquarium.message.avro.{MessageHelpers, MessageFactory, AvroHelpers}
import gr.grnet.aquarium.util.LogHelpers.Debug
import gr.grnet.aquarium.util.LogHelpers.DebugSeq
import gr.grnet.aquarium.util.LogHelpers.Warn
import gr.grnet.aquarium.util.date.{MutableDateCalc, TimeHelpers}
import gr.grnet.aquarium.util.{Lifecycle, Loggable}
import gr.grnet.aquarium.{AquariumInternalError, AquariumAwareSkeleton}
import gr.grnet.aquarium.util.LogHelpers.Debug
import gr.grnet.aquarium.util.LogHelpers.DebugSeq
import gr.grnet.aquarium.util.LogHelpers.Warn
import gr.grnet.aquarium.util.date.{MutableDateCalc, TimeHelpers}
import gr.grnet.aquarium.util.{Lifecycle, Loggable}
import gr.grnet.aquarium.{AquariumInternalError, AquariumAwareSkeleton}
- userState: UserStateModel,
+ userAgreementHistoryModel: UserAgreementHistoryModel,
+ userStateMsg: UserStateMsg,
- for( (resourceTypeName, workingResourcesState) ← stateOfResources) {
- userState.msg.getResourceTypesMap.get(resourceTypeName) match {
+ for( (resourceName, workingResourcesState) ← stateOfResources) {
+ resourceMapping.get(resourceName) match {
val stateOfResourceInstance = workingResourcesState.getStateOfResourceInstance.asScala
for((resourceInstanceID, resourceInstanceState) ← stateOfResourceInstance) {
val stateOfResourceInstance = workingResourcesState.getStateOfResourceInstance.asScala
for((resourceInstanceID, resourceInstanceState) ← stateOfResourceInstance) {
- Debug(logger, "Realtime calculation for %s, %s", resourceTypeName, resourceInstanceID)
+ Debug(logger, "Realtime calculation for %s, %s", resourceName, resourceInstanceID)
- userStateBootstrap: UserStateBootstrap,
- defaultResourceTypesMap: Map[String, ResourceType],
+ resourceMapping: JMap[String, ResourceTypeMsg],
setIsFullBillingMonth(true).
setBillingYear(billingMonthInfo.year).
setBillingMonth(billingMonthInfo.month). // FIXME What about the billingMonthDay?
setOriginalID("").
setIsFullBillingMonth(true).
setBillingYear(billingMonthInfo.year).
setBillingMonth(billingMonthInfo.month). // FIXME What about the billingMonthDay?
setOriginalID("").
Debug(logger, "Stored full %s %s", billingMonthInfo.toDebugString, AvroHelpers.jsonStringOfSpecificRecord(monthlyUserState1))
Debug(logger, "Stored full %s %s", billingMonthInfo.toDebugString, AvroHelpers.jsonStringOfSpecificRecord(monthlyUserState1))
- val userID = userStateBootstrap.userID
- val userCreationMillis = userStateBootstrap.userCreationMillis
+ val userID = userAgreementHistoryModel.userID
+ val userCreationMillis = userAgreementHistoryModel.unsafeUserCreationMillis
val userCreationDateCalc = new MutableDateCalc(userCreationMillis)
val billingMonthStartMillis = billingMonthInfo.monthStartMillis
val billingMonthStopMillis = billingMonthInfo.monthStopMillis
val userCreationDateCalc = new MutableDateCalc(userCreationMillis)
val billingMonthStartMillis = billingMonthInfo.monthStartMillis
val billingMonthStopMillis = billingMonthInfo.monthStopMillis
// TODO: The initial user state might have already been created.
// First ask if it exists and compute only if not
// TODO: The initial user state might have already been created.
// First ask if it exists and compute only if not
- val initialUserState0 = MessageFactory.createInitialUserStateMsg(
- userStateBootstrap,
- defaultResourceTypesMap,
+ val initialUserState0 = MessageFactory.newInitialUserStateMsg(
+ userID,
+ CreditsModel.from(0.0),
Debug(logger, "Stored initial state = %s", AvroHelpers.jsonStringOfSpecificRecord(initialUserState1))
Debug(logger, "Stored initial state = %s", AvroHelpers.jsonStringOfSpecificRecord(initialUserState1))
* @param billingMonthInfo
*/
def processResourceEvent(
resourceEvent: ResourceEventMsg,
* @param billingMonthInfo
*/
def processResourceEvent(
resourceEvent: ResourceEventMsg,
- userStateModel: UserStateModel,
+ userAgreementHistoryModel: UserAgreementHistoryModel,
+ userStateMsg: UserStateMsg,
- logger.warn("processResourceEvent:workingUserState=%s".format(userStateModel)) //
- val resourceTypeName = resourceEvent.getResource
- val resourceType = userStateModel.msg.getResourceTypesMap.get(resourceTypeName)
- if(resourceType eq null) {
+ logger.warn("processResourceEvent:workingUserState=%s".format(userStateMsg)) //
+ val resourceName = resourceEvent.getResource
+ val resourceTypeMsg = resourceMapping.get(resourceName)
+ if(resourceTypeMsg eq null) {
- val chargingBehavior = aquarium.chargingBehaviorOf(resourceType)
- val resourcesChargingState = userStateModel.msg.getStateOfResources.get(resourceTypeName) match {
+ val chargingBehavior = aquarium.chargingBehaviorOf(resourceTypeMsg)
+ val resourcesChargingState = userStateMsg.getStateOfResources.get(resourceName) match {
- val newState = new ResourcesChargingStateMsg
- newState.setResource(resourceTypeName)
- newState.setDetails(chargingBehavior.initialChargingDetails)
- newState.setStateOfResourceInstance(new JHashMap())
- userStateModel.msg.getStateOfResources.put(resourceTypeName,newState)
+ val newState = MessageFactory.newResourcesChargingStateMsg(
+ resourceName,
+ chargingBehavior.initialChargingDetails
+ )
+ userStateMsg.getStateOfResources.put(resourceName, newState)
- userStateModel.updateLatestResourceEventOccurredMillis(resourceEvent.getOccurredMillis)
- userStateModel.subtractCredits(creditsToSubtract)
+ MessageHelpers.updateLatestResourceEventOccurredMillis(userStateMsg, resourceEvent.getOccurredMillis)
+ MessageHelpers.subtractCredits(userStateMsg, creditsToSubtract)
true
}
def processResourceEvents(
resourceEvents: Traversable[ResourceEventMsg],
true
}
def processResourceEvents(
resourceEvents: Traversable[ResourceEventMsg],
- userState: UserStateModel,
+ userAgreementHistoryModel: UserAgreementHistoryModel,
+ userStateMsg: UserStateMsg,
*
* @param billingMonthInfo Which month to bill.
* @param billingEndTimeMillis Bill from start of month up to (and including) this time.
*
* @param billingMonthInfo Which month to bill.
* @param billingEndTimeMillis Bill from start of month up to (and including) this time.
billingMonthInfo: BillingMonthInfo,
billingEndTimeMillis: Long,
billingMonthInfo: BillingMonthInfo,
billingEndTimeMillis: Long,
- userStateBootstrap: UserStateBootstrap,
- resourceTypesMap: Map[String, ResourceType],
+ resourceMapping: JMap[String, ResourceTypeMsg],
// In order to replay the full month, we start with the state at the beginning of the month.
val previousBillingMonthInfo = billingMonthInfo.previousMonth
// In order to replay the full month, we start with the state at the beginning of the month.
val previousBillingMonthInfo = billingMonthInfo.previousMonth
// specified in the parameters.
// NOTE: The calculation reason is not the one we get from the previous user state but the one our caller specifies
// specified in the parameters.
// NOTE: The calculation reason is not the one we get from the previous user state but the one our caller specifies
Debug(logger, "previousBillingMonthUserState(%s) = %s",
previousBillingMonthInfo.toShortDebugString,
Debug(logger, "previousBillingMonthUserState(%s) = %s",
previousBillingMonthInfo.toShortDebugString,