use of org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat in project ozone by apache.
the class TestDatanodeMetrics method testSCMNodeMetric.
@Test
public void testSCMNodeMetric() {
SCMNodeStat stat = new SCMNodeStat(100L, 10L, 90L);
assertEquals((long) stat.getCapacity().get(), 100L);
assertEquals(10L, (long) stat.getScmUsed().get());
assertEquals(90L, (long) stat.getRemaining().get());
SCMNodeMetric metric = new SCMNodeMetric(stat);
SCMNodeStat newStat = new SCMNodeStat(100L, 10L, 90L);
assertEquals(100L, (long) stat.getCapacity().get());
assertEquals(10L, (long) stat.getScmUsed().get());
assertEquals(90L, (long) stat.getRemaining().get());
SCMNodeMetric newMetric = new SCMNodeMetric(newStat);
assertTrue(metric.isEqual(newMetric.get()));
newMetric.add(stat);
assertTrue(newMetric.isGreater(metric.get()));
SCMNodeMetric zeroMetric = new SCMNodeMetric(new SCMNodeStat());
// Assert we can handle zero capacity.
assertTrue(metric.isGreater(zeroMetric.get()));
}
use of org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat in project ozone by apache.
the class SCMNodeManager method getMostOrLeastUsedDatanodes.
/**
* Gets a sorted list of most or least used DatanodeUsageInfo containing
* healthy, in-service nodes. If the specified mostUsed is true, the returned
* list is in descending order of usage. Otherwise, the returned list is in
* ascending order of usage.
*
* @param mostUsed true if most used, false if least used
* @return List of DatanodeUsageInfo
*/
@Override
public List<DatanodeUsageInfo> getMostOrLeastUsedDatanodes(boolean mostUsed) {
List<DatanodeDetails> healthyNodes = getNodes(IN_SERVICE, NodeState.HEALTHY);
List<DatanodeUsageInfo> datanodeUsageInfoList = new ArrayList<>(healthyNodes.size());
// list
for (DatanodeDetails node : healthyNodes) {
SCMNodeStat stat = getNodeStatInternal(node);
datanodeUsageInfoList.add(new DatanodeUsageInfo(node, stat));
}
// sort the list according to appropriate comparator
if (mostUsed) {
datanodeUsageInfoList.sort(DatanodeUsageInfo.getMostUtilized().reversed());
} else {
datanodeUsageInfoList.sort(DatanodeUsageInfo.getMostUtilized());
}
return datanodeUsageInfoList;
}
use of org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat in project ozone by apache.
the class SCMNodeManager method getStats.
/**
* Returns the aggregated node stats.
*
* @return the aggregated node stats.
*/
@Override
public SCMNodeStat getStats() {
long capacity = 0L;
long used = 0L;
long remaining = 0L;
for (SCMNodeStat stat : getNodeStats().values()) {
capacity += stat.getCapacity().get();
used += stat.getScmUsed().get();
remaining += stat.getRemaining().get();
}
return new SCMNodeStat(capacity, used, remaining);
}
use of org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat in project ozone by apache.
the class SCMNodeManager method getNodeStatInternal.
private SCMNodeStat getNodeStatInternal(DatanodeDetails datanodeDetails) {
try {
long capacity = 0L;
long used = 0L;
long remaining = 0L;
final DatanodeInfo datanodeInfo = nodeStateManager.getNode(datanodeDetails);
final List<StorageReportProto> storageReportProtos = datanodeInfo.getStorageReports();
for (StorageReportProto reportProto : storageReportProtos) {
capacity += reportProto.getCapacity();
used += reportProto.getScmUsed();
remaining += reportProto.getRemaining();
}
return new SCMNodeStat(capacity, used, remaining);
} catch (NodeNotFoundException e) {
LOG.warn("Cannot generate NodeStat, datanode {} not found.", datanodeDetails.getUuid());
return null;
}
}
use of org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat in project ozone by apache.
the class ContainerBalancer method calculateAvgUtilization.
/**
* Calculates the average utilization for the specified nodes.
* Utilization is (capacity - remaining) divided by capacity.
*
* @param nodes List of DatanodeUsageInfo to find the average utilization for
* @return Average utilization value
*/
double calculateAvgUtilization(List<DatanodeUsageInfo> nodes) {
if (nodes.size() == 0) {
LOG.warn("No nodes to calculate average utilization for in " + "ContainerBalancer.");
return 0;
}
SCMNodeStat aggregatedStats = new SCMNodeStat(0, 0, 0);
for (DatanodeUsageInfo node : nodes) {
aggregatedStats.add(node.getScmNodeStat());
}
clusterCapacity = aggregatedStats.getCapacity().get();
clusterUsed = aggregatedStats.getScmUsed().get();
clusterRemaining = aggregatedStats.getRemaining().get();
return (clusterCapacity - clusterRemaining) / (double) clusterCapacity;
}
Aggregations