Search in sources :

Example 66 with URI

use of java.net.URI in project hadoop by apache.

the class TestHarFileSystemBasics method testPositiveListFilesNotEndInColon.

@Test
public void testPositiveListFilesNotEndInColon() throws Exception {
    // re-initialize the har file system with host name
    // make sure the qualified path name does not append ":" at the end of host name
    final URI uri = new URI("har://file-localhost" + harPath.toString());
    harFileSystem.initialize(uri, conf);
    Path p1 = new Path("har://file-localhost" + harPath.toString());
    Path p2 = harFileSystem.makeQualified(p1);
    assertTrue(p2.toUri().toString().startsWith("har://file-localhost/"));
}
Also used : URI(java.net.URI) Test(org.junit.Test)

Example 67 with URI

use of java.net.URI in project hadoop by apache.

the class TestHarFileSystemBasics method testListLocatedStatus.

@Test
public void testListLocatedStatus() throws Exception {
    String testHarPath = this.getClass().getResource("/test.har").getPath();
    URI uri = new URI("har://" + testHarPath);
    HarFileSystem hfs = new HarFileSystem(localFileSystem);
    hfs.initialize(uri, new Configuration());
    // test.har has the following contents:
    //   dir1/1.txt
    //   dir1/2.txt
    Set<String> expectedFileNames = new HashSet<String>();
    expectedFileNames.add("1.txt");
    expectedFileNames.add("2.txt");
    // List contents of dir, and ensure we find all expected files
    Path path = new Path("dir1");
    RemoteIterator<LocatedFileStatus> fileList = hfs.listLocatedStatus(path);
    while (fileList.hasNext()) {
        String fileName = fileList.next().getPath().getName();
        assertTrue(fileName + " not in expected files list", expectedFileNames.contains(fileName));
        expectedFileNames.remove(fileName);
    }
    assertEquals("Didn't find all of the expected file names: " + expectedFileNames, 0, expectedFileNames.size());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 68 with URI

use of java.net.URI in project hadoop by apache.

the class FileSystem method checkPath.

/**
   * Check that a Path belongs to this FileSystem.
   *
   * The base implementation performs case insensitive equality checks
   * of the URIs' schemes and authorities. Subclasses may implement slightly
   * different checks.
   * @param path to check
   * @throws IllegalArgumentException if the path is not considered to be
   * part of this FileSystem.
   *
   */
protected void checkPath(Path path) {
    URI uri = path.toUri();
    String thatScheme = uri.getScheme();
    if (// fs is relative
    thatScheme == null)
        return;
    URI thisUri = getCanonicalUri();
    String thisScheme = thisUri.getScheme();
    //authority and scheme are not case sensitive
    if (thisScheme.equalsIgnoreCase(thatScheme)) {
        // schemes match
        String thisAuthority = thisUri.getAuthority();
        String thatAuthority = uri.getAuthority();
        if (// path's authority is null
        thatAuthority == null && thisAuthority != null) {
            // fs has an authority
            URI defaultUri = getDefaultUri(getConf());
            if (thisScheme.equalsIgnoreCase(defaultUri.getScheme())) {
                // schemes match, so use this uri instead
                uri = defaultUri;
            } else {
                // can't determine auth of the path
                uri = null;
            }
        }
        if (uri != null) {
            // canonicalize uri before comparing with this fs
            uri = canonicalizeUri(uri);
            thatAuthority = uri.getAuthority();
            if (// authorities match
            thisAuthority == thatAuthority || (thisAuthority != null && thisAuthority.equalsIgnoreCase(thatAuthority)))
                return;
        }
    }
    throw new IllegalArgumentException("Wrong FS: " + path + ", expected: " + this.getUri());
}
Also used : URI(java.net.URI)

Example 69 with URI

use of java.net.URI in project hadoop by apache.

the class HarFileSystem method makeQualified.

/* this makes a path qualified in the har filesystem
   * (non-Javadoc)
   * @see org.apache.hadoop.fs.FilterFileSystem#makeQualified(
   * org.apache.hadoop.fs.Path)
   */
@Override
public Path makeQualified(Path path) {
    // make sure that we just get the 
    // path component 
    Path fsPath = path;
    if (!path.isAbsolute()) {
        fsPath = new Path(archivePath, path);
    }
    URI tmpURI = fsPath.toUri();
    //change this to Har uri 
    return new Path(uri.getScheme(), harAuth, tmpURI.getPath());
}
Also used : URI(java.net.URI)

Example 70 with URI

use of java.net.URI in project hadoop by apache.

the class HarFileSystem method decodeHarURI.

/**
   * decode the raw URI to get the underlying URI
   * @param rawURI raw Har URI
   * @return filtered URI of the underlying fileSystem
   */
private URI decodeHarURI(URI rawURI, Configuration conf) throws IOException {
    String tmpAuth = rawURI.getAuthority();
    //return it
    if (tmpAuth == null) {
        //create a path 
        return FileSystem.getDefaultUri(conf);
    }
    String authority = rawURI.getAuthority();
    int i = authority.indexOf('-');
    if (i < 0) {
        throw new IOException("URI: " + rawURI + " is an invalid Har URI since '-' not found." + "  Expecting har://<scheme>-<host>/<path>.");
    }
    if (rawURI.getQuery() != null) {
        // query component not allowed
        throw new IOException("query component in Path not supported  " + rawURI);
    }
    URI tmp;
    try {
        // convert <scheme>-<host> to <scheme>://<host>
        URI baseUri = new URI(authority.replaceFirst("-", "://"));
        tmp = new URI(baseUri.getScheme(), baseUri.getAuthority(), rawURI.getPath(), rawURI.getQuery(), rawURI.getFragment());
    } catch (URISyntaxException e) {
        throw new IOException("URI: " + rawURI + " is an invalid Har URI. Expecting har://<scheme>-<host>/<path>.");
    }
    return tmp;
}
Also used : IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

URI (java.net.URI)5680 Test (org.junit.Test)1852 URISyntaxException (java.net.URISyntaxException)1016 IOException (java.io.IOException)749 File (java.io.File)531 HashMap (java.util.HashMap)458 ArrayList (java.util.ArrayList)452 Test (org.testng.annotations.Test)394 Configuration (org.apache.hadoop.conf.Configuration)321 Path (org.apache.hadoop.fs.Path)267 URL (java.net.URL)266 Map (java.util.Map)262 Response (javax.ws.rs.core.Response)218 List (java.util.List)184 InputStream (java.io.InputStream)154 HashSet (java.util.HashSet)136 FileSystem (org.apache.hadoop.fs.FileSystem)135 RequestContext (com.linkedin.r2.message.RequestContext)129 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)128 RestRequest (com.linkedin.r2.message.rest.RestRequest)112