You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iota.apache.org by to...@apache.org on 2016/10/19 18:44:02 UTC
[3/8] incubator-iota git commit: converted the spray framework routes
to the play routes
converted the spray framework routes to the play routes
Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/fe606d70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/fe606d70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/fe606d70
Branch: refs/heads/master
Commit: fe606d70daf76f3de761223b3d44dcb9ab11f172
Parents: ba8eb4d
Author: Shivansh <sh...@gmail.com>
Authored: Wed Sep 28 12:08:20 2016 +0530
Committer: Shivansh <sh...@gmail.com>
Committed: Wed Sep 28 12:08:20 2016 +0530
----------------------------------------------------------------------
.../org/apache/iota/fey/FeyUIService.scala | 79 ++++++++++++++++++
.../scala/org/apache/iota/fey/MyService.scala | 88 --------------------
2 files changed, 79 insertions(+), 88 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/fe606d70/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala
new file mode 100644
index 0000000..f08790a
--- /dev/null
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyUIService.scala
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import com.typesafe.config.ConfigFactory
+import org.apache.iota.fey.FeyCore.JSON_TREE
+import play.api.BuiltInComponents
+import play.api.http.DefaultHttpErrorHandler
+import play.api.libs.json.Json
+import play.api.mvc._
+import play.api.routing.Router
+import play.api.routing.sird._
+import play.core.server._
+
+import scala.concurrent.Future
+
+object FeyUIService {
+ val config = ConfigFactory.load()
+ val port = config.getInt("port")
+ val urlPath = config.getString("urlPath")
+ val components = new FeyUIService(urlPath, port)
+ val server = components.server
+}
+
+class FeyUIService(urlPath: String, port: Int) extends NettyServerComponents with BuiltInComponents {
+
+ lazy val router = Router.from {
+ case GET(p"/fey/activeactors") => Action {
+ FEY_CORE_ACTOR.actorRef ! JSON_TREE
+ Thread.sleep(2000)
+ val json = IdentifyFeyActors.generateTreeJson()
+ val jsonTree: String = IdentifyFeyActors.getHTMLTree(json)
+ Results.Ok(jsonTree).as("text/html")
+ }
+ case GET(p"/fey/actorslifecycle") => Action {
+ val jsonTree = Json.stringify(Monitor.events.printWithEvents)
+ Results.Ok(jsonTree).as("application/json")
+ }
+ case GET(p"/fey/monitoringevents") => Action {
+ val returnValue: String = try {
+ if (CONFIG.MONITORING_TYPE == "COMPLETE") {
+ Monitor.getHTMLevents
+ } else {
+ Monitor.getSimpleHTMLEvents
+ }
+ } catch {
+ case e: Exception => ""
+ }
+ Results.Ok(returnValue).as("application/json")
+ }
+ }
+
+ override lazy val serverConfig = ServerConfig(
+ port = Some(port),
+ address = urlPath
+ )
+ override lazy val httpErrorHandler = new DefaultHttpErrorHandler(environment,
+ configuration, sourceMapper, Some(router)) {
+
+ override protected def onNotFound(request: RequestHeader, message: String) = {
+ Future.successful(Results.NotFound("NO_DATA_FOUND"))
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/fe606d70/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala b/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
deleted file mode 100644
index f686321..0000000
--- a/fey-core/src/main/scala/org/apache/iota/fey/MyService.scala
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.iota.fey
-
-import akka.actor.Actor
-import org.apache.iota.fey.FeyCore.JSON_TREE
-import play.api.libs.json.Json
-import spray.http.MediaTypes._
-import spray.routing._
-
-class MyServiceActor extends Actor with MyService {
-
- // the HttpService trait defines only one abstract member, which
- // connects the services environment to the enclosing actor or test
- def actorRefFactory = context
-
- // this actor only runs our route, but you could add
- // other things here, like request stream processing
- // or timeout handling
- def receive = runRoute(myRoute)
-}
-
-sealed trait MyService extends HttpService {
-
- val home = pathPrefix("fey")
- val activeActors = path("activeactors")
- val actorLifecycle = path("actorslifecycle")
- val eventsTable = path("monitoringevents")
- val test = path("test")
-
- val myRoute =
- home {
- activeActors {
- get{
- respondWithMediaType(`text/html`) {
- complete {
- FEY_CORE_ACTOR.actorRef ! JSON_TREE
- Thread.sleep(2000)
- val json = IdentifyFeyActors.generateTreeJson()
- IdentifyFeyActors.getHTMLTree(json)
- }
- }
- }
- } ~
- actorLifecycle {
- get{
- respondWithMediaType(`application/json`) {
- complete {
- Json.stringify(Monitor.events.printWithEvents)
- }
- }
- }
- } ~
- eventsTable {
- get{
- respondWithMediaType(`text/html`) {
- complete {
- try {
- if(CONFIG.MONITORING_TYPE == "COMPLETE") {
- Monitor.getHTMLevents
- }else{
- Monitor.getSimpleHTMLEvents
- }
- }catch {
- case e: Exception => ""
- }
- }
- }
- }
- }
- }
-
-}
\ No newline at end of file