Change API for contextual logger usage
authorChristos KK Loverdos <loverdos@gmail.com>
Mon, 7 May 2012 11:37:16 +0000 (14:37 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Mon, 7 May 2012 11:37:16 +0000 (14:37 +0300)
src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala
src/main/scala/gr/grnet/aquarium/user/UserStateComputations.scala
src/main/scala/gr/grnet/aquarium/util/ContextualLogger.scala
src/test/scala/gr/grnet/aquarium/user/UserStateComputationsTest.scala

index f715200..6a10e71 100644 (file)
@@ -119,9 +119,10 @@ trait Accounting extends DSLUtils with Loggable {
   protected
   def resolveEffectiveAlgorithmsAndPriceLists(alignedTimeslot: Timeslot,
                                               agreement: DSLAgreement,
-                                              clogM: Maybe[ContextualLogger] = NoVal): (Map[Timeslot, DSLAlgorithm], Map[Timeslot, DSLPriceList]) = {
+                                              clogOpt: Option[ContextualLogger] = None):
+          (Map[Timeslot, DSLAlgorithm], Map[Timeslot, DSLPriceList]) = {
 
-    val clog = ContextualLogger.fromOther(clogM, logger, "resolveEffectiveAlgorithmsAndPriceLists()")
+    val clog = ContextualLogger.fromOther(clogOpt, logger, "resolveEffectiveAlgorithmsAndPriceLists()")
 
     // Note that most of the code is taken from calcChangeChunks()
     val alg = resolveEffectiveAlgorithmsForTimeslot(alignedTimeslot, agreement)
@@ -140,9 +141,9 @@ trait Accounting extends DSLUtils with Loggable {
                                 dslResource: DSLResource,
                                 policiesByTimeslot: Map[Timeslot, DSLPolicy],
                                 agreementNamesByTimeslot: Map[Timeslot, String],
-                                contextualLogger: Maybe[ContextualLogger] = NoVal): Maybe[List[Chargeslot]] = Maybe {
+                                clogOpt: Option[ContextualLogger] = None): Maybe[List[Chargeslot]] = Maybe {
 
-    val clog = ContextualLogger.fromOther(contextualLogger, logger, "computeInitialChargeslots()")
+    val clog = ContextualLogger.fromOther(clogOpt, logger, "computeInitialChargeslots()")
 //    clog.begin()
 
     val policyTimeslots = policiesByTimeslot.keySet
@@ -191,7 +192,7 @@ trait Accounting extends DSLUtils with Loggable {
           // TODO: Factor this out, just like we did with:
           // TODO:  val alignedTimeslots = splitTimeslotByPoliciesAndAgreements
           // Note that most of the code is already taken from calcChangeChunks()
-          val r = resolveEffectiveAlgorithmsAndPriceLists(alignedTimeslot, agreement, Just(clog))
+          val r = resolveEffectiveAlgorithmsAndPriceLists(alignedTimeslot, agreement, Some(clog))
           val algorithmByTimeslot: Map[Timeslot, DSLAlgorithm] = r._1
           val pricelistByTimeslot: Map[Timeslot, DSLPriceList] = r._2
 
@@ -263,9 +264,9 @@ trait Accounting extends DSLUtils with Loggable {
                              agreementNamesByTimeslot: Map[Timeslot, String],
                              algorithmCompiler: CostPolicyAlgorithmCompiler,
                              policyStore: PolicyStore,
-                             contextualLogger: Maybe[ContextualLogger] = NoVal): Maybe[(Timeslot, List[Chargeslot])] = Maybe {
+                             clogOpt: Option[ContextualLogger] = None): Maybe[(Timeslot, List[Chargeslot])] = Maybe {
 
-    val clog = ContextualLogger.fromOther(contextualLogger, logger, "computeFullChargeslots()")
+    val clog = ContextualLogger.fromOther(clogOpt, logger, "computeFullChargeslots()")
 //    clog.begin()
 
     val occurredDate = currentResourceEvent.occurredDate
@@ -338,7 +339,7 @@ trait Accounting extends DSLUtils with Loggable {
       dslResource,
       relevantPolicies,
       agreementNamesByTimeslot,
-      Just(clog)
+      Some(clog)
     )
 
     val fullChargeslotsM = initialChargeslotsM.map { chargeslots ⇒
index 24fa20b..ec34ac6 100644 (file)
@@ -141,10 +141,10 @@ class UserStateComputations extends Loggable {
                                        accounting: Accounting,
                                        algorithmCompiler: CostPolicyAlgorithmCompiler,
                                        calculationReason: UserStateChangeReason,
-                                       contextualLogger: Maybe[ContextualLogger] = NoVal): Maybe[UserState] = {
+                                       clogOpt: Option[ContextualLogger] = None): Maybe[UserState] = {
 
     val clog = ContextualLogger.fromOther(
-      contextualLogger,
+      clogOpt,
       logger,
       "findUserStateAtEndOfBillingMonth(%s)", billingMonthInfo)
     clog.begin()
@@ -159,7 +159,7 @@ class UserStateComputations extends Loggable {
         accounting,
         algorithmCompiler,
         calculationReason,
-        Just(clog))
+        Some(clog))
     }
 
     val userStateStore = storeProvider.userStateStore
@@ -273,9 +273,9 @@ class UserStateComputations extends Loggable {
                            billingMonthInfo: BillingMonthInfo,
                            walletEntriesBuffer: mutable.Buffer[NewWalletEntry],
                            algorithmCompiler: CostPolicyAlgorithmCompiler,
-                           clogM: Maybe[ContextualLogger] = NoVal): UserState = {
+                           clogOpt: Option[ContextualLogger] = None): UserState = {
 
-    val clog = ContextualLogger.fromOther(clogM, logger, "walletEntriesForResourceEvent(%s)", currentResourceEvent.id)
+    val clog = ContextualLogger.fromOther(clogOpt, logger, "walletEntriesForResourceEvent(%s)", currentResourceEvent.id)
 
     var _workingUserState = startingUserState
 
@@ -343,7 +343,7 @@ class UserStateComputations extends Loggable {
               alltimeAgreements,
               algorithmCompiler,
               policyStore,
-              Just(clog)
+              Some(clog)
             )
 
             // We have the chargeslots, let's associate them with the current event
@@ -426,7 +426,7 @@ class UserStateComputations extends Loggable {
                             billingMonthInfo: BillingMonthInfo,
                             walletEntriesBuffer: mutable.Buffer[NewWalletEntry],
                             algorithmCompiler: CostPolicyAlgorithmCompiler,
-                            clogM: Maybe[ContextualLogger] = NoVal): UserState = {
+                            clogOpt: Option[ContextualLogger] = None): UserState = {
 
     var _workingUserState = startingUserState
 
@@ -441,7 +441,7 @@ class UserStateComputations extends Loggable {
         billingMonthInfo,
         walletEntriesBuffer,
         algorithmCompiler,
-        clogM
+        clogOpt
       )
     }
 
@@ -457,16 +457,16 @@ class UserStateComputations extends Loggable {
                            accounting: Accounting,
                            algorithmCompiler: CostPolicyAlgorithmCompiler,
                            calculationReason: UserStateChangeReason = NoSpecificChangeReason,
-                           contextualLogger: Maybe[ContextualLogger] = NoVal): Maybe[UserState] = Maybe {
+                           clogOpt: Option[ContextualLogger] = None): Maybe[UserState] = Maybe {
 
 
     val clog = ContextualLogger.fromOther(
-      contextualLogger,
+      clogOpt,
       logger,
       "doFullMonthlyBilling(%s)", billingMonthInfo)
     clog.begin()
 
-    val clogJ = Just(clog)
+    val clogSome = Some(clog)
 
     val previousBillingMonthUserStateM = findUserStateAtEndOfBillingMonth(
       userId,
@@ -477,7 +477,7 @@ class UserStateComputations extends Loggable {
       accounting,
       algorithmCompiler,
       calculationReason.forPreviousBillingMonth,
-      clogJ
+      clogSome
     )
 
     if(previousBillingMonthUserStateM.isNoVal) {
@@ -522,7 +522,7 @@ class UserStateComputations extends Loggable {
       billingMonthInfo,
       newWalletEntries,
       algorithmCompiler,
-      clogJ
+      clogSome
     )
 
     // Second, for the remaining events which must contribute an implicit OFF, we collect those OFFs
@@ -556,7 +556,7 @@ class UserStateComputations extends Loggable {
       billingMonthInfo,
       newWalletEntries,
       algorithmCompiler,
-      clogJ
+      clogSome
     )
 
     val lastUpdateTime = TimeHelpers.nowMillis()
index 0d1da6b..47b2971 100644 (file)
@@ -268,11 +268,12 @@ object ContextualLogger {
     }
   }
   
-  def fromOther(clogM: Maybe[ContextualLogger], logger: Logger,  fmt: String, args: Any*): ContextualLogger = {
-    clogM match {
-      case Just(clog) ⇒
+  def fromOther(clogOpt: Option[ContextualLogger], logger: Logger,  fmt: String, args: Any*): ContextualLogger = {
+    clogOpt match {
+      case Some(clog) ⇒
         new ContextualLogger(clog.logger, fmt, args:_*).indentAs(clog)
-      case _ ⇒
+
+      case None ⇒
         new ContextualLogger(logger, fmt, args:_*)
     }
   }
index 2edbf14..7335f2f 100644 (file)
@@ -299,7 +299,7 @@ aquariumpolicy:
       DefaultAccounting,
       DefaultCompiler,
       MonthlyBillingCalculation(billingMonthInfo),
-      Just(clog)
+      Some(clog)
     )
   }
   
@@ -333,7 +333,7 @@ aquariumpolicy:
   @Ignore
   @Test
   def testFullOnOff: Unit = {
-    val clog = ContextualLogger.fromOther(NoVal, logger, "testFullOnOff()")
+    val clog = ContextualLogger.fromOther(None, logger, "testFullOnOff()")
     clog.begin()
 
     ResourceEventStore.clearResourceEvents()
@@ -362,7 +362,7 @@ aquariumpolicy:
   @Ignore
   @Test
   def testLonelyON: Unit = {
-    val clog = ContextualLogger.fromOther(NoVal, logger, "testLonelyON()")
+    val clog = ContextualLogger.fromOther(None, logger, "testLonelyON()")
     clog.begin()
 
     ResourceEventStore.clearResourceEvents()
@@ -392,7 +392,7 @@ aquariumpolicy:
 //  @Ignore
   @Test
   def testOrphanOFF: Unit = {
-    val clog = ContextualLogger.fromOther(NoVal, logger, "testOrphanOFF()")
+    val clog = ContextualLogger.fromOther(None, logger, "testOrphanOFF()")
     clog.begin()
 
     ResourceEventStore.clearResourceEvents()
@@ -423,7 +423,7 @@ aquariumpolicy:
   @Ignore
   @Test
   def testOne: Unit = {
-    val clog = ContextualLogger.fromOther(NoVal, logger, "testOne()")
+    val clog = ContextualLogger.fromOther(None, logger, "testOne()")
     clog.begin()
 
     // Let's create our dates of interest