update document for new api route
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/455e1551 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/455e1551 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/455e1551 Branch: refs/heads/master Commit: 455e1551ce95dc6754ffbdf1c9311f09f16c2685 Parents: 955e21d Author: daewon <dae...@apache.org> Authored: Wed Dec 26 16:18:22 2018 +0900 Committer: daewon <dae...@apache.org> Committed: Wed Dec 26 16:18:22 2018 +0900 ---------------------------------------------------------------------- doc/source/getting_started/your_first_graph.rst | 14 ++++---- .../apache/s2graph/http/S2GraphAdminRoute.scala | 34 ++++++++++---------- .../scala/org/apache/s2graph/http/Server.scala | 6 ++-- 3 files changed, 28 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/455e1551/doc/source/getting_started/your_first_graph.rst ---------------------------------------------------------------------- diff --git a/doc/source/getting_started/your_first_graph.rst b/doc/source/getting_started/your_first_graph.rst index 72d6e08..916cf53 100644 --- a/doc/source/getting_started/your_first_graph.rst +++ b/doc/source/getting_started/your_first_graph.rst @@ -11,7 +11,7 @@ The following POST query will create a service named ``KakaoFavorites`` .. code:: bash - curl -XPOST localhost:9000/graphs/createService -H 'Content-Type: Application/json' -d ' + curl -XPOST localhost:9000/admin/createService -H 'Content-Type: Application/json' -d ' { "serviceName": "KakaoFavorites", "compressionAlgorithm" : "gz" @@ -21,7 +21,7 @@ To make sure the service is created correctly, check out the following .. code:: bash - curl -XGET localhost:9000/graphs/getService/KakaoFavorites + curl -XGET localhost:9000/admin/getService/KakaoFavorites Next, we will need some friends. --------------------------------------------- @@ -29,7 +29,7 @@ In S2Graph, relationships are organized as labels. Create a ``friends`` label wi .. code:: bash - curl -XPOST localhost:9000/graphs/createLabel -H 'Content-Type: Application/json' -d ' + curl -XPOST localhost:9000/admin/createLabel -H 'Content-Type: Application/json' -d ' { "label": "friends", "srcServiceName": "KakaoFavorites", @@ -48,13 +48,13 @@ Check if the label has been created correctly: .. code:: bash - curl -XGET localhost:9000/graphs/getLabel/friends + curl -XGET localhost:9000/admin/getLabel/friends Now that the label ``friends`` is ready, we can store the friendship data. Entries of a label are called edges, and you can add edges with ``edges/insert`` API: .. code:: bash - curl -XPOST localhost:9000/graphs/edges/insert -H 'Content-Type: Application/json' -d ' + curl -XPOST localhost:9000/mutate/edge/insert -H 'Content-Type: Application/json' -d ' [ {"from":"Elmo","to":"Big Bird","label":"friends","props":{},"timestamp":1444360152477}, {"from":"Elmo","to":"Ernie","label":"friends","props":{},"timestamp":1444360152478}, @@ -95,7 +95,7 @@ We will need a new label ``post`` for this data: .. code:: bash - curl -XPOST localhost:9000/graphs/createLabel -H 'Content-Type: Application/json' -d ' + curl -XPOST localhost:9000/admin/createLabel -H 'Content-Type: Application/json' -d ' { "label": "post", "srcServiceName": "KakaoFavorites", @@ -114,7 +114,7 @@ Now, insert some posts of the users: .. code:: bash - curl -XPOST localhost:9000/graphs/edges/insert -H 'Content-Type: Application/json' -d ' + curl -XPOST localhost:9000/mutate/edge/insert -H 'Content-Type: Application/json' -d ' [ {"from":"Big Bird","to":"www.kakaocorp.com/en/main","label":"post","props":{},"timestamp":1444360152477}, {"from":"Big Bird","to":"github.com/kakao/s2graph","label":"post","props":{},"timestamp":1444360152478}, http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/455e1551/s2http/src/main/scala/org/apache/s2graph/http/S2GraphAdminRoute.scala ---------------------------------------------------------------------- diff --git a/s2http/src/main/scala/org/apache/s2graph/http/S2GraphAdminRoute.scala b/s2http/src/main/scala/org/apache/s2graph/http/S2GraphAdminRoute.scala index 47ac86a..1219968 100644 --- a/s2http/src/main/scala/org/apache/s2graph/http/S2GraphAdminRoute.scala +++ b/s2http/src/main/scala/org/apache/s2graph/http/S2GraphAdminRoute.scala @@ -56,27 +56,27 @@ trait S2GraphAdminRoute extends PlayJsonSupport { // routes impl /* GET */ - // GET /graphs/getService/:serviceName + // GET /admin/getService/:serviceName lazy val getService = path("getService" / Segment) { serviceName => val serviceOpt = Management.findService(serviceName) complete(toHttpEntity(serviceOpt, message = s"Service not found: ${serviceName}")) } - // GET /graphs/getServiceColumn/:serviceName/:columnName + // GET /admin/getServiceColumn/:serviceName/:columnName lazy val getServiceColumn = path("getServiceColumn" / Segment / Segment) { (serviceName, columnName) => val ret = Management.findServiceColumn(serviceName, columnName) complete(toHttpEntity(ret, message = s"ServiceColumn not found: ${serviceName}, ${columnName}")) } - // GET /graphs/getLabel/:labelName + // GET /admin/getLabel/:labelName lazy val getLabel = path("getLabel" / Segment) { labelName => val labelOpt = Management.findLabel(labelName) complete(toHttpEntity(labelOpt, message = s"Label not found: ${labelName}")) } - // GET /graphs/getLabels/:serviceName + // GET /admin/getLabels/:serviceName lazy val getLabels = path("getLabels" / Segment) { serviceName => val ret = Management.findLabels(serviceName) @@ -84,7 +84,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } /* POST */ - // POST /graphs/createService + // POST /admin/createService lazy val createService = path("createService") { entity(as[JsValue]) { params => @@ -98,7 +98,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/createServiceColumn + // POST /admin/createServiceColumn lazy val createServiceColumn = path("createServiceColumn") { entity(as[JsValue]) { params => @@ -112,7 +112,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/createLabel + // POST /admin/createLabel lazy val createLabel = path("createLabel") { entity(as[JsValue]) { params => val labelTry = requestParser.toLabelElements(params) @@ -133,7 +133,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/addProp/:labelName + // POST /admin/addProp/:labelName lazy val addProp = path("addProp" / Segment) { labelName => entity(as[JsValue]) { params => val labelMetaTry = for { @@ -145,7 +145,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/addServiceColumnProp/:serviceName/:columnName + // POST /admin/addServiceColumnProp/:serviceName/:columnName lazy val addServiceColumnProp = path("addServiceColumnProp" / Segments) { params => val (serviceName, columnName, storeInGlobalIndex) = params match { case s :: c :: Nil => (s, c, false) @@ -166,7 +166,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/createHTable + // POST /admin/createHTable lazy val createHTable = path("createHTable") { entity(as[JsValue]) { params => params.validate[HTableParams] match { @@ -182,14 +182,14 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/copyLabel/:oldLabelName/:newLabelName + // POST /admin/copyLabel/:oldLabelName/:newLabelName lazy val copyLabel = path("copyLabel" / Segment / Segment) { (oldLabelName, newLabelName) => val copyTry = management.copyLabel(oldLabelName, newLabelName, Some(newLabelName)) complete(toHttpEntity(copyTry)) } - // POST /graphs/renameLabel/:oldLabelName/:newLabelName + // POST /admin/renameLabel/:oldLabelName/:newLabelName lazy val renameLabel = path("renameLabel" / Segment / Segment) { (oldLabelName, newLabelName) => Label.findByName(oldLabelName) match { case None => complete(toHttpEntity(None: Option[JsValue], status = StatusCodes.NotFound, message = s"Label $oldLabelName not found.")) @@ -200,7 +200,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/swapLabels/:leftLabelName/:rightLabelName + // POST /admin/swapLabels/:leftLabelName/:rightLabelName lazy val swapLabel = path("swapLabel" / Segment / Segment) { (leftLabelName, rightLabelName) => val left = Label.findByName(leftLabelName, useCache = false) val right = Label.findByName(rightLabelName, useCache = false) @@ -215,7 +215,7 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } } - // POST /graphs/updateHTable/:labelName/:newHTableName + // POST /admin/updateHTable/:labelName/:newHTableName lazy val updateHTable = path("updateHTable" / Segment / Segment) { (labelName, newHTableName) => val updateTry = Management.updateHTable(labelName, newHTableName).map(Json.toJson(_)) @@ -223,21 +223,21 @@ trait S2GraphAdminRoute extends PlayJsonSupport { } /* PUT */ - // PUT /graphs/deleteLabelReally/:labelName + // PUT /admin/deleteLabelReally/:labelName lazy val deleteLabelReally = path("deleteLabelReally" / Segment) { labelName => val ret = Management.deleteLabel(labelName).toOption complete(toHttpEntity(ret, message = s"Label not found: ${labelName}")) } - // PUT /graphs/markDeletedLabel/:labelName + // PUT /admin/markDeletedLabel/:labelName lazy val markDeletedLabel = path("markDeletedLabel" / Segment) { labelName => val ret = Management.markDeletedLabel(labelName).toOption.map(Json.toJson(_)) complete(toHttpEntity(ret, message = s"Label not found: ${labelName}")) } - // PUT /graphs/deleteServiceColumn/:serviceName/:columnName + // PUT /admin/deleteServiceColumn/:serviceName/:columnName lazy val deleteServiceColumn = path("deleteServiceColumn" / Segment / Segment) { (serviceName, columnName) => val ret = Management.deleteColumn(serviceName, columnName).toOption http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/455e1551/s2http/src/main/scala/org/apache/s2graph/http/Server.scala ---------------------------------------------------------------------- diff --git a/s2http/src/main/scala/org/apache/s2graph/http/Server.scala b/s2http/src/main/scala/org/apache/s2graph/http/Server.scala index 00146f6..03802ed 100644 --- a/s2http/src/main/scala/org/apache/s2graph/http/Server.scala +++ b/s2http/src/main/scala/org/apache/s2graph/http/Server.scala @@ -49,7 +49,9 @@ object Server extends App override val logger = LoggerFactory.getLogger(this.getClass) val port = sys.props.get("http.port").fold(8000)(_.toInt) - val serverStatus = s""" { "port": ${port}, "started_at": ${System.currentTimeMillis()} }""" + val interface = sys.props.get("http.interface").fold("0.0.0.0")(identity) + + val serverStatus = s""" { "port": ${port}, "interface": ${interface}, "started_at": ${System.currentTimeMillis()} }""" val health = HttpResponse(status = StatusCodes.OK, entity = HttpEntity(ContentTypes.`application/json`, serverStatus)) @@ -62,7 +64,7 @@ object Server extends App get(complete(health)) ) - val binding: Future[Http.ServerBinding] = Http().bindAndHandle(routes, "localhost", port) + val binding: Future[Http.ServerBinding] = Http().bindAndHandle(routes, interface, port) binding.onComplete { case Success(bound) => logger.info(s"Server online at http://${bound.localAddress.getHostString}:${bound.localAddress.getPort}/") case Failure(e) => logger.error(s"Server could not start!", e)