aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/HttpListNamedConfigsHandler.java
blob: 0a55d3585e01fe62fe662199ffbe6df15ff00c19 (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http.v2;

import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executor;

import com.google.inject.Inject;
import com.yahoo.config.provision.Zone;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.logging.AccessLog;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.server.RequestHandler;
import com.yahoo.vespa.config.server.tenant.Tenants;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.config.server.http.HttpConfigRequest;
import com.yahoo.vespa.config.server.http.HttpHandler;

/**
 * Handler for a list named configs operation. Lists all configs in model for a given application and tenant, config name and optionally config id.
 *
 * @author vegardh
 * @since 5.3
 */
public class HttpListNamedConfigsHandler extends HttpHandler {

    private final Tenants tenants;
    private final Zone zone;
    
    @Inject
    public HttpListNamedConfigsHandler(HttpHandler.Context ctx,
                                       Tenants tenants, Zone zone)
    {
        super(ctx);
        this.tenants = tenants;
        this.zone = zone;
    }
    
    @Override
    public HttpResponse handleGET(HttpRequest req) {
        HttpListConfigsRequest listReq = HttpListConfigsRequest.createFromNamedListRequest(req);
        RequestHandler requestHandler = HttpConfigRequests.getRequestHandler(tenants, listReq);
        ApplicationId appId = listReq.getApplicationId();
        HttpConfigRequest.validateRequestKey(listReq.getKey(), requestHandler, appId);
        Set<ConfigKey<?>> configs = requestHandler.listNamedConfigs(appId, Optional.empty(), listReq.getKey(), listReq.isRecursive());
        String urlBase = HttpListConfigsHandler.getUrlBase(req, listReq, appId, zone);
        Set<ConfigKey<?>> allConfigs = requestHandler.allConfigsProduced(appId, Optional.empty());
        return new HttpListConfigsHandler.ListConfigsResponse(configs, allConfigs, urlBase, listReq.isRecursive());
    }
}