Search in sources :

Example 71 with URI

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

the class Path method makeQualified.

/**
   * Returns a qualified path object.
   *
   * @param defaultUri if this path is missing the scheme or authority
   * components, borrow them from this URI
   * @param workingDir if this path isn't absolute, treat it as relative to this
   * working directory
   * @return this path if it contains a scheme and authority and is absolute, or
   * a new path that includes a path and authority and is fully qualified
   */
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" })
public Path makeQualified(URI defaultUri, Path workingDir) {
    Path path = this;
    if (!isAbsolute()) {
        path = new Path(workingDir, this);
    }
    URI pathUri = path.toUri();
    String scheme = pathUri.getScheme();
    String authority = pathUri.getAuthority();
    String fragment = pathUri.getFragment();
    if (scheme != null && (authority != null || defaultUri.getAuthority() == null))
        return path;
    if (scheme == null) {
        scheme = defaultUri.getScheme();
    }
    if (authority == null) {
        authority = defaultUri.getAuthority();
        if (authority == null) {
            authority = "";
        }
    }
    URI newUri = null;
    try {
        newUri = new URI(scheme, authority, normalizePath(scheme, pathUri.getPath()), null, fragment);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return new Path(newUri);
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HadoopIllegalArgumentException(org.apache.hadoop.HadoopIllegalArgumentException)

Example 72 with URI

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

the class FileUtil method compareFs.

public static boolean compareFs(FileSystem srcFs, FileSystem destFs) {
    if (srcFs == null || destFs == null) {
        return false;
    }
    URI srcUri = srcFs.getUri();
    URI dstUri = destFs.getUri();
    if (srcUri.getScheme() == null) {
        return false;
    }
    if (!srcUri.getScheme().equals(dstUri.getScheme())) {
        return false;
    }
    String srcHost = srcUri.getHost();
    String dstHost = dstUri.getHost();
    if ((srcHost != null) && (dstHost != null)) {
        if (srcHost.equals(dstHost)) {
            return srcUri.getPort() == dstUri.getPort();
        }
        try {
            srcHost = InetAddress.getByName(srcHost).getCanonicalHostName();
            dstHost = InetAddress.getByName(dstHost).getCanonicalHostName();
        } catch (UnknownHostException ue) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Could not compare file-systems. Unknown host: ", ue);
            }
            return false;
        }
        if (!srcHost.equals(dstHost)) {
            return false;
        }
    } else if (srcHost == null && dstHost != null) {
        return false;
    } else if (srcHost != null) {
        return false;
    }
    // check for ports
    return srcUri.getPort() == dstUri.getPort();
}
Also used : UnknownHostException(java.net.UnknownHostException) URI(java.net.URI)

Example 73 with URI

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

the class FileContext method isSameFS.

/**
   * Are qualSrc and qualDst of the same file system?
   * @param qualPath1 - fully qualified path
   * @param qualPath2 - fully qualified path
   * @return
   */
private static boolean isSameFS(Path qualPath1, Path qualPath2) {
    URI srcUri = qualPath1.toUri();
    URI dstUri = qualPath2.toUri();
    return (srcUri.getScheme().equals(dstUri.getScheme()) && !(srcUri.getAuthority() != null && dstUri.getAuthority() != null && srcUri.getAuthority().equals(dstUri.getAuthority())));
}
Also used : URI(java.net.URI)

Example 74 with URI

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

the class AbstractFileSystem method getAllStatistics.

protected static synchronized Map<URI, Statistics> getAllStatistics() {
    Map<URI, Statistics> statsMap = new HashMap<URI, Statistics>(STATISTICS_TABLE.size());
    for (Map.Entry<URI, Statistics> pair : STATISTICS_TABLE.entrySet()) {
        URI key = pair.getKey();
        Statistics value = pair.getValue();
        Statistics newStatsObj = new Statistics(value);
        statsMap.put(URI.create(key.toString()), newStatsObj);
    }
    return statsMap;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URI(java.net.URI) Statistics(org.apache.hadoop.fs.FileSystem.Statistics) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 75 with URI

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

the class TestKeyProviderDelegationTokenExtension method testCreateExtension.

@Test
public void testCreateExtension() throws Exception {
    Configuration conf = new Configuration();
    Credentials credentials = new Credentials();
    KeyProvider kp = new UserProvider.Factory().createProvider(new URI("user:///"), conf);
    KeyProviderDelegationTokenExtension kpDTE1 = KeyProviderDelegationTokenExtension.createKeyProviderDelegationTokenExtension(kp);
    Assert.assertNotNull(kpDTE1);
    // Default implementation should be a no-op and return null
    Assert.assertNull(kpDTE1.addDelegationTokens("user", credentials));
    MockKeyProvider mock = mock(MockKeyProvider.class);
    Mockito.when(mock.getConf()).thenReturn(new Configuration());
    when(mock.addDelegationTokens("renewer", credentials)).thenReturn(new Token<?>[] { new Token(null, null, new Text("kind"), new Text("service")) });
    KeyProviderDelegationTokenExtension kpDTE2 = KeyProviderDelegationTokenExtension.createKeyProviderDelegationTokenExtension(mock);
    Token<?>[] tokens = kpDTE2.addDelegationTokens("renewer", credentials);
    Assert.assertNotNull(tokens);
    Assert.assertEquals("kind", tokens[0].getKind().toString());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Token(org.apache.hadoop.security.token.Token) Text(org.apache.hadoop.io.Text) URI(java.net.URI) Credentials(org.apache.hadoop.security.Credentials) Test(org.junit.Test)

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