|
@@ -17,28 +17,55 @@
|
|
*/
|
|
*/
|
|
package org.apache.hadoop.hdfs.protocolPB;
|
|
package org.apache.hadoop.hdfs.protocolPB;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.Block;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.DatanodeID;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.BlockKeyProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.BlockProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.BlockWithLocationsProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.BlocksWithLocationsProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.CheckpointCommandProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.CheckpointSignatureProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeIDProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.ExportedBlockKeysProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamenodeCommandProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamenodeRegistrationProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamenodeRegistrationProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamespaceInfoProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.RemoteEditLogManifestProto;
|
|
|
|
+import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.RemoteEditLogProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamenodeRegistrationProto.NamenodeRoleProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.NamenodeRegistrationProto.NamenodeRoleProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.StorageInfoProto;
|
|
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.StorageInfoProto;
|
|
|
|
+import org.apache.hadoop.hdfs.security.token.block.BlockKey;
|
|
|
|
+import org.apache.hadoop.hdfs.security.token.block.ExportedBlockKeys;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
|
|
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NamenodeRole;
|
|
import org.apache.hadoop.hdfs.server.common.StorageInfo;
|
|
import org.apache.hadoop.hdfs.server.common.StorageInfo;
|
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.CheckpointSignature;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.CheckpointCommand;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.NamenodeCommand;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration;
|
|
import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.RemoteEditLog;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.RemoteEditLogManifest;
|
|
|
|
+import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations;
|
|
|
|
|
|
import com.google.protobuf.ByteString;
|
|
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.
|
|
*/
|
|
*/
|
|
class PBHelper {
|
|
class PBHelper {
|
|
private PBHelper() {
|
|
private PBHelper() {
|
|
/** Hidden constructor */
|
|
/** Hidden constructor */
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static ByteString getByteString(byte[] bytes) {
|
|
public static ByteString getByteString(byte[] bytes) {
|
|
return ByteString.copyFrom(bytes);
|
|
return ByteString.copyFrom(bytes);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static NamenodeRole convert(NamenodeRoleProto role) {
|
|
public static NamenodeRole convert(NamenodeRoleProto role) {
|
|
switch (role) {
|
|
switch (role) {
|
|
case NAMENODE:
|
|
case NAMENODE:
|
|
@@ -50,7 +77,7 @@ class PBHelper {
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static NamenodeRoleProto convert(NamenodeRole role) {
|
|
public static NamenodeRoleProto convert(NamenodeRole role) {
|
|
switch (role) {
|
|
switch (role) {
|
|
case NAMENODE:
|
|
case NAMENODE:
|
|
@@ -62,31 +89,196 @@ class PBHelper {
|
|
}
|
|
}
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static StorageInfoProto convert(StorageInfo info) {
|
|
public static StorageInfoProto convert(StorageInfo info) {
|
|
return StorageInfoProto.newBuilder().setClusterID(info.getClusterID())
|
|
return StorageInfoProto.newBuilder().setClusterID(info.getClusterID())
|
|
- .setCTime(info.getCTime())
|
|
|
|
- .setLayoutVersion(info.getLayoutVersion())
|
|
|
|
- .setNamespceID(info.getNamespaceID())
|
|
|
|
- .build();
|
|
|
|
|
|
+ .setCTime(info.getCTime()).setLayoutVersion(info.getLayoutVersion())
|
|
|
|
+ .setNamespceID(info.getNamespaceID()).build();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static StorageInfo convert(StorageInfoProto info) {
|
|
public static StorageInfo convert(StorageInfoProto info) {
|
|
return new StorageInfo(info.getLayoutVersion(), info.getNamespceID(),
|
|
return new StorageInfo(info.getLayoutVersion(), info.getNamespceID(),
|
|
info.getClusterID(), info.getCTime());
|
|
info.getClusterID(), info.getCTime());
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
public static NamenodeRegistrationProto convert(NamenodeRegistration reg) {
|
|
public static NamenodeRegistrationProto convert(NamenodeRegistration reg) {
|
|
return NamenodeRegistrationProto.newBuilder()
|
|
return NamenodeRegistrationProto.newBuilder()
|
|
- .setHttpAddress(reg.getHttpAddress())
|
|
|
|
- .setRole(convert(reg.getRole()))
|
|
|
|
|
|
+ .setHttpAddress(reg.getHttpAddress()).setRole(convert(reg.getRole()))
|
|
.setRpcAddress(reg.getAddress())
|
|
.setRpcAddress(reg.getAddress())
|
|
.setStorageInfo(convert((StorageInfo) reg)).build();
|
|
.setStorageInfo(convert((StorageInfo) reg)).build();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public static NamenodeRegistration convert(NamenodeRegistrationProto reg) {
|
|
public static NamenodeRegistration convert(NamenodeRegistrationProto reg) {
|
|
return new NamenodeRegistration(reg.getRpcAddress(), reg.getHttpAddress(),
|
|
return new NamenodeRegistration(reg.getRpcAddress(), reg.getHttpAddress(),
|
|
convert(reg.getStorageInfo()), convert(reg.getRole()));
|
|
convert(reg.getStorageInfo()), convert(reg.getRole()));
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ public static DatanodeID convert(DatanodeIDProto dn) {
|
|
|
|
+ return new DatanodeID(dn.getName(), dn.getStorageID(), dn.getInfoPort(),
|
|
|
|
+ dn.getIpcPort());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static DatanodeIDProto convert(DatanodeID dn) {
|
|
|
|
+ return DatanodeIDProto.newBuilder().setName(dn.getName())
|
|
|
|
+ .setInfoPort(dn.getInfoPort()).setIpcPort(dn.getIpcPort())
|
|
|
|
+ .setStorageID(dn.getStorageID()).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockProto convert(Block b) {
|
|
|
|
+ return BlockProto.newBuilder().setBlockId(b.getBlockId())
|
|
|
|
+ .setGenStamp(b.getGenerationStamp()).setNumBytes(b.getNumBytes())
|
|
|
|
+ .build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static Block convert(BlockProto b) {
|
|
|
|
+ return new Block(b.getBlockId(), b.getGenStamp(), b.getNumBytes());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockWithLocationsProto convert(BlockWithLocations blk) {
|
|
|
|
+ return BlockWithLocationsProto.newBuilder()
|
|
|
|
+ .setBlock(convert(blk.getBlock()))
|
|
|
|
+ .addAllDatanodeIDs(Arrays.asList(blk.getDatanodes())).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockWithLocations convert(BlockWithLocationsProto b) {
|
|
|
|
+ return new BlockWithLocations(convert(b.getBlock()), b.getDatanodeIDsList()
|
|
|
|
+ .toArray(new String[0]));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlocksWithLocationsProto convert(BlocksWithLocations blks) {
|
|
|
|
+ BlocksWithLocationsProto.Builder builder = BlocksWithLocationsProto
|
|
|
|
+ .newBuilder();
|
|
|
|
+ for (BlockWithLocations b : blks.getBlocks()) {
|
|
|
|
+ builder.addBlocks(convert(b));
|
|
|
|
+ }
|
|
|
|
+ return builder.build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlocksWithLocations convert(BlocksWithLocationsProto blocks) {
|
|
|
|
+ return new BlocksWithLocations(convert(blocks.getBlocksList()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockKeyProto convert(BlockKey key) {
|
|
|
|
+ byte[] encodedKey = key.getEncodedKey();
|
|
|
|
+ ByteString keyBytes = ByteString.copyFrom(encodedKey == null ? new byte[0]
|
|
|
|
+ : encodedKey);
|
|
|
|
+ return BlockKeyProto.newBuilder().setKeyId(key.getKeyId())
|
|
|
|
+ .setKeyBytes(keyBytes).setExpiryDate(key.getExpiryDate()).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockKey convert(BlockKeyProto k) {
|
|
|
|
+ return new BlockKey(k.getKeyId(), k.getExpiryDate(), k.getKeyBytes()
|
|
|
|
+ .toByteArray());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static ExportedBlockKeysProto convert(ExportedBlockKeys keys) {
|
|
|
|
+ ExportedBlockKeysProto.Builder builder = ExportedBlockKeysProto
|
|
|
|
+ .newBuilder();
|
|
|
|
+ builder.setIsBlockTokenEnabled(keys.isBlockTokenEnabled())
|
|
|
|
+ .setKeyUpdateInterval(keys.getKeyUpdateInterval())
|
|
|
|
+ .setTokenLifeTime(keys.getTokenLifetime())
|
|
|
|
+ .setCurrentKey(convert(keys.getCurrentKey()));
|
|
|
|
+ for (BlockKey k : keys.getAllKeys()) {
|
|
|
|
+ builder.addAllKeys(convert(k));
|
|
|
|
+ }
|
|
|
|
+ return builder.build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static ExportedBlockKeys convert(ExportedBlockKeysProto keys) {
|
|
|
|
+ return new ExportedBlockKeys(keys.getIsBlockTokenEnabled(),
|
|
|
|
+ keys.getKeyUpdateInterval(), keys.getTokenLifeTime(),
|
|
|
|
+ convert(keys.getCurrentKey()), convertBlockKeys(keys.getAllKeysList()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static CheckpointSignatureProto convert(CheckpointSignature s) {
|
|
|
|
+ return CheckpointSignatureProto.newBuilder()
|
|
|
|
+ .setBlockPoolId(s.getBlockpoolID())
|
|
|
|
+ .setCurSegmentTxId(s.getCurSegmentTxId())
|
|
|
|
+ .setMostRecentCheckpointTxId(s.getMostRecentCheckpointTxId())
|
|
|
|
+ .setStorageInfo(PBHelper.convert((StorageInfo) s)).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static CheckpointSignature convert(CheckpointSignatureProto s) {
|
|
|
|
+ return new CheckpointSignature(PBHelper.convert(s.getStorageInfo()),
|
|
|
|
+ s.getBlockPoolId(), s.getMostRecentCheckpointTxId(),
|
|
|
|
+ s.getCurSegmentTxId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static RemoteEditLogProto convert(RemoteEditLog log) {
|
|
|
|
+ return RemoteEditLogProto.newBuilder().setEndTxId(log.getEndTxId())
|
|
|
|
+ .setStartTxId(log.getStartTxId()).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static RemoteEditLog convert(RemoteEditLogProto l) {
|
|
|
|
+ return new RemoteEditLog(l.getStartTxId(), l.getEndTxId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static RemoteEditLogManifestProto convert(
|
|
|
|
+ RemoteEditLogManifest manifest) {
|
|
|
|
+ RemoteEditLogManifestProto.Builder builder = RemoteEditLogManifestProto
|
|
|
|
+ .newBuilder();
|
|
|
|
+ for (RemoteEditLog log : manifest.getLogs()) {
|
|
|
|
+ builder.addLogs(convert(log));
|
|
|
|
+ }
|
|
|
|
+ return builder.build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static RemoteEditLogManifest convert(
|
|
|
|
+ RemoteEditLogManifestProto manifest) {
|
|
|
|
+ List<RemoteEditLog> logs = new ArrayList<RemoteEditLog>(manifest
|
|
|
|
+ .getLogsList().size());
|
|
|
|
+ for (RemoteEditLogProto l : manifest.getLogsList()) {
|
|
|
|
+ logs.add(convert(l));
|
|
|
|
+ }
|
|
|
|
+ return new RemoteEditLogManifest(logs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static CheckpointCommandProto convert(CheckpointCommand cmd) {
|
|
|
|
+ return CheckpointCommandProto.newBuilder()
|
|
|
|
+ .setSignature(convert(cmd.getSignature())).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static NamenodeCommandProto convert(NamenodeCommand cmd) {
|
|
|
|
+ if (cmd instanceof CheckpointCommand) {
|
|
|
|
+ return NamenodeCommandProto.newBuilder().setAction(cmd.getAction())
|
|
|
|
+ .setType(NamenodeCommandProto.Type.NamenodeCommand)
|
|
|
|
+ .setCheckpointCmd(convert((CheckpointCommand) cmd)).build();
|
|
|
|
+ }
|
|
|
|
+ return NamenodeCommandProto.newBuilder().setAction(cmd.getAction()).build();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockWithLocations[] convert(List<BlockWithLocationsProto> b) {
|
|
|
|
+ BlockWithLocations[] ret = new BlockWithLocations[b.size()];
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (BlockWithLocationsProto entry : b) {
|
|
|
|
+ ret[i++] = convert(entry);
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static BlockKey[] convertBlockKeys(List<BlockKeyProto> list) {
|
|
|
|
+ BlockKey[] ret = new BlockKey[list.size()];
|
|
|
|
+ int i = 0;
|
|
|
|
+ for (BlockKeyProto k : list) {
|
|
|
|
+ ret[i++] = convert(k);
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static NamespaceInfo convert(NamespaceInfoProto info) {
|
|
|
|
+ StorageInfoProto storage = info.getStorageInfo();
|
|
|
|
+ return new NamespaceInfo(storage.getNamespceID(), storage.getClusterID(),
|
|
|
|
+ info.getBlockPoolID(), storage.getCTime(), info.getDistUpgradeVersion());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static NamenodeCommand convert(NamenodeCommandProto cmd) {
|
|
|
|
+ switch (cmd.getType()) {
|
|
|
|
+ case CheckPointCommand:
|
|
|
|
+ CheckpointCommandProto chkPt = cmd.getCheckpointCmd();
|
|
|
|
+ return new CheckpointCommand(PBHelper.convert(chkPt.getSignature()),
|
|
|
|
+ chkPt.getNeedToReturnImage());
|
|
|
|
+ default:
|
|
|
|
+ return new NamenodeCommand(cmd.getAction());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|