In the process, renamed a few Exceptions to AquariumExceptions.
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)
+ }
+ }
+}
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))
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))
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))
}
}
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))
}
}
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))
}
}
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))
}
case Just(folder) ⇒
logger.info("{} = {}", Configurator.Keys.events_store_folder, folder)
- case failed @ Failed(e, m) ⇒
+ case failed @ Failed(e) ⇒
throw e
case _ ⇒
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 _ ⇒
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)
}
}
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.
// 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)
}
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)
}
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(
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))
referenceTimeslot -> fullChargeslots
case NoVal ⇒
null
- case failed @ Failed(e, m) ⇒
- throw new Exception(m, e)
+ case failed @ Failed(e) ⇒
+ failed.throwMe
}
// clog.end()
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
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
}
/** An exception raised when something goes wrong with accounting */
-class AccountingException(msg: String) extends Exception(msg)
+class AccountingException(msg: String) extends AquariumException(msg)
} else {
config.policyStore.storePolicyEntry(newPolicy)
}
- case Failed(e, expl) =>
- throw e
+ case failed @ Failed(e) =>
+ failed.throwMe
}
}
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
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))
}
}
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) ⇒
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))
}
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)
}
}
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 ⇒
case NoVal => false
}
- case failed @ Failed(e, m) ⇒
- logger.error(m, e)
+ case failed @ Failed(e) ⇒
+ logger.error("While LocalFSEventStore.storeUserEvent", e)
false
case _ ⇒
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
/**
*
clog.end()
result
- case failed @ Failed(_, _) ⇒
+ case failed @ Failed(e) ⇒
clog.warn("Failure while quering cache for user state: %s", failed)
clog.end()
failed
clog.end()
result
- case failed @ Failed(_, _) ⇒
+ case failed @ Failed(_) ⇒
clog.warn("Failure while querying for out of sync events: %s", failed)
clog.end()
failed
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")
}
}
}
_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)
}
}
_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));
}
}
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))
}
def error(failed: Failed): Unit = {
- this.error(failed.exception, "%s", failed.explanation)
+ this.error(failed.exception, "")
}
def begin(message: String = ""): Unit = {
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 =>
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.
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])))
}
}
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")