blob: 0bce593e0cd5e364b47546f467ded59991fb94fa (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.http;
import com.yahoo.component.annotation.Inject;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import java.util.logging.Level;
import com.yahoo.vespa.config.protocol.ConfigResponse;
import com.yahoo.vespa.config.server.RequestHandler;
import com.yahoo.vespa.config.server.tenant.TenantRepository;
import java.util.Optional;
/**
* HTTP handler for a v1 getConfig operation
*
* @author Ulf Lilleengen
*/
// TODO: Make this API discoverable
public class HttpGetConfigHandler extends HttpHandler {
private final RequestHandler requestHandler;
public HttpGetConfigHandler(HttpHandler.Context ctx, RequestHandler requestHandler) {
super(ctx);
this.requestHandler = requestHandler;
}
@SuppressWarnings("unused") // injected
@Inject
public HttpGetConfigHandler(HttpHandler.Context ctx, TenantRepository tenantRepository) {
this(ctx, tenantRepository.defaultTenant().getRequestHandler());
}
@Override
public HttpResponse handleGET(HttpRequest req) {
HttpConfigRequest request = HttpConfigRequest.createFromRequestV1(req);
HttpConfigRequest.validateRequestKey(request.getConfigKey(), requestHandler, ApplicationId.defaultId());
return HttpConfigResponse.createFromConfig(resolveConfig(request));
}
private ConfigResponse resolveConfig(HttpConfigRequest request) {
log.log(Level.FINE, () -> "nocache=" + request.noCache());
ConfigResponse config = requestHandler.resolveConfig(ApplicationId.defaultId(), request, Optional.empty());
if (config == null) HttpConfigRequest.throwModelNotReady();
return config;
}
}
|