Skip to content
This repository has been archived by the owner on Apr 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from stripe/avi-brushfire-srv
Browse files Browse the repository at this point in the history
Simple Finatra-based HTTP scoring service
  • Loading branch information
avibryant committed Feb 9, 2015
2 parents 95383bf + 1815a72 commit f4560d8
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
67 changes: 67 additions & 0 deletions brushfire-finatra/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.stripe</groupId>
<artifactId>brushfire-finatra</artifactId>
<packaging>jar</packaging>

<parent>
<artifactId>brushfire-parent</artifactId>
<groupId>com.stripe</groupId>
<version>0.5.0-SNAPSHOT</version>
<relativePath>../brushfire-parent</relativePath>
</parent>

<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finatra_2.10</artifactId>
</dependency>
<dependency>
<groupId>com.stripe</groupId>
<artifactId>brushfire-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<outputFile>target/brushfire-finatra-${project.version}-jar-with-dependencies.jar</outputFile>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.stripe.brushfire.finatra

import com.stripe.brushfire._
import com.twitter.finatra._
import com.twitter.finagle.http._
import com.twitter.bijection._

class BrushfireServer extends FinatraServer {
def score[K, V, T, P](root: String, trees: Iterable[Tree[K, V, T]], voter: Voter[T, P])(fn: ParamMap => Map[K, V]) = {
register(new Controller {
get(root) { request =>
val row = fn(request.params)
val score = voter.predict(trees, row)
render.json(score).toFuture
}
})
}

def loadAndScore[K, V, T, P](root: String, treePath: String, voter: Voter[T, P])(fn: ParamMap => Map[K, V])(implicit inj: Injection[Tree[K, V, T], String]) = {
val trees = scala.io.Source.fromFile(treePath).getLines.map { line =>
val parts = line.split("\t")
inj.invert(parts(1)).get
}
score[K, V, T, P](root, trees.toList, voter)(fn)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.stripe.brushfire.finatra

import com.stripe.brushfire._

object Main {
import JsonInjections._

def main(args: Array[String]) {
val treePath = args(0)
val srv = new BrushfireServer
srv.loadAndScore("/iris", treePath, SoftVoter[String, Long]) { _.mapValues { _.toDouble } }
srv.main
}
}
5 changes: 5 additions & 0 deletions brushfire-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finatra_2.10</artifactId>
<version>1.6.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 4 additions & 0 deletions example/iris-srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
java -Xmx2G -cp ../brushfire-finatra/target/brushfire-finatra-0.5.0-SNAPSHOT-jar-with-dependencies.jar \
com.stripe.brushfire.finatra.Main \
iris.output/mem

0 comments on commit f4560d8

Please sign in to comment.