use of hex.ModelMojoWriter in project h2o-3 by h2oai.
the class ModelsHandler method exportMojo.
public ModelExportV3 exportMojo(int version, ModelExportV3 mexport) {
Model model = getFromDKV("model_id", mexport.model_id.key());
try {
// Really file, not dir
URI targetUri = FileUtils.getURI(mexport.dir);
Persist p = H2O.getPM().getPersistForURI(targetUri);
OutputStream os = p.create(targetUri.toString(), mexport.force);
ModelMojoWriter mojo = model.getMojo();
mojo.writeTo(os);
// Send back
mexport.dir = "file".equals(targetUri.getScheme()) ? new File(targetUri).getCanonicalPath() : targetUri.toString();
} catch (IOException e) {
throw new H2OIllegalArgumentException("dir", "exportModel", e);
}
return mexport;
}
use of hex.ModelMojoWriter in project h2o-3 by h2oai.
the class ModelBuildersHandler method detectMojoVersion.
private String detectMojoVersion(ModelBuilder builder) {
Class<? extends Model> modelClass = ReflectionUtils.findActualClassParameter(builder.getClass(), 0);
try {
Method getMojoMethod = modelClass.getDeclaredMethod("getMojo");
Class<?> retClass = getMojoMethod.getReturnType();
if (retClass == ModelMojoWriter.class || !ModelMojoWriter.class.isAssignableFrom(retClass))
throw new RuntimeException("Method getMojo() in " + modelClass + " must return the concrete implementation " + "of the ModelMojoWriter class. The return type is declared as " + retClass);
try {
ModelMojoWriter mmw = (ModelMojoWriter) retClass.newInstance();
return mmw.mojoVersion();
} catch (InstantiationException e) {
throw getMissingCtorException(retClass, e);
} catch (IllegalAccessException e) {
throw getMissingCtorException(retClass, e);
}
} catch (NoSuchMethodException e) {
throw new RuntimeException("Model class " + modelClass + " is expected to have method getMojo();");
}
}