• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DFSAdmin类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.hdfs.tools.DFSAdmin的典型用法代码示例。如果您正苦于以下问题:Java DFSAdmin类的具体用法?Java DFSAdmin怎么用?Java DFSAdmin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DFSAdmin类属于org.apache.hadoop.hdfs.tools包,在下文中一共展示了DFSAdmin类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testDFSAdminInvalidUsageHelp

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testDFSAdminInvalidUsageHelp() {
  ImmutableSet<String> args = ImmutableSet.of("-report", "-saveNamespace",
      "-rollEdits", "-restoreFailedStorage", "-refreshNodes",
      "-finalizeUpgrade", "-metasave", "-refreshUserToGroupsMappings",
      "-printTopology", "-refreshNamenodes", "-deleteBlockPool",
      "-setBalancerBandwidth", "-fetchImage");
  try {
    for (String arg : args)
      assertTrue(ToolRunner.run(new DFSAdmin(), fillArgs(arg)) == -1);
    
    assertTrue(ToolRunner.run(new DFSAdmin(),
        new String[] { "-help", "-some" }) == 0);
  } catch (Exception e) {
    fail("testDFSAdminHelp error" + e);
  }

  String pattern = "Usage: hdfs dfsadmin";
  checkOutput(new String[] { "-cancel", "-renew" }, pattern, System.err,
      DFSAdmin.class);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:TestTools.java


示例2: testMultipleRegistration

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testMultipleRegistration() throws Exception {
  RefreshRegistry.defaultRegistry().register("sharedId", firstHandler);
  RefreshRegistry.defaultRegistry().register("sharedId", secondHandler);

  // this should trigger both
  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "sharedId", "one"};
  int exitCode = admin.run(args);
  assertEquals(-1, exitCode); // -1 because one of the responses is unregistered

  // verify we called both
  Mockito.verify(firstHandler).handleRefresh("sharedId", new String[]{"one"});
  Mockito.verify(secondHandler).handleRefresh("sharedId", new String[]{"one"});

  RefreshRegistry.defaultRegistry().unregisterAll("sharedId");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestGenericRefresh.java


示例3: testExceptionResultsInNormalError

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testExceptionResultsInNormalError() throws Exception {
  // In this test, we ensure that all handlers are called even if we throw an exception in one
  RefreshHandler exceptionalHandler = Mockito.mock(RefreshHandler.class);
  Mockito.stub(exceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
    .toThrow(new RuntimeException("Exceptional Handler Throws Exception"));

  RefreshHandler otherExceptionalHandler = Mockito.mock(RefreshHandler.class);
  Mockito.stub(otherExceptionalHandler.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
    .toThrow(new RuntimeException("More Exceptions"));

  RefreshRegistry.defaultRegistry().register("exceptional", exceptionalHandler);
  RefreshRegistry.defaultRegistry().register("exceptional", otherExceptionalHandler);

  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "exceptional"};
  int exitCode = admin.run(args);
  assertEquals(-1, exitCode); // Exceptions result in a -1

  Mockito.verify(exceptionalHandler).handleRefresh("exceptional", new String[]{});
  Mockito.verify(otherExceptionalHandler).handleRefresh("exceptional", new String[]{});

  RefreshRegistry.defaultRegistry().unregisterAll("exceptional");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestGenericRefresh.java


示例4: testRefresh

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testRefresh() throws Exception {
  assertTrue("Mock queue should have been constructed", mockQueueConstructions > 0);
  assertTrue("Puts are routed through MockQueue", canPutInMockQueue());
  int lastMockQueueConstructions = mockQueueConstructions;

  // Replace queue with the queue specified in core-site.xml, which would be the LinkedBlockingQueue
  DFSAdmin admin = new DFSAdmin(config);
  String [] args = new String[]{"-refreshCallQueue"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should return 0", 0, exitCode);

  assertEquals("Mock queue should have no additional constructions", lastMockQueueConstructions, mockQueueConstructions);
  try {
    assertFalse("Puts are routed through LBQ instead of MockQueue", canPutInMockQueue());
  } catch (IOException ioe){
    fail("Could not put into queue at all");
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestRefreshCallQueue.java


示例5: runGetBalancerBandwidthCmd

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
private void runGetBalancerBandwidthCmd(DFSAdmin admin, String[] args,
    ClientDatanodeProtocol proxy, long expectedBandwidth) throws Exception {
  PrintStream initialStdOut = System.out;
  outContent.reset();
  try {
    System.setOut(outStream);
    int exitCode = admin.run(args);
    assertEquals("DFSAdmin should return 0", 0, exitCode);
    String bandwidthOutMsg = "Balancer bandwidth is " + expectedBandwidth
        + " bytes per second.";
    String strOut = new String(outContent.toByteArray(), UTF8);
    assertTrue("Wrong balancer bandwidth!", strOut.contains(bandwidthOutMsg));
  } finally {
    System.setOut(initialStdOut);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:17,代码来源:TestBalancerBandwidth.java


示例6: testSetSpaceQuotaWhenStorageTypeIsWrong

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testSetSpaceQuotaWhenStorageTypeIsWrong() throws Exception {
  Configuration conf = new HdfsConfiguration();
  conf.set(FS_DEFAULT_NAME_KEY, "hdfs://127.0.0.1:8020");
  DFSAdmin admin = new DFSAdmin(conf);
  ByteArrayOutputStream err = new ByteArrayOutputStream();
  PrintStream oldErr = System.err;
  try {
    System.setErr(new PrintStream(err));
    String[] args =
        { "-setSpaceQuota", "100", "-storageType", "COLD", "/testDir" };
    admin.run(args);
    String errOutput = new String(err.toByteArray(), Charsets.UTF_8);
    assertTrue(
        errOutput.contains(StorageType.getTypesSupportingQuota().toString()));
  } finally {
    System.setErr(oldErr);
  }
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:20,代码来源:TestQuota.java


示例7: testDFSAdminInvalidUsageHelp

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testDFSAdminInvalidUsageHelp() {
  ImmutableSet<String> args = ImmutableSet.of("-report", "-saveNamespace",
      "-rollEdits", "-restoreFailedStorage", "-refreshNodes",
      "-finalizeUpgrade", "-metasave", "-refreshUserToGroupsMappings",
      "-printTopology", "-refreshNamenodes", "-deleteBlockPool",
      "-setBalancerBandwidth", "-fetchImage");
  try {
    for (String arg : args)
      assertTrue(ToolRunner.run(new DFSAdmin(), fillArgs(arg)) == -1);
    
    assertTrue(ToolRunner.run(new DFSAdmin(),
        new String[] { "-help", "-some" }) == 0);
  } catch (Exception e) {
    fail("testDFSAdminHelp error" + e);
  }

  String pattern = "Usage: java DFSAdmin";
  checkOutput(new String[] { "-cancel", "-renew" }, pattern, System.err,
      DFSAdmin.class);
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre2,代码行数:22,代码来源:TestTools.java


示例8: testGroupMappingRefresh

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testGroupMappingRefresh() throws Exception {
  DFSAdmin admin = new DFSAdmin(config);
  String [] args =  new String[]{"-refreshUserToGroupsMappings"};
  Groups groups = Groups.getUserToGroupsMappingService(config);
  String user = UserGroupInformation.getCurrentUser().getUserName();
  System.out.println("first attempt:");
  List<String> g1 = groups.getGroups(user);
  String [] str_groups = new String [g1.size()];
  g1.toArray(str_groups);
  System.out.println(Arrays.toString(str_groups));
  
  System.out.println("second attempt, should be same:");
  List<String> g2 = groups.getGroups(user);
  g2.toArray(str_groups);
  System.out.println(Arrays.toString(str_groups));
  for(int i=0; i<g2.size(); i++) {
    assertEquals("Should be same group ", g1.get(i), g2.get(i));
  }
  admin.run(args);
  System.out.println("third attempt(after refresh command), should be different:");
  List<String> g3 = groups.getGroups(user);
  g3.toArray(str_groups);
  System.out.println(Arrays.toString(str_groups));
  for(int i=0; i<g3.size(); i++) {
    assertFalse("Should be different group: " + g1.get(i) + " and " + g3.get(i), 
        g1.get(i).equals(g3.get(i)));
  }
  
  // test time out
  Thread.sleep(groupRefreshTimeoutSec*1100);
  System.out.println("fourth attempt(after timeout), should be different:");
  List<String> g4 = groups.getGroups(user);
  g4.toArray(str_groups);
  System.out.println(Arrays.toString(str_groups));
  for(int i=0; i<g4.size(); i++) {
    assertFalse("Should be different group ", g3.get(i).equals(g4.get(i)));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:TestRefreshUserMappings.java


示例9: checkOutput

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
private void checkOutput(String[] args, String pattern, PrintStream out,
    Class<?> clazz) {       
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  try {
    PipedOutputStream pipeOut = new PipedOutputStream();
    PipedInputStream pipeIn = new PipedInputStream(pipeOut, PIPE_BUFFER_SIZE);
    if (out == System.out) {
      System.setOut(new PrintStream(pipeOut));
    } else if (out == System.err) {
      System.setErr(new PrintStream(pipeOut));
    }

    if (clazz == DelegationTokenFetcher.class) {
      expectDelegationTokenFetcherExit(args);
    } else if (clazz == JMXGet.class) {
      expectJMXGetExit(args);
    } else if (clazz == DFSAdmin.class) {
      expectDfsAdminPrint(args);
    }
    pipeOut.close();
    ByteStreams.copy(pipeIn, outBytes);      
    pipeIn.close();
    assertTrue(new String(outBytes.toByteArray()).contains(pattern));            
  } catch (Exception ex) {
    fail("checkOutput error " + ex);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestTools.java


示例10: expectDfsAdminPrint

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
private void expectDfsAdminPrint(String[] args) {
  try {
    ToolRunner.run(new DFSAdmin(), args);
  } catch (Exception ex) {
    fail("expectDelegationTokenFetcherExit ex error " + ex);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:TestTools.java


示例11: testInvalidCommand

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testInvalidCommand() throws Exception {
  DFSAdmin admin = new DFSAdmin(config);
  String [] args = new String[]{"-refresh", "nn"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should fail due to bad args", -1, exitCode);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:TestGenericRefresh.java


示例12: testInvalidIdentifier

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testInvalidIdentifier() throws Exception {
  DFSAdmin admin = new DFSAdmin(config);
  String [] args = new String[]{"-refresh", "localhost:" + 
      cluster.getNameNodePort(), "unregisteredIdentity"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should fail due to no handler registered", -1, exitCode);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:TestGenericRefresh.java


示例13: testValidIdentifier

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testValidIdentifier() throws Exception {
  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh",
      "localhost:" + cluster.getNameNodePort(), "firstHandler"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should succeed", 0, exitCode);

  Mockito.verify(firstHandler).handleRefresh("firstHandler", new String[]{});
  // Second handler was never called
  Mockito.verify(secondHandler, Mockito.never())
    .handleRefresh(Mockito.anyString(), Mockito.any(String[].class));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:TestGenericRefresh.java


示例14: testVariableArgs

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testVariableArgs() throws Exception {
  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "secondHandler", "one"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should return 2", 2, exitCode);

  exitCode = admin.run(new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "secondHandler", "one", "two"});
  assertEquals("DFSAdmin should now return 3", 3, exitCode);

  Mockito.verify(secondHandler).handleRefresh("secondHandler", new String[]{"one"});
  Mockito.verify(secondHandler).handleRefresh("secondHandler", new String[]{"one", "two"});
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:TestGenericRefresh.java


示例15: testUnregistration

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testUnregistration() throws Exception {
  RefreshRegistry.defaultRegistry().unregisterAll("firstHandler");

  // And now this should fail
  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "firstHandler"};
  int exitCode = admin.run(args);
  assertEquals("DFSAdmin should return -1", -1, exitCode);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:TestGenericRefresh.java


示例16: testMultipleReturnCodeMerging

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
@Test
public void testMultipleReturnCodeMerging() throws Exception {
  // Two handlers which return two non-zero values
  RefreshHandler handlerOne = Mockito.mock(RefreshHandler.class);
  Mockito.stub(handlerOne.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
    .toReturn(new RefreshResponse(23, "Twenty Three"));

  RefreshHandler handlerTwo = Mockito.mock(RefreshHandler.class);
  Mockito.stub(handlerTwo.handleRefresh(Mockito.anyString(), Mockito.any(String[].class)))
    .toReturn(new RefreshResponse(10, "Ten"));

  // Then registered to the same ID
  RefreshRegistry.defaultRegistry().register("shared", handlerOne);
  RefreshRegistry.defaultRegistry().register("shared", handlerTwo);

  // We refresh both
  DFSAdmin admin = new DFSAdmin(config);
  String[] args = new String[]{"-refresh", "localhost:" +
      cluster.getNameNodePort(), "shared"};
  int exitCode = admin.run(args);
  assertEquals(-1, exitCode); // We get -1 because of our logic for melding non-zero return codes

  // Verify we called both
  Mockito.verify(handlerOne).handleRefresh("shared", new String[]{});
  Mockito.verify(handlerTwo).handleRefresh("shared", new String[]{});

  RefreshRegistry.defaultRegistry().unregisterAll("shared");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:29,代码来源:TestGenericRefresh.java


示例17: testPipelineRecoveryOnOOB

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
/**
 * Test recovery on restart OOB message. It also tests the delivery of 
 * OOB ack originating from the primary datanode. Since there is only
 * one node in the cluster, failure of restart-recovery will fail the
 * test.
 */
@Test
public void testPipelineRecoveryOnOOB() throws Exception {
  Configuration conf = new HdfsConfiguration();
  conf.set(DFSConfigKeys.DFS_CLIENT_DATANODE_RESTART_TIMEOUT_KEY, "15");
  MiniDFSCluster cluster = null;
  try {
    int numDataNodes = 1;
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDataNodes).build();
    cluster.waitActive();
    FileSystem fileSys = cluster.getFileSystem();

    Path file = new Path("dataprotocol2.dat");
    DFSTestUtil.createFile(fileSys, file, 10240L, (short)1, 0L);
    DFSOutputStream out = (DFSOutputStream)(fileSys.append(file).
        getWrappedStream());
    out.write(1);
    out.hflush();

    DFSAdmin dfsadmin = new DFSAdmin(conf);
    DataNode dn = cluster.getDataNodes().get(0);
    final String dnAddr = dn.getDatanodeId().getIpcAddr(false);
    // issue shutdown to the datanode.
    final String[] args1 = {"-shutdownDatanode", dnAddr, "upgrade" };
    Assert.assertEquals(0, dfsadmin.run(args1));
    // Wait long enough to receive an OOB ack before closing the file.
    Thread.sleep(4000);
    // Retart the datanode 
    cluster.restartDataNode(0, true);
    // The following forces a data packet and end of block packets to be sent. 
    out.close();
  } finally {
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:43,代码来源:TestClientProtocolForPipelineRecovery.java


示例18: finalizeNamenode

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
/**
 * Finalize the namenode. Block pools corresponding to the namenode are
 * finalized on the datanode.
 */
private void finalizeNamenode(NameNode nn, Configuration conf) throws Exception {
  if (nn == null) {
    throw new IllegalStateException("Attempting to finalize "
                                    + "Namenode but it is not running");
  }
  ToolRunner.run(new DFSAdmin(conf), new String[] {"-finalizeUpgrade"});
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:MiniDFSCluster.java


示例19: testInvalidShell

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
/**
 * default setting is file:// which is not a DFS
 * so DFSAdmin should throw and catch InvalidArgumentException
 * and return -1 exit code.
 * @throws Exception
 */
@Test (timeout = 30000)
public void testInvalidShell() throws Exception {
  Configuration conf = new Configuration(); // default FS (non-DFS)
  DFSAdmin admin = new DFSAdmin();
  admin.setConf(conf);
  int res = admin.run(new String[] {"-refreshNodes"});
  assertEquals("expected to fail -1", res , -1);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:TestDFSShell.java


示例20: runCmd

import org.apache.hadoop.hdfs.tools.DFSAdmin; //导入依赖的package包/类
public static void runCmd(DFSAdmin dfsadmin, boolean success,
    String... args) throws  Exception {
  if (success) {
    Assert.assertEquals(0, dfsadmin.run(args));
  } else {
    Assert.assertTrue(dfsadmin.run(args) != 0);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:9,代码来源:TestRollingUpgrade.java



注:本文中的org.apache.hadoop.hdfs.tools.DFSAdmin类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CheckBoxListCell类代码示例发布时间:2022-05-21
下一篇:
Java TableMapper类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap