Synthetic resource events and wallet entries
authorChristos KK Loverdos <loverdos@gmail.com>
Tue, 20 Mar 2012 11:30:08 +0000 (13:30 +0200)
committerChristos KK Loverdos <loverdos@gmail.com>
Tue, 20 Mar 2012 13:31:20 +0000 (15:31 +0200)
src/main/scala/gr/grnet/aquarium/logic/events/NewWalletEntry.scala
src/main/scala/gr/grnet/aquarium/logic/events/ResourceEvent.scala
src/main/scala/gr/grnet/aquarium/user/UserStateComputations.scala

index 99b6188..1cce544 100644 (file)
@@ -66,7 +66,8 @@ case class NewWalletEntry(userId: String,
                           billingMonth: Int,
                           resourceEvents: List[ResourceEvent], // current is at the head
                           chargeslots: List[Chargeslot],
-                          resourceDef: DSLResource) {
+                          resourceDef: DSLResource,
+                          isSynthetic: Boolean) {
 
   def currentResourceEvent = resourceEvents.head
   def resource = currentResourceEvent.resource
@@ -74,7 +75,7 @@ case class NewWalletEntry(userId: String,
   def chargslotCount = chargeslots.length
   def isOutOfSync = currentResourceEvent.isOutOfSyncForBillingMonth(yearOfBillingMonth, billingMonth)
 
-  def toDebugString = "%s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)".format(
+  def toDebugString = "%s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)".format(
     gr.grnet.aquarium.util.shortClassNameOf(this),
     userId,
     referenceTimeslot,
@@ -86,7 +87,9 @@ case class NewWalletEntry(userId: String,
     billingMonth,
     resourceEvents,
     chargeslots,
-    resourceDef)
+    resourceDef,
+    if(isSynthetic) "SYNTHETIC" else ""
+  )
 }
 
 object NewWalletEntry {
index cdd0768..1207dab 100644 (file)
@@ -225,6 +225,16 @@ case class ResourceEvent(
       rc.costPolicy
     }
   }
+
+  /**
+   * `Synthetic` means that Aquarium has manufactured this resource event for some purpose. For example, the implicitly
+   * issued resource events at the end a a billing period.
+   *
+   * @return `true` iff this resource event is synthetic.
+   */
+  def isSynthetic = {
+    details contains ResourceEvent.JsonNames.details_aquarium_is_synthetic
+  }
 }
 
 object ResourceEvent {
index b3ad76d..a481a8f 100644 (file)
@@ -326,7 +326,8 @@ class UserStateComputations extends Loggable {
                     else
                       List(currentResourceEvent),
                     fullChargeslots,
-                    dslResource
+                    dslResource,
+                    currentResourceEvent.isSynthetic
                   )
                   clog.debug("New %s", newWalletEntry)
 
@@ -456,6 +457,7 @@ class UserStateComputations extends Loggable {
 
     val newWalletEntries = scala.collection.mutable.ListBuffer[NewWalletEntry]()
 
+    clog.debug("Process all occurred events")
     _workingUserState = processResourceEvents(
       allResourceEventsForMonth,
       _workingUserState,
@@ -482,6 +484,18 @@ class UserStateComputations extends Loggable {
       }
     }
 
+    clog.debug("Process implicitly issued events")
+    _workingUserState = processResourceEvents(
+      allEndEventsBuffer.toList,
+      _workingUserState,
+      userStateWorker,
+      policyStore,
+      calculationReason,
+      billingMonthInfo,
+      newWalletEntries,
+      clogJ
+    )
+
     val lastUpdateTime = TimeHelpers.nowMillis
 
     _workingUserState = _workingUserState.copy(