amazon ec2 - Deploying H2O-generated POJO to Jetty: /predict returns 404 -


i have generated pojo h2o model.

on separate ec2 instance, want deploy model jetty servelet used api scoring endpoint. how can this?

1. example pojo

here minimal example, demo_glm, predicting titanic passenger survival logistic regression on age, fare class, , sex:

/*   licensed under apache license, version 2.0     http://www.apache.org/licenses/license-2.0.html    autogenerated h2o @ 2017-09-13t17:30:17.931z   3.13.0.3908    standalone prediction code sample test data glmmodel named demo_glm    how download, compile , execute:       mkdir tmpdir       cd tmpdir       curl http://xxx.xx.xx.xxx:54321/3/h2o-genmodel.jar > h2o-genmodel.jar       curl http://xxx.xx.xx.xxx:54321/3/models.java/demo_glm > demo_glm.java       javac -cp h2o-genmodel.jar -j-xmx2g -j-xx:maxpermsize=128m demo_glm.java       (note:  try java argument -xx:+printcompilation show runtime jit compiler behavior.) */ import java.util.map; import hex.genmodel.genmodel; import hex.genmodel.annotations.modelpojo;  @modelpojo(name="demo_glm", algorithm="glm") public class demo_glm extends genmodel {   public hex.modelcategory getmodelcategory() { return hex.modelcategory.binomial; }    public boolean issupervised() { return true; }   public int nfeatures() { return 3; }   public int nclasses() { return 2; }    // names of columns used model.   public static final string[] names = namesholder_demo_glm.values;   // number of output classes included in training data response column.   public static final int nclasses = 2;    // column domains. last array contains domain of response column.   public static final string[][] domains = new string[][] {     /* pclass */ demo_glm_colinfo_0.values,     /* sex */ demo_glm_colinfo_1.values,     /* age */ null,     /* survived */ demo_glm_colinfo_3.values   };   // prior class distribution   public static final double[] prior_class_distrib = null;   // class distribution used model building   public static final double[] model_class_distrib = null;    public demo_glm() { super(names,domains); }   public string getuuid() { return long.tostring(-1806915013443955212l); }    // pass in data in double[], pre-aligned model's requirements.   // jam predictions preds[] array; preds[0] reserved   // main prediction (class classifiers or value regression),   // , remaining columns hold probability distribution classifiers.   public final double[] score0( double[] data, double[] preds ) {     final double [] b = beta.values;     for(int = 0; < 2; ++i) if(double.isnan(data[i])) data[i] = cat_modes.values[i];     for(int = 0; < 1; ++i) if(double.isnan(data[i + 2])) data[i+2] = num_means.values[i];     double eta = 0.0;     for(int = 0; < catoffs.length-1; ++i) if(data[i] != 0) {       int ival = (int)data[i] - 1;       if(ival != data[i] - 1) throw new illegalargumentexception("categorical value out of range");       ival += catoffs[i];       if(ival < catoffs[i + 1])         eta += b[ival];     }     for(int = 2; < b.length-1-1; ++i)     eta += b[1+i]*data[i];     eta += b[b.length-1]; // reduce intercept     double mu = hex.genmodel.genmodel.glm_logitinv(eta);     preds[0] = (mu >= 0.3701702514726391) ? 1 : 0; // threshold given roc     preds[1] = 1.0 - mu; // class 0     preds[2] =       mu; // class 1     return preds;   }     public static class beta implements java.io.serializable {       public static final double[] values = new double[5];       static {         beta_0.fill(values);       }       static final class beta_0 implements java.io.serializable {         static final void fill(double[] sa) {           sa[0] = -1.280567936795408;           sa[1] = -2.2896567020762353;           sa[2] = -2.4978421167555616;           sa[3] = -0.034393168117166584;           sa[4] = 3.5220688949789816;         }       } } // imputed numeric values     static class num_means implements java.io.serializable {       public static final double[] values = new double[1];       static {         num_means_0.fill(values);       }       static final class num_means_0 implements java.io.serializable {         static final void fill(double[] sa) {           sa[0] = 29.881134512434045;         }       } } // imputed categorical values.     static class cat_modes implements java.io.serializable {       public static final int[] values = new int[2];       static {         cat_modes_0.fill(values);       }       static final class cat_modes_0 implements java.io.serializable {         static final void fill(int[] sa) {           sa[0] = 2;           sa[1] = 1;         }       } }     // categorical offsets     public static final int[] catoffs = {0,2,3}; } // class representing training column names class namesholder_demo_glm implements java.io.serializable {   public static final string[] values = new string[3];   static {     namesholder_demo_glm_0.fill(values);   }   static final class namesholder_demo_glm_0 implements java.io.serializable {     static final void fill(string[] sa) {       sa[0] = "pclass";       sa[1] = "sex";       sa[2] = "age";     }   } } // class representing column pclass class demo_glm_colinfo_0 implements java.io.serializable {   public static final string[] values = new string[3];   static {     demo_glm_colinfo_0_0.fill(values);   }   static final class demo_glm_colinfo_0_0 implements java.io.serializable {     static final void fill(string[] sa) {       sa[0] = "1st";       sa[1] = "2nd";       sa[2] = "3rd";     }   } } // class representing column sex class demo_glm_colinfo_1 implements java.io.serializable {   public static final string[] values = new string[2];   static {     demo_glm_colinfo_1_0.fill(values);   }   static final class demo_glm_colinfo_1_0 implements java.io.serializable {     static final void fill(string[] sa) {       sa[0] = "female";       sa[1] = "male";     }   } } // class representing column survived class demo_glm_colinfo_3 implements java.io.serializable {   public static final string[] values = new string[2];   static {     demo_glm_colinfo_3_0.fill(values);   }   static final class demo_glm_colinfo_3_0 implements java.io.serializable {     static final void fill(string[] sa) {       sa[0] = "0";       sa[1] = "1";     }   } } 

2. i've tried far

after installing jetty on separate ec2 instance, follow instructions in comments above:

cd $jetty_home/demo-base/webapps mkdir model_demo cd model_demo curl http://xxx.xx.xx.xxx:54321/3/h2o-genmodel.jar > h2o-genmodel.jar curl http://xxx.xx.xx.xxx:54321/3/models.java/demo_glm > demo_glm.java javac -cp h2o-genmodel.jar -j-xmx2g -j-xx:maxpermsize=128m  

i can access servelet @ http://xxx.xx.xx.yy:8080/ , see "welcome jetty-9" screen in browser or via curl.

my problem when try:

curl http://xxx.xx.xx.yy:8080/predict?pclass=1st&age=29&sex=female 

or:

curl http://xxx.xx.xx.yy:8080/model_demo/predict?pclass=1st&age=29&s‌​ex=female 

i get:

http error 404

problem accessing /predict. reason:

  not found  

here 2 repos can @ see working examples of pojo deployed in jetty:

and mojo deployed in jetty:

with respect specific issue above, need add web.xml file .war file. web.xml app-mojo-servlet repo:

$ cat src/main/webapp/web-inf/web.xml  <web-app xmlns="http://java.sun.com/xml/ns/j2ee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"          version="2.4">     <servlet>         <servlet-name>predict</servlet-name>         <servlet-class>ai.h2o.predictservlet</servlet-class>     </servlet>     <servlet-mapping>         <servlet-name>predict</servlet-name>         <url-pattern>/predict</url-pattern>     </servlet-mapping> </web-app> 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -