summaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/hostinfo/StorageNodeStatsBridge.java
blob: 1e595839fa20080f476714938061e1ac1e54f5a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.hostinfo;

import com.yahoo.vespa.clustercontroller.core.*;
import com.yahoo.vespa.clustercontroller.core.ContentClusterStats;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Class used to create a StorageNodeStatsContainer from HostInfo.
 *
 * @author hakonhall
 */
public class StorageNodeStatsBridge {

    private StorageNodeStatsBridge() { }

    public static StorageNodeStatsContainer traverseHostInfo(HostInfo hostInfo) {
        StorageNodeStatsContainer container = new StorageNodeStatsContainer();
        List<StorageNode> storageNodes = hostInfo.getDistributor().getStorageNodes();
        for (StorageNode storageNode : storageNodes) {
            Integer storageNodeIndex = storageNode.getIndex();
            if (storageNodeIndex == null) {
                continue;
            }
            StorageNode.OpsLatency opsLatency = storageNode.getOpsLatenciesOrNull();
            if (opsLatency == null) {
                continue;
            }
            StorageNode.Put putLatency = opsLatency.getPut();
            Long putLatencyMsSum = putLatency.getLatencyMsSum();
            Long putLatencyCount = putLatency.getCount();
            if (putLatencyMsSum == null || putLatencyCount == null) {
                continue;
            }
            LatencyStats putLatencyStats = new LatencyStats(putLatencyMsSum, putLatencyCount);
            StorageNodeStats nodeStats = new StorageNodeStats(putLatencyStats);
            container.put(storageNodeIndex, nodeStats);
        }
        return container;
    }

    public static ContentClusterStats generate(Distributor distributor) {
        Map<Integer, ContentNodeStats> mapToNodeStats = new HashMap<>();
        for (StorageNode storageNode : distributor.getStorageNodes()) {
            mapToNodeStats.put(storageNode.getIndex(), new ContentNodeStats(storageNode));
        }
        return new ContentClusterStats(mapToNodeStats);
    }

}