|
@@ -127,10 +127,6 @@ import com.google.protobuf.ByteString;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Utilities for converting protobuf classes to and from implementation classes.
|
|
* 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 {
|
|
public class PBHelper {
|
|
private static final RegisterCommandProto REG_CMD_PROTO =
|
|
private static final RegisterCommandProto REG_CMD_PROTO =
|
|
@@ -374,7 +370,6 @@ public class PBHelper {
|
|
}
|
|
}
|
|
|
|
|
|
public static NamenodeCommand convert(NamenodeCommandProto cmd) {
|
|
public static NamenodeCommand convert(NamenodeCommandProto cmd) {
|
|
- if (cmd == null) return null;
|
|
|
|
switch (cmd.getType()) {
|
|
switch (cmd.getType()) {
|
|
case CheckPointCommand:
|
|
case CheckPointCommand:
|
|
CheckpointCommandProto chkPt = cmd.getCheckpointCmd();
|
|
CheckpointCommandProto chkPt = cmd.getCheckpointCmd();
|
|
@@ -431,8 +426,7 @@ public class PBHelper {
|
|
if (di == null) return null;
|
|
if (di == null) return null;
|
|
return new DatanodeInfo(
|
|
return new DatanodeInfo(
|
|
PBHelper.convert(di.getId()),
|
|
PBHelper.convert(di.getId()),
|
|
- di.hasLocation() ? di.getLocation() : null ,
|
|
|
|
- di.hasHostName() ? di.getHostName() : null,
|
|
|
|
|
|
+ di.getLocation(), di.getHostName(),
|
|
di.getCapacity(), di.getDfsUsed(), di.getRemaining(),
|
|
di.getCapacity(), di.getDfsUsed(), di.getRemaining(),
|
|
di.getBlockPoolUsed() , di.getLastUpdate() , di.getXceiverCount() ,
|
|
di.getBlockPoolUsed() , di.getLastUpdate() , di.getXceiverCount() ,
|
|
PBHelper.convert(di.getAdminState()));
|
|
PBHelper.convert(di.getAdminState()));
|
|
@@ -440,16 +434,10 @@ public class PBHelper {
|
|
|
|
|
|
static public DatanodeInfoProto convertDatanodeInfo(DatanodeInfo di) {
|
|
static public DatanodeInfoProto convertDatanodeInfo(DatanodeInfo di) {
|
|
if (di == null) return null;
|
|
if (di == null) return null;
|
|
- DatanodeInfoProto.Builder builder = DatanodeInfoProto.newBuilder();
|
|
|
|
- if (di.getHostName() != null) {
|
|
|
|
- builder.setHostName(di.getHostName());
|
|
|
|
- }
|
|
|
|
- if (di.getNetworkLocation() != null) {
|
|
|
|
- builder.setLocation(di.getNetworkLocation());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return builder.
|
|
|
|
|
|
+ return DatanodeInfoProto.newBuilder().
|
|
setId(PBHelper.convert((DatanodeID) di)).
|
|
setId(PBHelper.convert((DatanodeID) di)).
|
|
|
|
+ setLocation(di.getNetworkLocation()).
|
|
|
|
+ setHostName(di.getHostName()).
|
|
setCapacity(di.getCapacity()).
|
|
setCapacity(di.getCapacity()).
|
|
setDfsUsed(di.getDfsUsed()).
|
|
setDfsUsed(di.getDfsUsed()).
|
|
setRemaining(di.getRemaining()).
|
|
setRemaining(di.getRemaining()).
|
|
@@ -789,14 +777,9 @@ public class PBHelper {
|
|
|
|
|
|
public static ReceivedDeletedBlockInfoProto convert(
|
|
public static ReceivedDeletedBlockInfoProto convert(
|
|
ReceivedDeletedBlockInfo receivedDeletedBlockInfo) {
|
|
ReceivedDeletedBlockInfo receivedDeletedBlockInfo) {
|
|
- ReceivedDeletedBlockInfoProto.Builder builder =
|
|
|
|
- ReceivedDeletedBlockInfoProto.newBuilder();
|
|
|
|
-
|
|
|
|
- if (receivedDeletedBlockInfo.getDelHints() != null) {
|
|
|
|
- builder.setDeleteHint(receivedDeletedBlockInfo.getDelHints());
|
|
|
|
- }
|
|
|
|
- return builder.setBlock(PBHelper.convert(receivedDeletedBlockInfo.getBlock()))
|
|
|
|
- .build();
|
|
|
|
|
|
+ return ReceivedDeletedBlockInfoProto.newBuilder()
|
|
|
|
+ .setBlock(PBHelper.convert(receivedDeletedBlockInfo.getBlock()))
|
|
|
|
+ .setDeleteHint(receivedDeletedBlockInfo.getDelHints()).build();
|
|
}
|
|
}
|
|
|
|
|
|
public static UpgradeCommandProto convert(UpgradeCommand comm) {
|
|
public static UpgradeCommandProto convert(UpgradeCommand comm) {
|
|
@@ -820,7 +803,7 @@ public class PBHelper {
|
|
public static ReceivedDeletedBlockInfo convert(
|
|
public static ReceivedDeletedBlockInfo convert(
|
|
ReceivedDeletedBlockInfoProto proto) {
|
|
ReceivedDeletedBlockInfoProto proto) {
|
|
return new ReceivedDeletedBlockInfo(PBHelper.convert(proto.getBlock()),
|
|
return new ReceivedDeletedBlockInfo(PBHelper.convert(proto.getBlock()),
|
|
- proto.hasDeleteHint() ? proto.getDeleteHint() : null);
|
|
|
|
|
|
+ proto.getDeleteHint());
|
|
}
|
|
}
|
|
|
|
|
|
public static NamespaceInfoProto convert(NamespaceInfo info) {
|
|
public static NamespaceInfoProto convert(NamespaceInfo info) {
|
|
@@ -880,10 +863,13 @@ public class PBHelper {
|
|
|
|
|
|
// LocatedBlocks
|
|
// LocatedBlocks
|
|
public static LocatedBlocks convert(LocatedBlocksProto lb) {
|
|
public static LocatedBlocks convert(LocatedBlocksProto lb) {
|
|
|
|
+ if (lb == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
return new LocatedBlocks(
|
|
return new LocatedBlocks(
|
|
lb.getFileLength(), lb.getUnderConstruction(),
|
|
lb.getFileLength(), lb.getUnderConstruction(),
|
|
PBHelper.convertLocatedBlock(lb.getBlocksList()),
|
|
PBHelper.convertLocatedBlock(lb.getBlocksList()),
|
|
- lb.hasLastBlock() ? PBHelper.convert(lb.getLastBlock()) : null,
|
|
|
|
|
|
+ PBHelper.convert(lb.getLastBlock()),
|
|
lb.getIsLastBlockComplete());
|
|
lb.getIsLastBlockComplete());
|
|
}
|
|
}
|
|
|
|
|
|
@@ -891,15 +877,11 @@ public class PBHelper {
|
|
if (lb == null) {
|
|
if (lb == null) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- 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();
|
|
|
|
|
|
+ return LocatedBlocksProto.newBuilder().
|
|
|
|
+ setFileLength(lb.getFileLength()).
|
|
|
|
+ setUnderConstruction(lb.isUnderConstruction()).
|
|
|
|
+ addAllBlocks(PBHelper.convertLocatedBlock2(lb.getLocatedBlocks())).
|
|
|
|
+ setLastBlock(PBHelper.convert(lb.getLastLocatedBlock())).setIsLastBlockComplete(lb.isLastBlockComplete()).build();
|
|
}
|
|
}
|
|
|
|
|
|
public static FsServerDefaults convert(FsServerDefaultsProto fs) {
|
|
public static FsServerDefaults convert(FsServerDefaultsProto fs) {
|
|
@@ -1000,16 +982,11 @@ public class PBHelper {
|
|
setPermission(PBHelper.convert(fs.getPermission())).
|
|
setPermission(PBHelper.convert(fs.getPermission())).
|
|
setOwner(fs.getOwner()).
|
|
setOwner(fs.getOwner()).
|
|
setGroup(fs.getGroup()).
|
|
setGroup(fs.getGroup()).
|
|
|
|
+ setSymlink(ByteString.copyFrom(fs.getSymlinkInBytes())).
|
|
setPath(ByteString.copyFrom(fs.getLocalNameInBytes()));
|
|
setPath(ByteString.copyFrom(fs.getLocalNameInBytes()));
|
|
-
|
|
|
|
- if (fs.getSymlink() != null) {
|
|
|
|
- builder.setSymlink(ByteString.copyFrom(fs.getSymlinkInBytes()));
|
|
|
|
- }
|
|
|
|
|
|
+ LocatedBlocks locations = null;
|
|
if (fs instanceof HdfsLocatedFileStatus) {
|
|
if (fs instanceof HdfsLocatedFileStatus) {
|
|
- LocatedBlocks locations = ((HdfsLocatedFileStatus)fs).getBlockLocations();
|
|
|
|
- if (locations != null) {
|
|
|
|
- builder.setLocations(PBHelper.convert(locations));
|
|
|
|
- }
|
|
|
|
|
|
+ builder.setLocations(PBHelper.convert(locations));
|
|
}
|
|
}
|
|
return builder.build();
|
|
return builder.build();
|
|
}
|
|
}
|