Skip to content
Open

Coral #156

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f0455a4
Merge branch 'dev' into coral
brunokam May 7, 2014
8ca1c44
i07t04: Connectivity between the webservice and the core of Coral
brunokam May 8, 2014
c6011f4
i07t05: Coral workers implementation
brunokam May 10, 2014
362da82
Merge branch 'dev' into coral
brunokam May 16, 2014
0d848fc
Merge branch 'lionfish' of https://github.com/OceanVision/ocean into …
kudkudak May 18, 2014
0062adc
Clean-up graph_workers directory. By mistake
kudkudak May 18, 2014
f537a9c
Few modifications
kudkudak May 18, 2014
f5e01e0
Merge branch 'lionfish' of https://github.com/OceanVision/ocean into …
kudkudak May 19, 2014
900609a
Extended don corleone config parsing
kudkudak May 19, 2014
303b6a6
Lionfish_scala working
kudkudak May 19, 2014
3b85dc3
Passing tests, added new unit test.
kudkudak May 19, 2014
bd9cac0
Merge branch 'lionfish' of https://github.com/OceanVision/ocean into …
kudkudak May 19, 2014
328d072
Fixed (prototyped) params in lionfish.
kudkudak May 19, 2014
46e055f
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 19, 2014
1c5034c
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 20, 2014
d02b7b6
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 20, 2014
537884c
Fix build.sbt Please remember to add lionfish and neo4j
kudkudak May 21, 2014
cab31c6
Just to make sure added utf-8 encryption
kudkudak May 21, 2014
c9a8a49
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 21, 2014
fcafc9d
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 21, 2014
6a8aa97
Merge branch 'lionfish' of github.com:OceanVision/ocean into coral
brunokam May 21, 2014
68b13a2
i07t05: Coral workers implementation
brunokam May 21, 2014
cfe631a
i07t05: Coral workers implementation
brunokam May 21, 2014
a9d2cb9
i07t06: Introduction of Memcached in both Coral and Lionfish
brunokam May 22, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Binary files
*.pyc
*.jar
lionfish/project/
lionfish/target/
lionfish/lib/
*.jar
coral/core/project/
coral/core/target/

# Temporary files
*.~lock*
Expand Down
28 changes: 17 additions & 11 deletions coral/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,26 @@ The methods returns (in a HTTP response) a serialised **object**:

***

The whole communication begins when a client requests a handshake. It may be performed by a special operation:
The whole communication begins when the client requests a handshake. It may be performed by a special operation:

#### handshake

Parameter contains keys:
* _client_key_ `string`

Returned value: **object**

Returned value contains keys:
* _coral_key_ `string`
* _status_ `bool`
* _client_id_ `string`

***

When keys are successfully exchanged and a client ID is assigned, then a client service is eligible to perform other requests:
When the client ID is assigned, then the client service is eligible to perform other requests:

#### sign_in

Parameter contains keys:
* _client_id_ `string`
* _username_ `string`
* _password_ `string`
* _client_id_ `string`

Returned value: **object**

Expand Down Expand Up @@ -71,10 +68,12 @@ Parameter contains keys:
Returned value: **object**

Returned value contains keys:
* _status_ `bool`
* _article_list_ `list[object]`

Each element of _article_list_ contains keys:
* _article_id_ `string`
* _link_ `string`
* _author_ `string`
* _title_ `string`
* _time_ `int`
Expand All @@ -84,12 +83,13 @@ Each element of _article_list_ contains keys:
#### get_article_details

Parameter contains keys:
* _article_id_ `string`
* _client_id_ `string`
* _article_id_ `string`

Returned value: **object**

Returned value contains keys:
* _status_ `bool`
* _article_id_ `string`
* _body_ `string`

Expand All @@ -101,20 +101,26 @@ Parameter contains keys:
Returned value: **object**

Returned value contains keys:
* _status_ `bool`
* _feed_list_ `list[object]`

Each element of _feed_list_ contains keys:
* _link_ `string`
* _title_ `string`
* _id_ `string`
* _name_ `string`
* _included_tag_list_ `list[string]`
* _excluded_tag_list_ `list[string]`

#### create_feed

Parameter contains keys:
* _feed_tags_ `list[string]`
* _client_id_ `string`
* _name_ `string`
* _included_tag_list_ `list[string]`
* _excluded_tag_list_ `list[string]`

Returned value: **object**

Returned value contains keys:
* _status_ `bool`
* _non_existing_tag_list_ `list[string]`

16 changes: 16 additions & 0 deletions coral/core/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name := "coral-core"

version := "0.9"

scalaVersion := "2.10.4"

mainClass in (Compile, run) := Some("com.coral.connector.Launcher")

resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"

libraryDependencies ++= Seq("com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.3.3")

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.2",
"com.typesafe.akka" %% "akka-remote" % "2.3.2"
)
5 changes: 5 additions & 0 deletions coral/core/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

sbt << EOF
run
EOF
Empty file.
21 changes: 21 additions & 0 deletions coral/core/src/main/resources/cacheWorkerSystem.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include "application"

akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/parent/cacheWorkerPool {
router = round-robin-pool
nr-of-instances = 5
target.nodes = ["akka.tcp://cacheWorkerSystem@localhost:7781"]
}
}
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost",
port = 7781
}
}
}
21 changes: 21 additions & 0 deletions coral/core/src/main/resources/databaseWorkerSystem.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include "application"

akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
deployment {
/parent/databaseWorkerPool {
router = round-robin-pool
nr-of-instances = 5
target.nodes = ["akka.tcp://databaseWorkerSystem@localhost:7782"]
}
}
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost",
port = 7782
}
}
}
14 changes: 14 additions & 0 deletions coral/core/src/main/resources/masterSystem.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include "application"

akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost",
port = 7779
}
}
}
14 changes: 14 additions & 0 deletions coral/core/src/main/resources/sessionWorkerSystem.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
include "application"

akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname = "localhost",
port = 7780
}
}
}
48 changes: 48 additions & 0 deletions coral/core/src/main/scala/com/coral/connector/Launcher.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.coral.connector

import com.coral.utils.Config

object Launcher {
private def configure(args: Array[String]) = {
for (item <- args) {
val arg = item.split("=")
arg(0) match {
case "--num-of-request-handlers" => {
try {
val value = arg(1).toInt
if (value > 0) {
Config.numberOfRequestHandlers = value
}
} catch {
case e: Exception => println("Invalid parameter: num-of-request-handlers")
}
}
case "--num-of-cache-workers" => {
try {
val value = arg(1).toInt
if (value > 0) {
Config.numberOfCacheWorkers = value
}
} catch {
case e: Exception => println("Invalid parameter: num-of-cache-workers")
}
}
case "--num-of-db-workers" => {
try {
val value = arg(1).toInt
if (value > 0) {
Config.numberOfDatabaseWorkers = value
}
} catch {
case e: Exception => println("Invalid parameter: num-of-db-workers")
}
}
}
}
}

def main(args: Array[String]) = {
configure(args)
new Thread(WebserviceConnector).start()
}
}
28 changes: 28 additions & 0 deletions coral/core/src/main/scala/com/coral/connector/RequestHandler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.coral.connector

import java.net.Socket
import java.util.UUID
import akka.actor._
import com.coral.utils.IO
import com.coral.messages._

class RequestHandler(private val master: ActorRef) extends Actor {
private val uuid = UUID.randomUUID().toString
private implicit var socket: Socket = null

def handle() = {
// Processes request
val request = IO.receive[Map[String, Any]]()
master ! Request(uuid, request)
}

def receive = {
case Connection(newSocket) => {
socket = newSocket
handle()
}
case Response(_, _, result) => {
IO.send(result)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.coral.connector

import java.net.ServerSocket
import akka.actor.{Props, ActorSystem}
import akka.routing.RoundRobinPool
import com.typesafe.config.ConfigFactory
import com.coral.workers._
import com.coral.messages.Connection
import com.coral.utils.Config

object WebserviceConnector extends Runnable {
private val port = Config.webserviceConnectorPort

// Creates cache workers
private val cacheWorkerSystem = ActorSystem(
"cacheWorkerSystem", ConfigFactory.load("cacheWorkerSystem"))
private val cacheWorkerPool = cacheWorkerSystem.actorOf(
Props(new CacheWorker).withRouter(
RoundRobinPool(Config.numberOfCacheWorkers)), "cacheWorkerPool")
println("Starting " + Config.numberOfCacheWorkers + " cache workers.")

// Creates database workers
private val databaseWorkerSystem = ActorSystem(
"databaseWorkerSystem", ConfigFactory.load("databaseWorkerSystem"))
private val databaseWorkerPool = databaseWorkerSystem.actorOf(
Props(new DatabaseWorker).withRouter(
RoundRobinPool(Config.numberOfDatabaseWorkers)), "databaseWorkerPool")
println("Starting " + Config.numberOfDatabaseWorkers + " database workers.")

// Creates session worker
private val sessionWorkerSystem = ActorSystem(
"sessionWorkerSystem", ConfigFactory.load("sessionWorkerSystem"))
private val sessionWorker = sessionWorkerSystem.actorOf(Props(new SessionWorker), "sessionWorker")
println("Starting session worker.")

// Creates master worker
private val masterSystem = ActorSystem(
"masterSystem", ConfigFactory.load("masterSystem"))
private val master = masterSystem.actorOf(Props(new Master), "master")
println("Starting master.")

// Creates request handlers
private val requestHandlerSystem = ActorSystem("requestHandlerSystem")
private val requestHandlerPool = requestHandlerSystem.actorOf(
Props(new RequestHandler(master)).withRouter(
RoundRobinPool(Config.numberOfRequestHandlers)), "requestHandlerPool")
println("Starting " + Config.numberOfRequestHandlers + " request handlers.")

private def handleConnections(serverSocket: ServerSocket) = {
while (true) {
val socket = serverSocket.accept()
requestHandlerPool ! Connection(socket)
}
}

def run() = {
try {
// Initialises socket
val serverSocket = new ServerSocket(port)

handleConnections(serverSocket)
serverSocket.close()
} catch {
case e: Exception => {
println(s"Failed to start the Coral webservice connector. Error message: $e")
}
} finally {
println("The Coral webservice connector terminated.")
}
}
}
5 changes: 5 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/Connection.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.coral.messages

import java.net.Socket

case class Connection(socket: Socket) extends Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/Handshake.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class Handshake() extends Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/Message.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

trait Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/Request.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class Request(uuid: String, request: Map[String, Any]) extends Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/Response.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class Response(uuid: String, request: Map[String, Any], result: Any) extends Message
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class SessionDetails(clientUuid: String) extends Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/SignIn.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class SignIn(clientUuid: String, userUuid: String) extends Message
3 changes: 3 additions & 0 deletions coral/core/src/main/scala/com/coral/messages/SignOut.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.coral.messages

case class SignOut(clientUuid: String) extends Message
Loading