Java Code Examples for org.apache.hadoop.hdfs.DFSTestUtil#getLocalDatanodeInfo()

The following examples show how to use org.apache.hadoop.hdfs.DFSTestUtil#getLocalDatanodeInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertBlockRecoveryCommand() {
  DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };

  List<RecoveringBlock> blks = ImmutableList.of(
    new RecoveringBlock(getExtendedBlock(1), dnInfo, 3),
    new RecoveringBlock(getExtendedBlock(2), dnInfo, 3)
  );
  
  BlockRecoveryCommand cmd = new BlockRecoveryCommand(blks);
  BlockRecoveryCommandProto proto = PBHelper.convert(cmd);
  assertEquals(1, proto.getBlocks(0).getBlock().getB().getBlockId());
  assertEquals(2, proto.getBlocks(1).getBlock().getB().getBlockId());
  
  BlockRecoveryCommand cmd2 = PBHelper.convert(proto);
  
  List<RecoveringBlock> cmd2Blks = Lists.newArrayList(
      cmd2.getRecoveringBlocks());
  assertEquals(blks.get(0).getBlock(), cmd2Blks.get(0).getBlock());
  assertEquals(blks.get(1).getBlock(), cmd2Blks.get(1).getBlock());
  assertEquals(Joiner.on(",").join(blks), Joiner.on(",").join(cmd2Blks));
  assertEquals(cmd.toString(), cmd2.toString());
}
 
Example 2
Source File: TestPBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private LocatedBlock createLocatedBlock() {
  DatanodeInfo[] dnInfos = {
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1",
          AdminStates.DECOMMISSION_INPROGRESS),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2",
          AdminStates.DECOMMISSIONED),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3", 
          AdminStates.NORMAL),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h4",
          AdminStates.NORMAL),
  };
  String[] storageIDs = {"s1", "s2", "s3", "s4"};
  StorageType[] media = {
      StorageType.DISK,
      StorageType.SSD,
      StorageType.DISK,
      StorageType.RAM_DISK
  };
  LocatedBlock lb = new LocatedBlock(
      new ExtendedBlock("bp12", 12345, 10, 53),
      dnInfos, storageIDs, media, 5, false, new DatanodeInfo[]{});
  lb.setBlockToken(new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service")));
  return lb;
}
 
Example 3
Source File: TestPBHelper.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private LocatedBlock createLocatedBlockNoStorageMedia() {
  DatanodeInfo[] dnInfos = {
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1",
                                       AdminStates.DECOMMISSION_INPROGRESS),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2",
                                       AdminStates.DECOMMISSIONED),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3",
                                       AdminStates.NORMAL)
  };
  LocatedBlock lb = new LocatedBlock(
      new ExtendedBlock("bp12", 12345, 10, 53), dnInfos, 5, false);
  lb.setBlockToken(new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service")));
  return lb;
}
 
Example 4
Source File: TestPBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testConvertBlockRecoveryCommand() {
  DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };

  List<RecoveringBlock> blks = ImmutableList.of(
    new RecoveringBlock(getExtendedBlock(1), dnInfo, 3),
    new RecoveringBlock(getExtendedBlock(2), dnInfo, 3)
  );
  
  BlockRecoveryCommand cmd = new BlockRecoveryCommand(blks);
  BlockRecoveryCommandProto proto = PBHelper.convert(cmd);
  assertEquals(1, proto.getBlocks(0).getBlock().getB().getBlockId());
  assertEquals(2, proto.getBlocks(1).getBlock().getB().getBlockId());
  
  BlockRecoveryCommand cmd2 = PBHelper.convert(proto);
  
  List<RecoveringBlock> cmd2Blks = Lists.newArrayList(
      cmd2.getRecoveringBlocks());
  assertEquals(blks.get(0).getBlock(), cmd2Blks.get(0).getBlock());
  assertEquals(blks.get(1).getBlock(), cmd2Blks.get(1).getBlock());
  assertEquals(Joiner.on(",").join(blks), Joiner.on(",").join(cmd2Blks));
  assertEquals(cmd.toString(), cmd2.toString());
}
 
Example 5
Source File: TestPBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
private LocatedBlock createLocatedBlock() {
  DatanodeInfo[] dnInfos = {
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1",
          AdminStates.DECOMMISSION_INPROGRESS),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2",
          AdminStates.DECOMMISSIONED),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3", 
          AdminStates.NORMAL),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h4",
          AdminStates.NORMAL),
  };
  String[] storageIDs = {"s1", "s2", "s3", "s4"};
  StorageType[] media = {
      StorageType.DISK,
      StorageType.SSD,
      StorageType.DISK,
      StorageType.RAM_DISK
  };
  LocatedBlock lb = new LocatedBlock(
      new ExtendedBlock("bp12", 12345, 10, 53),
      dnInfos, storageIDs, media, 5, false, new DatanodeInfo[]{});
  lb.setBlockToken(new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service")));
  return lb;
}
 
Example 6
Source File: TestPBHelper.java    From big-c with Apache License 2.0 6 votes vote down vote up
private LocatedBlock createLocatedBlockNoStorageMedia() {
  DatanodeInfo[] dnInfos = {
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1",
                                       AdminStates.DECOMMISSION_INPROGRESS),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2",
                                       AdminStates.DECOMMISSIONED),
      DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3",
                                       AdminStates.NORMAL)
  };
  LocatedBlock lb = new LocatedBlock(
      new ExtendedBlock("bp12", 12345, 10, 53), dnInfos, 5, false);
  lb.setBlockToken(new Token<BlockTokenIdentifier>(
      "identifier".getBytes(), "password".getBytes(), new Text("kind"),
      new Text("service")));
  return lb;
}
 
Example 7
Source File: TestBlockRecovery.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private Collection<RecoveringBlock> initRecoveringBlocks() throws IOException {
  Collection<RecoveringBlock> blocks = new ArrayList<RecoveringBlock>(1);
  DatanodeInfo mockOtherDN = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] locs = new DatanodeInfo[] {
      new DatanodeInfo(dn.getDNRegistrationForBP(block.getBlockPoolId())),
      mockOtherDN };
  RecoveringBlock rBlock = new RecoveringBlock(block, locs, RECOVERY_ID);
  blocks.add(rBlock);
  return blocks;
}
 
Example 8
Source File: TestPBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertRecoveringBlock() {
  DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };
  RecoveringBlock b = new RecoveringBlock(getExtendedBlock(), dnInfo, 3);
  RecoveringBlockProto bProto = PBHelper.convert(b);
  RecoveringBlock b1 = PBHelper.convert(bProto);
  assertEquals(b.getBlock(), b1.getBlock());
  DatanodeInfo[] dnInfo1 = b1.getLocations();
  assertEquals(dnInfo.length, dnInfo1.length);
  for (int i=0; i < dnInfo.length; i++) {
    compare(dnInfo[0], dnInfo1[0]);
  }
}
 
Example 9
Source File: TestPBHelper.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBlockCommand() {
  Block[] blocks = new Block[] { new Block(21), new Block(22) };
  DatanodeInfo[][] dnInfos = new DatanodeInfo[][] { new DatanodeInfo[1],
      new DatanodeInfo[2] };
  dnInfos[0][0] = DFSTestUtil.getLocalDatanodeInfo();
  dnInfos[1][0] = DFSTestUtil.getLocalDatanodeInfo();
  dnInfos[1][1] = DFSTestUtil.getLocalDatanodeInfo();
  String[][] storageIDs = {{"s00"}, {"s10", "s11"}};
  StorageType[][] storageTypes = {{StorageType.DEFAULT},
      {StorageType.DEFAULT, StorageType.DEFAULT}};
  BlockCommand bc = new BlockCommand(DatanodeProtocol.DNA_TRANSFER, "bp1",
      blocks, dnInfos, storageTypes, storageIDs);
  BlockCommandProto bcProto = PBHelper.convert(bc);
  BlockCommand bc2 = PBHelper.convert(bcProto);
  assertEquals(bc.getAction(), bc2.getAction());
  assertEquals(bc.getBlocks().length, bc2.getBlocks().length);
  Block[] blocks2 = bc2.getBlocks();
  for (int i = 0; i < blocks.length; i++) {
    assertEquals(blocks[i], blocks2[i]);
  }
  DatanodeInfo[][] dnInfos2 = bc2.getTargets();
  assertEquals(dnInfos.length, dnInfos2.length);
  for (int i = 0; i < dnInfos.length; i++) {
    DatanodeInfo[] d1 = dnInfos[i];
    DatanodeInfo[] d2 = dnInfos2[i];
    assertEquals(d1.length, d2.length);
    for (int j = 0; j < d1.length; j++) {
      compare(d1[j], d2[j]);
    }
  }
}
 
Example 10
Source File: TestBlockRecovery.java    From big-c with Apache License 2.0 5 votes vote down vote up
private Collection<RecoveringBlock> initRecoveringBlocks() throws IOException {
  Collection<RecoveringBlock> blocks = new ArrayList<RecoveringBlock>(1);
  DatanodeInfo mockOtherDN = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] locs = new DatanodeInfo[] {
      new DatanodeInfo(dn.getDNRegistrationForBP(block.getBlockPoolId())),
      mockOtherDN };
  RecoveringBlock rBlock = new RecoveringBlock(block, locs, RECOVERY_ID);
  blocks.add(rBlock);
  return blocks;
}
 
Example 11
Source File: TestPBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertRecoveringBlock() {
  DatanodeInfo di1 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo di2 = DFSTestUtil.getLocalDatanodeInfo();
  DatanodeInfo[] dnInfo = new DatanodeInfo[] { di1, di2 };
  RecoveringBlock b = new RecoveringBlock(getExtendedBlock(), dnInfo, 3);
  RecoveringBlockProto bProto = PBHelper.convert(b);
  RecoveringBlock b1 = PBHelper.convert(bProto);
  assertEquals(b.getBlock(), b1.getBlock());
  DatanodeInfo[] dnInfo1 = b1.getLocations();
  assertEquals(dnInfo.length, dnInfo1.length);
  for (int i=0; i < dnInfo.length; i++) {
    compare(dnInfo[0], dnInfo1[0]);
  }
}
 
Example 12
Source File: TestPBHelper.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testConvertBlockCommand() {
  Block[] blocks = new Block[] { new Block(21), new Block(22) };
  DatanodeInfo[][] dnInfos = new DatanodeInfo[][] { new DatanodeInfo[1],
      new DatanodeInfo[2] };
  dnInfos[0][0] = DFSTestUtil.getLocalDatanodeInfo();
  dnInfos[1][0] = DFSTestUtil.getLocalDatanodeInfo();
  dnInfos[1][1] = DFSTestUtil.getLocalDatanodeInfo();
  String[][] storageIDs = {{"s00"}, {"s10", "s11"}};
  StorageType[][] storageTypes = {{StorageType.DEFAULT},
      {StorageType.DEFAULT, StorageType.DEFAULT}};
  BlockCommand bc = new BlockCommand(DatanodeProtocol.DNA_TRANSFER, "bp1",
      blocks, dnInfos, storageTypes, storageIDs);
  BlockCommandProto bcProto = PBHelper.convert(bc);
  BlockCommand bc2 = PBHelper.convert(bcProto);
  assertEquals(bc.getAction(), bc2.getAction());
  assertEquals(bc.getBlocks().length, bc2.getBlocks().length);
  Block[] blocks2 = bc2.getBlocks();
  for (int i = 0; i < blocks.length; i++) {
    assertEquals(blocks[i], blocks2[i]);
  }
  DatanodeInfo[][] dnInfos2 = bc2.getTargets();
  assertEquals(dnInfos.length, dnInfos2.length);
  for (int i = 0; i < dnInfos.length; i++) {
    DatanodeInfo[] d1 = dnInfos[i];
    DatanodeInfo[] d2 = dnInfos2[i];
    assertEquals(d1.length, d2.length);
    for (int j = 0; j < d1.length; j++) {
      compare(d1[j], d2[j]);
    }
  }
}