blob: 5c0439c0af37e196a827886262b4bed79d7351ca (
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
54
55
56
|
// Copyright 2018 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.status;
import com.google.inject.Inject;
import com.yahoo.config.model.api.ModelFactory;
import com.yahoo.config.provision.Version;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.slime.Cursor;
import com.yahoo.vespa.config.ConfigPayload;
import com.yahoo.vespa.config.SlimeUtils;
import com.yahoo.vespa.config.server.GlobalComponentRegistry;
import com.yahoo.vespa.config.server.http.HttpHandler;
import com.yahoo.vespa.config.server.http.JSONResponse;
import static com.yahoo.jdisc.http.HttpResponse.Status.OK;
/**
* Status handler that outputs config server config and config model versions in use
*
* @author hmusum
*/
public class StatusHandler extends HttpHandler {
private final GlobalComponentRegistry componentRegistry;
@Inject
public StatusHandler(Context ctx, GlobalComponentRegistry componentRegistry) {
super(ctx);
this.componentRegistry = componentRegistry;
}
@Override
public HttpResponse handleGET(HttpRequest req) {
return new StatusResponse(OK, componentRegistry);
}
private static class StatusResponse extends JSONResponse {
StatusResponse(int status, GlobalComponentRegistry componentRegistry) {
super(status);
Cursor configCursor = object.setObject("configserverConfig");
SlimeUtils.copyObject(ConfigPayload.fromInstance(componentRegistry.getConfigserverConfig()).getSlime().get(),
configCursor);
Cursor modelVersionsCursor = object.setArray("modelVersions");
componentRegistry.getModelFactoryRegistry().getFactories().stream()
.map(ModelFactory::getVersion)
.map(Version::toString)
.forEach(modelVersionsCursor::addString);
}
}
}
|