Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Akka HTTP server project #55

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions api/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
geoprocessing {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thought to start this configuration file early.

port = 8090
hostname = "0.0.0.0"
}
125 changes: 125 additions & 0 deletions api/src/main/scala/WebServer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package org.wikiwatershed.mmw.geoprocessing

import akka.http.scaladsl.unmarshalling.Unmarshaller._
import akka.http.scaladsl.server.{ HttpApp, Route }
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
import spray.json._
import DefaultJsonProtocol._

import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.LazyLogging

object WebServer extends HttpApp with App with LazyLogging {
def routes: Route =
get {
path("ping") {
complete("pong")
}
} ~
post {
path("run") {
entity(as[String]) { input =>
println(input)
val NODATA = Int.MinValue
val output = Map(
List(90, 1) -> 1,
List(31, 3) -> 57,
List(81, 7) -> 514,
List(52, 7) -> 416,
List(43, 7) -> 36,
List(21, 3) -> 8134,
List(43, 2) -> 46,
List(23, 2) -> 670,
List(24, 1) -> 62,
List(23, 1) -> 512,
List(23, 7) -> 311,
List(41, 1) -> 50,
List(21, 6) -> 176,
List(21, NODATA) -> 16027,
List(81, 3) -> 2647,
List(31, 2) -> 21,
List(71, 4) -> 126,
List(42, 3) -> 72,
List(52, 1) -> 13,
List(43, 4) -> 50,
List(31, 4) -> 165,
List(71, NODATA) -> 72,
List(22, 7) -> 969,
List(22, NODATA) -> 16279,
List(31, 7) -> 58,
List(24, 7) -> 33,
List(22, 1) -> 603,
List(81, 6) -> 10,
List(82, 4) -> 2133,
List(41, 4) -> 5379,
List(82, NODATA) -> 268,
List(22, 2) -> 1636,
List(21, 1) -> 1601,
List(81, 2) -> 1956,
List(90, 6) -> 19,
List(41, 2) -> 3008,
List(41, 7) -> 4232,
List(81, 1) -> 28,
List(95, 3) -> 14,
List(23, 6) -> 10,
List(82, 3) -> 1889,
List(42, 2) -> 13,
List(21, 4) -> 6982,
List(43, NODATA) -> 106,
List(52, 4) -> 971,
List(82, 7) -> 306,
List(90, 4) -> 509,
List(95, 4) -> 27,
List(21, 7) -> 3241,
List(81, NODATA) -> 1086,
List(52, NODATA) -> 585,
List(71, 6) -> 7,
List(11, 1) -> 2,
List(71, 2) -> 157,
List(90, NODATA) -> 399,
List(11, NODATA) -> 32,
List(41, 3) -> 4419,
List(24, 3) -> 372,
List(42, 4) -> 43,
List(11, 4) -> 5,
List(95, 7) -> 20,
List(22, 4) -> 2876,
List(90, 7) -> 2500,
List(24, 4) -> 100,
List(41, NODATA) -> 2068,
List(82, 2) -> 1716,
List(52, 3) -> 960,
List(42, NODATA) -> 25,
List(95, 2) -> 2,
List(90, 3) -> 404,
List(52, 2) -> 357,
List(22, 6) -> 47,
List(31, NODATA) -> 63,
List(95, NODATA) -> 49,
List(23, 3) -> 1188,
List(23, NODATA) -> 7223,
List(41, 6) -> 62,
List(24, NODATA) -> 3148,
List(24, 2) -> 78,
List(21, 2) -> 4397,
List(22, 3) -> 2820,
List(52, 6) -> 7,
List(90, 2) -> 108,
List(43, 3) -> 91,
List(71, 7) -> 101,
List(81, 4) -> 2681,
List(71, 3) -> 221,
List(23, 4) -> 1062,
List(82, 1) -> 33
) map { case (k, v) => k.toString -> v}
complete(output.toJson)
}
}
}

val config = ConfigFactory.load()
val port = config.getInt("geoprocessing.port")
val host = config.getString("geoprocessing.hostname")

startServer(host, port)
}
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=0.13.16
44 changes: 31 additions & 13 deletions project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ object Version {
Properties.envOrElse(environmentVariable, default)

val geotrellis = "0.10.0"
val scala = either("SCALA_VERSION", "2.10.6")
val scala = either("SCALA_VERSION", "2.11.11")
val scalatest = "2.2.1"
lazy val jobserver = either("SPARK_JOBSERVER_VERSION", "0.6.1")
lazy val hadoop = either("SPARK_HADOOP_VERSION", "2.6.0")
lazy val spark = either("SPARK_VERSION", "1.5.2")
lazy val akkaHttpVersion = "10.0.9"
lazy val akkaVersion = "2.4.16"
lazy val akkaHttpCorsVersion = "0.2.1"
lazy val scalaLoggingVersion = "3.7.2"
}

object Geoprocessing extends Build {
Expand All @@ -27,6 +31,14 @@ object Geoprocessing extends Build {
version := "2.1.0",
scalaVersion := Version.scala,
organization := "org.wikiwatershed.mmw.geoprocessing",
name := "mmw-geoprocessing",

scalaVersion := Version.scala,
fork := true,

// raise memory limits here if necessary
javaOptions += "-Xmx2G",
javaOptions += "-Djava.library.path=/usr/local/lib",

// disable annoying warnings about 2.10.x
conflictWarning in ThisBuild := ConflictWarning.disable,
Expand Down Expand Up @@ -71,23 +83,29 @@ object Geoprocessing extends Build {
)

lazy val root = Project(id = "mmw-geoprocessing",
base = file(".")).aggregate(summary)
base = file(".")).aggregate(api, summary)

lazy val api = Project("api", file("api"))
.settings(apiSettings:_*)

lazy val summary = Project("summary", file("summary"))
lazy val summary = Project("summary", file("summary"))
.settings(summarySettings:_*)

lazy val summarySettings =
lazy val apiSettings =
Seq(
organization := "org.wikiwatershed.mmw.geoprocessing",
name := "mmw-geoprocessing",

scalaVersion := Version.scala,

fork := true,
// raise memory limits here if necessary
javaOptions += "-Xmx2G",
javaOptions += "-Djava.library.path=/usr/local/lib",
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % Version.akkaVersion,
"com.typesafe.akka" %% "akka-http" % Version.akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % Version.akkaVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % Version.akkaHttpVersion,
"org.scalatest" %% "scalatest" % Version.scalatest % "test",
"com.typesafe.scala-logging" %% "scala-logging" % Version.scalaLoggingVersion
)
) ++
defaultAssemblySettings

lazy val summarySettings =
Seq(
libraryDependencies ++= Seq(
"com.azavea.geotrellis" %% "geotrellis-spark" % Version.geotrellis,
"com.azavea.geotrellis" %% "geotrellis-s3" % Version.geotrellis,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.1")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.8.0")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
4 changes: 4 additions & 0 deletions scripts/cibuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

./sbt "project api" assembly
4 changes: 4 additions & 0 deletions scripts/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

./sbt
4 changes: 4 additions & 0 deletions scripts/server
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

./sbt "project api" ~reStart
4 changes: 4 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

./scripts/update
4 changes: 4 additions & 0 deletions scripts/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -ex

./sbt "project api" compile