Search in sources :

Example 1 with ForwardingLocationFactory

use of org.apache.twill.filesystem.ForwardingLocationFactory in project cdap by caskdata.

the class SparkPackageUtils method resolveURI.

/**
   * Resolves a {@link URI} representation from the given {@link Location}. It resolves the URI in the same way
   * as Spark does.
   */
private static URI resolveURI(Location location) throws IOException {
    LocationFactory locationFactory = location.getLocationFactory();
    while (locationFactory instanceof ForwardingLocationFactory) {
        locationFactory = ((ForwardingLocationFactory) locationFactory).getDelegate();
    }
    if (!(locationFactory instanceof FileContextLocationFactory)) {
        return location.toURI();
    }
    // Resolves the URI the way as Spark does
    Configuration hConf = ((FileContextLocationFactory) locationFactory).getConfiguration();
    org.apache.hadoop.fs.Path path = new org.apache.hadoop.fs.Path(location.toURI().getPath());
    path = path.getFileSystem(hConf).makeQualified(path);
    return ((FileContextLocationFactory) locationFactory).getFileContext().resolvePath(path).toUri();
}
Also used : Path(java.nio.file.Path) Configuration(org.apache.hadoop.conf.Configuration) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory) ForwardingLocationFactory(org.apache.twill.filesystem.ForwardingLocationFactory) ForwardingLocationFactory(org.apache.twill.filesystem.ForwardingLocationFactory) LocationFactory(org.apache.twill.filesystem.LocationFactory) FileContextLocationFactory(org.apache.twill.filesystem.FileContextLocationFactory)

Aggregations

Path (java.nio.file.Path)1 Configuration (org.apache.hadoop.conf.Configuration)1 FileContextLocationFactory (org.apache.twill.filesystem.FileContextLocationFactory)1 ForwardingLocationFactory (org.apache.twill.filesystem.ForwardingLocationFactory)1 LocationFactory (org.apache.twill.filesystem.LocationFactory)1