object ResourceEvent {
type Details = Map[String, String]
+ final val EmptyDetails: Details = Map()
type ResourceType = String
type ResourceIdType = String
package gr.grnet.aquarium.user.simulation
-import gr.grnet.aquarium.logic.accounting.dsl.{DSLResourcesMap, DSLComplexResource, DSLCostPolicy}
+import gr.grnet.aquarium.logic.accounting.dsl.DSLResourcesMap
+import gr.grnet.aquarium.store.ResourceEventStore
+import java.util.Date
/**
* @author Christos KK Loverdos <loverdos@gmail.com>
*/
-case class AquariumSim(resources: List[ResourceSim]) {
+case class AquariumSim(resources: List[ResourceSim], resourceEventStore: ResourceEventStore) {
def resourcesMap = new DSLResourcesMap(resources.map(_.toDSLResource))
+
+ def newUser(userId: String, userCreationDate: Date) = UserSim(userId, userCreationDate, this)
}
+++ /dev/null
-/*
- * Copyright 2011 GRNET S.A. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the following
- * disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and
- * documentation are those of the authors and should not be
- * interpreted as representing official policies, either expressed
- * or implied, of GRNET S.A.
- */
-package gr.grnet.aquarium.user.simulation
-
-import gr.grnet.aquarium.util.date.MutableDateCalc
-import gr.grnet.aquarium.logic.events.ResourceEvent
-import java.util.Date
-import gr.grnet.aquarium.logic.accounting.dsl.OnOffCostPolicyValues
-import gr.grnet.aquarium.store.memory.MemStore
-import com.ckkloverdos.maybe.Maybe
-import gr.grnet.aquarium.store.RecordID
-
-/**
- * A simulator for an Aquarium client service, which is an event generator.
- *
- * @author Christos KK Loverdos <loverdos@gmail.com>
- */
-
-case class ClientServiceSim(clientId: String)(implicit uidGen: UIDGenerator) {
- private[this] val UserProto = UserSim("", new Date(0), new MemStore().resourceEventStore)
- private[this] val VMTimeProto = VMTimeSim(UserProto, "")
- private[this] val DiskspaceProto = DiskspaceSim(UserProto, "")
- private[this] val BandwidthProto = BandwidthSim(UserProto, "")
-
- private[this] var _resources = List[ResourceSim]()
-
- sealed abstract class ResourceSim(_resource: String, val owner: UserSim, val instanceId: String = "") {
- def resource = _resource
- }
-
- case class VMTimeSim(override val owner: UserSim,
- override val instanceId: String = "")
- extends ResourceSim("vmtime", owner, instanceId) {
-
- def newON(occurredDate: Date): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val time = occurredDate.getTime
- val occurredTime = time
- val receivedTime = time
- val event = ResourceEvent(
- id,
- occurredTime,
- receivedTime,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- OnOffCostPolicyValues.ON,
- Map())
-
- owner._addResourceEvent(event)
- }
-
- def newON_OutOfSync(occuredDate: Date, outOfSyncHours: Int): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val occurredDateCalc = new MutableDateCalc(occuredDate)
- val occurredTime = occurredDateCalc.toMillis
- val receivedTime = occurredDateCalc.goPlusHours(outOfSyncHours).toMillis
-
- val event = ResourceEvent(
- id,
- occurredTime,
- receivedTime,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- OnOffCostPolicyValues.ON,
- Map())
-
- owner._addResourceEvent(event)
- }
-
- def newOFF(occurredDate: Date): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val time = occurredDate.getTime
- val occurredTime = time
- val receivedTime = time
- val event = ResourceEvent(
- id,
- occurredTime,
- receivedTime,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- OnOffCostPolicyValues.OFF,
- Map())
-
- owner._addResourceEvent(event)
- }
-
- def newOFF_OutOfSync(occuredDate: Date, outOfSyncHours: Int): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val occurredDateCalc = new MutableDateCalc(occuredDate)
- val occurredTime = occurredDateCalc.toMillis
- val receivedTime = occurredDateCalc.goPlusHours(outOfSyncHours).toMillis
-
- val event = ResourceEvent(
- id,
- occurredTime,
- receivedTime,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- OnOffCostPolicyValues.OFF,
- Map())
-
- owner._addResourceEvent(event)
- }
-
- def newONOFF(occurredDateForON: Date, totalVMTimeInHours: Int): (Maybe[RecordID], Maybe[RecordID]) = {
- val onID = newON(occurredDateForON)
- val offDate = new MutableDateCalc(occurredDateForON).goPlusHours(totalVMTimeInHours).toDate
- val offID = newOFF(offDate)
-
- (onID, offID)
- }
-
- def newONOFF_OutOfSync(occurredDateForON: Date,
- totalVMTimeInHours: Int,
- outOfSyncONHours: Int,
- outOfSyncOFFHours: Int): (Maybe[RecordID], Maybe[RecordID]) = {
- val onID = newON_OutOfSync(occurredDateForON, outOfSyncONHours)
- val occurredDateCalcForOFF = new MutableDateCalc(occurredDateForON).goPlusHours(totalVMTimeInHours)
- val occurredDateForOFF = occurredDateCalcForOFF.toDate
- val offID = newOFF_OutOfSync(occurredDateForOFF, outOfSyncOFFHours)
-
- (onID, offID)
- }
- }
-
- case class BandwidthSim(override val owner: UserSim,
- override val instanceId: String = "") extends ResourceSim("bandwidth", owner, instanceId) {
-
- def useBandwidth(occurredDate: Date, megaBytes: Double): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val time = occurredDate.getTime
- val event = ResourceEvent(
- id,
- time,
- time,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- megaBytes,
- Map()
- )
-
- owner._addResourceEvent(event)
- }
- }
-
- case class DiskspaceSim(override val owner: UserSim,
- override val instanceId: String = "") extends ResourceSim("diskspace", owner, instanceId) {
-
- def consumeMB(occurredDate: Date, megaBytes: Double): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val time = occurredDate.getTime
- val event = ResourceEvent(
- id,
- time,
- time,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- megaBytes,
- Map()
- )
-
- owner._addResourceEvent(event)
- }
-
- def freeMB(occurredDate: Date, megaBytes: Double): Maybe[RecordID] = {
- consumeMB(occurredDate, -megaBytes)
- }
-
- def consumeMB_OutOfSync(occurredDate: Date, outOfSyncHours: Int, megaBytes: Double): Maybe[RecordID] = {
- val id = uidGen.nextUID()
- val occurredDateCalc = new MutableDateCalc(occurredDate)
- val occurredTime = occurredDateCalc.toMillis
- val receivedTime = occurredDateCalc.goPlusHours(outOfSyncHours).toMillis
-
- val event = ResourceEvent(
- id,
- occurredTime,
- receivedTime,
- owner.userId,
- clientId,
- resource,
- instanceId,
- "1.0",
- megaBytes,
- Map()
- )
-
- owner._addResourceEvent(event)
- }
-
- def freeMB_OutOfSync(occurredDate: Date, outOfSyncHours: Int, megaBytes: Double): Maybe[RecordID] = {
- consumeMB_OutOfSync(occurredDate, outOfSyncHours, -megaBytes)
- }
- }
-
- private[simulation]
- def _addVMTime(vmtime: VMTimeSim): VMTimeSim = {
- _resources = vmtime :: _resources
- vmtime
- }
-
- private[simulation]
- def _addDiskspace(diskspace: DiskspaceSim): DiskspaceSim = {
- _resources = diskspace :: _resources
- diskspace
- }
-
- private[simulation]
- def _addBandwidth(bandwidth: BandwidthSim): BandwidthSim = {
- _resources = bandwidth :: _resources
- bandwidth
- }
-
- def qualifyResource(resource: String, instanceId: String) = {
- "%s/%s/%s".format(clientId, resource, instanceId)
- }
-
- def newVMTime(owner: UserSim, _instanceId: String): VMTimeSim = {
- owner._addServiceClient(this)
- _addVMTime(VMTimeSim(owner, this.qualifyResource(VMTimeProto.resource, _instanceId)))
- }
-
- def newDiskspace(owner: UserSim, _instanceId: String): DiskspaceSim = {
- owner._addServiceClient(this)
- _addDiskspace(DiskspaceSim(owner, this.qualifyResource(DiskspaceProto.resource, _instanceId)))
- }
-
- def newBandwidth(owner: UserSim, _instanceId: String): BandwidthSim = {
- owner._addServiceClient(this)
- _addBandwidth(BandwidthSim(owner, this.qualifyResource(BandwidthProto.resource, _instanceId)))
- }
-
- def myResources: List[ResourceSim] = _resources
-}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+/**
+ * A simulator for an aquarium client system.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+case class ClientSim(clientId: String)(implicit val uidGen: UIDGenerator)
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.events.ResourceEvent
+
+/**
+ * A simulator for a resource instance.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+class ResourceInstanceSim (val resource: ResourceSim,
+ val instanceId: String,
+ val owner: UserSim,
+ val client: ClientSim) {
+
+ def uidGen = client.uidGen
+
+ def newResourceEvent(occurredMillis: Long,
+ receivedMillis: Long,
+ value: Double,
+ details: ResourceEvent.Details,
+ eventVersion: String = "1.0") = {
+
+ val event = ResourceEvent(
+ uidGen.nextUID(),
+ occurredMillis,
+ receivedMillis,
+ owner.userId,
+ client.clientId,
+ resource.name,
+ instanceId,
+ eventVersion,
+ value,
+ details
+ )
+
+ owner._addResourceEvent(event)
+ }
+}
+
+object ResourceInstanceSim {
+ def apply(resource: ResourceSim, instanceId: String, owner: UserSim, client: ClientSim) =
+ new ResourceInstanceSim(resource, instanceId, owner, client)
+}
\ No newline at end of file
package gr.grnet.aquarium.user.simulation
-import gr.grnet.aquarium.logic.accounting.dsl.{DSLCostPolicy, DSLComplexResource}
+import gr.grnet.aquarium.logic.accounting.dsl.{DiscreteCostPolicy, ContinuousCostPolicy, OnOffCostPolicy, DSLCostPolicy, DSLComplexResource}
/**
- * A resource simulator.
+ * A simulator for a resource.
*
* @author Christos KK Loverdos <loverdos@gmail.com>
*/
-case class ResourceSim(name: String, unit: String, costPolicy: DSLCostPolicy) {
+class ResourceSim(val name: String, val unit: String, val costPolicy: DSLCostPolicy) {
def toDSLResource = DSLComplexResource(name, unit, costPolicy, "")
+
+ def newInstance(instanceId: String, owner: UserSim, client: ClientSim)=
+ new ResourceInstanceSim(this, instanceId, owner, client)
+}
+
+
+object ResourceSim {
+ def apply(name: String, unit: String, costPolicy: DSLCostPolicy) =
+ new ResourceSim(name, unit, costPolicy)
}
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import java.util.Date
+import com.ckkloverdos.maybe.Maybe
+import gr.grnet.aquarium.store.RecordID
+import gr.grnet.aquarium.logic.events.ResourceEvent
+
+/**
+ * A simulator for an instance of the standard `bandwidth` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+case class StdBandwidthInstanceSim(override val instanceId: String,
+ override val owner: UserSim,
+ override val client: ClientSim)
+extends ResourceInstanceSim(StdBandwidthResourceSim, instanceId, owner, client) {
+ def useBandwidth(occurredDate: Date,
+ megaBytes: Double,
+ details: ResourceEvent.Details = Map(),
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+
+ newResourceEvent(
+ occurredDate.getTime,
+ occurredDate.getTime,
+ megaBytes,
+ details,
+ eventVersion
+ )
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.accounting.dsl.DiscreteCostPolicy
+
+/**
+ * A simulator for the standard `bandwidth` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+object StdBandwidthResourceSim extends ResourceSim("bandwidth", "MB/Hr", DiscreteCostPolicy) {
+ override def newInstance(instanceId: String, owner: UserSim, client: ClientSim) =
+ StdBandwidthInstanceSim(instanceId, owner, client)
+}
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.events.ResourceEvent
+import gr.grnet.aquarium.store.RecordID
+import com.ckkloverdos.maybe.Maybe
+import java.util.Date
+import gr.grnet.aquarium.util.date.MutableDateCalc
+
+/**
+ * A simulator for an instance of the standard `diskspace` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+case class StdDiskspaceInstanceSim(override val instanceId: String,
+ override val owner: UserSim,
+ override val client: ClientSim)
+extends ResourceInstanceSim(StdDiskspaceResourceSim, instanceId, owner, client) {
+ def consumeMB(occurredDate: Date,
+ megaBytes: Double,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+ newResourceEvent(
+ occurredDate.getTime,
+ occurredDate.getTime,
+ megaBytes,
+ details,
+ eventVersion
+ )
+ }
+
+
+ def freeMB(occurredDate: Date,
+ megaBytes: Double,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+
+ consumeMB(occurredDate, -megaBytes)
+ }
+
+ def consumeMB_OutOfSync(occurredDate: Date,
+ outOfSyncHours: Int,
+ megaBytes: Double,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+
+ val occurredDateCalc = new MutableDateCalc(occurredDate)
+ val occurredTime = occurredDateCalc.toMillis
+ val receivedTime = occurredDateCalc.goPlusHours(outOfSyncHours).toMillis
+
+ newResourceEvent(
+ occurredTime,
+ receivedTime,
+ megaBytes,
+ details,
+ eventVersion
+ )
+ }
+
+ def freeMB_OutOfSync(occurredDate: Date,
+ outOfSyncHours: Int,
+ megaBytes: Double,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+
+ consumeMB_OutOfSync(occurredDate, outOfSyncHours, -megaBytes)
+ }
+}
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.accounting.dsl.ContinuousCostPolicy
+
+/**
+ * A simulator for the standard `diskspace` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+object StdDiskspaceResourceSim extends ResourceSim("diskspace", "MB/Hr", ContinuousCostPolicy) {
+ override def newInstance(instanceId: String, owner: UserSim, client: ClientSim) =
+ StdDiskspaceInstanceSim(instanceId, owner, client)
+}
+
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.accounting.dsl.OnOffCostPolicyValues
+import gr.grnet.aquarium.store.RecordID
+import com.ckkloverdos.maybe.Maybe
+import java.util.Date
+import gr.grnet.aquarium.util.date.MutableDateCalc
+import gr.grnet.aquarium.logic.events.ResourceEvent
+
+/**
+ * A simulator for an instance of the standard `vmtime` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+case class StdVMTimeInstanceSim(override val instanceId: String,
+ override val owner: UserSim,
+ override val client: ClientSim)
+extends ResourceInstanceSim(StdVMTimeResourceSim, instanceId, owner, client) {
+
+ def newON(occurredDate: Date,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+ newResourceEvent(
+ occurredDate.getTime,
+ occurredDate.getTime,
+ OnOffCostPolicyValues.ON,
+ details,
+ eventVersion
+ )
+ }
+
+ def newOFF(occurredDate: Date,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+ newResourceEvent(
+ occurredDate.getTime,
+ occurredDate.getTime,
+ OnOffCostPolicyValues.OFF,
+ details,
+ eventVersion
+ )
+ }
+
+ def newONOFF(occurredDateForON: Date, totalVMTimeInHours: Int): (Maybe[RecordID], Maybe[RecordID]) = {
+ val onID = newON(occurredDateForON)
+ val offDate = new MutableDateCalc(occurredDateForON).goPlusHours(totalVMTimeInHours).toDate
+ val offID = newOFF(offDate)
+
+ (onID, offID)
+ }
+
+ def newOFF_OutOfSync(occuredDate: Date,
+ outOfSyncHours: Int,
+ details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ eventVersion: String = "1.0"): Maybe[RecordID] = {
+
+ val occurredDateCalc = new MutableDateCalc(occuredDate)
+ val occurredTime = occurredDateCalc.toMillis
+ val receivedTime = occurredDateCalc.goPlusHours(outOfSyncHours).toMillis
+
+ newResourceEvent(
+ occurredTime,
+ receivedTime,
+ OnOffCostPolicyValues.OFF,
+ details,
+ eventVersion
+ )
+ }
+}
--- /dev/null
+/*
+ * Copyright 2011 GRNET S.A. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and
+ * documentation are those of the authors and should not be
+ * interpreted as representing official policies, either expressed
+ * or implied, of GRNET S.A.
+ */
+
+package gr.grnet.aquarium.user.simulation
+
+import gr.grnet.aquarium.logic.accounting.dsl.OnOffCostPolicy
+
+/**
+ * A simulator for the standard `vmtime` resource.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+object StdVMTimeResourceSim extends ResourceSim("vmtime", "Hr", OnOffCostPolicy) {
+ override def newInstance(instanceId: String, owner: UserSim, client: ClientSim) =
+ StdVMTimeInstanceSim(instanceId, owner, client)
+}
* @author Christos KK Loverdos <loverdos@gmail.com>
*/
-case class UserSim(userId: String, userCreationDate: Date, resourceEventStore: ResourceEventStore) { userSelf ⇒
- private[this] var _serviceClients = List[ClientServiceSim]()
+case class UserSim(userId: String, userCreationDate: Date, aquarium: AquariumSim) { userSelf ⇒
+ private[this]
+ def resourceEventStore = aquarium.resourceEventStore
- private[this] val myResourcesGen: () => List[ClientServiceSim#ResourceSim] = () => {
- for {
- serviceClient <- _serviceClients
- resource <- serviceClient.myResources if(resource.owner == this)
- } yield {
- resource
- }
- }
-
- private[simulation]
- def _addServiceClient(serviceClient: ClientServiceSim): ClientServiceSim = {
- if(!_serviceClients.exists(_ == serviceClient)) {
- _serviceClients = serviceClient :: _serviceClients
- }
- serviceClient
- }
-
private[simulation]
def _addResourceEvent(resourceEvent: ResourceEvent): Maybe[RecordID] = {
resourceEventStore.storeResourceEvent(resourceEvent)
}
- def myServiceClients: List[ClientServiceSim] = {
- _serviceClients
- }
-
- def myResources: List[ClientServiceSim#ResourceSim] = {
- myResourcesGen.apply()
- }
-
def myResourceEvents: List[ResourceEvent] = {
resourceEventStore.findResourceEventsByUserId(userId)(None)
}
import gr.grnet.aquarium.logic.accounting.{Policy, Accounting}
import gr.grnet.aquarium.util.{Loggable, ContextualLogger}
import com.ckkloverdos.maybe.{Just, NoVal}
-import simulation.{AquariumSim, ResourceSim, ConcurrentVMLocalUIDGenerator, ClientServiceSim, UserSim}
+import simulation._
/**
// TODO: integrate this with the rest of the simulation stuff
// TODO: since, right now, the resource strings have to be given twice
- val VMTimeResource = ResourceSim("vmtime", "Hr", OnOffCostPolicy)
- val DiskspaceResource = ResourceSim("diskspace", "MB/Hr", ContinuousCostPolicy)
- val BandwidthResource = ResourceSim("bandwidth", "MB/Hr", DiscreteCostPolicy)
-
- val Aquarium = AquariumSim(List(VMTimeResource, DiskspaceResource, BandwidthResource))
- val DefaultResourcesMap = Aquarium.resourcesMap
+ val VMTimeResource = StdVMTimeResourceSim
+ val DiskspaceResource = StdDiskspaceResourceSim
+ val BandwidthResource = StdBandwidthResourceSim
// There are two client services, synnefo and pithos.
val TheUIDGenerator = new ConcurrentVMLocalUIDGenerator
- val Synnefo = ClientServiceSim("synnefo")(TheUIDGenerator)
- val Pithos = ClientServiceSim("pithos")(TheUIDGenerator)
+ val Synnefo = ClientSim("synnefo")(TheUIDGenerator)
+ val Pithos = ClientSim("pithos" )(TheUIDGenerator)
@Test
def testOne: Unit = {
val clog = ContextualLogger.fromOther(NoVal, logger, "testOne()")
val StartOfBillingYearDateCalc = new MutableDateCalc(2012, 1, 1)
-// println("StartOfBillingYearDateCalc = %s".format(StartOfBillingYearDateCalc))
val UserCreationDateCalc = StartOfBillingYearDateCalc.copy.goMinusMonths(2)
-// println("UserCreationDateCalc = %s".format(UserCreationDateCalc))
val computer = new UserStateComputations
val policyValidToMillis = StartOfBillingYearDateCalc.copy.goNextYear.toMillis
policyStore.storePolicyEntry(DefaultPolicy.toPolicyEntry(policyOccurredMillis, policyValidFromMillis, policyValidToMillis))
+ val Aquarium = AquariumSim(List(VMTimeResource, DiskspaceResource, BandwidthResource), storeProvider.resourceEventStore)
+ val DefaultResourcesMap = Aquarium.resourcesMap
+
// A new user is created on 2012-01-15 00:00:00.000
- val UserCKKL = UserSim("CKKL", UserCreationDateCalc.toDate, storeProvider.resourceEventStore)
+ val UserCKKL = Aquarium.newUser("CKKL", UserCreationDateCalc.toDate)
// By convention
// - synnefo is for VMTime and Bandwidth
// - pithos is for Diskspace
- val VMTimeInstance = Synnefo.newVMTime (UserCKKL, "VM.1")
- val BandwidthInstance = Synnefo.newBandwidth(UserCKKL, "3G.1")
- val DiskInstance = Pithos .newDiskspace(UserCKKL, "DISK.1")
+ val VMTimeInstance = StdVMTimeInstanceSim ("VM.1", UserCKKL, Synnefo)
+ val BandwidthInstance = StdBandwidthInstanceSim("3G.1", UserCKKL, Synnefo)
+ val DiskInstance = StdDiskspaceInstanceSim("DISK.1", UserCKKL, Pithos)
// Let's create our dates of interest
val vmStartDateCalc = StartOfBillingYearDateCalc.copy.goPlusDays(1).goPlusHours(1)
-// println("vmStartDateCalc = %s".format(vmStartDateCalc))
// 2012-01-16 01:00:00.000
val vmStartDate = vmStartDateCalc.toDate
// Within January, create one VM ON-OFF ...
- val onOff1_M = VMTimeInstance.newONOFF(vmStartDate, 9)
+ VMTimeInstance.newONOFF(vmStartDate, 9)
val diskConsumptionDateCalc = StartOfBillingYearDateCalc.copy.goPlusHours(3)
// 2012-01-16 04:00:00.000
val diskConsumptionDate2 = diskConsumptionDateCalc2.toDate
// ... and two diskspace changes
- val consume1_M = DiskInstance.consumeMB(diskConsumptionDate1, 99)
- val consume2_M = DiskInstance.consumeMB(diskConsumptionDate2, 23)
+ DiskInstance.consumeMB(diskConsumptionDate1, 99)
+ DiskInstance.consumeMB(diskConsumptionDate2, 23)
// 100MB 3G bandwidth
val bwDateCalc = diskConsumptionDateCalc2.copy.goPlusDays(1)