use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.
the class PersistManager method importFiles.
/**
* From a path produce a list of files and keys for parsing.
*
* Use as follows:
*
* ArrayList<String> files = new ArrayList();
* ArrayList<String> keys = new ArrayList();
* ArrayList<String> fails = new ArrayList();
* ArrayList<String> dels = new ArrayList();
* importFiles(importFiles.path, files, keys, fails, dels);
*
* @param path (Input) Path to import data from
* @param pattern (Input) Regex pattern to match files by
* @param files (Output) List of files found
* @param keys (Output) List of keys corresponding to files
* @param fails (Output) List of failed files which mismatch among nodes
* @param dels (Output) I don't know what this is
*/
public void importFiles(String path, String pattern, ArrayList<String> files, ArrayList<String> keys, ArrayList<String> fails, ArrayList<String> dels) {
URI uri = FileUtils.getURI(path);
String scheme = uri.getScheme();
if (scheme == null || "file".equals(scheme)) {
I[Value.NFS].importFiles(path, pattern, files, keys, fails, dels);
} else if ("http".equals(scheme) || "https".equals(scheme)) {
try {
java.net.URL url = new URL(path);
Key destination_key = Key.make(path);
java.io.InputStream is = url.openStream();
UploadFileVec.ReadPutStats stats = new UploadFileVec.ReadPutStats();
UploadFileVec.readPut(destination_key, is, stats);
files.add(path);
keys.add(destination_key.toString());
} catch (Throwable e) {
// Fails for e.g. broken sockets silently swallow exceptions and just record the failed path
fails.add(path);
}
} else if ("s3".equals(scheme)) {
if (I[Value.S3] == null)
throw new H2OIllegalArgumentException("S3 support is not configured");
I[Value.S3].importFiles(path, pattern, files, keys, fails, dels);
} else if ("hdfs".equals(scheme) || "s3n:".equals(scheme) || "s3a:".equals(scheme) || "maprfs:".equals(scheme) || (useHdfsAsFallback() && I[Value.HDFS] != null && I[Value.HDFS].canHandle(path))) {
if (I[Value.HDFS] == null)
throw new H2OIllegalArgumentException("HDFS, S3N, and S3A support is not configured");
I[Value.HDFS].importFiles(path, pattern, files, keys, fails, dels);
}
if (pattern != null && !pattern.isEmpty()) {
//New files ArrayList after matching pattern of choice
files.retainAll(matchPattern(path, files, pattern));
//New keys ArrayList after matching pattern of choice
keys.retainAll(matchPattern(path, keys, pattern));
//New fails ArrayList after matching pattern of choice. Only show failures that match pattern
if (!fails.isEmpty()) {
fails.retainAll(matchPattern(path, fails, pattern));
}
}
return;
}
use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.
the class PersistManager method anyURIToKey.
/** Convert given URI into a specific H2O key representation.
*
* The representation depends on persistent backend, since it will
* deduce file location from the key content.
*
* The method will look at scheme of URI and based on it, it will
* ask a backend to provide a conversion to a key (i.e., URI with scheme
* 'hdfs' will be forwared to HDFS backend).
*
* @param uri file location
* @return a key encoding URI
* @throws IOException in the case of uri conversion problem
* @throws water.exceptions.H2OIllegalArgumentException in case of unsupported scheme
*/
public final Key anyURIToKey(URI uri) throws IOException {
Key ikey = null;
String scheme = uri.getScheme();
if ("s3".equals(scheme)) {
ikey = I[Value.S3].uriToKey(uri);
} else if ("hdfs".equals(scheme)) {
ikey = I[Value.HDFS].uriToKey(uri);
} else if ("s3".equals(scheme) || "s3n".equals(scheme) || "s3a".equals(scheme)) {
ikey = I[Value.HDFS].uriToKey(uri);
} else if ("file".equals(scheme) || scheme == null) {
ikey = I[Value.NFS].uriToKey(uri);
} else if (useHdfsAsFallback() && I[Value.HDFS].canHandle(uri.toString())) {
ikey = I[Value.HDFS].uriToKey(uri);
} else {
throw new H2OIllegalArgumentException("Unsupported schema '" + scheme + "' for given uri " + uri);
}
return ikey;
}
use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.
the class ZipUtil method isZipDirectory.
/**
* This method check if the input argument is a zip directory containing files.
*
* @param key
* @return true if bv is a zip directory containing files, false otherwise.
*/
static boolean isZipDirectory(Key key) {
Iced ice = DKV.getGet(key);
if (ice == null)
throw new H2OIllegalArgumentException("Missing data", "Did not find any data under " + "key " + key);
ByteVec bv = (ByteVec) (ice instanceof ByteVec ? ice : ((Frame) ice).vecs()[0]);
return isZipDirectory(bv);
}
Aggregations