diff options
Diffstat (limited to 'configserver/src/main/java/com/yahoo')
5 files changed, 69 insertions, 148 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/status/StatusHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/status/StatusHandler.java new file mode 100644 index 00000000000..a6249104c7f --- /dev/null +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/status/StatusHandler.java @@ -0,0 +1,69 @@ +package com.yahoo.vespa.config.server.http.status; + +import com.google.inject.Inject; +import com.yahoo.cloud.config.ConfigserverConfig; +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.slime.JsonFormat; +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.HttpConfigResponse; +import com.yahoo.vespa.config.server.http.HttpHandler; +import com.yahoo.vespa.config.server.http.JSONResponse; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; +import java.util.stream.Collectors; + +import static com.yahoo.jdisc.http.HttpResponse.Status.OK; + + +public class StatusHandler extends HttpHandler { + + private final ConfigserverConfig config; + private final List<String> modelVersions; + + @Inject + public StatusHandler(Context ctx, GlobalComponentRegistry componentRegistry) { + super(ctx); + this.config = componentRegistry.getConfigserverConfig(); + this.modelVersions = componentRegistry.getModelFactoryRegistry().getFactories().stream() + .map(ModelFactory::getVersion) + .map(Version::toString) + .collect(Collectors.toList()); + } + + @Override + public HttpResponse handleGET(HttpRequest req) { + return new StatusResponse(OK, config, modelVersions); + } + + private static class StatusResponse extends JSONResponse { + + StatusResponse(int status, ConfigserverConfig config, List<String> modelVersions) { + super(status); + + Cursor configCursor = object.setObject("configserverConfig"); + SlimeUtils.copyObject(ConfigPayload.fromInstance(config).getSlime().get(), configCursor); + + Cursor modelVersionsCursor = object.setArray("modelVersions"); + modelVersions.forEach(modelVersionsCursor::addString); + } + + @Override + public void render(OutputStream outputStream) throws IOException { + new JsonFormat(true).encode(outputStream, object); + } + + @Override + public String getContentType() { + return HttpConfigResponse.JSON_CONTENT_TYPE; + } + } + +} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/StatusResource.java b/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/StatusResource.java deleted file mode 100644 index 1aabbb9aeb3..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/StatusResource.java +++ /dev/null @@ -1,57 +0,0 @@ -// 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.restapi.impl; - -import com.google.common.annotations.Beta; -import com.yahoo.cloud.config.ConfigserverConfig; -import com.yahoo.config.model.api.ModelFactory; -import com.yahoo.config.provision.Version; -import com.yahoo.container.jaxrs.annotation.Component; -import com.yahoo.vespa.config.server.GlobalComponentRegistry; -import com.yahoo.vespa.config.server.http.v2.HttpGetConfigHandler; -import com.yahoo.vespa.config.server.http.v2.HttpListConfigsHandler; -import com.yahoo.vespa.config.server.http.v2.HttpListNamedConfigsHandler; -import com.yahoo.vespa.config.server.http.v2.SessionActiveHandler; -import com.yahoo.vespa.config.server.http.v2.SessionContentHandler; -import com.yahoo.vespa.config.server.http.v2.SessionCreateHandler; -import com.yahoo.vespa.config.server.http.v2.SessionPrepareHandler; -import com.yahoo.vespa.config.server.restapi.resources.StatusInformation; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import java.util.List; -import java.util.stream.Collectors; - -/** - * A simple status handler that can provide the status of the config server. - * - * @author lulf - * @since 5.1 - */ -@Beta -@Path("/") -@Produces(MediaType.APPLICATION_JSON) -public class StatusResource { - private final ConfigserverConfig configserverConfig; - private final List<String> modelVersions; - - @SuppressWarnings("UnusedParameters") - public StatusResource(@Component SessionCreateHandler create, - @Component SessionContentHandler content, - @Component SessionPrepareHandler prepare, - @Component SessionActiveHandler active, - @Component HttpGetConfigHandler getHandler, - @Component HttpListConfigsHandler listHandler, - @Component HttpListNamedConfigsHandler listNamedHandler, - @Component GlobalComponentRegistry componentRegistry) { - this.configserverConfig = componentRegistry.getConfigserverConfig(); - this.modelVersions = componentRegistry.getModelFactoryRegistry().getFactories().stream() - .map(ModelFactory::getVersion).map(Version::toString).collect(Collectors.toList()); - } - - @GET - public StatusInformation getStatus() { - return new StatusInformation(configserverConfig, modelVersions); - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/package-info.java b/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/package-info.java deleted file mode 100644 index 5b17eed4b7f..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/impl/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.vespa.config.server.restapi.impl; - -import com.yahoo.osgi.annotation.ExportPackage; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/StatusInformation.java b/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/StatusInformation.java deleted file mode 100644 index 5acd56c252e..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/StatusInformation.java +++ /dev/null @@ -1,81 +0,0 @@ -// 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.restapi.resources; - -import static com.yahoo.vespa.defaults.Defaults.getDefaults; - -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Status information of config server. Currently needs to convert generated configserver config to a POJO that can - * be serialized to JSON. - * - * @author lulf - * @since 5.21 - */ -public class StatusInformation { - - public ConfigserverConfig configserverConfig; - public List<String> modelVersions; - - public StatusInformation(com.yahoo.cloud.config.ConfigserverConfig configserverConfig, List<String> modelVersions) { - this.configserverConfig = new ConfigserverConfig(configserverConfig); - this.modelVersions = modelVersions; - } - - public static class ConfigserverConfig { - public final int rpcport; - public final int numthreads; - public final String zookeepercfg; - public final Collection<ZooKeeperServer> zookeeeperserver; - public final long zookeeperBarrierTimeout; - public final Collection<String> configModelPluginDir; - public final String configServerDBDir; - public final int maxgetconfigclients; - public final long sessionLifetime; - public final String applicationDirectory; - public final long masterGeneration; - public final boolean multitenant; - public final int numDelayedResponseThreads; - public final com.yahoo.cloud.config.ConfigserverConfig.PayloadCompressionType.Enum payloadCompressionType; - public final boolean useVespaVersionInRequest; - public final String serverId; - public final String region; - public final String environment; - - - public ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig configserverConfig) { - this.rpcport = configserverConfig.rpcport(); - this.numthreads = configserverConfig.numthreads(); - this.zookeepercfg = getDefaults().underVespaHome(configserverConfig.zookeepercfg()); - this.zookeeeperserver = configserverConfig.zookeeperserver().stream() - .map(zks -> new ZooKeeperServer(zks.hostname(), zks.port())) - .collect(Collectors.toList()); - this.zookeeperBarrierTimeout = configserverConfig.zookeeper().barrierTimeout(); - this.configModelPluginDir = configserverConfig.configModelPluginDir(); - this.configServerDBDir = getDefaults().underVespaHome(configserverConfig.configServerDBDir()); - this.maxgetconfigclients = configserverConfig.maxgetconfigclients(); - this.sessionLifetime = configserverConfig.sessionLifetime(); - this.applicationDirectory = getDefaults().underVespaHome(configserverConfig.applicationDirectory()); - this.masterGeneration = configserverConfig.masterGeneration(); - this.multitenant = configserverConfig.multitenant(); - this.numDelayedResponseThreads = configserverConfig.numDelayedResponseThreads(); - this.payloadCompressionType = configserverConfig.payloadCompressionType(); - this.useVespaVersionInRequest = configserverConfig.useVespaVersionInRequest(); - this.serverId = configserverConfig.serverId(); - this.region = configserverConfig.region(); - this.environment = configserverConfig.environment(); - } - } - - public static class ZooKeeperServer { - public final String hostname; - public final int port; - - public ZooKeeperServer(String hostname, int port) { - this.hostname = hostname; - this.port = port; - } - } -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/package-info.java b/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/package-info.java deleted file mode 100644 index 520094cd593..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/restapi/resources/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.vespa.config.server.restapi.resources; - -import com.yahoo.osgi.annotation.ExportPackage; |