保持h2o mojo(版本3.20.0.1)时出错,

时间:2018-06-19 16:05:28

标签: h2o

我一直无法在最新的h2o版本中保持mojos。该代码在旧版本(3.10)上运行良好

这是示例代码和正在抛出的异常。

   public static Schema[] getAllSchemas() {
        ServiceLoader<Schema> schemaLoader = 
        ServiceLoader.load(Schema.class);
        List<Schema> allSchemas = new ArrayList<>();
        for (Schema schema : schemaLoader) {
            allSchemas.add(schema);
        }
        return allSchemas.toArray(new Schema[allSchemas.size()]);
   }

   public static byte[] extractIce(Model model) throws IOException {
       final UUID uuid = UUID.randomUUID();
       String tempFile = "/tmp/" + uuid;
       model.exportMojo(tempFile, true);
       final byte[] bytes = IOUtils.toByteArray(new 
                                   FileInputStream(tempFile)); 
       return bytes; 
    }


   public static void main (String []args) {
      H2OApp.main();
      SchemaServer.registerAllSchemasIfNecessary(getAllSchemas());
      // get the model that needs to be persisted
      // Model model = getH2OModel();
      byte[] extractIce(model);
   }

这是抛出的异常。

Caused by: java.lang.IllegalArgumentException: Cannot find Builder for algo url name drf
   at hex.ModelBuilder.ensureBuilderIndex(ModelBuilder.java:141) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelBuilder.havePojo(ModelBuilder.java:120) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.Model.havePojo(Model.java:118) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:73) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at water.api.schemas3.ModelSchemaV3.fillFromImpl(ModelSchemaV3.java:21) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeModelDetails(ModelMojoWriter.java:277) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:178) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:169) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]
   at hex.ModelMojoWriter.writeTo(ModelMojoWriter.java:161) ~[xyz-platform-all-7.9.0-SNAPSHOT.jar:7.9.0-SNAPSHOT]

1 个答案:

答案 0 :(得分:1)

以防万一有人遇到相同问题。 H2OApp启动后,我可以通过调用以下方法(registerSchemasAndAlgos)来保持mojos的持久性。

import hex.api.RegisterAlgos;
import water.api.RequestServer;
import water.api.Schema;
import water.api.SchemaServer;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

public void registerSchemasAndAlgos() {
    // schemas
    SchemaServer.registerAllSchemasIfNecessary(getAllSchemas());

    // algos
    RegisterAlgos algos = new RegisterAlgos();
    algos.registerEndPoints(new RequestServer.DummyRestApiContext());
}

public void registerAlgos() {
    RegisterAlgos algos = new RegisterAlgos();
    algos.registerEndPoints(new RequestServer.DummyRestApiContext());
}

public Schema[] getAllSchemas() {
    ServiceLoader<Schema> schemaLoader = ServiceLoader.load(Schema.class);
    List<Schema> allSchemas = new ArrayList<>();
    for (Schema schema : schemaLoader) {
        allSchemas.add(schema);
    }
    return allSchemas.toArray(new Schema[allSchemas.size()]);
}