public static BlockStoragePolicyProto convert(BlockStoragePolicy policy) { BlockStoragePolicyProto.Builder builder = BlockStoragePolicyProto .newBuilder().setPolicyId(policy.getId()).setName(policy.getName()); // creation storage types StorageTypesProto creationProto = convert(policy.getStorageTypes()); Preconditions.checkArgument(creationProto != null); builder.setCreationPolicy(creationProto); // creation fallback StorageTypesProto creationFallbackProto = convert( policy.getCreationFallbacks()); if (creationFallbackProto != null) { builder.setCreationFallbackPolicy(creationFallbackProto); } // replication fallback StorageTypesProto replicationFallbackProto = convert( policy.getReplicationFallbacks()); if (replicationFallbackProto != null) { builder.setReplicationFallbackPolicy(replicationFallbackProto); } return builder.build(); }
public static DatanodeInfoProto convert(DatanodeInfo info) { DatanodeInfoProto.Builder builder = DatanodeInfoProto.newBuilder(); if (info.getNetworkLocation() != null) { builder.setLocation(info.getNetworkLocation()); } builder .setId(PBHelper.convert((DatanodeID)info)) .setCapacity(info.getCapacity()) .setDfsUsed(info.getDfsUsed()) .setRemaining(info.getRemaining()) .setBlockPoolUsed(info.getBlockPoolUsed()) .setCacheCapacity(info.getCacheCapacity()) .setCacheUsed(info.getCacheUsed()) .setLastUpdate(info.getLastUpdate()) .setLastUpdateMonotonic(info.getLastUpdateMonotonic()) .setXceiverCount(info.getXceiverCount()) .setAdminState(PBHelper.convert(info.getAdminState())) .build(); return builder.build(); }
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 LocatedBlocksProto convert(LocatedBlocks lb) { if (lb == null) { return null; } LocatedBlocksProto.Builder builder = LocatedBlocksProto.newBuilder(); if (lb.getLastLocatedBlock() != null) { builder.setLastBlock(PBHelper.convert(lb.getLastLocatedBlock())); } if (lb.getFileEncryptionInfo() != null) { builder.setFileEncryptionInfo(convert(lb.getFileEncryptionInfo())); } return builder.setFileLength(lb.getFileLength()) .setUnderConstruction(lb.isUnderConstruction()) .addAllBlocks(PBHelper.convertLocatedBlock2(lb.getLocatedBlocks())) .setIsLastBlockComplete(lb.isLastBlockComplete()).build(); }
public static SnapshottableDirectoryStatusProto convert( SnapshottableDirectoryStatus status) { if (status == null) { return null; } int snapshotNumber = status.getSnapshotNumber(); int snapshotQuota = status.getSnapshotQuota(); byte[] parentFullPath = status.getParentFullPath(); ByteString parentFullPathBytes = ByteString.copyFrom( parentFullPath == null ? DFSUtil.EMPTY_BYTES : parentFullPath); HdfsFileStatusProto fs = convert(status.getDirStatus()); SnapshottableDirectoryStatusProto.Builder builder = SnapshottableDirectoryStatusProto .newBuilder().setSnapshotNumber(snapshotNumber) .setSnapshotQuota(snapshotQuota).setParentFullpath(parentFullPathBytes) .setDirStatus(fs); return builder.build(); }
public static GetFsStatsResponseProto convert(long[] fsStats) { GetFsStatsResponseProto.Builder result = GetFsStatsResponseProto .newBuilder(); if (fsStats.length >= ClientProtocol.GET_STATS_CAPACITY_IDX + 1) result.setCapacity(fsStats[ClientProtocol.GET_STATS_CAPACITY_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_USED_IDX + 1) result.setUsed(fsStats[ClientProtocol.GET_STATS_USED_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_REMAINING_IDX + 1) result.setRemaining(fsStats[ClientProtocol.GET_STATS_REMAINING_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_UNDER_REPLICATED_IDX + 1) result.setUnderReplicated( fsStats[ClientProtocol.GET_STATS_UNDER_REPLICATED_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_CORRUPT_BLOCKS_IDX + 1) result.setCorruptBlocks( fsStats[ClientProtocol.GET_STATS_CORRUPT_BLOCKS_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_MISSING_BLOCKS_IDX + 1) result.setMissingBlocks( fsStats[ClientProtocol.GET_STATS_MISSING_BLOCKS_IDX]); if (fsStats.length >= ClientProtocol.GET_STATS_MISSING_REPL_ONE_BLOCKS_IDX + 1) result.setMissingReplOneBlocks( fsStats[ClientProtocol.GET_STATS_MISSING_REPL_ONE_BLOCKS_IDX]); return result.build(); }
public static ContentSummary convert(ContentSummaryProto cs) { if (cs == null) return null; ContentSummary.Builder builder = new ContentSummary.Builder(); builder.length(cs.getLength()). fileCount(cs.getFileCount()). directoryCount(cs.getDirectoryCount()). quota(cs.getQuota()). spaceConsumed(cs.getSpaceConsumed()). spaceQuota(cs.getSpaceQuota()); if (cs.hasTypeQuotaInfos()) { for (HdfsProtos.StorageTypeQuotaInfoProto info : cs.getTypeQuotaInfos().getTypeQuotaInfoList()) { StorageType type = PBHelper.convertStorageType(info.getType()); builder.typeConsumed(type, info.getConsumed()); builder.typeQuota(type, info.getQuota()); } } return builder.build(); }
public static ContentSummaryProto convert(ContentSummary cs) { if (cs == null) return null; ContentSummaryProto.Builder builder = ContentSummaryProto.newBuilder(); builder.setLength(cs.getLength()). setFileCount(cs.getFileCount()). setDirectoryCount(cs.getDirectoryCount()). setQuota(cs.getQuota()). setSpaceConsumed(cs.getSpaceConsumed()). setSpaceQuota(cs.getSpaceQuota()); if (cs.isTypeQuotaSet() || cs.isTypeConsumedAvailable()) { HdfsProtos.StorageTypeQuotaInfosProto.Builder isb = HdfsProtos.StorageTypeQuotaInfosProto.newBuilder(); for (StorageType t: StorageType.getTypesSupportingQuota()) { HdfsProtos.StorageTypeQuotaInfoProto info = HdfsProtos.StorageTypeQuotaInfoProto.newBuilder(). setType(convertStorageType(t)). setConsumed(cs.getTypeConsumed(t)). setQuota(cs.getTypeQuota(t)). build(); isb.addTypeQuotaInfo(info); } builder.setTypeQuotaInfos(isb); } return builder.build(); }
public static NNHAStatusHeartbeatProto convert(NNHAStatusHeartbeat hb) { if (hb == null) return null; NNHAStatusHeartbeatProto.Builder builder = NNHAStatusHeartbeatProto.newBuilder(); switch (hb.getState()) { case ACTIVE: builder.setState(NNHAStatusHeartbeatProto.State.ACTIVE); break; case STANDBY: builder.setState(NNHAStatusHeartbeatProto.State.STANDBY); break; default: throw new IllegalArgumentException("Unexpected NNHAStatusHeartbeat.State:" + hb.getState()); } builder.setTxid(hb.getTxId()); return builder.build(); }
public static SnapshotDiffReportEntryProto convert(DiffReportEntry entry) { if (entry == null) { return null; } ByteString sourcePath = ByteString .copyFrom(entry.getSourcePath() == null ? DFSUtil.EMPTY_BYTES : entry .getSourcePath()); String modification = entry.getType().getLabel(); SnapshotDiffReportEntryProto.Builder builder = SnapshotDiffReportEntryProto .newBuilder().setFullpath(sourcePath) .setModificationLabel(modification); if (entry.getType() == DiffType.RENAME) { ByteString targetPath = ByteString .copyFrom(entry.getTargetPath() == null ? DFSUtil.EMPTY_BYTES : entry .getTargetPath()); builder.setTargetPath(targetPath); } return builder.build(); }
public static CacheDirectiveInfoProto convert (CacheDirectiveInfo info) { CacheDirectiveInfoProto.Builder builder = CacheDirectiveInfoProto.newBuilder(); if (info.getId() != null) { builder.setId(info.getId()); } if (info.getPath() != null) { builder.setPath(info.getPath().toUri().getPath()); } if (info.getReplication() != null) { builder.setReplication(info.getReplication()); } if (info.getPool() != null) { builder.setPool(info.getPool()); } if (info.getExpiration() != null) { builder.setExpiration(convert(info.getExpiration())); } return builder.build(); }
public static CacheDirectiveInfo convert (CacheDirectiveInfoProto proto) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); if (proto.hasId()) { builder.setId(proto.getId()); } if (proto.hasPath()) { builder.setPath(new Path(proto.getPath())); } if (proto.hasReplication()) { builder.setReplication(Shorts.checkedCast( proto.getReplication())); } if (proto.hasPool()) { builder.setPool(proto.getPool()); } if (proto.hasExpiration()) { builder.setExpiration(convert(proto.getExpiration())); } return builder.build(); }
public static CachePoolInfoProto convert(CachePoolInfo info) { CachePoolInfoProto.Builder builder = CachePoolInfoProto.newBuilder(); builder.setPoolName(info.getPoolName()); if (info.getOwnerName() != null) { builder.setOwnerName(info.getOwnerName()); } if (info.getGroupName() != null) { builder.setGroupName(info.getGroupName()); } if (info.getMode() != null) { builder.setMode(info.getMode().toShort()); } if (info.getLimit() != null) { builder.setLimit(info.getLimit()); } if (info.getMaxRelativeExpiryMs() != null) { builder.setMaxRelativeExpiry(info.getMaxRelativeExpiryMs()); } return builder.build(); }
public static List<XAttrProto> convertXAttrProto( List<XAttr> xAttrSpec) { if (xAttrSpec == null) { return Lists.newArrayListWithCapacity(0); } ArrayList<XAttrProto> xAttrs = Lists.newArrayListWithCapacity( xAttrSpec.size()); for (XAttr a : xAttrSpec) { XAttrProto.Builder builder = XAttrProto.newBuilder(); builder.setNamespace(convert(a.getNameSpace())); if (a.getName() != null) { builder.setName(a.getName()); } if (a.getValue() != null) { builder.setValue(getByteString(a.getValue())); } xAttrs.add(builder.build()); } return xAttrs; }
public static CipherOptionProto convert(CipherOption option) { if (option != null) { CipherOptionProto.Builder builder = CipherOptionProto. newBuilder(); if (option.getCipherSuite() != null) { builder.setSuite(convert(option.getCipherSuite())); } if (option.getInKey() != null) { builder.setInKey(ByteString.copyFrom(option.getInKey())); } if (option.getInIv() != null) { builder.setInIv(ByteString.copyFrom(option.getInIv())); } if (option.getOutKey() != null) { builder.setOutKey(ByteString.copyFrom(option.getOutKey())); } if (option.getOutIv() != null) { builder.setOutIv(ByteString.copyFrom(option.getOutIv())); } return builder.build(); } return null; }
public static DatanodeInfoProto convert(DatanodeInfo info) { DatanodeInfoProto.Builder builder = DatanodeInfoProto.newBuilder(); if (info.getNetworkLocation() != null) { builder.setLocation(info.getNetworkLocation()); } if (info.getUpgradeDomain() != null) { builder.setUpgradeDomain(info.getUpgradeDomain()); } builder .setId(convert((DatanodeID) info)) .setCapacity(info.getCapacity()) .setDfsUsed(info.getDfsUsed()) .setRemaining(info.getRemaining()) .setBlockPoolUsed(info.getBlockPoolUsed()) .setCacheCapacity(info.getCacheCapacity()) .setCacheUsed(info.getCacheUsed()) .setLastUpdate(info.getLastUpdate()) .setLastUpdateMonotonic(info.getLastUpdateMonotonic()) .setXceiverCount(info.getXceiverCount()) .setAdminState(convert(info.getAdminState())) .build(); return builder.build(); }
public static HdfsProtos.CipherOptionProto convert(CipherOption option) { if (option != null) { HdfsProtos.CipherOptionProto.Builder builder = HdfsProtos.CipherOptionProto.newBuilder(); if (option.getCipherSuite() != null) { builder.setSuite(convert(option.getCipherSuite())); } if (option.getInKey() != null) { builder.setInKey(getByteString(option.getInKey())); } if (option.getInIv() != null) { builder.setInIv(getByteString(option.getInIv())); } if (option.getOutKey() != null) { builder.setOutKey(getByteString(option.getOutKey())); } if (option.getOutIv() != null) { builder.setOutIv(getByteString(option.getOutIv())); } return builder.build(); } return null; }
public static CacheDirectiveInfoProto convert(CacheDirectiveInfo info) { CacheDirectiveInfoProto.Builder builder = CacheDirectiveInfoProto.newBuilder(); if (info.getId() != null) { builder.setId(info.getId()); } if (info.getPath() != null) { builder.setPath(info.getPath().toUri().getPath()); } if (info.getReplication() != null) { builder.setReplication(info.getReplication()); } if (info.getPool() != null) { builder.setPool(info.getPool()); } if (info.getExpiration() != null) { builder.setExpiration(convert(info.getExpiration())); } return builder.build(); }
public static CacheDirectiveInfo convert(CacheDirectiveInfoProto proto) { CacheDirectiveInfo.Builder builder = new CacheDirectiveInfo.Builder(); if (proto.hasId()) { builder.setId(proto.getId()); } if (proto.hasPath()) { builder.setPath(new Path(proto.getPath())); } if (proto.hasReplication()) { builder.setReplication(Shorts.checkedCast( proto.getReplication())); } if (proto.hasPool()) { builder.setPool(proto.getPool()); } if (proto.hasExpiration()) { builder.setExpiration(convert(proto.getExpiration())); } return builder.build(); }
public static ContentSummary convert(ContentSummaryProto cs) { if (cs == null) return null; ContentSummary.Builder builder = new ContentSummary.Builder(); builder.length(cs.getLength()). fileCount(cs.getFileCount()). directoryCount(cs.getDirectoryCount()). quota(cs.getQuota()). spaceConsumed(cs.getSpaceConsumed()). spaceQuota(cs.getSpaceQuota()); if (cs.hasTypeQuotaInfos()) { for (HdfsProtos.StorageTypeQuotaInfoProto info : cs.getTypeQuotaInfos().getTypeQuotaInfoList()) { StorageType type = convertStorageType(info.getType()); builder.typeConsumed(type, info.getConsumed()); builder.typeQuota(type, info.getQuota()); } } return builder.build(); }
public static LocatedBlocksProto convert(LocatedBlocks lb) { if (lb == null) { return null; } LocatedBlocksProto.Builder builder = LocatedBlocksProto.newBuilder(); if (lb.getLastLocatedBlock() != null) { builder.setLastBlock( convertLocatedBlock(lb.getLastLocatedBlock())); } if (lb.getFileEncryptionInfo() != null) { builder.setFileEncryptionInfo(convert(lb.getFileEncryptionInfo())); } if (lb.getErasureCodingPolicy() != null) { builder.setEcPolicy(convertErasureCodingPolicy( lb.getErasureCodingPolicy())); } return builder.setFileLength(lb.getFileLength()) .setUnderConstruction(lb.isUnderConstruction()) .addAllBlocks(convertLocatedBlocks2(lb.getLocatedBlocks())) .setIsLastBlockComplete(lb.isLastBlockComplete()).build(); }
public static SnapshottableDirectoryStatusProto convert( SnapshottableDirectoryStatus status) { if (status == null) { return null; } int snapshotNumber = status.getSnapshotNumber(); int snapshotQuota = status.getSnapshotQuota(); byte[] parentFullPath = status.getParentFullPath(); ByteString parentFullPathBytes = getByteString( parentFullPath == null ? DFSUtilClient.EMPTY_BYTES : parentFullPath); HdfsFileStatusProto fs = convert(status.getDirStatus()); SnapshottableDirectoryStatusProto.Builder builder = SnapshottableDirectoryStatusProto .newBuilder() .setSnapshotNumber(snapshotNumber) .setSnapshotQuota(snapshotQuota) .setParentFullpath(parentFullPathBytes) .setDirStatus(fs); return builder.build(); }
public static SnapshotDiffReportEntryProto convert(DiffReportEntry entry) { if (entry == null) { return null; } ByteString sourcePath = getByteString(entry.getSourcePath() == null ? DFSUtilClient.EMPTY_BYTES : entry.getSourcePath()); String modification = entry.getType().getLabel(); SnapshotDiffReportEntryProto.Builder builder = SnapshotDiffReportEntryProto .newBuilder().setFullpath(sourcePath) .setModificationLabel(modification); if (entry.getType() == DiffType.RENAME) { ByteString targetPath = getByteString(entry.getTargetPath() == null ? DFSUtilClient.EMPTY_BYTES : entry.getTargetPath()); builder.setTargetPath(targetPath); } return builder.build(); }