public static BlockIdCommandProto convert(BlockIdCommand cmd) { BlockIdCommandProto.Builder builder = BlockIdCommandProto.newBuilder() .setBlockPoolId(cmd.getBlockPoolId()); switch (cmd.getAction()) { case DatanodeProtocol.DNA_CACHE: builder.setAction(BlockIdCommandProto.Action.CACHE); break; case DatanodeProtocol.DNA_UNCACHE: builder.setAction(BlockIdCommandProto.Action.UNCACHE); break; default: throw new AssertionError("Invalid action"); } long[] blockIds = cmd.getBlockIds(); for (int i = 0; i < blockIds.length; i++) { builder.addBlockIds(blockIds[i]); } return builder.build(); }
public static BlockIdCommand convert(BlockIdCommandProto blkIdCmd) { int numBlockIds = blkIdCmd.getBlockIdsCount(); long blockIds[] = new long[numBlockIds]; for (int i = 0; i < numBlockIds; i++) { blockIds[i] = blkIdCmd.getBlockIds(i); } int action = DatanodeProtocol.DNA_UNKNOWN; switch (blkIdCmd.getAction()) { case CACHE: action = DatanodeProtocol.DNA_CACHE; break; case UNCACHE: action = DatanodeProtocol.DNA_UNCACHE; break; default: throw new AssertionError("Unknown action type: " + blkIdCmd.getAction()); } return new BlockIdCommand(action, blkIdCmd.getBlockPoolId(), blockIds); }