示例#1
0
  @SuppressWarnings("unused") // called through reflection by RequestServer
  /** Return a list of all REST API Routes and a Markdown Table of Contents. */
  public MetadataV3 listRoutes(int version, MetadataV3 docs) {
    MarkdownBuilder builder = new MarkdownBuilder();
    builder.comment("Preview with http://jbt.github.io/markdown-editor");
    builder.heading1("REST API Routes Table of Contents");
    builder.hline();

    builder.tableHeader("HTTP method", "URI pattern", "Input schema", "Output schema", "Summary");

    docs.routes = new RouteBase[RequestServer.numRoutes()];
    int i = 0;
    for (Route route : RequestServer.routes()) {
      docs.routes[i++] = (RouteBase) Schema.schema(version, Route.class).fillFromImpl(route);

      builder.tableRow(
          route._http_method,
          route._url_pattern.toString().replace("(?<", "{").replace(">.*)", "}"),
          Handler.getHandlerMethodInputSchema(route._handler_method).getSimpleName(),
          Handler.getHandlerMethodOutputSchema(route._handler_method).getSimpleName(),
          route._summary);
    }

    docs.markdown = builder.toString();
    return docs;
  }
示例#2
0
  @SuppressWarnings("unused") // called through reflection by RequestServer
  /** Return the metadata for a REST API Route, specified either by number or path. */
  public MetadataV3 fetchRoute(int version, MetadataV3 docs) {
    Route route = null;
    if (null != docs.path && null != docs.http_method) {
      route = RequestServer.lookup(docs.http_method, docs.path);
    } else {
      // Linear scan for the route, plus each route is asked for in-order
      // during doc-gen leading to an O(n^2) execution cost.
      int i = 0;
      for (Route r : RequestServer.routes())
        if (i++ == docs.num) {
          route = r;
          break;
        }
      // Crash-n-burn if route not found (old code thru an AIOOBE), so we
      // something similarly bad.
      docs.routes =
          new RouteBase[] {(RouteBase) Schema.schema(version, Route.class).fillFromImpl(route)};
    }

    Schema sinput, soutput;
    if (route._handler_class.equals(water.api.ModelBuilderHandler.class)) {
      String ss[] = route._url_pattern_raw.split("/");
      String algoURLName = ss[3]; // {}/{3}/{ModelBuilders}/{gbm}/{parameters}
      int version2 = Integer.valueOf(ss[1]);
      String algoName =
          ModelBuilder.algoName(algoURLName); // gbm -> GBM; deeplearning -> DeepLearning
      String schemaDir = ModelBuilder.schemaDirectory(algoURLName);
      String inputSchemaName = schemaDir + algoName + "V" + version2; // hex.schemas.GBMV3
      sinput = (Schema) TypeMap.theFreezable(TypeMap.onIce(inputSchemaName));
      sinput.init_meta();
      // hex.schemas.GBMModelV3$GBMModelOutputV3
      String outputSchemaName =
          schemaDir + algoName + "ModelV" + version2 + "$" + algoName + "ModelOutputV" + version2;
      soutput = (Schema) TypeMap.theFreezable(TypeMap.onIce(outputSchemaName));
      soutput.init_meta();
    } else {
      sinput = Schema.newInstance(Handler.getHandlerMethodInputSchema(route._handler_method));
      soutput = Schema.newInstance(Handler.getHandlerMethodOutputSchema(route._handler_method));
    }
    docs.routes[0].markdown = route.markdown(sinput, soutput).toString();
    return docs;
  }