use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.
the class InteractionHandler method run.
public JobV3 run(int version, InteractionV3 cf) {
Interaction cfr = new Interaction();
cf.fillImpl(cfr);
return new JobV3(cfr.execImpl(cf.dest == null ? null : cf.dest.key()));
}
use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.
the class JobsHandler method list.
/** Impl class for a collection of jobs; only used in the API to make it easier to cons up the jobs array via the magic of PojoUtils.copyProperties. */
// called through reflection by RequestServer
@SuppressWarnings("unused")
public JobsV3 list(int version, JobsV3 s) {
Job[] jobs = Job.jobs();
// Jobs j = new Jobs();
// j._jobs = Job.jobs();
// PojoUtils.copyProperties(s, j, PojoUtils.FieldNaming.ORIGIN_HAS_UNDERSCORES);
s.jobs = new JobV3[jobs.length];
int i = 0;
for (Job j : jobs) {
try {
s.jobs[i] = (JobV3) SchemaServer.schema(version, j).fillFromImpl(j);
}// no special schema for this job subclass, so fall back to JobV3
catch (H2ONotFoundArgumentException e) {
s.jobs[i] = new JobV3().fillFromImpl(j);
}
// Java does the increment before the function call which throws?!
i++;
}
return s;
}
use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.
the class ParseHandler method parseSVMLight.
// called through reflection by RequestServer
@SuppressWarnings("unused")
public JobV3 parseSVMLight(int version, ParseSVMLightV3 parse) {
Key[] fkeys = new Key[parse.source_frames.length];
for (int i = 0; i < fkeys.length; ++i) fkeys[i] = parse.source_frames[i].key();
Key<Frame> destKey = parse.destination_frame == null ? null : parse.destination_frame.key();
if (destKey == null)
destKey = Key.make(ParseSetup.createHexName(parse.source_frames[0].toString()));
ParseSetup setup = ParseSetup.guessSetup(fkeys, ParseSetup.makeSVMLightSetup());
return new JobV3().fillFromImpl(ParseDataset.forkParseSVMLight(destKey, fkeys, setup));
}
use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.
the class Schema method parse.
// URL parameter parse
static <E> Object parse(String field_name, String s, Class fclz, boolean required, Class schemaClass) {
if (fclz.isPrimitive() || String.class.equals(fclz)) {
try {
return parsePrimitve(s, fclz);
} catch (NumberFormatException ne) {
String msg = "Illegal argument for field: " + field_name + " of schema: " + schemaClass.getSimpleName() + ": cannot convert \"" + s + "\" to type " + fclz.getSimpleName();
throw new H2OIllegalArgumentException(msg);
}
}
// An array?
if (fclz.isArray()) {
// Get component type
Class<E> afclz = (Class<E>) fclz.getComponentType();
// Result
E[] a = null;
// Handle simple case with null-array
if (s.equals("null") || s.length() == 0)
return null;
// Splitted values
// "".split(",") => {""} so handle the empty case explicitly
String[] splits;
if (s.startsWith("[") && s.endsWith("]")) {
// It looks like an array
read(s, 0, '[', fclz);
read(s, s.length() - 1, ']', fclz);
String inside = s.substring(1, s.length() - 1).trim();
if (inside.length() == 0)
splits = new String[] {};
else
splits = splitArgs(inside);
} else {
// Lets try to parse single value as an array!
// See PUBDEV-1955
splits = new String[] { s.trim() };
}
// Can't cast an int[] to an Object[]. Sigh.
if (afclz == int.class) {
// TODO: other primitive types. . .
a = (E[]) Array.newInstance(Integer.class, splits.length);
} else if (afclz == double.class) {
a = (E[]) Array.newInstance(Double.class, splits.length);
} else if (afclz == float.class) {
a = (E[]) Array.newInstance(Float.class, splits.length);
} else {
// Fails with primitive classes; need the wrapper class. Thanks, Java.
a = (E[]) Array.newInstance(afclz, splits.length);
}
for (int i = 0; i < splits.length; i++) {
if (String.class == afclz || KeyV3.class.isAssignableFrom(afclz)) {
// strip quotes off string values inside array
String stripped = splits[i].trim();
if ("null".equals(stripped.toLowerCase()) || "na".equals(stripped.toLowerCase())) {
a[i] = null;
continue;
}
// Quotes are now optional because standard clients will send arrays of length one as just strings.
if (stripped.startsWith("\"") && stripped.endsWith("\"")) {
stripped = stripped.substring(1, stripped.length() - 1);
}
a[i] = (E) parse(field_name, stripped, afclz, required, schemaClass);
} else {
a[i] = (E) parse(field_name, splits[i].trim(), afclz, required, schemaClass);
}
}
return a;
}
// Are we parsing an object from a string? NOTE: we might want to make this check more restrictive.
if (!fclz.isAssignableFrom(Schema.class) && s != null && s.startsWith("{") && s.endsWith("}")) {
return gson.fromJson(s, fclz);
}
if (fclz.equals(Key.class))
if ((s == null || s.length() == 0) && required)
throw new H2OKeyNotFoundArgumentException(field_name, s);
else if (!required && (s == null || s.length() == 0))
return null;
else
// If the key name is in an array we need to trim surrounding quotes.
return Key.make(s.startsWith("\"") ? s.substring(1, s.length() - 1) : s);
if (KeyV3.class.isAssignableFrom(fclz)) {
if ((s == null || s.length() == 0) && required)
throw new H2OKeyNotFoundArgumentException(field_name, s);
if (!required && (s == null || s.length() == 0))
return null;
// If the key name is in an array we need to trim surrounding quotes.
return KeyV3.make(fclz, Key.make(s.startsWith("\"") ? s.substring(1, s.length() - 1) : s));
}
if (Enum.class.isAssignableFrom(fclz)) {
return EnumUtils.valueOf(fclz, s);
}
// TODO: these can be refactored into a single case using the facilities in Schema:
if (FrameV3.class.isAssignableFrom(fclz)) {
if ((s == null || s.length() == 0) && required)
throw new H2OKeyNotFoundArgumentException(field_name, s);
else if (!required && (s == null || s.length() == 0))
return null;
else {
Value v = DKV.get(s);
// not required
if (null == v)
return null;
if (!v.isFrame())
throw H2OIllegalArgumentException.wrongKeyType(field_name, s, "Frame", v.get().getClass());
// TODO: version!
return new FrameV3((Frame) v.get());
}
}
if (JobV3.class.isAssignableFrom(fclz)) {
if ((s == null || s.length() == 0) && required)
throw new H2OKeyNotFoundArgumentException(s);
else if (!required && (s == null || s.length() == 0))
return null;
else {
Value v = DKV.get(s);
// not required
if (null == v)
return null;
if (!v.isJob())
throw H2OIllegalArgumentException.wrongKeyType(field_name, s, "Job", v.get().getClass());
// TODO: version!
return new JobV3().fillFromImpl((Job) v.get());
}
}
// where the frame name is also specified.
if (FrameV3.ColSpecifierV3.class.isAssignableFrom(fclz)) {
return new FrameV3.ColSpecifierV3(s);
}
if (ModelSchemaV3.class.isAssignableFrom(fclz))
throw H2O.fail("Can't yet take ModelSchemaV3 as input.");
/*
if( (s==null || s.length()==0) && required ) throw new IllegalArgumentException("Missing key");
else if (!required && (s == null || s.length() == 0)) return null;
else {
Value v = DKV.get(s);
if (null == v) return null; // not required
if (! v.isModel()) throw new IllegalArgumentException("Model argument points to a non-model object.");
return v.get();
}
*/
throw H2O.fail("Unimplemented schema fill from " + fclz.getSimpleName());
}
use of water.api.schemas3.JobV3 in project h2o-3 by h2oai.
the class JobV3 method fillFromImpl.
// Version&Schema-specific filling from the impl
@Override
public JobV3 fillFromImpl(Job job) {
if (job == null)
return this;
// Handle fields in subclasses:
PojoUtils.copyProperties(this, job, PojoUtils.FieldNaming.ORIGIN_HAS_UNDERSCORES);
// TODO: make consistent and remove
PojoUtils.copyProperties(this, job, PojoUtils.FieldNaming.CONSISTENT);
key = new JobKeyV3(job._key);
description = job._description;
warnings = job.warns();
progress = job.progress();
progress_msg = job.progress_msg();
// Notice new state "CANCEL_PENDING".
if (job.isRunning())
if (job.stop_requested())
status = "CANCEL_PENDING";
else
status = "RUNNING";
else if (job.stop_requested())
status = "CANCELLED";
else
status = "DONE";
Throwable ex = job.ex();
if (ex != null)
status = "FAILED";
exception = ex == null ? null : ex.toString();
if (ex != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
stacktrace = sw.toString();
}
msec = job.msec();
ready_for_view = job.readyForView();
Keyed dest_type = (Keyed) TypeMap.theFreezable(job._typeid);
dest = job._result == null ? null : KeyV3.make(dest_type.makeSchema(), job._result);
return this;
}
Aggregations