@Test public void register() { assertEquals(NEW_BLOCKS, mInfo.getBlocks()); assertEquals(TOTAL_BYTES_ON_TIERS, mInfo.getTotalBytesOnTiers()); assertEquals(Constants.KB * 6L, mInfo.getCapacityBytes()); assertEquals(USED_BYTES_ON_TIERS, mInfo.getUsedBytesOnTiers()); assertEquals(Constants.KB * 2L, mInfo.getUsedBytes()); }
public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) { for (int i = 0; i < storageTierAliases.size() - 1; i++) { if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc .getOrdinal(storageTierAliases.get(i + 1))) { throw new IllegalArgumentException( "Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy"); } } mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases); if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) { throw new IllegalArgumentException( "totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers"); } mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers); mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers); mCapacityBytes = 0; for (long bytes : mTotalBytesOnTiers.values()) { mCapacityBytes += bytes; } mUsedBytes = 0; for (long bytes : mUsedBytesOnTiers.values()) { mUsedBytes += bytes; } Set<Long> removedBlocks; if (mIsRegistered) { LOG.info("re-registering an existing workerId: {}", mId); removedBlocks = Sets.difference(mBlocks, blocks); } else { removedBlocks = Collections.emptySet(); } mBlocks = new HashSet<>(blocks); mIsRegistered = true; return removedBlocks; }
MasterWorkerInfo { public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) { for (int i = 0; i < storageTierAliases.size() - 1; i++) { if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc .getOrdinal(storageTierAliases.get(i + 1))) { throw new IllegalArgumentException( "Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy"); } } mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases); if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) { throw new IllegalArgumentException( "totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers"); } mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers); mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers); mCapacityBytes = 0; for (long bytes : mTotalBytesOnTiers.values()) { mCapacityBytes += bytes; } mUsedBytes = 0; for (long bytes : mUsedBytesOnTiers.values()) { mUsedBytes += bytes; } Set<Long> removedBlocks; if (mIsRegistered) { LOG.info("re-registering an existing workerId: {}", mId); removedBlocks = Sets.difference(mBlocks, blocks); } else { removedBlocks = Collections.emptySet(); } mBlocks = new HashSet<>(blocks); mIsRegistered = true; return removedBlocks; } }
MasterWorkerInfo { public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) { for (int i = 0; i < storageTierAliases.size() - 1; i++) { if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc .getOrdinal(storageTierAliases.get(i + 1))) { throw new IllegalArgumentException( "Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy"); } } mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases); if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) { throw new IllegalArgumentException( "totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers"); } mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers); mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers); mCapacityBytes = 0; for (long bytes : mTotalBytesOnTiers.values()) { mCapacityBytes += bytes; } mUsedBytes = 0; for (long bytes : mUsedBytesOnTiers.values()) { mUsedBytes += bytes; } Set<Long> removedBlocks; if (mIsRegistered) { LOG.info("re-registering an existing workerId: {}", mId); removedBlocks = Sets.difference(mBlocks, blocks); } else { removedBlocks = Collections.emptySet(); } mBlocks = new HashSet<>(blocks); mIsRegistered = true; return removedBlocks; } MasterWorkerInfo(long id, WorkerNetAddress address); }
MasterWorkerInfo { public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) { for (int i = 0; i < storageTierAliases.size() - 1; i++) { if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc .getOrdinal(storageTierAliases.get(i + 1))) { throw new IllegalArgumentException( "Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy"); } } mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases); if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) { throw new IllegalArgumentException( "totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers"); } mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers); mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers); mCapacityBytes = 0; for (long bytes : mTotalBytesOnTiers.values()) { mCapacityBytes += bytes; } mUsedBytes = 0; for (long bytes : mUsedBytesOnTiers.values()) { mUsedBytes += bytes; } Set<Long> removedBlocks; if (mIsRegistered) { LOG.info("re-registering an existing workerId: {}", mId); removedBlocks = Sets.difference(mBlocks, blocks); } else { removedBlocks = Collections.emptySet(); } mBlocks = new HashSet<>(blocks); mIsRegistered = true; return removedBlocks; } MasterWorkerInfo(long id, WorkerNetAddress address); Set<Long> register(final StorageTierAssoc globalStorageTierAssoc,
      final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers,
      final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks); void addBlock(long blockId); void removeBlock(long blockId); void addLostStorage(String tierAlias, String dirPath); void addLostStorage(Map<String, StorageList> lostStorage); WorkerInfo generateWorkerInfo(Set<WorkerInfoField> fieldRange, boolean isLiveWorker); WorkerNetAddress getWorkerAddress(); long getAvailableBytes(); Set<Long> getBlocks(); long getCapacityBytes(); long getId(); long getLastUpdatedTimeMs(); List<Long> getToRemoveBlocks(); long getUsedBytes(); StorageTierAssoc getStorageTierAssoc(); Map<String, Long> getTotalBytesOnTiers(); Map<String, Long> getUsedBytesOnTiers(); long getStartTime(); boolean isRegistered(); Map<String, Long> getFreeBytesOnTiers(); Map<String, List<String>> getLostStorage(); boolean hasLostStorage(); @Override String toString(); void updateLastUpdatedTimeMs(); void updateToRemovedBlock(boolean add, long blockId); void updateCapacityBytes(Map<String, Long> capacityBytesOnTiers); void updateUsedBytes(Map<String, Long> usedBytesOnTiers); void updateUsedBytes(String tierAlias, long usedBytesOnTier); }
MasterWorkerInfo { public Set<Long> register(final StorageTierAssoc globalStorageTierAssoc, final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers, final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks) { for (int i = 0; i < storageTierAliases.size() - 1; i++) { if (globalStorageTierAssoc.getOrdinal(storageTierAliases.get(i)) >= globalStorageTierAssoc .getOrdinal(storageTierAliases.get(i + 1))) { throw new IllegalArgumentException( "Worker cannot place storage tier " + storageTierAliases.get(i) + " above " + storageTierAliases.get(i + 1) + " in the hierarchy"); } } mStorageTierAssoc = new WorkerStorageTierAssoc(storageTierAliases); if (mStorageTierAssoc.size() != totalBytesOnTiers.size() || mStorageTierAssoc.size() != usedBytesOnTiers.size()) { throw new IllegalArgumentException( "totalBytesOnTiers and usedBytesOnTiers should have the same number of tiers as " + "storageTierAliases, but storageTierAliases has " + mStorageTierAssoc.size() + " tiers, while totalBytesOnTiers has " + totalBytesOnTiers.size() + " tiers and usedBytesOnTiers has " + usedBytesOnTiers.size() + " tiers"); } mTotalBytesOnTiers = new HashMap<>(totalBytesOnTiers); mUsedBytesOnTiers = new HashMap<>(usedBytesOnTiers); mCapacityBytes = 0; for (long bytes : mTotalBytesOnTiers.values()) { mCapacityBytes += bytes; } mUsedBytes = 0; for (long bytes : mUsedBytesOnTiers.values()) { mUsedBytes += bytes; } Set<Long> removedBlocks; if (mIsRegistered) { LOG.info("re-registering an existing workerId: {}", mId); removedBlocks = Sets.difference(mBlocks, blocks); } else { removedBlocks = Collections.emptySet(); } mBlocks = new HashSet<>(blocks); mIsRegistered = true; return removedBlocks; } MasterWorkerInfo(long id, WorkerNetAddress address); Set<Long> register(final StorageTierAssoc globalStorageTierAssoc,
      final List<String> storageTierAliases, final Map<String, Long> totalBytesOnTiers,
      final Map<String, Long> usedBytesOnTiers, final Set<Long> blocks); void addBlock(long blockId); void removeBlock(long blockId); void addLostStorage(String tierAlias, String dirPath); void addLostStorage(Map<String, StorageList> lostStorage); WorkerInfo generateWorkerInfo(Set<WorkerInfoField> fieldRange, boolean isLiveWorker); WorkerNetAddress getWorkerAddress(); long getAvailableBytes(); Set<Long> getBlocks(); long getCapacityBytes(); long getId(); long getLastUpdatedTimeMs(); List<Long> getToRemoveBlocks(); long getUsedBytes(); StorageTierAssoc getStorageTierAssoc(); Map<String, Long> getTotalBytesOnTiers(); Map<String, Long> getUsedBytesOnTiers(); long getStartTime(); boolean isRegistered(); Map<String, Long> getFreeBytesOnTiers(); Map<String, List<String>> getLostStorage(); boolean hasLostStorage(); @Override String toString(); void updateLastUpdatedTimeMs(); void updateToRemovedBlock(boolean add, long blockId); void updateCapacityBytes(Map<String, Long> capacityBytesOnTiers); void updateUsedBytes(Map<String, Long> usedBytesOnTiers); void updateUsedBytes(String tierAlias, long usedBytesOnTier);  }