Code Monkey home page Code Monkey logo

org.lappsgrid.examples's Introduction

Wrapping a LAPPS service

Introduction

This is a short introduction to creating web services that can be deployed to any Language Grid server. The Service Grid uses SOAP for inter-service communications, however the complexities of working with SOAP have been abstracted away by the Service Grid and Language Grid layers.

Requirements

For this tutorial you will require:

  1. Java 1.7 (or later)
  2. Maven 3.0.x
  3. an IDE such as IntelliJ or Eclipse
  4. about < 2 hours

Overview

We will go through a step-by-step tutorial to create a simple Lappsgrid service, WhitespaceTokenizer implementing all requirement for a language grid service. The tutorial includes writing java programs, packaging to Maven WAR package, and testing the package. Each step covers a single topic, and will take 15 - 30 minutes

Step1: Maven project setup

In step #1, we will set up a Maven project (POM) with lappgrid API dependencies for Lappsgrid services. (Goto step1)

Step2: Implementing Lappsgrid service

In step #2, we will take a close look at implementation requirements for a Lappsgrid service - especially I/O specifications, and then write a simple toknization method satisfying partial requirements in the WhitespaceTokenizer service implementation. (Goto step2)

Step3: Service metadata

In step #3, we will see what should be implemented as metadata for our WhitespaceTokenizer service, and then go through two example ways to implement getMetadata(), another required method for a Lappsgrid service. (Goto step3)

Step4: Packaging a service

In step #4, we will see how to compile a service into a Maven WAR package with service manifests. We also taks a quick look at how to deploy compiled service onto a tomcat server. (Goto step4)

Step5: Testing a service

In step #5, we will test out WhitespaceTokenizer service, first as a java program, then as a web-service. (Goto step5)

Step6: Wrapping existing Java program

Coming soon.

Step7: Wrapping Python program

Coming soon.

Up Next

To start the tutorial from the first step, run the command:

> git checkout step1

Or follow the link: step1

org.lappsgrid.examples's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

org.lappsgrid.examples's Issues

update step#3 for new API version

following these points:

  1. experimental for this step is now all included in org.lappsgrid.all
  2. need to specify what classes need to be imported for here

Various comments on the steps

Step 1:

  • mentions ANC's Nexus repository, but this is not mentioned further during step 1 or any later step
  • the properties table gives groupID=org.lappsgrid.tutorial, which is different from the pom

Step 4:

  • The archive with manifest files has a syntax error in the embedded bean tag (missing closing tag)

Step 5:

Old versions of pom and all

References to the parent pom and org.lappsgrid.all should be updated to the latest versions:

  • parent-pom:2.0.5
  • org.lappsgrid.all:2.3.1

mvn jetty:run fails

Hello

I'm going through the tutorial and I'm having an issue in step 5 with mvn jetty:run. I get the following stacktrace:

[ERROR] Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.26:run (default-cli) on project lappsgrid_example: Failure: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.mortbay.jetty:maven-jetty-plugin:6.1.26:run (default-cli) on project lappsgrid_example: Failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failure
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:479)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:396)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
    at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: java.lang.NullPointerException
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.checkWebXml(AbstractJettyRunMojo.java:358)
    at org.mortbay.jetty.plugin.AbstractJettyRunMojo.configureWebApplication(AbstractJettyRunMojo.java:383)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:438)
    ... 25 more

I checked the effective POM and I am importing the jetty plugin, and I am using a carbon copy of the web.xml and pom.xml defined in the source.

Step2 comments

  • LIF is LAPPS Interchange Format
  • when reading I know a lot, but what do I actually do?
  • add new Java class
  • call it something
  • remove content and cut and paste parts of the step2 code
  • add what packages need to be imported
  • package need not be added

Step1 branch comments

  • expand on parent adding a bit
  • spell out that 'packaging', 'name' and 'description' need to be added
  • mention that repositories needs to be added if not done by global setting

All tests are failing

All the unit tests in step 5 are failing. For example, testMetadata checks that the produces/required encoding is UTF-8, but the encoding is never set in the metadata.

Javadoc and groovydoc

For instance, the serialization module has both javadoc and groovydoc.
Should we worry about putting them together for later references, or at least an URL-aggregating web page?

Step3 comments

  • make clear up front that there are two alternatives
  • option 1, mention that code needs to be pasted in under class definition
  • there are errors after the previous step
  • there is a mistake in what is pasted
  • Returning Metadata, spell out that the code snippet replaces curent getMetadata method
  • metadata vbl needs to be declared

Step4 comments

  • spell out when unit test can be skipped
  • say where to put the test
  • use skeleton, then add in the two methods
  • need to import LAPPS classes (easiest way: copy all from main class)
  • issue with ProcessingService and WebService
  • import java.util.*
  • add link to file with all asserts (currently only path to it is given)
  • some asserts are fixed, some service specific
  • service.execute
  • add link to full example code
  • incompatible types (service.execute() returns String and container needs a Map)
  • integration test only possible after step5 (need to re-arrange)

update tutorial

  1. many lapps APIs now using java 8
  2. apply changes in schema 1.1.0
    1. lif - added $schema, dropped label, type
    2. metadata - added licenseDesc

step 4 and step 5 need to be switched

Due to the fact that current step 4 (testing) includes details on WAR integration test, which only can be proceeded after WAR packaging covered in step 5, two steps need to be switched.

Found a bug in WhitespaceTokenize.java from tutorial

    for (String word : words) {
        start = text.indexOf(word, start);
        if (start < 0) {
            return new Data<String>(Uri.ERROR, "Unable to match word: " + word).asJson();
        }
        int end = start + word.length();
        Annotation a = view.newAnnotation("tok" + (++id), Uri.TOKEN, start, end);
        a.addFeature(Features.Token.WORD, word);
    }

This loop is from WhitespaceTokenize.java and the bug of this code is that it forgets to add begin=end; at the end of the loop.

For example, this bug code will fail with input text "a a".
It will obtain two annotations which are token a and have the same begin and end.

Tutorial for service grid

Question: do we need to provide a hands-on tutorial for setting up service grid locally, and/or registering a new service to an existing service grid?

Write tutorial

  • Maven setup
  • Project setup
  • Lapp interfaces and base classes
  • Implementation
  • Service Metadata
  • web.xml and generating a war file.
    • Deployment.

Taken from whitespace_tokenizer tutorial


Then go further with more examples

  • wrapping external java program into a service (using stanfordnlp tagger)
  • wrapping non-java program into a service (using nltk tagger)
    • call python from java (using pycaller module)
    • wrap results from python into LAPPS grid API

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.