--- /dev/null
+package gr.grnet.aquarium.logic.accounting
+
+import java.util.Date
+
+/**The result of processing an accounting event*/
+class AccountingEntry(sourceEvents: List[Long], when: Date,
+ amount: Float, entryType: AccountingEntryType.Value) {
+
+}
+
--- /dev/null
+package gr.grnet.aquarium.logic.accounting
+
+object AccountingEntryType extends Enumeration {
+ type InputEvent = Value
+ val STORAGE_CHARGE, NET_CHARGE, DEBIT = Value
+}
package gr.grnet.aquarium.logic.accounting
import java.util.Date
+import gr.grnet.aquarium.model.{Entity, DB}
-/**The result of processing an input event*/
-class AccountingEvent(e: InputEvent, when: Date, amount: Float) {
+class AccountingEvent(et: AccountingEventType.Value, when: Date,
+ who: Long, amount: Double, rel: List[Long]) {
-}
\ No newline at end of file
+ def process() = {}
+ def policy() : Policy = {null}
+
+ def getRate() : Float = {
+ val ent = DB.find(classOf[Entity], who).get
+
+ 0F
+ }
+
+
+}
package gr.grnet.aquarium.logic.accounting
-object InputEventType extends Enumeration {
+object AccountingEventType extends Enumeration {
type InputEvent = Value
val NetDataUp, NetDataDown, DiskSpace, VMTime = Value
}
\ No newline at end of file
package gr.grnet.aquarium.logic.accounting
import java.util.Date
+import collection.mutable.{HashMap, Map}
abstract class Agreement {
- def policy(et: InputEventType.Value, d: Date) : Policy
+
+ var policies = new HashMap[AccountingEventType.Value, HashMap[Date,Policy]]
+
+ def addPolicy(et: AccountingEventType.Value, p: Policy, d: Date) = {
+ policies + Map(et -> Map(d -> p))
+ }
+
+ def policy(et: AccountingEventType.Value, d: Date) : Option[Policy] = {
+ val ruleset = policies.getOrElse(et, new HashMap[Date, Policy])
+ val key = ruleset.keys.toList.sorted.find(k => k.compareTo(d) >= 0).orElse(new Date())
+ ruleset.get(key)
+ }
}
\ No newline at end of file
+++ /dev/null
-package gr.grnet.aquarium.logic.accounting
-
-import java.util.Date
-import gr.grnet.aquarium.model.{Entity, DB}
-
-class InputEvent(et: InputEventType.Value, when: Date,
- who: Long, amount: Double, rel: List[Long]) {
-
- def process() = {}
-
- def findRule(): Policy = {
- val e = DB.find[Entity](classOf[Entity], who)
- null
- //who.agreement.policy(et, when)
- }
-}
-
package gr.grnet.aquarium.logic.accounting
-abstract class Policy {
+abstract class Policy(et: AccountingEntryType.Value) {
+
+ private def makeEntry(event: AccountingEvent, amount: Float) = {
+ //val entry = new AccountingEntry(event.rel(), event.when, )
+ }
+
+ def process(evt: AccountingEvent) = {
+ makeEntry(evt, calculateAmount(evt))
+ }
def calculateAmount(evt: AccountingEvent) : Float
}
\ No newline at end of file
package gr.grnet.aquarium.logic.accounting.agreements
-import java.util.Date
-import gr.grnet.aquarium.logic.accounting.{InputEventType, Policy, Agreement}
+import gr.grnet.aquarium.logic.accounting.{Agreement}
class DefaultAgreement extends Agreement {
- def policy(et: InputEventType.Value, d: Date) : Policy = {
- null
- }
+
}
\ No newline at end of file
package gr.grnet.aquarium.logic.accounting.policies
-import gr.grnet.aquarium.logic.accounting.{InputEventType, AccountingEvent, Policy}
+import gr.grnet.aquarium.logic.accounting.{AccountingEventType, AccountingEntry, Policy}
import collection.immutable.HashMap
object DefaultRatePolicy extends Policy {
- val rates = new HashMap[InputEventType.Value, Float]
+ val rates = new HashMap[AccountingEventType.Value, Float]
private def init() = {
}
- def calculateAmount(evt: AccountingEvent) : Float = {
+ def calculateAmount(evt: AccountingEntry) : Float = {
if (rates.isEmpty) init()
0F
package gr.grnet.aquarium.logic.events
-import gr.grnet.aquarium.logic.accounting.{InputEventType, InputEvent}
+import gr.grnet.aquarium.logic.accounting.{AccountingEventType, AccountingEvent}
import java.util.Date
object EventProcessor {
def process(from: Option[Date], to: Option[Date],
- events: (Option[Date], Option[Date]) => List[Event]): List[InputEvent] = {
+ events: (Option[Date], Option[Date]) => List[Event]): List[AccountingEvent] = {
val evts = events(from, to)
- val dummy = new InputEvent(InputEventType.VMTime, new Date() , 0, 0, List())
+ val dummy = new AccountingEvent(AccountingEventType.VMTime, new Date() , 0, 0, List())
evts.map {f => f.who}.distinct.map {
//Events are calculated per user
case Some(x) => x.id
case None => -1 //Now
}
- new InputEvent(InputEventType.VMTime, e.when(),
+ new AccountingEvent(AccountingEventType.VMTime, e.when(),
u, time.getTime - v.w.getTime,
List(v.id, stopid))
// case v : VMStarted =>None
// case v : VMStopped =>None
case v: DiskSpaceChanged =>
- new InputEvent(InputEventType.DiskSpace,
+ new AccountingEvent(AccountingEventType.DiskSpace,
e.when(), u, v.bytes, List(v.id()))
case v: DataUploaded =>
- new InputEvent(InputEventType.NetDataUp, e.when, u,
+ new AccountingEvent(AccountingEventType.NetDataUp, e.when, u,
v.bytes, List(v.id()))
case v: DataDownloaded =>
- new InputEvent(InputEventType.NetDataDown, e.when, u,
+ new AccountingEvent(AccountingEventType.NetDataDown, e.when, u,
v.bytes, List(v.id()))
// case v : SSaasVMCreated => None
// case v : SSaasVMStarted =>None
}
@Test
- def testCalcBill = {
-
- }
-
- @Test
def testAccountingRules() = {
-
+
}
@After
@Column(name = "CREDITS", nullable = true)
var credits: Float = 0
+ @Column(name = "AGREEMENT", nullable = true)
+ var agreement: Long = 0
+
@OneToMany(mappedBy = "entity", targetEntity = classOf[Permission],
cascade = Array(CascadeType.ALL))
var permissions : Set[Permission] = new HashSet[Permission]()
@OneToMany(mappedBy = "owner", targetEntity = classOf[ServiceItem],
cascade = Array(CascadeType.ALL))
var serviceItems : Set[ServiceItem] = new HashSet[ServiceItem]()
-
- @Column(name = "AGREEMENT", nullable = true)
- var agreement: Long = 0
}
\ No newline at end of file