Skip to content

Commit

Permalink
Merge pull request #2222 from adriangonz/release-java-wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Gonzalez-Martin authored Aug 17, 2020
2 parents 8c633bf + 382d9c4 commit b903bbf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
34 changes: 17 additions & 17 deletions doc/source/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ s2i usage seldonio/seldon-core-s2i-java-build:0.1

To use our s2i builder image to package your Java model you will need:

* A Maven project that depends on ```io.seldon.wrapper``` library
* A Maven project that depends on `io.seldon.wrapper` library
* A Spring Boot configuration class
* A class that implements ```io.seldon.wrapper.api.SeldonPredictionService``` for the type of component you are creating
* A class that implements `io.seldon.wrapper.api.SeldonPredictionService` for the type of component you are creating
* .s2i/environment - model definitions used by the s2i builder to correctly wrap your model

We will go into detail for each of these steps:
Expand All @@ -38,18 +38,18 @@ Create a Spring Boot Maven project and include the dependency:
<dependency>
<groupId>io.seldon.wrapper</groupId>
<artifactId>seldon-core-wrapper</artifactId>
<version>0.1.3</version>
<version>0.2.0</version>
</dependency>
```

A full example can be found at ```incubating/wrappers/s2i/java/test/model-template-app/pom.xml```.
A full example can be found at `incubating/wrappers/s2i/java/test/model-template-app/pom.xml`.

### Spring Boot Intialization

Create a main App class:
* Add @EnableAsync annotation (to allow the embedded gRPC server to start at Spring Boot startup)
* include the ```io.seldon.wrapper``` in the scan base packages list along with your App's package, in the example below the Apps's package is ```io.seldon.example```.
* Import the config class at ```io.seldon.wrapper.config.AppConfig.class```
* include the `io.seldon.wrapper` in the scan base packages list along with your App's package, in the example below the Apps's package is `io.seldon.example`.
* Import the config class at `io.seldon.wrapper.config.AppConfig.class`

For example:

Expand All @@ -65,7 +65,7 @@ public class App {
```

### Prediction Class
To handle requests to your model or other component you need to implement one or more of the methods in ```io.seldon.wrapper.api.SeldonPredictionService```, in particular:
To handle requests to your model or other component you need to implement one or more of the methods in `io.seldon.wrapper.api.SeldonPredictionService`, in particular:

```java
default public SeldonMessage predict(SeldonMessage request);
Expand All @@ -76,7 +76,7 @@ default public SeldonMessage transformOutput(SeldonMessage request);
default public SeldonMessage aggregate(SeldonMessageList request);
```

Your implementing class should be created as a Spring Component so it will be managed by Spring. There is a full H2O example in ```examples/models/h2o_mojo/src/main/java/io/seldon/example/h2o/model```, whose implementation is shown below:
Your implementing class should be created as a Spring Component so it will be managed by Spring. There is a full H2O example in `examples/models/h2o_mojo/src/main/java/io/seldon/example/h2o/model`, whose implementation is shown below:

```java
@Component
Expand Down Expand Up @@ -122,15 +122,15 @@ The above code:

* loads a model from the local resources folder on startup
* Converts the proto buffer message into H2O RowData using provided utility classes.
* Runs a BionomialModel prediction and converts the result back into a ```SeldonMessage``` for return
* Runs a BionomialModel prediction and converts the result back into a `SeldonMessage` for return

#### H2O Helper Classes

We provide H2O utility class ```io.seldon.wrapper.utils.H2OUtils``` in seldon-core-wrapper to convert to and from the seldon-core proto buffer message types.
We provide H2O utility class `io.seldon.wrapper.utils.H2OUtils` in seldon-core-wrapper to convert to and from the seldon-core proto buffer message types.

#### DL4J Helper Classes

We provide a DL4J utility class ```io.seldon.wrapper.utils.DL4JUtils``` in seldon-core-wrapper to convert to and from the seldon-core proto buffer message types.
We provide a DL4J utility class `io.seldon.wrapper.utils.DL4JUtils` in seldon-core-wrapper to convert to and from the seldon-core proto buffer message types.

### .s2i/environment

Expand All @@ -144,7 +144,7 @@ SERVICE_TYPE=MODEL
These values can also be provided or overridden on the command line when building the image.

## Step 3 - Build your image
Use ```s2i build``` to create your Docker image from source code. You will need Docker installed on the machine and optionally git if your source code is in a public git repo.
Use `s2i build` to create your Docker image from source code. You will need Docker installed on the machine and optionally git if your source code is in a public git repo.

Using s2i you can build directly from a git repo or from a local source folder. See the [s2i docs](https://github.com/openshift/source-to-image/blob/master/docs/cli.md#s2i-build) for further details. The general format is:

Expand All @@ -161,10 +161,10 @@ s2i build https://github.com/seldonio/seldon-core.git --context-dir=incubating/w

The above s2i build invocation:

* uses the GitHub repo: https://github.com/seldonio/seldon-core.git and the directory ```incubating/wrappers/s2i/java/test/model-template-app``` inside that repo.
* uses the builder image ```seldonio/seldon-core-s2i-java-build```
* uses the runtime image ```seldonio/seldon-core-s2i-java-runtime```
* creates a docker image ```seldon-core-template-model```
* uses the GitHub repo: https://github.com/seldonio/seldon-core.git and the directory `incubating/wrappers/s2i/java/test/model-template-app` inside that repo.
* uses the builder image `seldonio/seldon-core-s2i-java-build`
* uses the runtime image `seldonio/seldon-core-s2i-java-runtime`
* creates a docker image `seldon-core-template-model`


For building from a local source folder, an example where we clone the seldon-core repo:
Expand All @@ -185,7 +185,7 @@ s2i build --help
## Reference

## Environment Variables
The required environment variables understood by the builder image are explained below. You can provide them in the ```.s2i/environment``` file or on the ```s2i build``` command line.
The required environment variables understood by the builder image are explained below. You can provide them in the `.s2i/environment` file or on the `s2i build` command line.


### API_TYPE
Expand Down
37 changes: 16 additions & 21 deletions incubating/wrappers/java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<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">
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>io.seldon.wrapper</groupId>
Expand All @@ -10,9 +10,9 @@
<name>Seldon Core Java Wrapper</name>
<url>http://maven.apache.org</url>
<description>Wrapper for seldon-core Java prediction models.
Allows easy creation of a Spring Boot app with Tomcat and gRPC
servers for handling the microservice APIs for
seldon-core.</description>
Allows easy creation of a Spring Boot app with Tomcat and gRPC
servers for handling the microservice APIs for
seldon-core.</description>
<organization>
<name>Seldon</name>
<url>https://www.seldon.io/</url>
Expand All @@ -23,7 +23,6 @@
<url>http://www.apache.org/licenses/LICENSE-2.0</url>
</license>
</licenses>

<developers>
<developer>
<id>cc</id>
Expand All @@ -36,45 +35,42 @@
</roles>
</developer>
</developers>

<scm>
<connection>
scm:git:git://github.com/SeldonIO/seldon-core.git</connection>
scm:git:git://github.com/SeldonIO/seldon-core.git</connection>
<url>https://github.com/SeldonIO/seldon-core/tree/master</url>
<developerConnection>
scm:git:[email protected]:SeldonIO/seldon-core.git</developerConnection>
scm:git:[email protected]:SeldonIO/seldon-core.git</developerConnection>
</scm>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
</parent>

<properties>
<java.version>13</java.version>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>
UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>
UTF-8</project.reporting.outputEncoding>
<grpc.version>1.25.0</grpc.version>
<pb.version>3.11.1</pb.version>
<start-class>io.seldon.wrapper.App</start-class>
</properties>

<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>
https://oss.sonatype.org/content/repositories/snapshots</url>
https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<extensions>
Expand All @@ -89,7 +85,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution >
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
Expand Down Expand Up @@ -119,10 +115,10 @@
<version>0.6.1</version>
<configuration>
<protocArtifact>
com.google.protobuf:protoc:${pb.version}:exe:${os.detected.classifier}</protocArtifact>
com.google.protobuf:protoc:${pb.version}:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>
io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
<clearOutputDirectory>false</clearOutputDirectory>
<checkStaleness>true</checkStaleness>
</configuration>
Expand Down Expand Up @@ -199,7 +195,6 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down

0 comments on commit b903bbf

Please sign in to comment.