<artifactId>xstream</artifactId>
<version>1.4.1</version>
</dependency>
+
+ <dependency>
+ <groupId>org.mongodb</groupId>
+ <artifactId>mongo-java-driver</artifactId>
+ <version>2.7.2</version>
+ </dependency>
+
+ <!-- Official MongoDB scala driver -->
+ <!-- For issues with the driver see: https://jira.mongodb.org/browse/SCALA -->
+ <dependency>
+ <groupId>com.mongodb.casbah</groupId>
+ <artifactId>casbah-core_2.9.1</artifactId>
+ <version>2.1.5-1</version>
+ </dependency>
</dependencies>
</project>
--- /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.store
+
+/**
+ * Represents an ID given to a message by the store.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class MessageID(id: String)
\ 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.store
+
+import com.ckkloverdos.maybe.Maybe
+import net.liftweb.json.JsonAST.JValue
+
+
+/**
+ * An abstraction for message stores. We assume that our messages are
+ * documents with a string representation, e.g. `JSON`.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+trait MessageStore {
+ def storeString(message: String): Maybe[MessageID]
+
+ def storeJson(json: JValue): Maybe[MessageID] = {
+ storeString(json.toString)
+ }
+}
\ 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.store
+package mongodb
+
+import confmodel.MongoDBConfigurationModel
+import com.mongodb.casbah.MongoConnection
+import com.mongodb.{WriteConcern, ServerAddress}
+import gr.grnet.aquarium.util.Loggable
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBConnection(val confModel: MongoDBConfigurationModel) extends Loggable {
+
+ private[mongodb] lazy val _mongoConnection = {
+ val hosts = confModel.hosts
+ val serverAddresses = hosts.map(sacm => new ServerAddress(sacm.host, sacm.port))
+
+ val mongo = MongoConnection(serverAddresses)
+ logger.info("Created MongoDB connection %s".format(mongo))
+
+ if(confModel.slaveOK) {
+ mongo.slaveOk()
+ logger.info("Set slaveOK for MongoDB connection %s".format(mongo))
+ }
+ val writeConcern = WriteConcern.valueOf(confModel.writeConcern)
+ mongo.setWriteConcern(writeConcern)
+ logger.info("Set WriteConcern %s for MongoDB connection %s".format(confModel.writeConcern, mongo))
+
+ mongo
+ }
+}
+
+object MongoDBConnection {
+ object RCFolders {
+ val mongodb = "mongodb"
+ }
+
+ object PropFiles {
+ val local_message_store = "local-message-store.xml"
+ }
+
+ object DBNames {
+ val test = "test"
+ }
+
+ object CollectionNames {
+ val test = "test"
+ }
+}
\ 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.store.mongodb
+
+import gr.grnet.aquarium.store.MessageStore
+import com.ckkloverdos.maybe.NoVal
+
+/**
+ * Mongodb implementation of the message store.
+ *
+ * Using Casbah as the underlying library.
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBStore(connection: MongoDBConnection) extends MessageStore {
+ def storeString(message: String) = {
+ val mongo = connection._mongoConnection
+
+ // FIXME: implement
+ NoVal
+ }
+}
\ 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.store.mongodb
+package confmodel
+
+import com.mongodb.ServerAddress
+
+////////////////////////////////////////////////////////////////////////////
+// The WriteConcerns are as follows:
+////////////////////////////////////////////////////////////////////////////
+// NONE: No exceptions are raised, even for network issues
+// NORMAL: Exceptions are raised for network issues, but not server errors
+// SAFE: Exceptions are raised for network issues, and server errors; waits on a server for the write operation
+// MAJORITY: Exceptions are raised for network issues, and server errors; waits on a majority of servers for the write operation
+// FSYNC_SAFE: Exceptions are raised for network issues, and server errors; the write operation waits for the server to flush the data to disk
+// JOURNAL_SAFE: Exceptions are raised for network issues, and server errors; the write operation waits for the server to group commit to the journal file on disk
+// REPLICAS_SAFE: Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation
+////////////////////////////////////////////////////////////////////////////
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class MongoDBConfigurationModel(
+ hosts: List[ServerAddressConfigurationModel],
+ slaveOK: Boolean,
+ writeConcern: String)
\ 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.store.mongodb.confmodel
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+case class ServerAddressConfigurationModel(host: String, port: Int)
\ No newline at end of file
import com.ckkloverdos.maybe.{Failed, Just, Maybe}
import com.ckkloverdos.resource.StreamResource
import gr.grnet.aquarium.messaging.amqp.rabbitmq.v091.confmodel._
+import gr.grnet.aquarium.store.mongodb.confmodel._
/**
}
def prepareXStreamAliases(xs: XStream): XStream = {
+ // RabbitMQ
prepareXStreamAlias[RabbitMQConfigurationsModel](xs)
prepareXStreamAlias[RabbitMQConfigurationModel](xs)
prepareXStreamAlias[RabbitMQConnectionModel](xs)
prepareXStreamAlias[RabbitMQProducerModel](xs)
prepareXStreamAlias[RabbitMQConsumerModel](xs)
+ // MongoDB
+ prepareXStreamAlias[MongoDBConfigurationModel](xs)
+ prepareXStreamAlias[ServerAddressConfigurationModel](xs)
+
xs.alias("List", classOf[::[_]])
xs.alias("Nil", manifest[Nil.type].erasure)
xs
--- /dev/null
+<MongoDBConfigurationModel>
+ <slaveOK>true</slaveOK>
+ <writeConcern>SAFE</writeConcern>
+ <hosts class="List">
+ <ServerAddressConfigurationModel>
+ <host>aquarium.dev.grnet.gr</host>
+ <port>27017</port>
+ </ServerAddressConfigurationModel>
+ </hosts>
+</MongoDBConfigurationModel>
xml
}
+
@Test
def testConfigurationsExist {
assertTrue(rabbitmqRC.getResource(PropFiles.configurations).isJust)
--- /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.store
+package mongodb
+
+import confmodel.{ServerAddressConfigurationModel, MongoDBConfigurationModel}
+import org.junit.Test
+import org.junit.Assert._
+
+import com.ckkloverdos.resource.DefaultResourceContext
+import MongoDBConnection.{RCFolders, PropFiles, DBNames, CollectionNames}
+import gr.grnet.aquarium.util.xstream.XStreamHelpers
+import com.mongodb.casbah.commons.MongoDBObject
+
+/**
+ *
+ * @author Christos KK Loverdos <loverdos@gmail.com>.
+ */
+class MongoDBStoreTest {
+ val baseRC = DefaultResourceContext
+ val mongodbRC = baseRC / RCFolders.mongodb
+ val xs = XStreamHelpers.newXStream
+
+ private def _getTestConf: String = {
+ val address1 = ServerAddressConfigurationModel("aquarium.dev.grnet.gr", 27017)
+ val model = new MongoDBConfigurationModel(List(address1), true, "SAFE")
+ val xml = xs.toXML(model)
+ xml
+ }
+
+ @Test
+ def testConfigurationExists: Unit = {
+ assertTrue(mongodbRC.getLocalResource(PropFiles.local_message_store).isJust)
+ }
+
+ @Test
+ def testConnection: Unit = {
+ for {
+ confResource <- mongodbRC.getLocalResource(PropFiles.local_message_store)
+ } {
+ val xs = XStreamHelpers.newXStream
+ val maybeModel = XStreamHelpers.parseType[MongoDBConfigurationModel](confResource, xs)
+ assertTrue(maybeModel.isJust)
+ for(model <- maybeModel) {
+ val mongo = new MongoDBConnection(model)
+ println(mongo._mongoConnection)
+ println(mongo._mongoConnection.getAllAddress())
+ println(mongo._mongoConnection.getConnectPoint())
+ val db = mongo._mongoConnection(DBNames.test)
+ val collection = db.apply(CollectionNames.test)
+ val obj = MongoDBObject("1" -> "one", "2" -> "two")
+ collection.insert(obj)
+ }
+ }
+ }
+}
\ No newline at end of file
val lib_yaml = "org.yaml" % "snakeyaml" % "1.9" withSources()
val lib_jcrontab = "com.kenai.crontab-parser" % "crontab-parser" % "1.0.1" withSources()
val lib_xstream = "com.thoughtworks.xstream" % "xstream" % "1.4.1" withSources()
- val lib_rabbit = "com.rabbitmq" % "amqp-client" % "2.7.0" withSources()
+ val lib_rabbit = "com.rabbitmq" % "amqp-client" % "2.7.0" withSources()
+// val lib_mongo = "org.mongodb" % "mongo-java-driver" % "2.7.2" withSources()
+ val lib_casbah = "com.mongodb.casbah" % "casbah-core_2.9.1" % "2.1.5-1" withSources()
val lib_converter = "com.ckkloverdos" % "converter_2.9.1" % "0.3.0" withSources()
val lib_streamresource = "com.ckkloverdos" % "streamresource_2.9.1" % "0.2.0" withSources()