Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BC8C8200BA5 for ; Wed, 19 Oct 2016 22:30:44 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BB226160AEA; Wed, 19 Oct 2016 20:30:44 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id DBC09160ADC for ; Wed, 19 Oct 2016 22:30:43 +0200 (CEST) Received: (qmail 85081 invoked by uid 500); 19 Oct 2016 20:30:43 -0000 Mailing-List: contact commits-help@iota.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@iota.incubator.apache.org Delivered-To: mailing list commits@iota.incubator.apache.org Received: (qmail 85072 invoked by uid 99); 19 Oct 2016 20:30:43 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 20:30:43 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id A6CFE1804F7 for ; Wed, 19 Oct 2016 20:30:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id JQehnwwqqsqf for ; Wed, 19 Oct 2016 20:30:41 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 81EBC5F2C3 for ; Wed, 19 Oct 2016 20:30:40 +0000 (UTC) Received: (qmail 66664 invoked by uid 99); 19 Oct 2016 18:44:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2016 18:44:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 371C1E0A59; Wed, 19 Oct 2016 18:44:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: tonyfaustini@apache.org To: commits@iota.incubator.apache.org Date: Wed, 19 Oct 2016 18:44:02 -0000 Message-Id: <683a8d8a98f04b7c8a5dc56b6fdc500a@git.apache.org> In-Reply-To: <598635938e4f481ea5485482ad115327@git.apache.org> References: <598635938e4f481ea5485482ad115327@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/8] incubator-iota git commit: converted the spray framework routes to the play routes archived-at: Wed, 19 Oct 2016 20:30:44 -0000 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 Authored: Wed Sep 28 12:08:20 2016 +0530 Committer: Shivansh 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