doc/arch/arch.texshop
build.log
_gitstats/
+_localrest
*.aquarium.properties
sshfs/
aquarium-dist/
package events
-import util.json.JsonSupport
import util.xml.XmlSupport
import util.Loggable
val id: String, // The id at the client side (the sender) TODO: Rename to remoteId or something...
val occurredMillis: Long, // When it occurred at client side (the sender)
val receivedMillis: Long) // When it was received by Aquarium
- extends JsonSupport
+ extends AquariumEventModel
with XmlSupport
with Loggable {
toJson.getBytes("UTF-8")
}
- /**
- * Return a new instance with all state the same as this one except for `receivedMillis`, which
- * acquires the new value.
- */
+ def storeID: Option[AnyRef] = Some(id)
+
+ def details: Map[String, String] = Map()
+
+ def eventVersion = "1.0"
+
def copyWithReceivedMillis(receivedMillis: Long): AquariumEvent
}
--- /dev/null
+/*
+ * Copyright 2011-2012 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.events
+
+import gr.grnet.aquarium.util.json.JsonSupport
+
+/**
+ * The base model for all events coming from external systems.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+trait AquariumEventModel extends JsonSupport {
+ def id: String
+ def occurredMillis: Long
+ def receivedMillis: Long
+// def userID: String
+ def eventVersion: String
+ def details: Map[String, String]
+
+ /**
+ * The ID given to this event if/when persisted to a store.
+ * The exact type of the id is store-specific.
+ */
+ def storeID: Option[AnyRef]
+}
clientID: String,
isActive: Boolean,
role: String,
- eventVersion: String,
+ override val eventVersion: String,
eventType: String,
- details: IMEvent.Details,
- _id: AnyRef = new ObjectId())
- extends AquariumEvent(id, occurredMillis, receivedMillis) {
+ override val details: Map[String, String],
+ _id: ObjectId = new ObjectId())
+ extends AquariumEvent(id, occurredMillis, receivedMillis) with IMEventModel {
+
// assert(eventType.equalsIgnoreCase(IMEvent.EventTypes.create) ||
// eventType.equalsIgnoreCase(IMEvent.EventTypes.modify))
// assert(!role.isEmpty)
+ override def storeID = {
+ _id match {
+ case null ⇒ None
+ case _ ⇒ Some(_id)
+ }
+ }
+
/**
* Validate this event according to the following rules:
*
val modify = "modify"
}
- type Details = Map[String, String]
-
def fromJson(json: String): IMEvent = {
StdConverters.StdConverters.convertEx[IMEvent](JsonTextFormat(json))
}
--- /dev/null
+/*
+ * Copyright 2011-2012 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.events
+
+/**
+ * The model of any event sent from the `Identity Management` (IM) external system.
+ *
+ * We use this to not reveal storage-specific stuff, like IDs.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>
+ */
+
+trait IMEventModel extends AquariumEventModel {
+ def clientID: String
+ def isActive: Boolean
+ def role: String
+ def eventType: String
+}
clientID: String, // The unique client identifier (usually some hash)
resource: String, // String representation of the resource type (e.g. "bndup", "vmtime").
instanceID: String, // String representation of the resource instance id
- eventVersion: String,
+ override val eventVersion: String,
value: Double,
- details: ResourceEvent.Details)
+ override val details: Map[String, String])
extends AquariumEvent(id, occurredMillis, receivedMillis) {
def validate() : Boolean = {
}
object ResourceEvent {
- type Details = Map[String, String]
- final val EmptyDetails: Details = Map()
-
type ResourceType = String
type ResourceIdType = String
type FullResourceType = (ResourceType, ResourceIdType)
StdConverters.StdConverters.convertEx[ResourceEvent](JsonTextFormat(makeString(bytes)))
}
- def setAquariumSynthetic(map: ResourceEvent.Details): ResourceEvent.Details = {
+ def setAquariumSynthetic(map: Map[String, String]): Map[String, String] = {
map.updated(JsonNames.details_aquarium_is_synthetic, "true")
}
- def setAquariumSyntheticAndImplicitEnd(map: ResourceEvent.Details): ResourceEvent.Details = {
+ def setAquariumSyntheticAndImplicitEnd(map: Map[String, String]): Map[String, String] = {
map.
updated(JsonNames.details_aquarium_is_synthetic, "true").
updated(JsonNames.details_aquarium_is_implicit_end, "true")
import java.util.Date
import converter.{JsonTextFormat, StdConverters}
+import util.json.JsonSupport
/**
* A WalletEntry is a derived entity. Its data represent money/credits and are calculated based on
finalized: Boolean)
extends AquariumEvent(id, occurredMillis, receivedMillis) {
+
assert(occurredMillis > 0)
assert(value >= 0F)
assert(!userId.isEmpty)
def newResourceEvent(occurredMillis: Long,
receivedMillis: Long,
value: Double,
- details: ResourceEvent.Details,
+ details: Map[String, String],
eventVersion: String = "1.0") = {
val event = ResourceEvent(
extends ResourceInstanceSim(resource, instanceId, owner, client) {
def useBandwidth(occurredDate: Date,
megaBytes: Double,
- details: ResourceEvent.Details = Map(),
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
newResourceEvent(
extends ResourceInstanceSim(resource, instanceId, owner, client) {
def consumeMB(occurredDate: Date,
megaBytes: Double,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
newResourceEvent(
occurredDate.getTime,
def freeMB(occurredDate: Date,
megaBytes: Double,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
consumeMB(occurredDate, -megaBytes)
def consumeMB_OutOfSync(occurredDate: Date,
outOfSyncHours: Int,
megaBytes: Double,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
val occurredDateCalc = new MutableDateCalc(occurredDate)
def freeMB_OutOfSync(occurredDate: Date,
outOfSyncHours: Int,
megaBytes: Double,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
consumeMB_OutOfSync(occurredDate, outOfSyncHours, -megaBytes)
extends ResourceInstanceSim(resource, instanceId, owner, client) {
def newON(occurredDate: Date,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
newResourceEvent(
occurredDate.getTime,
}
def newOFF(occurredDate: Date,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
newResourceEvent(
occurredDate.getTime,
def newOFF_OutOfSync(occuredDate: Date,
outOfSyncHours: Int,
- details: ResourceEvent.Details = ResourceEvent.EmptyDetails,
+ details: Map[String, String] = Map(),
eventVersion: String = "1.0"): RecordID = {
val occurredDateCalc = new MutableDateCalc(occuredDate)
db.getCollection(name)
}
- private[this] def _sortByTimestampAsc[A <: AquariumEvent](one: A, two: A): Boolean = {
+ private[this] def _sortByTimestampAsc[A <: AquariumEventModel](one: A, two: A): Boolean = {
if (one.occurredMillis > two.occurredMillis) false
else if (one.occurredMillis < two.occurredMillis) true
else true
PolicyEntry.fromJson(JSON.serialize(dbObj))
}
- def findById[A >: Null <: AquariumEvent](id: String, collection: DBCollection, deserializer: (DBObject) => A) : Maybe[A] = Maybe {
+ def findById[A >: Null <: AnyRef](id: String, collection: DBCollection, deserializer: (DBObject) => A) : Maybe[A] =
+ Maybe {
val query = new BasicDBObject(ResourceJsonNames.id, id)
val cursor = collection find query
}
}
- def runQuery[A <: AquariumEvent](query: DBObject, collection: DBCollection, orderBy: DBObject = null)
+ def runQuery[A <: AquariumEventModel](query: DBObject, collection: DBCollection, orderBy: DBObject = null)
(deserializer: (DBObject) => A)
(sortWith: Option[(A, A) => Boolean]): List[A] = {
val cursor0 = collection find query