Search in sources :

Example 41 with H2OIllegalArgumentException

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;
}
Also used : UploadFileVec(water.fvec.UploadFileVec) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) URI(java.net.URI) URL(java.net.URL) Key(water.Key)

Example 42 with H2OIllegalArgumentException

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;
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) Key(water.Key)

Example 43 with H2OIllegalArgumentException

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);
}
Also used : Frame(water.fvec.Frame) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) Iced(water.Iced) ByteVec(water.fvec.ByteVec)

Aggregations

H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)43 Frame (water.fvec.Frame)16 Key (water.Key)6 H2OKeyNotFoundArgumentException (water.exceptions.H2OKeyNotFoundArgumentException)6 Vec (water.fvec.Vec)6 Field (java.lang.reflect.Field)3 Chunk (water.fvec.Chunk)3 NewChunk (water.fvec.NewChunk)3 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)2 GLMModel (hex.glm.GLMModel)2 DRFModel (hex.tree.drf.DRFModel)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Iced (water.Iced)2 FrameV3 (water.api.schemas3.FrameV3)2 JobV3 (water.api.schemas3.JobV3)2 KeyV3 (water.api.schemas3.KeyV3)2 ByteVec (water.fvec.ByteVec)2 C0DChunk (water.fvec.C0DChunk)2