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
54
55
56
57
58
59
60
61
62
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.clustercontroller.core.restapiv2.requests;
import com.yahoo.vespa.clustercontroller.core.LatencyStats;
import com.yahoo.vespa.clustercontroller.core.NodeInfo;
import com.yahoo.vespa.clustercontroller.core.RemoteClusterControllerTask;
import com.yahoo.vespa.clustercontroller.core.StorageNodeStats;
import com.yahoo.vespa.clustercontroller.core.restapiv2.Id;
import com.yahoo.vespa.clustercontroller.core.restapiv2.Request;
import com.yahoo.vespa.clustercontroller.core.restapiv2.Response;
import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.MissingResourceException;
import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.StateRestApiException;
import java.util.Set;
public class NodeStateRequest extends Request<Response.NodeResponse> {
private final Id.Node id;
private final int recursive;
private final Set<VerboseReport> verboseReports;
public NodeStateRequest(Id.Node id, int recursive, Set<VerboseReport> verboseReports) {
super(MasterState.MUST_BE_MASTER);
this.id = id;
this.recursive = recursive;
this.verboseReports = verboseReports;
}
@Override
public Response.NodeResponse calculateResult(RemoteClusterControllerTask.Context context) throws StateRestApiException {
Response.NodeResponse result = new Response.NodeResponse();
NodeInfo info = context.cluster.getNodeInfo(id.getNode());
if (info == null) {
throw new MissingResourceException("node " + id.getNode());
}
if (info.getGroup() != null) {
result.addAttribute("hierarchical-group", info.getGroup().getPath());
}
result.addState("generated", new Response.UnitStateImpl(context.currentState.getNodeState(id.getNode())));
result.addState("unit", new Response.UnitStateImpl(info.getReportedState()));
result.addState("user", new Response.UnitStateImpl(info.getWantedState()));
if (info.isStorage() && verboseReports.contains(VerboseReport.STATISTICS)) {
StorageNodeStats storageStats = context.cluster.getStorageNodeStats(info.getNodeIndex());
LatencyStats latencyStats = storageStats.getDistributorPutLatency();
result.addMetric("distributor-put-latency-ms-sum", latencyStats.getLatencyMsSum());
result.addMetric("distributor-put-latency-count", latencyStats.getCount());
}
for (int i=0; i<info.getReportedState().getDiskCount(); ++i) {
Id.Partition partitionId = new Id.Partition(id, i);
if (recursive > 0) {
PartitionStateRequest psr = new PartitionStateRequest(partitionId, verboseReports);
result.addEntry("partition", String.valueOf(i), psr.calculateResult(context));
} else {
result.addLink("partition", String.valueOf(i), partitionId.toString());
}
}
return result;
}
}
|