} else {
updateAgreementHistoryFrom(imEvent)
updateLatestIMEventIDFrom(imEvent)
+ //Thread.sleep(3000)
}
}
package gr.grnet.aquarium.charging
-import gr.grnet.aquarium.Aquarium
+import gr.grnet.aquarium.{AquariumInternalError, Aquarium}
import gr.grnet.aquarium.charging.state.{AgreementHistoryModel, WorkingResourcesChargingState, WorkingResourceInstanceChargingState}
import gr.grnet.aquarium.charging.wallet.WalletEntry
import gr.grnet.aquarium.computation.BillingMonthInfo
import gr.grnet.aquarium.util.LogHelpers.Debug
import scala.collection.mutable
import gr.grnet.aquarium.event.model.EventModel
+import java.util.Date
/**
* In practice a resource usage will be charged for the total amount of usage
)
val dummyFirstEventValue = 0.0 // TODO From configuration
+
+ val millis = userAgreements.agreementByTimeslot.headOption match {
+ case None =>
+ throw new AquariumInternalError("No agreement!!!")
+ case Some((_,aggr)) =>
+ val millisAgg = aggr.timeslot.from.getTime
+ val millisMon = billingMonthInfo.monthStartMillis
+ if(millisAgg>millisMon) millisAgg else millisMon
+ }
+
val dummyFirstEvent = resourceEvent.withDetailsAndValue(
dummyFirstEventDetails,
dummyFirstEventValue,
- billingMonthInfo.monthStartMillis // TODO max(billingMonthInfo.monthStartMillis, userAgreementModel.validFromMillis)
- )
-
+ millis)
Debug(logger, "Dummy first event %s", dummyFirstEvent.toDebugString)
-
dummyFirstEvent
}
case "diskspace" =>
val action = w.currentResourceEvent.details("action")
val path = w.currentResourceEvent.details("path")
- "%s@%s".format(action,path)
+ //"%s@%s".format(action,path)
+ action
case "vmtime" =>
w.currentResourceEvent.value.toInt match {
case 0 => // OFF
var sum = 0.0
//Console.err.println("Wallet entries: " + w.walletEntries)
val walletEntries = w.walletEntries
+ /*Console.err.println("Wallet entries ")
+ for { i <- walletEntries }
+ Console.err.println("WALLET ENTRY\n%s\nEND WALLET ENTRY".format(i.toJsonString))
+ Console.err.println("End wallet entries")*/
for { i <- walletEntries} {
if(t.contains(i.referenceTimeslot) && i.sumOfCreditsToSubtract != 0.0){
- //Console.err.println("i.sumOfCreditsToSubtract : " + i.sumOfCreditsToSubtract)
+ /*Console.err.println("i.sumOfCreditsToSubtract : " + i.sumOfCreditsToSubtract)*/
if(i.sumOfCreditsToSubtract > 0.0D) sum += i.sumOfCreditsToSubtract
ret += toResourceEntry(i)
} else {
- //Console.err.println("WALLET ENTERY : " + i + "\n" +
- // t + " does not contain " + i.referenceTimeslot + " !!!!")
+ /*Console.err.println("WALLET ENTERY : " + i.toJsonString + "\n" +
+ t + " does not contain " + i.referenceTimeslot + " !!!!")*/
}
}
(ret.toList,sum)
case Some(w) =>
val (rcEntries,rcEntriesCredits) = resourceEntriesAt(t,w)
val resMap = aggregateResourceEntries(rcEntries)
+ Console.err.println("Working user state: %s".format(w.toString))
new BillEntry(counter.getAndIncrement.toString,
userID,"ok",
w.totalCredits.toString,
if(a.isEmpty) return b
if(b.isEmpty) return a
-
+ if(a.head.from != b.head.from)
assert(a.head.from == b.head.from)
if(a.head.endsAfter(b.head)) {
* @author Prodromos Gerakios <pgerakios@grnet.gr>
*/
-
+/*
+ * Format:
+ * minutes hours day-of-month Month Day-of-Week (we do not specify seconds)
+ * see: http://quartz-scheduler.org/api/2.0.0/org/quartz/CronExpression.html
+ * */
case class CronSpec(cronSpec: String) {
private val cronExpr = {
exec("mongo aquarium --eval db.resevents.remove();db.imevents.remove();db.policies.remove();db.userstates.remove()",
Console.err.println(_))
new AquariumBuilder(props, ResourceLocator.DefaultPolicyModel).
- update(Aquarium.EnvKeys.storeProvider, new MemStoreProvider).
+ //update(Aquarium.EnvKeys.storeProvider, new MemStoreProvider).
update(Aquarium.EnvKeys.eventsStoreFolder,Some(new File(".."))).
build()
}
val eventType = "addcredits"
new StdIMEvent(id,occurredMillis,receivedMillis,userID,
clientID,isActive,role,eventVersion,eventType,
- Map()).toJsonString
+ Map("credits" -> amount.toString)).toJsonString
}
private [this] def makePithos(date:DATE,uid:UID,path:String,
val creationDate = "15/00/00/03/08/2012"
/* ADD CREDITS */
val addCreditsDate = "18/15/00/05/08/2012"
- val creditsToAdd = 5000
+ val creditsToAdd = 6000
/* Pithos STUFF */
val pithosPath = "/Papers/GOTO_HARMFUL.PDF"
- val pithosDate1 = "08/30/00/05/08/2012"
+ val pithosDate1 = "20/30/00/05/08/2012"
val pithosAction1 = "update"
val pithosValue1 = 2000
val pithosAction2 = "update"
val pithosValue2 = 4000
+
+ val pithosDate3 = "08/05/00/20/08/2012"
+ val pithosAction3 = "update"
+ val pithosValue3 = 100
+
val id =
sendCreate(creationDate)
+ //Thread.sleep(5000)
sendAddCredits(addCreditsDate,id,creditsToAdd)
+ //Thread.sleep(5000)
sendPithos(pithosDate1,id,pithosPath,pithosValue1,pithosAction1)
+ //Thread.sleep(5000)
sendPithos(pithosDate2,id,pithosPath,pithosValue2,pithosAction2)
+ //
+ sendPithos(pithosDate3,id,pithosPath,pithosValue3,pithosAction3)
+
Console.err.println("Waiting for stuff to be processed")
- Thread.sleep(2000)
+ Thread.sleep(5000)
var resp = ""
var count = 0
def runTestCase(f: => JSON) = {
var json = ""
aquarium.start
+ Thread.sleep(2000)
try{
json = f
} catch{
e.printStackTrace
}
aquarium.stop
+ Thread.sleep(1000)
Console.err.println("Response : " + json )
}