aboutsummaryrefslogtreecommitdiffstats
path: root/clustercontroller-core/src/main/java/com/yahoo/vespa/clustercontroller/core/restapiv2/requests/ServiceStateRequest.java
blob: 907b81c47e77eb386c8bbcda2fc542d07f590eeb (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
// Copyright Vespa.ai. 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.RemoteClusterControllerTask;
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.StateRestApiException;

public class ServiceStateRequest extends Request<Response.ServiceResponse> {
    private final Id.Service id;
    private final int recursive;

    public ServiceStateRequest(Id.Service id, int recursive) {
        super(MasterState.MUST_BE_MASTER);
        this.id = id;
        this.recursive = recursive;
    }

    @Override
    public Response.ServiceResponse calculateResult(RemoteClusterControllerTask.Context context) throws StateRestApiException {
        Response.ServiceResponse result = new Response.ServiceResponse();
        for (Integer i : context.cluster.getConfiguredNodes().keySet()) {
            Id.Node nodeId = new Id.Node(id, i);
            if (recursive > 0) {
                // Don't include per-node statistics when aggregating over all nodes
                NodeStateRequest nsr = new NodeStateRequest(nodeId);
                result.addEntry("node", String.valueOf(i), nsr.calculateResult(context));
            } else {
                result.addLink("node", String.valueOf(i), nodeId.toString());
            }
        }
        return result;
    }
}