type ResourceType = String
type ResourceIdType = String
type FullResourceType = (ResourceType, ResourceIdType)
- type FullResourceTypeMap = Map[FullResourceType, ResourceEvent]
+// type FullResourceTypeMap = Map[FullResourceType, ResourceEvent]
type FullMutableResourceTypeMap = scala.collection.mutable.Map[FullResourceType, ResourceEvent]
def fromJson(json: String): ResourceEvent = {
* Keeps the implicit OFF events when a billing period ends.
* This is normally recorded in the [[gr.grnet.aquarium.user.UserState]].
*
- * @param implicitOFFEventsMap
+ * @param implicitlyIssuedEvents
* @param snapshotTime
*
* @author Christos KK Loverdos <loverdos@gmail.com>
*/
-case class ImplicitOFFResourceEventsSnapshot(implicitOFFEventsMap: FullResourceTypeMap,
- snapshotTime: Long) extends DataSnapshot {
+case class ImplicitlyIssuedResourceEventsSnapshot(implicitlyIssuedEvents: List[ResourceEvent],
+ snapshotTime: Long) extends DataSnapshot {
/**
* The gateway to playing with mutable state.
*
- * @return A fresh instance of [[gr.grnet.aquarium.user.ImplicitOFFResourceEventsWorker]].
+ * @return A fresh instance of [[gr.grnet.aquarium.user.ImplicitlyIssuedResourceEventsWorker]].
*/
def toMutableWorker = {
- ImplicitOFFResourceEventsWorker(scala.collection.mutable.Map(implicitOFFEventsMap.toSeq: _*))
- }
+ val map = scala.collection.mutable.Map[ResourceEvent.FullResourceType, ResourceEvent]()
+ for(implicitEvent <- implicitlyIssuedEvents) {
+ map(implicitEvent.fullResourceInfo) = implicitEvent
+ }
- def findResourceEvent(resource: String, instanceId: String): Maybe[ResourceEvent] = {
- findFromMapAsMaybe(implicitOFFEventsMap, (resource, instanceId))
+ ImplicitlyIssuedResourceEventsWorker(map)
}
}
/**
- * This is the mutable cousin of [[gr.grnet.aquarium.user.ImplicitOFFResourceEventsSnapshot]].
+ * This is the mutable cousin of [[gr.grnet.aquarium.user.ImplicitlyIssuedResourceEventsSnapshot]].
*
- * @param implicitOFFEventsMap
+ * @param implicitlyIssuedEventsMap
*
* @author Christos KK Loverdos <loverdos@gmail.com>
*/
-case class ImplicitOFFResourceEventsWorker(implicitOFFEventsMap: FullMutableResourceTypeMap) {
+case class ImplicitlyIssuedResourceEventsWorker(implicitlyIssuedEventsMap: FullMutableResourceTypeMap) {
def toImmutableSnapshot(snapshotTime: Long) =
- ImplicitOFFResourceEventsSnapshot(implicitOFFEventsMap.toMap, snapshotTime)
+ ImplicitlyIssuedResourceEventsSnapshot(implicitlyIssuedEventsMap.values.toList, snapshotTime)
def findAndRemoveResourceEvent(resource: String, instanceId: String): Maybe[ResourceEvent] = {
- findAndRemoveFromMap(implicitOFFEventsMap, (resource, instanceId))
+ findAndRemoveFromMap(implicitlyIssuedEventsMap, (resource, instanceId))
}
- def size = implicitOFFEventsMap.size
+ def size = implicitlyIssuedEventsMap.size
def foreach[U](f: ResourceEvent => U): Unit = {
- implicitOFFEventsMap.valuesIterator.foreach(f)
+ implicitlyIssuedEventsMap.valuesIterator.foreach(f)
}
}
\ No newline at end of file
/**
* If this is a state for a full billing month, then keep here the implicit OFF
- * resource events.
+ * resource events or any other whose cost policy demands an implicit event at the end of the billing period.
*
* The use case is this: A VM may have been started (ON state) before the end of the billing period
* and ended (OFF state) after the beginning of the next billing period. In order to bill this, we must assume
* an implicit OFF even right at the end of the billing period and an implicit ON event with the beginning of the
* next billing period.
*/
- implicitOFFsSnapshot: ImplicitOFFResourceEventsSnapshot,
+ implicitlyTerminatedSnapshot: ImplicitlyIssuedResourceEventsSnapshot,
/**
* So far computed wallet entries for the current billing month.
activeStateSnapshot.snapshotTime,
creditsSnapshot.snapshotTime, agreementsSnapshot.snapshotTime, rolesSnapshot.snapshotTime,
ownedResourcesSnapshot.snapshotTime,
- implicitOFFsSnapshot.snapshotTime,
+ implicitlyTerminatedSnapshot.snapshotTime,
latestResourceEventsSnapshot.snapshotTime
)
}
0L,
false,
null,
- ImplicitOFFResourceEventsSnapshot(Map(), now),
+ ImplicitlyIssuedResourceEventsSnapshot(Map(), now),
Nil, Nil,
LatestResourceEventsSnapshot(Map(), now),
0L, 0L,
0L,
false,
null,
- ImplicitOFFResourceEventsSnapshot(Map(), now),
+ ImplicitlyIssuedResourceEventsSnapshot(Map(), now),
Nil, Nil,
LatestResourceEventsSnapshot(Map(), now),
0L, 0L,
val previousBillingMonthData = billingMonthInfo.previousMonth
- val previousBillingMonth = previousBillingMonthData.month
- val yearOfPreviousBillingMonth = previousBillingMonthData.year
-
val clog = ContextualLogger.fromOther(
contextualLogger,
logger,
var _workingUserState = startingUserState
// Prepare the implicit OFF resource events
- val theImplicitOFFs = _workingUserState.implicitOFFsSnapshot.toMutableWorker
+ val theImplicitOFFs = _workingUserState.implicitlyTerminatedSnapshot.toMutableWorker
clog.debug("theImplicitOFFs = %s", theImplicitOFFs)
/**
[DEBUG] 2012-02-13 12:54:53,663 main - findUserStateAtEndOfBillingMonth(2011-11) Computing full month billing
[DEBUG] 2012-02-13 12:54:53,664 main - doFullMonthlyBilling(2011-11) BEGIN
[DEBUG] 2012-02-13 12:54:53,664 main - findUserStateAtEndOfBillingMonth(2011-10) BEGIN
- [DEBUG] 2012-02-13 12:54:53,667 main - findUserStateAtEndOfBillingMonth(2011-10) User did not exist before 2011-11-01 00:00:00.000. Returning UserState(Christos,0,0,false,null,ImplicitOFFResourceEventsSnapshot(Map(),0),List(),List(),LatestResourceEventsSnapshot(Map(),0),0,ActiveStateSnapshot(false,0),CreditSnapshot(0.0,0),AgreementSnapshot(List(Agreement(default,0,-1)),0),RolesSnapshot(List(),0),OwnedResourcesSnapshot(List(),0))
+ [DEBUG] 2012-02-13 12:54:53,667 main - findUserStateAtEndOfBillingMonth(2011-10) User did not exist before 2011-11-01 00:00:00.000. Returning UserState(Christos,0,0,false,null,ImplicitlyIssuedResourceEventsSnapshot(Map(),0),List(),List(),LatestResourceEventsSnapshot(Map(),0),0,ActiveStateSnapshot(false,0),CreditSnapshot(0.0,0),AgreementSnapshot(List(Agreement(default,0,-1)),0),RolesSnapshot(List(),0),OwnedResourcesSnapshot(List(),0))
[DEBUG] 2012-02-13 12:54:53,668 main - findUserStateAtEndOfBillingMonth(2011-10) END
[DEBUG] 2012-02-13 12:54:53,672 main - doFullMonthlyBilling(2011-11) previousResourceEvents = LatestResourceEventsWorker(Map())
- [DEBUG] 2012-02-13 12:54:53,673 main - doFullMonthlyBilling(2011-11) theImplicitOFFs = ImplicitOFFResourceEventsWorker(Map())
+ [DEBUG] 2012-02-13 12:54:53,673 main - doFullMonthlyBilling(2011-11) theImplicitOFFs = ImplicitlyIssuedResourceEventsWorker(Map())
[DEBUG] 2012-02-13 12:54:53,680 main - doFullMonthlyBilling(2011-11) resourceEventStore = MemStore(Map(UserState -> 0, WalletEntry -> 0, ResourceEvent -> 5, PolicyEntry -> 0, UserEvent -> 0))
[DEBUG] 2012-02-13 12:54:53,681 main - doFullMonthlyBilling(2011-11) Found 0 resource events, starting processing...
[DEBUG] 2012-02-13 12:54:53,683 main - doFullMonthlyBilling(2011-11) END
[DEBUG] 2012-02-13 12:54:53,683 main - findUserStateAtEndOfBillingMonth(2011-11) END
[DEBUG] 2012-02-13 12:54:53,684 main - doFullMonthlyBilling(2011-12) previousResourceEvents = LatestResourceEventsWorker(Map())
- [DEBUG] 2012-02-13 12:54:53,684 main - doFullMonthlyBilling(2011-12) theImplicitOFFs = ImplicitOFFResourceEventsWorker(Map())
+ [DEBUG] 2012-02-13 12:54:53,684 main - doFullMonthlyBilling(2011-12) theImplicitOFFs = ImplicitlyIssuedResourceEventsWorker(Map())
[DEBUG] 2012-02-13 12:54:53,685 main - doFullMonthlyBilling(2011-12) resourceEventStore = MemStore(Map(UserState -> 0, WalletEntry -> 0, ResourceEvent -> 5, PolicyEntry -> 0, UserEvent -> 0))
[DEBUG] 2012-02-13 12:54:53,686 main - doFullMonthlyBilling(2011-12) Found 0 resource events, starting processing...
[DEBUG] 2012-02-13 12:54:53,686 main - doFullMonthlyBilling(2011-12) END
[DEBUG] 2012-02-13 12:54:53,687 main - findUserStateAtEndOfBillingMonth(2011-12) END
[DEBUG] 2012-02-13 12:54:53,687 main - doFullMonthlyBilling(2012-01) previousResourceEvents = LatestResourceEventsWorker(Map())
- [DEBUG] 2012-02-13 12:54:53,688 main - doFullMonthlyBilling(2012-01) theImplicitOFFs = ImplicitOFFResourceEventsWorker(Map())
+ [DEBUG] 2012-02-13 12:54:53,688 main - doFullMonthlyBilling(2012-01) theImplicitOFFs = ImplicitlyIssuedResourceEventsWorker(Map())
[DEBUG] 2012-02-13 12:54:53,688 main - doFullMonthlyBilling(2012-01) resourceEventStore = MemStore(Map(UserState -> 0, WalletEntry -> 0, ResourceEvent -> 5, PolicyEntry -> 0, UserEvent -> 0))
[DEBUG] 2012-02-13 12:54:53,689 main - doFullMonthlyBilling(2012-01) Found 4 resource events, starting processing...
[DEBUG] 2012-02-13 12:54:53,690 main - doFullMonthlyBilling(2012-01) Processing EVENT(2, [2012-01-01 03:00:00.000], 99.0 [MB/Hr], diskspace::pithos/diskspace/DISK.1, Map(), Christos, pithos)