Search in sources :

Example 1 with SCMNodeStat

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()));
}
Also used : SCMNodeMetric(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric) SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat) Test(org.junit.Test)

Example 2 with SCMNodeStat

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;
}
Also used : DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ArrayList(java.util.ArrayList) SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)

Example 3 with SCMNodeStat

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);
}
Also used : SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)

Example 4 with SCMNodeStat

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;
    }
}
Also used : NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException) StorageReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto) SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)

Example 5 with SCMNodeStat

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;
}
Also used : SCMNodeStat(org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat) DatanodeUsageInfo(org.apache.hadoop.hdds.scm.node.DatanodeUsageInfo)

Aggregations

SCMNodeStat (org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat)19 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)7 ArrayList (java.util.ArrayList)5 StorageReportProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto)4 Test (org.junit.Test)4 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)3 NodeReportProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.NodeReportProto)3 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)3 DatanodeUsageInfo (org.apache.hadoop.hdds.scm.node.DatanodeUsageInfo)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 UUID (java.util.UUID)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)2 StorageContainerDatanodeProtocolProtos (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos)2 LayoutVersionProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.LayoutVersionProto)2 SCMNodeMetric (org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric)2 NetworkTopology (org.apache.hadoop.hdds.scm.net.NetworkTopology)2 NodeReportFromDatanode (org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.NodeReportFromDatanode)2 EventPublisher (org.apache.hadoop.hdds.server.events.EventPublisher)2