Search in sources :

Example 11 with WebHdfsFileSystem

use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.

the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForDirectory.

@Test
public void testGetContentSummaryForDirectory() throws Exception {
    try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
        viewer.initServer(originalFsimage.getAbsolutePath());
        int port = viewer.getPort();
        URL url = new URL("http://localhost:" + port + "/webhdfs/v1/parentDir/?op=GETCONTENTSUMMARY");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
        // create a WebHdfsFileSystem instance
        URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
        Configuration conf = new Configuration();
        WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
        ContentSummary summary = webfs.getContentSummary(new Path("/parentDir/"));
        verifyContentSummary(summaryFromDFS, summary);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HttpURLConnection(java.net.HttpURLConnection) Configuration(org.apache.hadoop.conf.Configuration) ContentSummary(org.apache.hadoop.fs.ContentSummary) URI(java.net.URI) WebHdfsFileSystem(org.apache.hadoop.hdfs.web.WebHdfsFileSystem) URL(java.net.URL) Test(org.junit.Test)

Example 12 with WebHdfsFileSystem

use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.

the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForSymlink.

@Test
public void testGetContentSummaryForSymlink() throws Exception {
    try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
        viewer.initServer(originalFsimage.getAbsolutePath());
        int port = viewer.getPort();
        // create a WebHdfsFileSystem instance
        URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
        Configuration conf = new Configuration();
        WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
        ContentSummary summary = webfs.getContentSummary(new Path("/link1"));
        verifyContentSummary(symLinkSummaryFromDFS, summary);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) ContentSummary(org.apache.hadoop.fs.ContentSummary) URI(java.net.URI) WebHdfsFileSystem(org.apache.hadoop.hdfs.web.WebHdfsFileSystem) Test(org.junit.Test)

Example 13 with WebHdfsFileSystem

use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.

the class TestOfflineImageViewerForXAttr method testWithWebHdfsFileSystem.

@Test
public void testWithWebHdfsFileSystem() throws Exception {
    try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
        viewer.initServer(originalFsimage.getAbsolutePath());
        int port = viewer.getPort();
        // create a WebHdfsFileSystem instance
        URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
        Configuration conf = new Configuration();
        WebHdfsFileSystem webhdfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
        List<String> names = webhdfs.listXAttrs(new Path("/dir1"));
        assertTrue(names.contains("user.attr1"));
        assertTrue(names.contains("user.attr2"));
        String value = new String(webhdfs.getXAttr(new Path("/dir1"), "user.attr1"));
        assertEquals("value1", value);
        value = new String(webhdfs.getXAttr(new Path("/dir1"), "USER.attr1"));
        assertEquals("value1", value);
        Map<String, byte[]> contentMap = webhdfs.getXAttrs(new Path("/dir1"), names);
        assertEquals("value1", new String(contentMap.get("user.attr1")));
        assertEquals("value2", new String(contentMap.get("user.attr2")));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) URI(java.net.URI) WebHdfsFileSystem(org.apache.hadoop.hdfs.web.WebHdfsFileSystem) Test(org.junit.Test)

Example 14 with WebHdfsFileSystem

use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.

the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForDirContainsSymlink.

@Test
public void testGetContentSummaryForDirContainsSymlink() throws Exception {
    try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
        viewer.initServer(originalFsimage.getAbsolutePath());
        int port = viewer.getPort();
        // create a WebHdfsFileSystem instance
        URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
        Configuration conf = new Configuration();
        WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
        ContentSummary summary = webfs.getContentSummary(new Path("/dirForLinks/"));
        verifyContentSummary(symLinkSummaryForDirContainsFromDFS, summary);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) ContentSummary(org.apache.hadoop.fs.ContentSummary) URI(java.net.URI) WebHdfsFileSystem(org.apache.hadoop.hdfs.web.WebHdfsFileSystem) Test(org.junit.Test)

Example 15 with WebHdfsFileSystem

use of org.apache.hadoop.hdfs.web.WebHdfsFileSystem in project hadoop by apache.

the class TestOfflineImageViewerForContentSummary method testGetContentSummaryForFile.

@Test
public void testGetContentSummaryForFile() throws Exception {
    try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) {
        viewer.initServer(originalFsimage.getAbsolutePath());
        int port = viewer.getPort();
        URL url = new URL("http://localhost:" + port + "/webhdfs/v1/parentDir/file1?op=GETCONTENTSUMMARY");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();
        assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode());
        // create a WebHdfsFileSystem instance
        URI uri = new URI("webhdfs://localhost:" + String.valueOf(port));
        Configuration conf = new Configuration();
        WebHdfsFileSystem webfs = (WebHdfsFileSystem) FileSystem.get(uri, conf);
        ContentSummary summary = webfs.getContentSummary(new Path("/parentDir/file1"));
        verifyContentSummary(fileSummaryFromDFS, summary);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) HttpURLConnection(java.net.HttpURLConnection) Configuration(org.apache.hadoop.conf.Configuration) ContentSummary(org.apache.hadoop.fs.ContentSummary) URI(java.net.URI) WebHdfsFileSystem(org.apache.hadoop.hdfs.web.WebHdfsFileSystem) URL(java.net.URL) Test(org.junit.Test)

Aggregations

WebHdfsFileSystem (org.apache.hadoop.hdfs.web.WebHdfsFileSystem)21 Test (org.junit.Test)19 Path (org.apache.hadoop.fs.Path)18 Configuration (org.apache.hadoop.conf.Configuration)10 URI (java.net.URI)9 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 ContentSummary (org.apache.hadoop.fs.ContentSummary)5 FsPermission (org.apache.hadoop.fs.permission.FsPermission)5 FileStatus (org.apache.hadoop.fs.FileStatus)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FsShell (org.apache.hadoop.fs.FsShell)2 HdfsAdmin (org.apache.hadoop.hdfs.client.HdfsAdmin)2 DelegationTokenIdentifier (org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier)2 Text (org.apache.hadoop.io.Text)2 AccessControlException (org.apache.hadoop.security.AccessControlException)2 Credentials (org.apache.hadoop.security.Credentials)2 Token (org.apache.hadoop.security.token.Token)2 Mockito.anyString (org.mockito.Mockito.anyString)2