[3/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f2311f25/s2rest_play/app/controllers/AdminController.scala
--
diff --git a/s2rest_play/app/controllers/AdminController.scala 
b/s2rest_play/app/controllers/AdminController.scala
new file mode 100644
index 000..2eb248b
--- /dev/null
+++ b/s2rest_play/app/controllers/AdminController.scala
@@ -0,0 +1,419 @@
+package controllers
+
+import com.kakao.s2graph.core._
+import com.kakao.s2graph.core.mysqls._
+import com.kakao.s2graph.core.rest.RequestParser
+import com.kakao.s2graph.core.utils.logger
+import play.api.mvc
+import play.api.mvc.{Action, Controller}
+import play.api.libs.json._
+import play.api.libs.functional.syntax._
+
+import scala.util.{Failure, Success, Try}
+
+object AdminController extends Controller {
+
+  import ApplicationController._
+  private val requestParser: RequestParser = 
com.kakao.s2graph.rest.Global.s2parser
+
+  /**
+   * admin message formatter
+   * @tparam T
+   */
+  trait AdminMessageFormatter[T] {
+def toJson(msg: T): JsValue
+  }
+
+  object AdminMessageFormatter {
+implicit def jsValueToJson[T <: JsValue] = new AdminMessageFormatter[T] {
+  def toJson(js: T) = js
+}
+
+implicit val stringToJson = new AdminMessageFormatter[String] {
+  def toJson(js: String) = Json.obj("message" -> js)
+}
+  }
+
+  def format[T: AdminMessageFormatter](f: JsValue => play.mvc.Result)(message: 
T) = {
+val formatter = implicitly[AdminMessageFormatter[T]]
+f(formatter.toJson(message))
+  }
+
+  /**
+   * ok response
+   * @param message
+   * @tparam T
+   * @return
+   */
+  def ok[T: AdminMessageFormatter](message: T) = {
+val formatter = implicitly[AdminMessageFormatter[T]]
+Ok(formatter.toJson(message)).as(applicationJsonHeader)
+  }
+
+  /**
+   * bad request response
+   * @param message
+   * @tparam T
+   * @return
+   */
+  def bad[T: AdminMessageFormatter](message: T) = {
+val formatter = implicitly[AdminMessageFormatter[T]]
+BadRequest(formatter.toJson(message)).as(applicationJsonHeader)
+  }
+
+  /**
+   * not found response
+   * @param message
+   * @tparam T
+   * @return
+   */
+  def notFound[T: AdminMessageFormatter](message: T) = {
+val formatter = implicitly[AdminMessageFormatter[T]]
+NotFound(formatter.toJson(message)).as(applicationJsonHeader)
+  }
+
+  private[AdminController] def tryResponse[T, R: AdminMessageFormatter](res: 
Try[T])(callback: T => R): mvc.Result = res match {
+case Success(m) =>
+  val ret = callback(m)
+  logger.info(ret.toString)
+  ok(ret)
+case Failure(error) =>
+  logger.error(error.getMessage, error)
+  error match {
+case JsResultException(e) => bad(JsError.toFlatJson(e))
+case _ => bad(error.getMessage)
+  }
+  }
+
+  def optionResponse[T, R: AdminMessageFormatter](res: Option[T])(callback: T 
=> R): mvc.Result = res match {
+case Some(m) => ok(callback(m))
+case None => notFound("not found")
+  }
+
+  /**
+   * load all model cache
+   * @return
+   */
+  def loadCache() = Action { request =>
+val startTs = System.currentTimeMillis()
+
+if (!ApplicationController.isHealthy) {
+  loadCacheInner()
+}
+
+ok(s"${System.currentTimeMillis() - startTs}")
+  }
+
+  def loadCacheInner() = {
+Service.findAll()
+ServiceColumn.findAll()
+Label.findAll()
+LabelMeta.findAll()
+LabelIndex.findAll()
+ColumnMeta.findAll()
+  }
+
+  /**
+   * read
+   */
+
+  /**
+   * get service info
+   * @param serviceName
+   * @return
+   */
+  def getService(serviceName: String) = Action { request =>
+val serviceOpt = Management.findService(serviceName)
+optionResponse(serviceOpt)(_.toJson)
+  }
+
+  /**
+   * get label info
+   * @param labelName
+   * @return
+   */
+  def getLabel(labelName: String) = Action { request =>
+val labelOpt = Management.findLabel(labelName)
+optionResponse(labelOpt)(_.toJson)
+  }
+
+  /**
+   * get all labels of service
+   * @param serviceName
+   * @return
+   */
+  def getLabels(serviceName: String) = Action { request =>
+Service.findByName(serviceName) match {
+  case None => notFound(s"Service $serviceName not found")
+  case Some(service) =>
+val src = Label.findBySrcServiceId(service.id.get)
+val tgt = Label.findByTgtServiceId(service.id.get)
+
+ok(Json.obj("from" -> src.map(_.toJson), "to" -> tgt.map(_.toJson)))
+}
+  }
+
+  /**
+   * get service columns
+   * @param serviceName
+   * @param columnName
+   * @return
+   */
+  def getServiceColumn(serviceName: String, columnName: String) = Action { 
request =>
+val serviceColumnOpt = for {
+  service <- Service.findByName(serviceName)
+  serviceColumn <- ServiceColumn.find(service.id.get, columnName, useCache 
= false)
+} yield serviceColumn
+
+optionResponse(serviceColumnOpt)(_.toJson)
+  }
+
+  /**
+   * create
+   */

[5/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f2311f25/s2core/src/main/scala/com/kakao/s2graph/core/OrderingUtil.scala
--
diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/OrderingUtil.scala 
b/s2core/src/main/scala/com/kakao/s2graph/core/OrderingUtil.scala
index 217b6eb..33ec7d9 100644
--- a/s2core/src/main/scala/com/kakao/s2graph/core/OrderingUtil.scala
+++ b/s2core/src/main/scala/com/kakao/s2graph/core/OrderingUtil.scala
@@ -3,9 +3,6 @@ package com.kakao.s2graph.core
 import com.kakao.s2graph.core.types.InnerValLike
 import play.api.libs.json.{JsNumber, JsString, JsValue}
 
-/**
- * Created by hsleep(honeysl...@gmail.com) on 2015. 11. 5..
- */
 object OrderingUtil {
 
   implicit object JsValueOrdering extends Ordering[JsValue] {
@@ -38,9 +35,54 @@ object OrderingUtil {
   }
 }
   }
+
+  def TupleMultiOrdering[T](ascendingLs: Seq[Boolean])(implicit ord: 
Ordering[T]): Ordering[(T, T, T, T)] = {
+new Ordering[(T, T, T, T)] {
+  override def compare(tx: (T, T, T, T), ty: (T, T, T, T)): Int = {
+val len = ascendingLs.length
+val it = ascendingLs.iterator
+if (len >= 1) {
+  val (x, y) = it.next() match {
+case true => tx -> ty
+case false => ty -> tx
+  }
+  val compare1 = ord.compare(x._1, y._1)
+  if (compare1 != 0) return compare1
+}
+
+if (len >= 2) {
+  val (x, y) = it.next() match {
+case true => tx -> ty
+case false => ty -> tx
+  }
+  val compare2 = ord.compare(x._2, y._2)
+  if (compare2 != 0) return compare2
+}
+
+if (len >= 3) {
+  val (x, y) = it.next() match {
+case true => tx -> ty
+case false => ty -> tx
+  }
+  val compare3 = ord.compare(x._3, y._3)
+  if (compare3 != 0) return compare3
+}
+
+if (len >= 4) {
+  val (x, y) = it.next() match {
+case true => tx -> ty
+case false => ty -> tx
+  }
+  val compare4 = ord.compare(x._4, y._4)
+  if (compare4 != 0) return compare4
+}
+0
+  }
+}
+  }
 }
 
-class SeqMultiOrdering[T: Ordering](ascendingLs: Seq[Boolean], 
defaultAscending: Boolean = true)(implicit ord: Ordering[T]) extends 
Ordering[Seq[T]] {
+class SeqMultiOrdering[T](ascendingLs: Seq[Boolean], defaultAscending: Boolean 
= true)(implicit ord: Ordering[T]) extends Ordering[Seq[T]] {
   override def compare(x: Seq[T], y: Seq[T]): Int = {
 val xe = x.iterator
 val ye = y.iterator
@@ -60,45 +102,45 @@ class SeqMultiOrdering[T: Ordering](ascendingLs: 
Seq[Boolean], defaultAscending:
   }
 }
 
-class TupleMultiOrdering[T: Ordering](ascendingLs: Seq[Boolean])(implicit ord: 
Ordering[T]) extends Ordering[(T, T, T, T)] {
-  override def compare(tx: (T, T, T, T), ty: (T, T, T, T)): Int = {
-val len = ascendingLs.length
-val it = ascendingLs.iterator
-if (len >= 1) {
-  val (x, y) = it.next() match {
-case true => tx -> ty
-case false => ty -> tx
-  }
-  val compare1 = ord.compare(x._1, y._1)
-  if (compare1 != 0) return compare1
-}
-
-if (len >= 2) {
-  val (x, y) = it.next() match {
-case true => tx -> ty
-case false => ty -> tx
-  }
-  val compare2 = ord.compare(x._2, y._2)
-  if (compare2 != 0) return compare2
-}
-
-if (len >= 3) {
-  val (x, y) = it.next() match {
-case true => tx -> ty
-case false => ty -> tx
-  }
-  val compare3 = ord.compare(x._3, y._3)
-  if (compare3 != 0) return compare3
-}
-
-if (len >= 4) {
-  val (x, y) = it.next() match {
-case true => tx -> ty
-case false => ty -> tx
-  }
-  val compare4 = ord.compare(x._4, y._4)
-  if (compare4 != 0) return compare4
-}
-0
-  }
-}
+//class TupleMultiOrdering[T](ascendingLs: Seq[Boolean])(implicit ord: 
Ordering[T]) extends Ordering[(T, T, T, T)] {
+//  override def compare(tx: (T, T, T, T), ty: (T, T, T, T)): Int = {
+//val len = ascendingLs.length
+//val it = ascendingLs.iterator
+//if (len >= 1) {
+//  val (x, y) = it.next() match {
+//case true => tx -> ty
+//case false => ty -> tx
+//  }
+//  val compare1 = ord.compare(x._1, y._1)
+//  if (compare1 != 0) return compare1
+//}
+//
+//if (len >= 2) {
+//  val (x, y) = it.next() match {
+//case true => tx -> ty
+//case false => ty -> tx
+//  }
+//  val compare2 = ord.compare(x._2, y._2)
+//  if (compare2 != 0) return compare2
+//}
+//
+//if (len >= 3) {
+//  val (x, y) = it.next() match {
+//case true => tx -> ty
+//case false => ty -> tx
+//  }
+//  val compare3 = ord.compare(x._3, y._3)
+//  if (compare3 != 0) return compare3
+//}
+//
+//if (len >= 4) {

[4/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f2311f25/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
--
diff --git 
a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala 
b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
new file mode 100644
index 000..5b0dfbd
--- /dev/null
+++ b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
@@ -0,0 +1,528 @@
+package com.kakao.s2graph.core.Integrate
+
+import org.scalatest.BeforeAndAfterEach
+import play.api.libs.json._
+
+class QueryTest extends IntegrateCommon with BeforeAndAfterEach {
+
+  import TestUtil._
+
+  val insert = "insert"
+  val e = "e"
+  val weight = "weight"
+  val is_hidden = "is_hidden"
+
+  test("interval") {
+def queryWithInterval(id: Int, index: String, prop: String, fromVal: Int, 
toVal: Int) = Json.parse(
+  s"""
+{ "srcVertices": [
+  { "serviceName": "$testServiceName",
+"columnName": "$testColumnName",
+"id": $id
+   }],
+  "steps": [
+  [ {
+  "label": "$testLabelName",
+  "index": "$index",
+  "interval": {
+  "from": [ { "$prop": $fromVal } ],
+  "to": [ { "$prop": $toVal } ]
+  }
+}
+  ]]
+}
+""")
+
+var edges = getEdgesSync(queryWithInterval(0, index2, "_timestamp", 1000, 
1001)) // test interval on timestamp index
+(edges \ "size").toString should be("1")
+
+edges = getEdgesSync(queryWithInterval(0, index2, "_timestamp", 1000, 
2000)) // test interval on timestamp index
+(edges \ "size").toString should be("2")
+
+edges = getEdgesSync(queryWithInterval(2, index1, "weight", 10, 11)) // 
test interval on weight index
+(edges \ "size").toString should be("1")
+
+edges = getEdgesSync(queryWithInterval(2, index1, "weight", 10, 20)) // 
test interval on weight index
+(edges \ "size").toString should be("2")
+  }
+
+  test("get edge with where condition") {
+def queryWhere(id: Int, where: String) = Json.parse(
+  s"""
+{ "srcVertices": [
+  { "serviceName": "${testServiceName}",
+"columnName": "${testColumnName}",
+"id": ${id}
+   }],
+  "steps": [
+  [ {
+  "label": "${testLabelName}",
+  "direction": "out",
+  "offset": 0,
+  "limit": 100,
+  "where": "${where}"
+}
+  ]]
+}""")
+
+var result = getEdgesSync(queryWhere(0, "is_hidden=false and _from in (-1, 
0)"))
+(result \ "results").as[List[JsValue]].size should be(1)
+
+result = getEdgesSync(queryWhere(0, "is_hidden=true and _to in (1)"))
+(result \ "results").as[List[JsValue]].size should be(1)
+
+result = getEdgesSync(queryWhere(0, "_from=0"))
+(result \ "results").as[List[JsValue]].size should be(2)
+
+result = getEdgesSync(queryWhere(2, "_from=2 or weight in (-1)"))
+(result \ "results").as[List[JsValue]].size should be(2)
+
+result = getEdgesSync(queryWhere(2, "_from=2 and weight in (10, 20)"))
+(result \ "results").as[List[JsValue]].size should be(2)
+  }
+
+  test("get edge exclude") {
+def queryExclude(id: Int) = Json.parse(
+  s"""
+{ "srcVertices": [
+  { "serviceName": "${testServiceName}",
+"columnName": "${testColumnName}",
+"id": ${id}
+   }],
+  "steps": [
+  [ {
+  "label": "${testLabelName}",
+  "direction": "out",
+  "offset": 0,
+  "limit": 2
+},
+{
+  "label": "${testLabelName}",
+  "direction": "in",
+  "offset": 0,
+  "limit": 2,
+  "exclude": true
+}
+  ]]
+}""")
+
+val result = getEdgesSync(queryExclude(0))
+(result \ "results").as[List[JsValue]].size should be(1)
+  }
+
+  test("get edge groupBy property") {
+def queryGroupBy(id: Int, props: Seq[String]): JsValue = {
+  Json.obj(
+"groupBy" -> props,
+"srcVertices" -> Json.arr(
+  Json.obj("serviceName" -> testServiceName, "columnName" -> 
testColumnName, "id" -> id)
+),
+"steps" -> Json.arr(
+  Json.obj(
+"step" -> Json.arr(
+  Json.obj(
+"label" -> testLabelName
+  )
+)
+  )
+)
+  )
+}
+
+val result = getEdgesSync(queryGroupBy(0, Seq("weight")))
+(result \ "size").as[Int] should be(2)
+val weights = (result \\ "groupBy").map { js =>
+  (js \ "weight").as[Int]
+}
+weights should contain(30)
+weights should contain(40)
+
+weights should not contain (10)
+  }
+
+  test("edge transform") {
+def queryTransform(id: Int, 

[6/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f2311f25/app/controllers/PostProcess.scala
--
diff --git a/app/controllers/PostProcess.scala 
b/app/controllers/PostProcess.scala
deleted file mode 100644
index bbc7266..000
--- a/app/controllers/PostProcess.scala
+++ /dev/null
@@ -1,432 +0,0 @@
-package controllers
-
-import com.kakao.s2graph.core._
-import com.kakao.s2graph.core.mysqls._
-import com.kakao.s2graph.core.types.{InnerVal, InnerValLike}
-import play.api.libs.json.{Json, _}
-
-import scala.collection.mutable.ListBuffer
-
-object PostProcess extends JSONParser {
-  /**
-   * Result Entity score field name
-   */
-  val SCORE_FIELD_NAME = "scoreSum"
-  val timeoutResults = Json.obj("size" -> 0, "results" -> Json.arr(), 
"isTimeout" -> true)
-  val reservedColumns = Set("cacheRemain", "from", "to", "label", "direction", 
"_timestamp", "timestamp", "score", "props")
-
-  def groupEdgeResult(queryRequestWithResultLs: Seq[QueryRequestWithResult], 
exclude: Seq[QueryRequestWithResult]) = {
-val excludeIds = resultInnerIds(exclude).map(innerId => innerId -> 
true).toMap
-//filterNot {case (edge, score) => 
edge.props.contains(LabelMeta.degreeSeq)}
-val groupedEdgesWithRank = (for {
-  queryRequestWithResult <- queryRequestWithResultLs
-  (queryRequest, queryResult) = 
QueryRequestWithResult.unapply(queryRequestWithResult).get
-  edgeWithScore <- queryResult.edgeWithScoreLs
-  (edge, score) = EdgeWithScore.unapply(edgeWithScore).get
-  if !excludeIds.contains(toHashKey(edge, queryRequest.queryParam, 
queryRequest.query.filterOutFields))
-} yield {
-(queryRequest.queryParam, edge, score)
-  }).groupBy {
-  case (queryParam, edge, rank) if edge.labelWithDir.dir == 
GraphUtil.directions("in") =>
-(queryParam.label.srcColumn, queryParam.label.label, 
queryParam.label.tgtColumn, edge.tgtVertex.innerId, edge.isDegree)
-  case (queryParam, edge, rank) =>
-(queryParam.label.tgtColumn, queryParam.label.label, 
queryParam.label.srcColumn, edge.tgtVertex.innerId, edge.isDegree)
-}
-
-val ret = for {
-  ((tgtColumn, labelName, srcColumn, target, isDegreeEdge), edgesAndRanks) 
<- groupedEdgesWithRank if !isDegreeEdge
-  edgesWithRanks = edgesAndRanks.groupBy(x => 
x._2.srcVertex).map(_._2.head)
-  id <- innerValToJsValue(target, tgtColumn.columnType)
-} yield {
-Json.obj("name" -> tgtColumn.columnName, "id" -> id,
-  SCORE_FIELD_NAME -> edgesWithRanks.map(_._3).sum,
-  "label" -> labelName,
-  "aggr" -> Json.obj(
-"name" -> srcColumn.columnName,
-"ids" -> edgesWithRanks.flatMap { case (queryParam, edge, rank) =>
-  innerValToJsValue(edge.srcVertex.innerId, srcColumn.columnType)
-},
-"edges" -> edgesWithRanks.map { case (queryParam, edge, rank) =>
-  Json.obj("id" -> innerValToJsValue(edge.srcVertex.innerId, 
srcColumn.columnType),
-"props" -> propsToJson(edge),
-"score" -> rank
-  )
-}
-  )
-)
-  }
-
-ret.toList
-  }
-
-  def sortWithFormatted(jsons: Seq[JsObject],
-scoreField: String = "scoreSum",
-queryRequestWithResultLs: Seq[QueryRequestWithResult],
-decrease: Boolean = true): JsObject = {
-val ordering = if (decrease) -1 else 1
-val sortedJsons = jsons.sortBy { jsObject => (jsObject \ 
scoreField).as[Double] * ordering }
-
-if (queryRequestWithResultLs.isEmpty) Json.obj("size" -> sortedJsons.size, 
"results" -> sortedJsons)
-else Json.obj(
-  "size" -> sortedJsons.size,
-  "results" -> sortedJsons,
-  "impressionId" -> 
queryRequestWithResultLs.head.queryRequest.query.impressionId()
-)
-  }
-
-  private def toHashKey(edge: Edge, queryParam: QueryParam, fields: 
Seq[String], delimiter: String = ","): Int = {
-val ls = for {
-  field <- fields
-} yield {
-field match {
-  case "from" | "_from" => edge.srcVertex.innerId
-  case "to" | "_to" => edge.tgtVertex.innerId
-  case "label" => edge.labelWithDir.labelId
-  case "direction" => 
JsString(GraphUtil.fromDirection(edge.labelWithDir.dir))
-  case "_timestamp" | "timestamp" => edge.ts
-  case _ =>
-queryParam.label.metaPropsInvMap.get(field) match {
-  case None => throw new RuntimeException(s"unknow column: $field")
-  case Some(labelMeta) => edge.propsWithTs.get(labelMeta.seq) 
match {
-case None => labelMeta.defaultValue
-case Some(propVal) => propVal
-  }
-}
-}
-  }
-val ret = ls.hashCode()
-ret
-  }
-
-  def resultInnerIds(queryRequestWithResultLs: Seq[QueryRequestWithResult], 
isSrcVertex: Boolean = false): Seq[Int] = 

[7/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
[S2GRAPH-7] Abstract common codes for rest project into s2core

  Move PostProcess.scala to s2core from root project
  Move RequestParser from Root to s2core
  Make RestCaller for abstract over http layer
  Move root project to s2rest_play
  Move Test from root to s2core

JIRA:
  [S2GRAPH-7] https://issues.apache.org/jira/browse/S2GRAPH-7

Pull Request:
  Closes #4


Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/f2311f25
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/f2311f25
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/f2311f25

Branch: refs/heads/master
Commit: f2311f25c5edf46104d149e91ff746ef808ded55
Parents: be304d6
Author: daewon 
Authored: Wed Jan 13 17:50:47 2016 +0900
Committer: daewon 
Committed: Wed Jan 13 18:05:01 2016 +0900

--
 CHANGES |   6 +-
 app/Bootstrap.scala |  75 --
 app/actors/QueueActor.scala |  92 ---
 app/config/Config.scala |  41 -
 app/config/CounterConfig.scala  |  10 -
 app/controllers/AdminController.scala   | 417 ---
 app/controllers/ApplicationController.scala |  83 ---
 app/controllers/CounterController.scala | 747 ---
 app/controllers/EdgeController.scala| 220 --
 app/controllers/ExperimentController.scala  | 113 ---
 app/controllers/JsonBodyParser.scala|  73 --
 app/controllers/PostProcess.scala   | 432 ---
 app/controllers/PublishController.scala |  54 --
 app/controllers/QueryController.scala   | 310 
 app/controllers/RequestParser.scala | 460 
 app/controllers/TestController.scala|  24 -
 app/controllers/VertexController.scala  |  84 ---
 app/models/ExactCounterItem.scala   |  38 -
 app/models/RankCounterItem.scala|  40 -
 app/models/package.scala|   8 -
 app/util/TestDataLoader.scala   |  70 --
 build.sbt   |  23 +-
 conf/logger.xml |  83 ---
 conf/reference.conf | 129 
 conf/routes | 124 ---
 conf/test.conf  |   2 -
 project/plugins.sbt |   8 +-
 s2core/src/main/resources/logback.xml   |  29 +-
 .../scala/com/kakao/s2graph/core/Graph.scala|  13 +-
 .../com/kakao/s2graph/core/OrderingUtil.scala   | 134 ++--
 .../com/kakao/s2graph/core/PostProcess.scala| 439 +++
 .../com/kakao/s2graph/core/mysqls/Model.scala   |  13 +
 .../kakao/s2graph/core/rest/RequestParser.scala | 509 +
 .../kakao/s2graph/core/rest/RestCaller.scala| 183 +
 .../storage/hbase/AsynchbaseQueryBuilder.scala  |   2 +-
 .../com/kakao/s2graph/core/utils/Logger.scala   |   6 +-
 .../scala/com/kakao/s2graph/core/EdgeTest.scala |  29 +
 .../com/kakao/s2graph/core/GraphTest.scala  |   8 -
 .../kakao/s2graph/core/Integrate/CrudTest.scala | 226 ++
 .../core/Integrate/IntegrateCommon.scala| 311 
 .../s2graph/core/Integrate/QueryTest.scala  | 528 +
 .../core/Integrate/StrongLabelDeleteTest.scala  | 282 +++
 .../core/Integrate/VertexTestHelper.scala   |  71 ++
 .../core/Integrate/WeakLabelDeleteTest.scala| 129 
 .../com/kakao/s2graph/core/JsonParserTest.scala |   3 -
 .../kakao/s2graph/core/OrderingUtilTest.scala   |  13 +-
 .../com/kakao/s2graph/core/TestCommon.scala | 190 +++--
 .../s2graph/core/TestCommonWithModels.scala |  88 ++-
 .../kakao/s2graph/core/models/ModelTest.scala   | 190 ++---
 .../s2graph/core/mysqls/ExperimentSpec.scala|  38 +-
 .../s2graph/core/parsers/WhereParserTest.scala  |   1 -
 .../hbase/AsynchbaseQueryBuilderTest.scala  |  12 +-
 .../kakao/s2graph/core/types/InnerValTest.scala | 154 ++--
 s2rest_play/app/Bootstrap.scala |  77 ++
 s2rest_play/app/actors/QueueActor.scala |  92 +++
 s2rest_play/app/config/Config.scala |  41 +
 s2rest_play/app/config/CounterConfig.scala  |  10 +
 .../app/controllers/AdminController.scala   | 419 +++
 .../app/controllers/ApplicationController.scala |  83 +++
 .../app/controllers/CounterController.scala | 747 +++
 .../app/controllers/EdgeController.scala| 222 ++
 .../app/controllers/ExperimentController.scala  | 114 +++
 .../app/controllers/JsonBodyParser.scala|  73 ++
 .../app/controllers/PublishController.scala |  54 ++
 .../app/controllers/QueryController.scala   | 311 
 .../app/controllers/TestController.scala|  24 +
 

[1/7] incubator-s2graph git commit: [S2GRAPH-7] Abstract common codes for rest project into s2core

2016-01-13 Thread daewon
Repository: incubator-s2graph
Updated Branches:
  refs/heads/master be304d6c9 -> f2311f25c


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f2311f25/test/controllers/QuerySpec.scala
--
diff --git a/test/controllers/QuerySpec.scala b/test/controllers/QuerySpec.scala
deleted file mode 100644
index f6381bc..000
--- a/test/controllers/QuerySpec.scala
+++ /dev/null
@@ -1,604 +0,0 @@
-package controllers
-
-import play.api.libs.json._
-import play.api.test.{FakeApplication, FakeRequest, PlaySpecification}
-import play.api.{Application => PlayApplication}
-
-import scala.concurrent.Await
-
-class QuerySpec extends SpecCommon with PlaySpecification {
-
-  import Helper._
-
-  implicit val app = FakeApplication()
-
-  init()
-
-  "query test" should {
-running(FakeApplication()) {
-
-  // insert bulk and wait ..
-  val bulkEdges: String = Seq(
-edge"1000 insert e 0 1 $testLabelName"($(weight = 40, is_hidden = 
true)),
-edge"2000 insert e 0 2 $testLabelName"($(weight = 30, is_hidden = 
false)),
-edge"3000 insert e 2 0 $testLabelName"($(weight = 20)),
-edge"4000 insert e 2 1 $testLabelName"($(weight = 10)),
-edge"3000 insert e 10 20 $testLabelName"($(weight = 20)),
-edge"4000 insert e 20 20 $testLabelName"($(weight = 10)),
-edge"1 insert e -1 1000 $testLabelName",
-edge"1 insert e -1 2000 $testLabelName",
-edge"1 insert e -1 3000 $testLabelName",
-edge"1 insert e 1000 1 $testLabelName",
-edge"1 insert e 1000 11000 $testLabelName",
-edge"1 insert e 2000 11000 $testLabelName",
-edge"1 insert e 2000 12000 $testLabelName",
-edge"1 insert e 3000 12000 $testLabelName",
-edge"1 insert e 3000 13000 $testLabelName",
-edge"1 insert e 1 10 $testLabelName",
-edge"2 insert e 11000 20 $testLabelName",
-edge"3 insert e 12000 30 $testLabelName").mkString("\n")
-
-  val jsResult = contentAsJson(EdgeController.mutateAndPublish(bulkEdges, 
withWait = true))
-}
-
-def queryParents(id: Long) = Json.parse( s"""
-{
-  "returnTree": true,
-  "srcVertices": [
-  { "serviceName": "${testServiceName}",
-"columnName": "${testColumnName}",
-"id": ${id}
-   }],
-  "steps": [
-  [ {
-  "label": "${testLabelName}",
-  "direction": "out",
-  "offset": 0,
-  "limit": 2
-}
-  ],[{
-  "label": "${testLabelName}",
-  "direction": "in",
-  "offset": 0,
-  "limit": -1
-}
-  ]]
-}""".stripMargin)
-
-def queryExclude(id: Int) = Json.parse( s"""
-{ "srcVertices": [
-  { "serviceName": "${testServiceName}",
-"columnName": "${testColumnName}",
-"id": ${id}
-   }],
-  "steps": [
-  [ {
-  "label": "${testLabelName}",
-  "direction": "out",
-  "offset": 0,
-  "limit": 2
-},
-{
-  "label": "${testLabelName}",
-  "direction": "in",
-  "offset": 0,
-  "limit": 2,
-  "exclude": true
-}
-  ]]
-}""")
-
-def queryTransform(id: Int, transforms: String) = Json.parse( s"""
-{ "srcVertices": [
-  { "serviceName": "${testServiceName}",
-"columnName": "${testColumnName}",
-"id": ${id}
-   }],
-  "steps": [
-  [ {
-  "label": "${testLabelName}",
-  "direction": "out",
-  "offset": 0,
-  "transform": $transforms
-}
-  ]]
-}""")
-
-def queryWhere(id: Int, where: String) = Json.parse( s"""
-{ "srcVertices": [
-  { "serviceName": "${testServiceName}",
-"columnName": "${testColumnName}",
-"id": ${id}
-   }],
-  "steps": [
-  [ {
-  "label": "${testLabelName}",
-  "direction": "out",
-  "offset": 0,
-  "limit": 100,
-  "where": "${where}"
-}
-  ]]
-}""")
-
-def querySingleWithTo(id: Int, offset: Int = 0, limit: Int = 100, to: Int) 
= Json.parse( s"""
-{ "srcVertices": [
-  { "serviceName": "${testServiceName}",
-"columnName": "${testColumnName}",
-"id": ${id}
-   }],
-  "steps": [
-  [ {
-  "label": "${testLabelName}",
-  "direction": "out",
-  "offset": $offset,
-  "limit": $limit,
-  "_to": $to
-}
-  ]]
-}
-""")
-
-def querySingle(id: Int, offset: Int = 0, limit: Int = 100) = Json.parse( 
s"""
-{