Search in sources :

Example 6 with Server

use of org.apache.hadoop.lib.server.Server in project hadoop by apache.

the class TestFileSystemAccessService method fileSystemCache.

@Test
@TestDir
@TestHdfs
public void fileSystemCache() throws Exception {
    String dir = TestDirHelper.getTestDir().getAbsolutePath();
    String services = StringUtils.join(",", Arrays.asList(InstrumentationService.class.getName(), SchedulerService.class.getName(), FileSystemAccessService.class.getName()));
    Configuration hadoopConf = new Configuration(false);
    hadoopConf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, TestHdfsHelper.getHdfsConf().get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY));
    createHadoopConf(hadoopConf);
    Configuration conf = new Configuration(false);
    conf.set("server.services", services);
    conf.set("server.hadoop.filesystem.cache.purge.frequency", "1");
    conf.set("server.hadoop.filesystem.cache.purge.timeout", "1");
    Server server = new Server("server", dir, dir, dir, dir, conf);
    try {
        server.init();
        FileSystemAccess hadoop = server.get(FileSystemAccess.class);
        FileSystem fs1 = hadoop.createFileSystem("u", hadoop.getFileSystemConfiguration());
        Assert.assertNotNull(fs1);
        fs1.mkdirs(new Path("/tmp/foo1"));
        hadoop.releaseFileSystem(fs1);
        //still around because of caching
        fs1.mkdirs(new Path("/tmp/foo2"));
        FileSystem fs2 = hadoop.createFileSystem("u", hadoop.getFileSystemConfiguration());
        //should be same instance because of caching
        Assert.assertEquals(fs1, fs2);
        Thread.sleep(4 * 1000);
        //still around because of lease count is 1 (fs2 is out)
        fs1.mkdirs(new Path("/tmp/foo2"));
        Thread.sleep(4 * 1000);
        //still around because of lease count is 1 (fs2 is out)
        fs2.mkdirs(new Path("/tmp/foo"));
        hadoop.releaseFileSystem(fs2);
        Thread.sleep(4 * 1000);
        //should not be around as lease count is 0
        try {
            fs2.mkdirs(new Path("/tmp/foo"));
            Assert.fail();
        } catch (IOException ex) {
        } catch (Exception ex) {
            Assert.fail();
        }
    } finally {
        server.destroy();
    }
}
Also used : FileSystemAccess(org.apache.hadoop.lib.service.FileSystemAccess) Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.lib.server.Server) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) TestException(org.apache.hadoop.test.TestException) IOException(java.io.IOException) FileSystemAccessException(org.apache.hadoop.lib.service.FileSystemAccessException) ServiceException(org.apache.hadoop.lib.server.ServiceException) TestHdfs(org.apache.hadoop.test.TestHdfs) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 7 with Server

use of org.apache.hadoop.lib.server.Server in project hadoop by apache.

the class TestInstrumentationService method sampling.

@Test
@TestDir
@SuppressWarnings("unchecked")
public void sampling() throws Exception {
    String dir = TestDirHelper.getTestDir().getAbsolutePath();
    String services = StringUtils.join(",", Arrays.asList(InstrumentationService.class.getName(), SchedulerService.class.getName()));
    Configuration conf = new Configuration(false);
    conf.set("server.services", services);
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();
    Instrumentation instrumentation = server.get(Instrumentation.class);
    final AtomicInteger count = new AtomicInteger();
    Instrumentation.Variable<Long> varToSample = new Instrumentation.Variable<Long>() {

        @Override
        public Long getValue() {
            return (long) count.incrementAndGet();
        }
    };
    instrumentation.addSampler("g", "s", 10, varToSample);
    sleep(2000);
    int i = count.get();
    assertTrue(i > 0);
    Map<String, Map<String, ?>> snapshot = instrumentation.getSnapshot();
    Map<String, Map<String, Object>> samplers = (Map<String, Map<String, Object>>) snapshot.get("samplers");
    InstrumentationService.Sampler sampler = (InstrumentationService.Sampler) samplers.get("g").get("s");
    assertTrue(sampler.getRate() > 0);
    server.destroy();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.lib.server.Server) Instrumentation(org.apache.hadoop.lib.service.Instrumentation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 8 with Server

use of org.apache.hadoop.lib.server.Server in project hadoop by apache.

the class TestSchedulerService method service.

@Test
@TestDir
public void service() throws Exception {
    String dir = TestDirHelper.getTestDir().getAbsolutePath();
    Configuration conf = new Configuration(false);
    conf.set("server.services", StringUtils.join(",", Arrays.asList(InstrumentationService.class.getName(), SchedulerService.class.getName())));
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();
    assertNotNull(server.get(Scheduler.class));
    server.destroy();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.lib.server.Server) Scheduler(org.apache.hadoop.lib.service.Scheduler) InstrumentationService(org.apache.hadoop.lib.service.instrumentation.InstrumentationService) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 9 with Server

use of org.apache.hadoop.lib.server.Server in project hadoop by apache.

the class TestGroupsService method invalidGroupsMapping.

@Test(expected = RuntimeException.class)
@TestDir
public void invalidGroupsMapping() throws Exception {
    String dir = TestDirHelper.getTestDir().getAbsolutePath();
    Configuration conf = new Configuration(false);
    conf.set("server.services", StringUtils.join(",", Arrays.asList(GroupsService.class.getName())));
    conf.set("server.groups.hadoop.security.group.mapping", String.class.getName());
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.lib.server.Server) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Example 10 with Server

use of org.apache.hadoop.lib.server.Server in project hadoop by apache.

the class TestFileSystemAccessService method NameNodeNotinWhitelists.

@Test
@TestException(exception = FileSystemAccessException.class, msgRegExp = "H05.*")
@TestDir
public void NameNodeNotinWhitelists() throws Exception {
    String dir = TestDirHelper.getTestDir().getAbsolutePath();
    String services = StringUtils.join(",", Arrays.asList(InstrumentationService.class.getName(), SchedulerService.class.getName(), FileSystemAccessService.class.getName()));
    Configuration conf = new Configuration(false);
    conf.set("server.services", services);
    conf.set("server.hadoop.name.node.whitelist", "NN");
    Server server = new Server("server", dir, dir, dir, dir, conf);
    server.init();
    FileSystemAccessService fsAccess = (FileSystemAccessService) server.get(FileSystemAccess.class);
    fsAccess.validateNamenode("NNx");
}
Also used : FileSystemAccess(org.apache.hadoop.lib.service.FileSystemAccess) Configuration(org.apache.hadoop.conf.Configuration) Server(org.apache.hadoop.lib.server.Server) TestException(org.apache.hadoop.test.TestException) TestDir(org.apache.hadoop.test.TestDir) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)19 Server (org.apache.hadoop.lib.server.Server)19 TestDir (org.apache.hadoop.test.TestDir)19 Test (org.junit.Test)19 FileSystemAccess (org.apache.hadoop.lib.service.FileSystemAccess)10 TestException (org.apache.hadoop.test.TestException)10 IOException (java.io.IOException)5 FileSystem (org.apache.hadoop.fs.FileSystem)5 TestHdfs (org.apache.hadoop.test.TestHdfs)5 Path (org.apache.hadoop.fs.Path)4 ServiceException (org.apache.hadoop.lib.server.ServiceException)4 FileSystemAccessException (org.apache.hadoop.lib.service.FileSystemAccessException)4 Map (java.util.Map)2 Instrumentation (org.apache.hadoop.lib.service.Instrumentation)2 JSONObject (org.json.simple.JSONObject)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 StringWriter (java.io.StringWriter)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1