Fix API breakage from previous upgrade
authorChristos KK Loverdos <loverdos@gmail.com>
Wed, 4 Apr 2012 15:52:52 +0000 (18:52 +0300)
committerChristos KK Loverdos <loverdos@gmail.com>
Wed, 4 Apr 2012 15:52:52 +0000 (18:52 +0300)
In the process, renamed a few Exceptions to AquariumExceptions.

17 files changed:
src/main/scala/gr/grnet/aquarium/AquariumException.scala
src/main/scala/gr/grnet/aquarium/Configurator.scala
src/main/scala/gr/grnet/aquarium/Main.scala
src/main/scala/gr/grnet/aquarium/ResourceLocator.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/Accounting.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/Policy.scala
src/main/scala/gr/grnet/aquarium/logic/accounting/dsl/DSLCostPolicy.scala
src/main/scala/gr/grnet/aquarium/logic/events/UserEvent.scala
src/main/scala/gr/grnet/aquarium/processor/actor/ReflectiveAquariumActor.scala
src/main/scala/gr/grnet/aquarium/processor/actor/ResourceEventProcessorService.scala
src/main/scala/gr/grnet/aquarium/processor/actor/UserEventProcessorService.scala
src/main/scala/gr/grnet/aquarium/user/UserStateComputations.scala
src/main/scala/gr/grnet/aquarium/user/actor/UserActor.scala
src/main/scala/gr/grnet/aquarium/util/ContextualLogger.scala
src/main/scala/gr/grnet/aquarium/util/LogUtils.scala
src/main/scala/gr/grnet/aquarium/util/xstream/XStreamHelpers.scala
src/test/scala/gr/grnet/aquarium/util/TestMethods.scala

index fe0b8d5..d9a9bf7 100644 (file)
@@ -48,3 +48,15 @@ class AquariumException(cause: Throwable, message: String) extends Exception(mes
   def this(message: String)  = this(null, message)
   def this(message: String, cause: Throwable) = this(cause, message)
 }
+
+object AquariumException {
+  def rethrow(e: Exception): Nothing = {
+    e match {
+      case ae: AquariumException ⇒
+        throw ae
+
+      case _ ⇒
+        throw new AquariumException(e)
+    }
+  }
+}
index 8419912..a7a0e82 100644 (file)
@@ -63,7 +63,7 @@ class Configurator(val props: Props) extends Loggable {
           Maybe(configurable configure props) match {
             case Just(_) ⇒
               instance
-            case Failed(e, _) ⇒
+            case Failed(e) ⇒
               throw new AquariumException("Could not configure instance of %s".format(className), e)
             case NoVal ⇒
               throw new AquariumException("Could not configure instance of %s".format(className))
@@ -71,7 +71,7 @@ class Configurator(val props: Props) extends Loggable {
         case _ ⇒
           instance
       }
-      case Failed(e, _) ⇒
+      case Failed(e) ⇒
         throw new AquariumException("Could not instantiate %s".format(className), e)
       case NoVal ⇒
         throw new AquariumException("Could not instantiate %s".format(className))
@@ -316,8 +316,8 @@ object Configurator {
         masterConfResource
       case NoVal ⇒
         throw new AquariumException("Could not find master configuration file: %s".format(MasterConfName))
-      case Failed(e, m) ⇒
-        throw new AquariumException(m, e)
+      case Failed(e) ⇒
+        throw new AquariumException(e, "Could not find master configuration file: %s".format(MasterConfName))
     }
   }
 
@@ -328,8 +328,8 @@ object Configurator {
         props
       case NoVal ⇒
         throw new AquariumException("Could not load master configuration file: %s".format(MasterConfName))
-      case Failed(e, m) ⇒
-        throw new AquariumException(m, e)
+      case Failed(e) ⇒
+        throw new AquariumException(e, "Could not load master configuration file: %s".format(MasterConfName))
     }
   }
 
@@ -339,8 +339,8 @@ object Configurator {
         masterConf
       case NoVal ⇒
         throw new AquariumException("Could not initialize master configuration file: %s".format(MasterConfName))
-      case Failed(e, m) ⇒
-        throw new AquariumException(m, e)
+      case Failed(e) ⇒
+        throw new AquariumException(e, "Could not initialize master configuration file: %s".format(MasterConfName))
     }
   }
 
index f2bb2ad..5122a90 100644 (file)
@@ -75,11 +75,11 @@ object Main extends LazyLoggable {
           context.reset()
           joran.doConfigure(ResourceLocator.LOGBACK_XML_FILE)
           logger.info("Logging subsystem configured from {}", ResourceLocator.LOGBACK_XML_FILE)
-        } map { x ⇒
-          StatusPrinter.printInCaseOfErrorsOrWarnings(context)
-          x
+        } forJust {
+          case _ ⇒
+            StatusPrinter.printInCaseOfErrorsOrWarnings(context)
         } forFailed {
-          case failed @ Failed(e, m) ⇒
+          case failed @ Failed(e) ⇒
             StatusPrinter.print(context)
             throw new AquariumException(e, "Could not configure logging from %s".format(ResourceLocator.LOGBACK_XML_FILE))
         }
@@ -107,7 +107,7 @@ object Main extends LazyLoggable {
       case Just(folder) ⇒
         logger.info("{} = {}", Configurator.Keys.events_store_folder, folder)
 
-      case failed @ Failed(e, m) ⇒
+      case failed @ Failed(e) ⇒
         throw e
 
       case _ ⇒
index 41d6d04..cd86050 100644 (file)
@@ -69,7 +69,7 @@ object ResourceLocator {
       case Just(home) ⇒
         val file = new File(home)
         if(!file.isDirectory) {
-          throw new Exception("%s (%s) is not a folder".format(AQUARIUM_HOME.name, home))
+          throw new AquariumException("%s (%s) is not a folder".format(AQUARIUM_HOME.name, home))
         }
         file.getCanonicalFile()
       case _ ⇒
@@ -126,8 +126,8 @@ object ResourceLocator {
         new CompositeStreamResourceContext(Just(BasicResourceContext), new FileStreamResourceContext(value))
       case NoVal ⇒
         BasicResourceContext
-      case Failed(e, m) ⇒
-        throw new AquariumException(m , e)
+      case Failed(e) ⇒
+        throw new AquariumException(e)
     }
   }
 
index 41863bd..aeb9a43 100644 (file)
@@ -45,6 +45,7 @@ import com.ckkloverdos.maybe.{NoVal, Maybe, Failed, Just}
 import gr.grnet.aquarium.util.date.MutableDateCalc
 import gr.grnet.aquarium.util.{ContextualLogger, CryptoUtils, Loggable}
 import gr.grnet.aquarium.store.PolicyStore
+import gr.grnet.aquarium.AquariumException
 
 /**
  * A timeslot together with the algorithm and unit price that apply for this particular timeslot.
@@ -292,13 +293,13 @@ trait Accounting extends DSLUtils with Loggable {
 
           // We do not have a previous event
           case NoVal ⇒
-            throw new Exception(
+            throw new AquariumException(
               "Unable to charge. No previous event given for %s".
                 format(currentResourceEvent.toDebugString()))
 
           // We could not obtain a previous event
-          case failed @ Failed(e, m) ⇒
-            throw new Exception(
+          case failed @ Failed(e) ⇒
+            throw new AquariumException(
               "Unable to charge. Could not obtain previous event for %s".
                 format(currentResourceEvent.toDebugString()), e)
         }
@@ -322,9 +323,9 @@ trait Accounting extends DSLUtils with Loggable {
           case Just(relevantPolicy) ⇒
             Map(referenceTimeslot -> relevantPolicy)
           case NoVal ⇒
-            throw new Exception("No relevant policy found for %s".format(referenceTimeslot))
-          case failed @ Failed(e, _) ⇒
-            throw new Exception("No relevant policy found for %s".format(referenceTimeslot), e)
+            throw new AquariumException("No relevant policy found for %s".format(referenceTimeslot))
+          case failed @ Failed(e) ⇒
+            throw new AquariumException("No relevant policy found for %s".format(referenceTimeslot), e)
 
         }
 
@@ -345,10 +346,10 @@ trait Accounting extends DSLUtils with Loggable {
           val execAlgorithmM = algorithmCompiler.compile(algorithmDefinition)
           execAlgorithmM match {
             case NoVal ⇒
-              throw new Exception("Could not compile algorithm %s".format(algorithmDefinition))
+              throw new AquariumException("Could not compile algorithm %s".format(algorithmDefinition))
 
-            case failed @ Failed(e, m) ⇒
-              throw new Exception(m, e)
+            case failed @ Failed(e) ⇒
+              failed.throwMe
 
             case Just(execAlgorithm) ⇒
               val valueMap = costPolicy.makeValueMap(
@@ -369,12 +370,12 @@ trait Accounting extends DSLUtils with Loggable {
 
               creditsM match {
                 case NoVal ⇒
-                  throw new Exception(
+                  throw new AquariumException(
                     "Could not compute credits for resource %s during %s".
                       format(dslResource.name, Timeslot(new Date(startMillis), new Date(stopMillis))))
 
-                case failed @ Failed(e, m) ⇒
-                  throw new Exception(m, e)
+                case failed @ Failed(e) ⇒
+                  failed.throwMe
 
                 case Just(credits) ⇒
                   chargeslot.copy(computedCredits = Some(credits))
@@ -388,8 +389,8 @@ trait Accounting extends DSLUtils with Loggable {
         referenceTimeslot -> fullChargeslots
       case NoVal ⇒
         null
-      case failed @ Failed(e, m) ⇒
-        throw new Exception(m, e)
+      case failed @ Failed(e) ⇒
+        failed.throwMe
     }
 
 //    clog.end()
@@ -463,7 +464,7 @@ trait Accounting extends DSLUtils with Loggable {
           Some(x)
         ) match {
           case Just(x) => x
-          case Failed(f, e) => return Failed(f,e)
+          case Failed(f) => return Failed(f)
           case NoVal => List()
         }
         entries
@@ -523,7 +524,7 @@ trait Accounting extends DSLUtils with Loggable {
 
     val creditCalculationValueM = dslResource.costPolicy.getValueForCreditCalculation(Just(previousAmount), event.value)
     val amount = creditCalculationValueM match {
-      case failed @ Failed(_, _) ⇒
+      case failed @ Failed(_) ⇒
         return failed
       case Just(amount) ⇒
         amount
@@ -755,4 +756,4 @@ case class ChargeChunk(value: Double, algorithm: String,
 }
 
 /** An exception raised when something goes wrong with accounting */
-class AccountingException(msg: String) extends Exception(msg)
+class AccountingException(msg: String) extends AquariumException(msg)
index 2870f83..11ee01a 100644 (file)
@@ -206,8 +206,8 @@ object Policy extends DSL with Loggable {
           } else {
             config.policyStore.storePolicyEntry(newPolicy)
           }
-        case Failed(e, expl) =>
-          throw e
+        case failed @ Failed(e) =>
+          failed.throwMe
       }
     }
 
index 073f4e5..f180109 100644 (file)
@@ -37,6 +37,7 @@ package gr.grnet.aquarium.logic.accounting.dsl
 
 import com.ckkloverdos.maybe.{NoVal, Failed, Just, Maybe}
 import gr.grnet.aquarium.logic.events.ResourceEvent
+import gr.grnet.aquarium.AquariumException
 
 /**
  * A cost policy indicates how charging for a resource will be done
@@ -356,9 +357,9 @@ case object OnOffCostPolicy
       case Just(oldAmount) ⇒
         Maybe(getValueForCreditCalculation(oldAmount, newEventValue))
       case NoVal ⇒
-        Failed(new Exception("NoVal for oldValue instead of Just"))
-      case Failed(e, m) ⇒
-        Failed(new Exception("Failed for oldValue instead of Just", e), m)
+        Failed(new AquariumException("NoVal for oldValue instead of Just"))
+      case Failed(e) ⇒
+        Failed(new AquariumException("Failed for oldValue instead of Just", e))
     }
   }
 
@@ -367,7 +368,7 @@ case object OnOffCostPolicy
     import OnOffCostPolicyValues.{ON, OFF}
 
     def exception(rs: OnOffPolicyResourceState) =
-      new Exception("Resource state transition error (%s -> %s)".format(rs, rs))
+      new AquariumException("Resource state transition error (%s -> %s)".format(rs, rs))
 
     (oldAmount, newEventValue) match {
       case (ON, ON) ⇒
index 74a45bf..cd6da08 100644 (file)
@@ -89,7 +89,7 @@ case class  UserEvent(
           logger.warn("Inexistent user to modify. IMEvent:".format(this.toJson))
           return false
         }
-      case Failed(x,y) =>
+      case Failed(x) =>
         logger.warn("Error retrieving user state: %s".format(x))
     }
 
index 28f79e7..99b70c8 100644 (file)
@@ -59,9 +59,9 @@ trait ReflectiveAquariumActor extends Actor with Loggable {
           method.setAccessible(true)
           (knownMessageType, method)
         case NoVal =>
-          throw new Exception("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType))
-        case Failed(e, m) =>
-          throw new Exception("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType), e)
+          throw new AquariumException("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType))
+        case Failed(e) =>
+          throw new AquariumException("Reflective actor %s does not know how to process message %s".format(this.getClass, knownMessageType), e)
       }
     }
 
index 7ba8f57..79941a4 100644 (file)
@@ -76,8 +76,8 @@ final class ResourceEventProcessorService extends EventProcessorService[Resource
           case NoVal => false
         }
 
-      case failed @ Failed(e, m) ⇒
-        logger.error(m, e)
+      case failed @ Failed(e) ⇒
+        logger.error("While LocalFSEventStore.storeResourceEvent", e)
         false
 
       case NoVal ⇒
index 012f4a1..7d875d3 100644 (file)
@@ -75,8 +75,8 @@ class UserEventProcessorService extends EventProcessorService[UserEvent] {
           case NoVal => false
         }
 
-      case failed @ Failed(e, m) ⇒
-        logger.error(m, e)
+      case failed @ Failed(e) ⇒
+        logger.error("While LocalFSEventStore.storeUserEvent", e)
         false
 
       case _ ⇒
index 6b027c4..1587c03 100644 (file)
@@ -45,6 +45,7 @@ import gr.grnet.aquarium.logic.accounting.dsl.{DSLAgreement, DSLResourcesMap}
 import gr.grnet.aquarium.store.{StoreProvider, PolicyStore}
 import gr.grnet.aquarium.logic.accounting.Accounting
 import gr.grnet.aquarium.logic.accounting.algorithm.CostPolicyAlgorithmCompiler
+import gr.grnet.aquarium.AquariumException
 
 /**
  *
@@ -157,7 +158,7 @@ class UserStateComputations extends Loggable {
           clog.end()
           result
 
-        case failed @ Failed(_, _) ⇒
+        case failed @ Failed(e) ⇒
           clog.warn("Failure while quering cache for user state: %s", failed)
           clog.end()
           failed
@@ -179,7 +180,7 @@ class UserStateComputations extends Loggable {
              clog.end()
              result
 
-           case failed @ Failed(_, _) ⇒
+           case failed @ Failed(_) ⇒
              clog.warn("Failure while querying for out of sync events: %s", failed)
              clog.end()
              failed
@@ -346,10 +347,10 @@ class UserStateComputations extends Loggable {
 
               case NoVal ⇒
                 // At least one chargeslot is required.
-                throw new Exception("No chargeslots computed")
+                throw new AquariumException("No chargeslots computed")
 
-              case failed@Failed(e, m) ⇒
-                throw new Exception(m, e)
+              case failed@Failed(e) ⇒
+                throw new AquariumException(e, "Error computing chargeslots")
             }
           }
         }
@@ -533,7 +534,7 @@ class UserStateComputations extends Loggable {
           _workingUserState = storedUserState
         case NoVal ⇒
           clog.warn("Could not store %s", _workingUserState)
-        case failed @ Failed(e, m) ⇒
+        case failed @ Failed(e) ⇒
           clog.error(e, "Could not store %s", _workingUserState)
       }
     }
index 17d3fb5..6732e8e 100644 (file)
@@ -134,8 +134,8 @@ class UserActor extends AquariumActor
     _configurator.storeProvider.userStateStore.storeUserState(this._userState) match {
       case Just(record) => record
       case NoVal => ERROR("Unknown error saving state")
-      case Failed(e, a) =>
-        ERROR("Saving state failed: %s error was: %s".format(a,e));
+      case Failed(e) =>
+        ERROR("Saving state failed: %s".format(e));
     }
   }
 
@@ -167,8 +167,8 @@ class UserActor extends AquariumActor
     usersDB.findUserStateByUserId(userId) match {
       case Just(userState) ⇒
         WARN("User already created, state = %s".format(userState))
-      case failed @ Failed(e, m) ⇒
-        ERROR("[%s][%s] %s", e.getClass.getName, e.getMessage, m)
+      case failed @ Failed(e) ⇒
+        ERROR("[%s] %s", e.getClass.getName, e.getMessage)
       case NoVal ⇒
         val agreement = RoleAgreements.agreementForRole(event.role)
         DEBUG("User %s assigned agreement %s".format(userId, agreement.name))
index 0b4c5b1..6d3e321 100644 (file)
@@ -185,7 +185,7 @@ final class ContextualLogger(val logger: Logger, fmt: String, args: Any*) {
   }
   
   def error(failed: Failed): Unit = {
-    this.error(failed.exception, "%s", failed.explanation)
+    this.error(failed.exception, "")
   }
 
   def begin(message: String = ""): Unit = {
index d87ed94..21b7b20 100644 (file)
@@ -48,8 +48,8 @@ object LogUtils {
       case Just(value) =>
         logger.debug("[%s] Found value '%s' for system property '%s'".format(msg, value, name))
         value
-      case Failed(e, m) =>
-        logger.error("[%s][%s]: %s".format(m, e.getClass.getName, e.getMessage))
+      case Failed(e) =>
+        logger.error("[%s]: %s".format(e.getClass.getName, e.getMessage))
         logger.error("[%s] Error loading system property '%s'. Using default value '%s'".format(msg, name, default))
         default
       case NoVal =>
index b4a3c78..32a06ba 100644 (file)
@@ -39,6 +39,7 @@ package xstream
 import com.thoughtworks.xstream.XStream
 import com.ckkloverdos.maybe.{Failed, Just, Maybe}
 import com.ckkloverdos.resource.StreamResource
+import gr.grnet.aquarium.AquariumException
 
 /**
  * Utilities for making our life easier with the XStream library.
@@ -75,9 +76,9 @@ object XStreamHelpers {
   def newXStream: XStream = prepareXStream(new XStream)
   
   def parseType[T: Manifest](xml: String, xs: XStream = DefaultXStream): Maybe[T] = {
-    try Just(xs.fromXML(xml).asInstanceOf[T])
-    catch {
-      case e: Exception => Failed(e, "XStream could not parse XML to value of type %s".format(manifest[T]))
+    Maybe(xs.fromXML(xml)).castTo[T] mapFailed {
+      case failed @ Failed(e) ⇒
+        Failed(new AquariumException(e, "XStream could not parse XML to value of type %s".format(manifest[T])))
     }
   }
   
index ccf7975..22f5aed 100644 (file)
@@ -109,8 +109,8 @@ trait TestMethods {
   def assertFailed[A <: Throwable, B <: Any](f: => Maybe[B])
                                   (implicit m: ClassManifest[A]): Unit = {
     f match {
-      case Failed(e,r) if (m.erasure.isAssignableFrom(e.getClass)) => return
-      case Failed(e,r) => fail("Expected exception of type " + m.erasure.getName +
+      case Failed(e) if (m.erasure.isAssignableFrom(e.getClass)) => return
+      case Failed(e) => fail("Expected exception of type " + m.erasure.getName +
         " not thrown. Instead, " + e.getClass.getName + " was thrown")
       case NoVal => fail("Operation not failed")
       case Just(x) => fail("Operation not failed")