aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Burns <brian.p.burns@gmail.com>2017-01-08 14:40:49 -0500
committerBrian Burns <brian.p.burns@gmail.com>2017-01-08 14:40:49 -0500
commit22099a4b1c7c5f1f225b5cc1b257855d558d1905 (patch)
treec12bc01982721fddddbb6935efa5cc4d3162dfc8
downloadtoree-gateway-22099a4b1c7c5f1f225b5cc1b257855d558d1905.tar.gz
toree-gateway-22099a4b1c7c5f1f225b5cc1b257855d558d1905.tar.bz2
toree-gateway-22099a4b1c7c5f1f225b5cc1b257855d558d1905.zip
initial commit
-rw-r--r--.gitignore16
-rw-r--r--pom.xml117
-rw-r--r--src/main/scala/com/ibm/ToreeClient.scala60
3 files changed, 193 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9d830ae
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,16 @@
+*.iml
+.idea
+target
+dependency-reduced-pom.xml
+.DS_Store
+module*.zip
+**/node_modules/**
+java/.idea/*
+java/javascriptspark.iml
+java/target/*
+java/dependency-reduced-pom.xml
+.__browserify_string_empty.js
+.DS_Store
+jupyter-js-services
+examples/airline/public/data/2008bd.json/*
+incubator-toree/*
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..e0385c2
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,117 @@
+<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.ibm</groupId>
+ <artifactId>toree-client</artifactId>
+ <version>0.1</version>
+
+ <name>Toree Client</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <argLine>-Dlog4j.configuration=file:"./src/test/resources/conf/log4j.prop"
+ </argLine>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.3</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>2.4.1</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <shadedArtifactAttached>true</shadedArtifactAttached>
+ <shadedClassifierName>jar-with-dependencies</shadedClassifierName> <!-- Any name that makes sense -->
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>META-INF/*.SF</exclude>
+ <exclude>META-INF/*.DSA</exclude>
+ <exclude>META-INF/*.RSA</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>net.alchim31.maven</groupId>
+ <artifactId>scala-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>scala-compile-first</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>add-source</goal>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>scala-test-compile</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>testCompile</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <toree.version>0.2.0.dev1-incubating-SNAPSHOT</toree.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.typesafe</groupId>
+ <artifactId>config</artifactId>
+ <version>1.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.toree.kernel</groupId>
+ <artifactId>toree-client_2.11</artifactId>
+ <version>${toree.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.py4j</groupId>
+ <artifactId>py4j</artifactId>
+ <version>0.10.3</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/scala/com/ibm/ToreeClient.scala b/src/main/scala/com/ibm/ToreeClient.scala
new file mode 100644
index 0000000..a075f77
--- /dev/null
+++ b/src/main/scala/com/ibm/ToreeClient.scala
@@ -0,0 +1,60 @@
+package com.ibm
+
+import com.typesafe.config.ConfigFactory
+import org.apache.toree.kernel.protocol.v5.client.boot.ClientBootstrap
+import com.typesafe.config.Config
+import org.apache.toree.kernel.protocol.v5.MIMEType
+import org.apache.toree.kernel.protocol.v5.client.SparkKernelClient
+import org.apache.toree.kernel.protocol.v5.client.boot.layers.{StandardHandlerInitialization, StandardSystemInitialization}
+import org.apache.toree.kernel.protocol.v5.client.execution.DeferredExecution
+import org.apache.toree.kernel.protocol.v5.content.ExecuteResult
+import py4j.GatewayServer
+
+import scala.concurrent.{Await, Promise}
+import scala.concurrent.duration.Duration
+
+class ToreeGateway(client: SparkKernelClient) {
+ // Define our callback
+ def printResult(result: ExecuteResult) = {
+ println(s"Result was: ${result.data.get(MIMEType.PlainText).get}")
+ }
+
+ def eval(code: String): Object = {
+ val promise = Promise[String]
+ val exRes: DeferredExecution = client.execute(code).onResult(er => {
+ promise.success(er.data.get(MIMEType.PlainText).get)
+ })
+
+ Await.result(promise.future, Duration.Inf)
+ }
+}
+
+object ToreeClient extends App {
+
+ val profileJSON: String = """
+{
+ "stdin_port": 48691,
+ "control_port": 44808,
+ "hb_port": 49691,
+ "shell_port": 40544,
+ "iopub_port": 43462,
+ "ip": "127.0.0.1",
+ "transport": "tcp",
+ "signature_scheme": "hmac-sha256",
+ "key": ""
+}
+""".stripMargin
+
+ // Parse our configuration and create a client connecting to our kernel
+ val config: Config = ConfigFactory.parseString(profileJSON)
+
+ val client = (new ClientBootstrap(config)
+ with StandardSystemInitialization
+ with StandardHandlerInitialization).createClient()
+
+ val toreeGateway = new ToreeGateway(client)
+ print(toreeGateway.eval("sc"))
+
+ val gatewayServer: GatewayServer = new GatewayServer(toreeGateway)
+ gatewayServer.start()
+}