|
@@ -127,6 +127,10 @@ import com.google.protobuf.ByteString;
|
|
|
|
|
|
/**
|
|
|
* Utilities for converting protobuf classes to and from implementation classes.
|
|
|
+ *
|
|
|
+ * Note that when converting from an internal type to protobuf type, the
|
|
|
+ * converter never return null for protobuf type. The check for internal type
|
|
|
+ * being null must be done before calling the convert() method.
|
|
|
*/
|
|
|
public class PBHelper {
|
|
|
private static final RegisterCommandProto REG_CMD_PROTO =
|
|
@@ -367,6 +371,7 @@ public class PBHelper {
|
|
|
}
|
|
|
|
|
|
public static NamenodeCommand convert(NamenodeCommandProto cmd) {
|
|
|
+ if (cmd == null) return null;
|
|
|
switch (cmd.getType()) {
|
|
|
case CheckPointCommand:
|
|
|
CheckpointCommandProto chkPt = cmd.getCheckpointCmd();
|
|
@@ -423,7 +428,8 @@ public class PBHelper {
|
|
|
if (di == null) return null;
|
|
|
return new DatanodeInfo(
|
|
|
PBHelper.convert(di.getId()),
|
|
|
- di.getLocation(), di.getHostName(),
|
|
|
+ di.hasLocation() ? di.getLocation() : null ,
|
|
|
+ di.hasHostName() ? di.getHostName() : null,
|
|
|
di.getCapacity(), di.getDfsUsed(), di.getRemaining(),
|
|
|
di.getBlockPoolUsed() , di.getLastUpdate() , di.getXceiverCount() ,
|
|
|
PBHelper.convert(di.getAdminState()));
|
|
@@ -431,10 +437,16 @@ public class PBHelper {
|
|
|
|
|
|
static public DatanodeInfoProto convertDatanodeInfo(DatanodeInfo di) {
|
|
|
if (di == null) return null;
|
|
|
- return DatanodeInfoProto.newBuilder().
|
|
|
+ DatanodeInfoProto.Builder builder = DatanodeInfoProto.newBuilder();
|
|
|
+ if (di.getHostName() != null) {
|
|
|
+ builder.setHostName(di.getHostName());
|
|
|
+ }
|
|
|
+ if (di.getNetworkLocation() != null) {
|
|
|
+ builder.setLocation(di.getNetworkLocation());
|
|
|
+ }
|
|
|
+
|
|
|
+ return builder.
|
|
|
setId(PBHelper.convert((DatanodeID) di)).
|
|
|
- setLocation(di.getNetworkLocation()).
|
|
|
- setHostName(di.getHostName()).
|
|
|
setCapacity(di.getCapacity()).
|
|
|
setDfsUsed(di.getDfsUsed()).
|
|
|
setRemaining(di.getRemaining()).
|
|
@@ -774,9 +786,14 @@ public class PBHelper {
|
|
|
|
|
|
public static ReceivedDeletedBlockInfoProto convert(
|
|
|
ReceivedDeletedBlockInfo receivedDeletedBlockInfo) {
|
|
|
- return ReceivedDeletedBlockInfoProto.newBuilder()
|
|
|
- .setBlock(PBHelper.convert(receivedDeletedBlockInfo.getBlock()))
|
|
|
- .setDeleteHint(receivedDeletedBlockInfo.getDelHints()).build();
|
|
|
+ ReceivedDeletedBlockInfoProto.Builder builder =
|
|
|
+ ReceivedDeletedBlockInfoProto.newBuilder();
|
|
|
+
|
|
|
+ if (receivedDeletedBlockInfo.getDelHints() != null) {
|
|
|
+ builder.setDeleteHint(receivedDeletedBlockInfo.getDelHints());
|
|
|
+ }
|
|
|
+ return builder.setBlock(PBHelper.convert(receivedDeletedBlockInfo.getBlock()))
|
|
|
+ .build();
|
|
|
}
|
|
|
|
|
|
public static UpgradeCommandProto convert(UpgradeCommand comm) {
|
|
@@ -800,7 +817,7 @@ public class PBHelper {
|
|
|
public static ReceivedDeletedBlockInfo convert(
|
|
|
ReceivedDeletedBlockInfoProto proto) {
|
|
|
return new ReceivedDeletedBlockInfo(PBHelper.convert(proto.getBlock()),
|
|
|
- proto.getDeleteHint());
|
|
|
+ proto.hasDeleteHint() ? proto.getDeleteHint() : null);
|
|
|
}
|
|
|
|
|
|
public static NamespaceInfoProto convert(NamespaceInfo info) {
|
|
@@ -860,13 +877,10 @@ public class PBHelper {
|
|
|
|
|
|
// LocatedBlocks
|
|
|
public static LocatedBlocks convert(LocatedBlocksProto lb) {
|
|
|
- if (lb == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
return new LocatedBlocks(
|
|
|
lb.getFileLength(), lb.getUnderConstruction(),
|
|
|
PBHelper.convertLocatedBlock(lb.getBlocksList()),
|
|
|
- PBHelper.convert(lb.getLastBlock()),
|
|
|
+ lb.hasLastBlock() ? PBHelper.convert(lb.getLastBlock()) : null,
|
|
|
lb.getIsLastBlockComplete());
|
|
|
}
|
|
|
|
|
@@ -874,11 +888,15 @@ public class PBHelper {
|
|
|
if (lb == null) {
|
|
|
return null;
|
|
|
}
|
|
|
- return LocatedBlocksProto.newBuilder().
|
|
|
- setFileLength(lb.getFileLength()).
|
|
|
- setUnderConstruction(lb.isUnderConstruction()).
|
|
|
- addAllBlocks(PBHelper.convertLocatedBlock2(lb.getLocatedBlocks())).
|
|
|
- setLastBlock(PBHelper.convert(lb.getLastLocatedBlock())).setIsLastBlockComplete(lb.isLastBlockComplete()).build();
|
|
|
+ LocatedBlocksProto.Builder builder =
|
|
|
+ LocatedBlocksProto.newBuilder();
|
|
|
+ if (lb.getLastLocatedBlock() != null) {
|
|
|
+ builder.setLastBlock(PBHelper.convert(lb.getLastLocatedBlock()));
|
|
|
+ }
|
|
|
+ return builder.setFileLength(lb.getFileLength())
|
|
|
+ .setUnderConstruction(lb.isUnderConstruction())
|
|
|
+ .addAllBlocks(PBHelper.convertLocatedBlock2(lb.getLocatedBlocks()))
|
|
|
+ .setIsLastBlockComplete(lb.isLastBlockComplete()).build();
|
|
|
}
|
|
|
|
|
|
public static FsServerDefaults convert(FsServerDefaultsProto fs) {
|
|
@@ -979,11 +997,16 @@ public class PBHelper {
|
|
|
setPermission(PBHelper.convert(fs.getPermission())).
|
|
|
setOwner(fs.getOwner()).
|
|
|
setGroup(fs.getGroup()).
|
|
|
- setSymlink(ByteString.copyFrom(fs.getSymlinkInBytes())).
|
|
|
setPath(ByteString.copyFrom(fs.getLocalNameInBytes()));
|
|
|
- LocatedBlocks locations = null;
|
|
|
+
|
|
|
+ if (fs.getSymlink() != null) {
|
|
|
+ builder.setSymlink(ByteString.copyFrom(fs.getSymlinkInBytes()));
|
|
|
+ }
|
|
|
if (fs instanceof HdfsLocatedFileStatus) {
|
|
|
- builder.setLocations(PBHelper.convert(locations));
|
|
|
+ LocatedBlocks locations = ((HdfsLocatedFileStatus)fs).getBlockLocations();
|
|
|
+ if (locations != null) {
|
|
|
+ builder.setLocations(PBHelper.convert(locations));
|
|
|
+ }
|
|
|
}
|
|
|
return builder.build();
|
|
|
}
|