@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; }
@SuppressWarnings("unused") // called through reflection by RequestServer /** Fetch the metadata for all the Schemas. */ public MetadataV3 listSchemas(int version, MetadataV3 docs) { Map<String, Class<? extends Schema>> ss = Schema.schemas(); docs.schemas = new SchemaMetadataBase[ss.size()]; // NOTE: this will throw an exception if the classname isn't found: int i = 0; for (Class<? extends Schema> schema_class : ss.values()) { // No hardwired version! YAY! FINALLY! docs.schemas[i++] = (SchemaMetadataBase) Schema.schema(version, SchemaMetadata.class) .fillFromImpl(new SchemaMetadata(Schema.newInstance(schema_class))); } return docs; }
@SuppressWarnings("unused") // called through reflection by RequestServer /** * Fetch the metadata for a Schema by its simple Schema name (e.g., "DeepLearningParametersV2"). */ public MetadataV3 fetchSchemaMetadata(int version, MetadataV3 docs) { if ("void".equals(docs.schemaname)) { docs.schemas = new SchemaMetadataBase[0]; return docs; } docs.schemas = new SchemaMetadataBase[1]; // NOTE: this will throw an exception if the classname isn't found: SchemaMetadataBase meta = (SchemaMetadataBase) Schema.schema(version, SchemaMetadata.class) .fillFromImpl(new SchemaMetadata(Schema.newInstance(docs.schemaname))); docs.schemas[0] = meta; return docs; }