Search in sources :

Example 21 with HdfsConfiguration

use of org.apache.hadoop.hdfs.HdfsConfiguration in project hadoop by apache.

the class TestStorageLocationChecker method testTimeoutInCheck.

/**
   * Verify that a {@link StorageLocation#check} timeout is correctly detected
   * as a failure.
   *
   * This is hard to test without a {@link Thread#sleep} call.
   *
   * @throws Exception
   */
@Test(timeout = 300000)
public void testTimeoutInCheck() throws Exception {
    final Configuration conf = new HdfsConfiguration();
    conf.setTimeDuration(DFS_DATANODE_DISK_CHECK_TIMEOUT_KEY, 1, TimeUnit.SECONDS);
    conf.setInt(DFS_DATANODE_FAILED_VOLUMES_TOLERATED_KEY, 1);
    final FakeTimer timer = new FakeTimer();
    // Generate a list of storage locations the first of which sleeps
    // for 2 seconds in its check() routine.
    final List<StorageLocation> locations = makeSlowLocations(2000, 1);
    StorageLocationChecker checker = new StorageLocationChecker(conf, timer);
    try {
        // Check the two locations and ensure that only one of them
        // was filtered out.
        List<StorageLocation> filteredList = checker.check(conf, locations);
        assertThat(filteredList.size(), is(1));
    } finally {
        checker.shutdownAndWait(10, TimeUnit.SECONDS);
    }
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation) FakeTimer(org.apache.hadoop.util.FakeTimer) Test(org.junit.Test)

Example 22 with HdfsConfiguration

use of org.apache.hadoop.hdfs.HdfsConfiguration in project hadoop by apache.

the class TestEditLogTailer method getConf.

private static Configuration getConf() {
    Configuration conf = new HdfsConfiguration();
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_EDITS_ASYNC_LOGGING, useAsyncEditLog);
    return conf;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration)

Example 23 with HdfsConfiguration

use of org.apache.hadoop.hdfs.HdfsConfiguration in project hadoop by apache.

the class TestWebHdfsTokens method testSetTokenServiceAndKind.

@Test
public void testSetTokenServiceAndKind() throws Exception {
    MiniDFSCluster cluster = null;
    try {
        final Configuration clusterConf = new HdfsConfiguration(conf);
        SecurityUtil.setAuthenticationMethod(SIMPLE, clusterConf);
        clusterConf.setBoolean(DFSConfigKeys.DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true);
        // trick the NN into thinking s[ecurity is enabled w/o it trying
        // to login from a keytab
        UserGroupInformation.setConfiguration(clusterConf);
        cluster = new MiniDFSCluster.Builder(clusterConf).numDataNodes(0).build();
        cluster.waitActive();
        SecurityUtil.setAuthenticationMethod(KERBEROS, clusterConf);
        final WebHdfsFileSystem fs = WebHdfsTestUtil.getWebHdfsFileSystem(clusterConf, "webhdfs");
        Whitebox.setInternalState(fs, "canRefreshDelegationToken", true);
        URLConnectionFactory factory = new URLConnectionFactory(new ConnectionConfigurator() {

            @Override
            public HttpURLConnection configure(HttpURLConnection conn) throws IOException {
                return conn;
            }
        }) {

            @Override
            public URLConnection openConnection(URL url) throws IOException {
                return super.openConnection(new URL(url + "&service=foo&kind=bar"));
            }
        };
        Whitebox.setInternalState(fs, "connectionFactory", factory);
        Token<?> token1 = fs.getDelegationToken();
        Assert.assertEquals(new Text("bar"), token1.getKind());
        final HttpOpParam.Op op = GetOpParam.Op.GETDELEGATIONTOKEN;
        Token<DelegationTokenIdentifier> token2 = fs.new FsPathResponseRunner<Token<DelegationTokenIdentifier>>(op, null, new RenewerParam(null)) {

            @Override
            Token<DelegationTokenIdentifier> decodeResponse(Map<?, ?> json) throws IOException {
                return JsonUtilClient.toDelegationToken(json);
            }
        }.run();
        Assert.assertEquals(new Text("bar"), token2.getKind());
        Assert.assertEquals(new Text("foo"), token2.getService());
    } finally {
        if (cluster != null) {
            cluster.shutdown();
        }
    }
}
Also used : ConnectionConfigurator(org.apache.hadoop.security.authentication.client.ConnectionConfigurator) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) DelegationTokenIdentifier(org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier) Text(org.apache.hadoop.io.Text) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) Token(org.apache.hadoop.security.token.Token) IOException(java.io.IOException) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) Test(org.junit.Test)

Example 24 with HdfsConfiguration

use of org.apache.hadoop.hdfs.HdfsConfiguration in project hadoop by apache.

the class TestGetConf method testTool.

/**
   * Tests commands other than {@link Command#NAMENODE}, {@link Command#BACKUP},
   * {@link Command#SECONDARY} and {@link Command#NNRPCADDRESSES}
   */
@Test(timeout = 10000)
public void testTool() throws Exception {
    HdfsConfiguration conf = new HdfsConfiguration(false);
    for (Command cmd : Command.values()) {
        CommandHandler handler = Command.getHandler(cmd.getName());
        if (handler.key != null && !"-confKey".equals(cmd.getName())) {
            // Add the key to the conf and ensure tool returns the right value
            String[] args = { cmd.getName() };
            conf.set(handler.key, "value");
            assertTrue(runTool(conf, args, true).contains("value"));
        }
    }
}
Also used : Command(org.apache.hadoop.hdfs.tools.GetConf.Command) CommandHandler(org.apache.hadoop.hdfs.tools.GetConf.CommandHandler) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Test(org.junit.Test)

Example 25 with HdfsConfiguration

use of org.apache.hadoop.hdfs.HdfsConfiguration in project hadoop by apache.

the class TestGetConf method testInvalidArgument.

/**
   * Test invalid argument to the tool
   */
@Test(timeout = 10000)
public void testInvalidArgument() throws Exception {
    HdfsConfiguration conf = new HdfsConfiguration();
    String[] args = { "-invalidArgument" };
    String ret = runTool(conf, args, false);
    assertTrue(ret.contains(GetConf.USAGE));
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Test(org.junit.Test)

Aggregations

HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)454 Configuration (org.apache.hadoop.conf.Configuration)311 Test (org.junit.Test)311 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)267 Path (org.apache.hadoop.fs.Path)152 FileSystem (org.apache.hadoop.fs.FileSystem)94 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)92 File (java.io.File)72 IOException (java.io.IOException)69 Before (org.junit.Before)56 ExtendedBlock (org.apache.hadoop.hdfs.protocol.ExtendedBlock)40 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)35 MetricsRecordBuilder (org.apache.hadoop.metrics2.MetricsRecordBuilder)33 DataNode (org.apache.hadoop.hdfs.server.datanode.DataNode)30 LocatedBlock (org.apache.hadoop.hdfs.protocol.LocatedBlock)27 RandomAccessFile (java.io.RandomAccessFile)22 ArrayList (java.util.ArrayList)20 NameNodeFile (org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeFile)20 URI (java.net.URI)19 FsPermission (org.apache.hadoop.fs.permission.FsPermission)19