@@ -204,6 +204,11 @@ public String infer(String aggregateExpression, String groupByColumn, String whe
204
204
return outputPath ;
205
205
}
206
206
207
+ private String unescapeString (String s ) {
208
+ // remove beginning/ending double quotes and unescape
209
+ return StringEscapeUtils .unescapeJava (s .replaceAll ("^\" |\" $" , "" ));
210
+ }
211
+
207
212
@ Override
208
213
public String listHyperparameters (String className , String uri ) throws Exception {
209
214
URL url = new URL (checkTrailingSlash (uri ) + "modeltype/" + className + "/hyperparams" );
@@ -222,8 +227,32 @@ public String listHyperparameters(String className, String uri) throws Exception
222
227
response .append (line );
223
228
}
224
229
225
- // remove beginning/ending double quotes and unescape
226
- return StringEscapeUtils .unescapeJava (response .toString ().replaceAll ("^\" |\" $" , "" ));
230
+ return unescapeString (response .toString ());
231
+ }
232
+
233
+ @ Override
234
+ public boolean checkAvailable (String modelName ) throws Exception {
235
+ MModeltype mModeltype = catalogContext .getModel (modelName ).getModeltype ();
236
+ URL url = new URL (checkTrailingSlash (mModeltype .getUri ()) + "model/" + modelName + "/status" );
237
+ HttpURLConnection httpConn = (HttpURLConnection ) url .openConnection ();
238
+ httpConn .setRequestMethod ("GET" );
239
+
240
+ if (httpConn .getResponseCode () != HttpURLConnection .HTTP_OK ) {
241
+ throw new TrainDBException ("failed to get model status" );
242
+ }
243
+
244
+ StringBuilder response = new StringBuilder ();
245
+ BufferedReader reader = new BufferedReader (
246
+ new InputStreamReader (httpConn .getInputStream (), StandardCharsets .UTF_8 ));
247
+ String line ;
248
+ while ((line = reader .readLine ()) != null ) {
249
+ response .append (line );
250
+ }
251
+ String res = unescapeString (response .toString ());
252
+ if (res .equalsIgnoreCase ("FINISHED" )) {
253
+ return true ;
254
+ }
255
+ return false ;
227
256
}
228
257
229
258
}
0 commit comments