Add ping functionality to two of the stores
[aquarium] / src / main / scala / gr / grnet / aquarium / store / mongodb / MongoDBStore.scala
index 870fd13..1171045 100644 (file)
@@ -39,14 +39,13 @@ import com.mongodb.util.JSON
 import gr.grnet.aquarium.computation.UserState.{JsonNames ⇒ UserStateJsonNames}
 import gr.grnet.aquarium.util.json.JsonSupport
 import collection.mutable.ListBuffer
-import gr.grnet.aquarium.event._
-import gr.grnet.aquarium.event.im.IMEventModel
-import gr.grnet.aquarium.event.im.IMEventModel.{Names ⇒ IMEventNames}
-import gr.grnet.aquarium.event.resource.ResourceEventModel
-import gr.grnet.aquarium.event.resource.ResourceEventModel.{Names ⇒ ResourceEventNames}
+import gr.grnet.aquarium.event.model.im.IMEventModel
+import gr.grnet.aquarium.event.model.im.IMEventModel.{Names ⇒ IMEventNames}
+import gr.grnet.aquarium.event.model.resource.ResourceEventModel
+import gr.grnet.aquarium.event.model.resource.ResourceEventModel.{Names ⇒ ResourceEventNames}
 import gr.grnet.aquarium.store._
-import gr.grnet.aquarium.event.WalletEntry.{JsonNames ⇒ WalletJsonNames}
-import gr.grnet.aquarium.event.PolicyEntry.{JsonNames ⇒ PolicyJsonNames}
+import gr.grnet.aquarium.event.model.WalletEntry.{JsonNames ⇒ WalletJsonNames}
+import gr.grnet.aquarium.event.model.PolicyEntry.{JsonNames ⇒ PolicyJsonNames}
 import java.util.Date
 import gr.grnet.aquarium.logic.accounting.Policy
 import com.mongodb._
@@ -55,6 +54,7 @@ import com.ckkloverdos.maybe.Maybe
 import gr.grnet.aquarium.util._
 import gr.grnet.aquarium.converter.Conversions
 import gr.grnet.aquarium.computation.UserState
+import gr.grnet.aquarium.event.model.{ExternalEventModel, WalletEntry, PolicyEntry}
 
 /**
  * Mongodb implementation of the various aquarium stores.
@@ -104,6 +104,10 @@ class MongoDBStore(
     MongoDBResourceEvent.fromOther(event, null)
   }
 
+  def pingResourceEventStore(): Unit = {
+    MongoDBStore.ping(mongo)
+  }
+
   def insertResourceEvent(event: ResourceEventModel) = {
     val localEvent = MongoDBResourceEvent.fromOther(event, new ObjectId().toStringMongod)
     MongoDBStore.insertObject(localEvent, resourceEvents, MongoDBStore.jsonSupportToDBObject)
@@ -330,6 +334,10 @@ class MongoDBStore(
     MongoDBStore.createIMEventFromOther(event)
   }
 
+  def pingIMEventStore(): Unit = {
+    MongoDBStore.ping(mongo)
+  }
+
   def insertIMEvent(event: IMEventModel): IMEvent = {
     val localEvent = MongoDBIMEvent.fromOther(event, new ObjectId().toStringMongod)
     MongoDBStore.insertObject(localEvent, imEvents, MongoDBStore.jsonSupportToDBObject)
@@ -371,7 +379,7 @@ object MongoDBStore {
   }
 
   /**
-   * Collection holding the [[gr.grnet.aquarium.event.resource.ResourceEventModel]]s.
+   * Collection holding the [[gr.grnet.aquarium.event.model.resource.ResourceEventModel]]s.
    *
    * Resource events are coming from all systems handling billable resources.
    */
@@ -385,14 +393,14 @@ object MongoDBStore {
   final val USER_STATES_COLLECTION = "userstates"
 
   /**
-   * Collection holding [[gr.grnet.aquarium.event.im.IMEventModel]]s.
+   * Collection holding [[gr.grnet.aquarium.event.model.im.IMEventModel]]s.
    *
    * User events are coming from the IM module (external).
    */
   final val IM_EVENTS_COLLECTION = "imevents"
 
   /**
-   * Collection holding [[gr.grnet.aquarium.event.im.IMEventModel]]s that could not be parsed to normal objects.
+   * Collection holding [[gr.grnet.aquarium.event.model.im.IMEventModel]]s that could not be parsed to normal objects.
    *
    * We of course assume at least a valid JSON representation.
    *
@@ -401,7 +409,7 @@ object MongoDBStore {
   final val UNPARSED_IM_EVENTS_COLLECTION = "unparsed_imevents"
 
   /**
-   * Collection holding [[gr.grnet.aquarium.event.WalletEntry]].
+   * Collection holding [[gr.grnet.aquarium.event.model.WalletEntry]].
    *
    * Wallet entries are generated internally in Aquarium.
    */
@@ -413,7 +421,7 @@ object MongoDBStore {
 //  final val POLICIES_COLLECTION = "policies"
 
   /**
-   * Collection holding [[gr.grnet.aquarium.event.PolicyEntry]].
+   * Collection holding [[gr.grnet.aquarium.event.model.PolicyEntry]].
    */
   final val POLICY_ENTRIES_COLLECTION = "policyEntries"
 
@@ -429,6 +437,11 @@ object MongoDBStore {
     PolicyEntry.fromJson(JSON.serialize(dbObj))
   }
 
+  def ping(mongo: Mongo): Unit = {
+    // This requires a network roundtrip
+    mongo.isLocked
+  }
+
   def findBy[A >: Null <: AnyRef](name: String,
                                   value: String,
                                   collection: DBCollection,