aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgjoranv <gjoranv@gmail.com>2022-07-11 14:38:11 +0200
committerGitHub <noreply@github.com>2022-07-11 14:38:11 +0200
commit7c548b4c8c29ec60d432d819daaf4ad2f6806a41 (patch)
tree3a9c2fdf05ca919a04f7a0cc392fe52906e4f416
parent64028e00179ec394e961be89da3cd919bf40c664 (diff)
parentd4d9c2f002f78122d492c6f56dcdeba0e9bf200f (diff)
Merge pull request #23442 from vespa-engine/inject-default-threadpool-to-handlers
Inject default threadpool to handlers [run-systemtest]
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/admin/LogserverContainerCluster.java2
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainer.java4
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java6
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/application/validation/UriBindingsValidator.java2
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomClientProviderBuilder.java3
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java19
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java40
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java2
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/Container.java6
-rwxr-xr-xconfig-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java30
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java4
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java10
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java6
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java46
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/component/chain/ProcessingHandler.java14
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/docproc/MbusClient.java3
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java14
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java3
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java4
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java31
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerClusterTest.java2
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java8
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java16
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java94
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java12
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java118
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java (renamed from config-model/src/test/java/com/yahoo/vespa/model/container/xml/ApplicationBuilderTest.java)11
-rw-r--r--config-model/src/test/schema-test-files/services.xml3
-rw-r--r--container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java2
-rw-r--r--container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java20
30 files changed, 316 insertions, 219 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/LogserverContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/LogserverContainerCluster.java
index 75b13a89e83..c50b9b7f842 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/admin/LogserverContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/LogserverContainerCluster.java
@@ -36,7 +36,7 @@ public class LogserverContainerCluster extends ContainerCluster<LogserverContain
protected boolean messageBusEnabled() { return false; }
private void addLogHandler() {
- Handler<?> logHandler = Handler.fromClassName(ContainerCluster.LOG_HANDLER_CLASS);
+ Handler logHandler = Handler.fromClassName(ContainerCluster.LOG_HANDLER_CLASS);
logHandler.addServerBindings(SystemBindingPattern.fromHttpPath("/logs"));
addComponent(logHandler);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainer.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainer.java
index 1da5e190c70..5d60cec0679 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainer.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/clustercontroller/ClusterControllerContainer.java
@@ -118,7 +118,7 @@ public class ClusterControllerContainer extends Container implements
ZOOKEEPER_SERVER_BUNDLE);
}
- private void addHandler(Handler<?> h, String path) {
+ private void addHandler(Handler h, String path) {
h.addServerBindings(SystemBindingPattern.fromHttpPath(path));
super.addHandler(h);
}
@@ -138,7 +138,7 @@ public class ClusterControllerContainer extends Container implements
}
private void addHandler(String id, String className, String path, ComponentSpecification bundle) {
- addHandler(new Handler<>(createComponentModel(id, className, bundle)), path);
+ addHandler(new Handler(createComponentModel(id, className, bundle)), path);
}
private ReindexingContext reindexingContext() {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java
index a29647b062a..680a4b97f86 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerCluster.java
@@ -119,12 +119,12 @@ public class MetricsProxyContainerCluster extends ContainerCluster<MetricsProxyC
}
private void addHttpHandler(Class<? extends ThreadedHttpRequestHandler> clazz, String bindingPath) {
- Handler<AbstractConfigProducer<?>> metricsHandler = createMetricsHandler(clazz, bindingPath);
+ Handler metricsHandler = createMetricsHandler(clazz, bindingPath);
addComponent(metricsHandler);
}
- static Handler<AbstractConfigProducer<?>> createMetricsHandler(Class<? extends ThreadedHttpRequestHandler> clazz, String bindingPath) {
- Handler<AbstractConfigProducer<?>> metricsHandler = new Handler<>(
+ static Handler createMetricsHandler(Class<? extends ThreadedHttpRequestHandler> clazz, String bindingPath) {
+ Handler metricsHandler = new Handler(
new ComponentModel(clazz.getName(), null, METRICS_PROXY_BUNDLE_NAME, null));
metricsHandler.addServerBindings(
SystemBindingPattern.fromHttpPath(bindingPath),
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/UriBindingsValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/UriBindingsValidator.java
index 4f322578b1c..718f1646126 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/UriBindingsValidator.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/UriBindingsValidator.java
@@ -24,7 +24,7 @@ class UriBindingsValidator extends Validator {
@Override
public void validate(VespaModel model, DeployState deployState) {
for (ApplicationContainerCluster cluster : model.getContainerClusters().values()) {
- for (Handler<?> handler : cluster.getHandlers()) {
+ for (Handler handler : cluster.getHandlers()) {
for (BindingPattern binding : handler.getServerBindings()) {
validateUserBinding(binding, model, deployState);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomClientProviderBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomClientProviderBuilder.java
index 69613944e74..170e8940787 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomClientProviderBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomClientProviderBuilder.java
@@ -5,7 +5,6 @@ import com.yahoo.config.model.deploy.DeployState;
import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
-import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.container.component.UserBindingPattern;
import org.w3c.dom.Element;
@@ -22,7 +21,7 @@ public class DomClientProviderBuilder extends DomHandlerBuilder {
@Override
protected Handler doBuild(DeployState deployState, AbstractConfigProducer parent, Element clientElement) {
- Handler<? super Component<?, ?>> client = createHandler(clientElement);
+ Handler client = createHandler(clientElement);
for (Element binding : XML.getChildren(clientElement, "binding"))
client.addClientBindings(UserBindingPattern.fromPattern(XML.getValue(binding)));
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java
index 025a6377b04..7bfe971981e 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/builder/xml/dom/DomHandlerBuilder.java
@@ -9,15 +9,12 @@ import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.text.XML;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.component.BindingPattern;
-import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.container.component.UserBindingPattern;
import com.yahoo.vespa.model.container.xml.BundleInstantiationSpecificationBuilder;
import org.w3c.dom.Element;
-import java.util.List;
import java.util.Set;
-import java.util.logging.Level;
import static com.yahoo.vespa.model.container.ApplicationContainerCluster.METRICS_V2_HANDLER_BINDING_1;
import static com.yahoo.vespa.model.container.ApplicationContainerCluster.METRICS_V2_HANDLER_BINDING_2;
@@ -29,7 +26,7 @@ import static java.util.logging.Level.INFO;
/**
* @author gjoranv
*/
-public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<Handler<?>> {
+public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<Handler> {
private static final Set<BindingPattern> reservedBindings =
Set.of(METRICS_V2_HANDLER_BINDING_1,
@@ -45,8 +42,8 @@ public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<
}
@Override
- protected Handler<?> doBuild(DeployState deployState, AbstractConfigProducer<?> parent, Element handlerElement) {
- Handler<? super Component<?, ?>> handler = createHandler(handlerElement);
+ protected Handler doBuild(DeployState deployState, AbstractConfigProducer<?> parent, Element handlerElement) {
+ Handler handler = createHandler(handlerElement);
for (Element binding : XML.getChildren(handlerElement, "binding"))
addServerBinding(handler, UserBindingPattern.fromPattern(XML.getValue(binding)), deployState.getDeployLogger());
@@ -56,18 +53,18 @@ public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<
return handler;
}
- Handler<? super Component<?, ?>> createHandler(Element handlerElement) {
+ Handler createHandler(Element handlerElement) {
BundleInstantiationSpecification bundleSpec = BundleInstantiationSpecificationBuilder.build(handlerElement);
- return new Handler<>(new ComponentModel(bundleSpec));
+ return new Handler(new ComponentModel(bundleSpec));
}
- private void addServerBinding(Handler<? super Component<?, ?>> handler, BindingPattern binding, DeployLogger log) {
+ private void addServerBinding(Handler handler, BindingPattern binding, DeployLogger log) {
throwIfBindingIsReserved(binding, handler);
handler.addServerBindings(binding);
removeExistingServerBinding(binding, handler, log);
}
- private void throwIfBindingIsReserved(BindingPattern binding, Handler<?> newHandler) {
+ private void throwIfBindingIsReserved(BindingPattern binding, Handler newHandler) {
for (var reserved : reservedBindings) {
if (binding.hasSamePattern(reserved)) {
throw new IllegalArgumentException("Binding '" + binding.patternString() + "' is a reserved Vespa binding and " +
@@ -76,7 +73,7 @@ public class DomHandlerBuilder extends VespaDomBuilder.DomConfigProducerBuilder<
}
}
- private void removeExistingServerBinding(BindingPattern binding, Handler<?> newHandler, DeployLogger log) {
+ private void removeExistingServerBinding(BindingPattern binding, Handler newHandler, DeployLogger log) {
for (var handler : cluster.getHandlers()) {
for (BindingPattern serverBinding : handler.getServerBindings()) {
if (serverBinding.hasSamePattern(binding)) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java b/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
index 33c125dcecf..d5f41353616 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/clients/ContainerDocumentApi.java
@@ -1,8 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.clients;
-import com.yahoo.config.model.producer.AbstractConfigProducer;
-import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.ContainerCluster;
@@ -41,31 +39,31 @@ public class ContainerDocumentApi {
private static void addFeedHandler(ContainerCluster<?> cluster, HandlerOptions handlerOptions) {
String bindingSuffix = ContainerCluster.RESERVED_URI_PREFIX + "/feedapi";
- var handler = newVespaClientHandler("com.yahoo.vespa.http.server.FeedHandler", bindingSuffix, handlerOptions);
- cluster.addComponent(handler);
var executor = new Threadpool("feedapi-handler", handlerOptions.feedApiThreadpoolOptions);
- handler.inject(executor);
- handler.addComponent(executor);
+ var handler = newVespaClientHandler("com.yahoo.vespa.http.server.FeedHandler",
+ bindingSuffix, handlerOptions, executor);
+ cluster.addComponent(handler);
}
private static void addRestApiHandler(ContainerCluster<?> cluster, HandlerOptions handlerOptions) {
- var handler = newVespaClientHandler("com.yahoo.document.restapi.resource.DocumentV1ApiHandler", DOCUMENT_V1_PREFIX + "/*", handlerOptions);
+ var handler = newVespaClientHandler("com.yahoo.document.restapi.resource.DocumentV1ApiHandler",
+ DOCUMENT_V1_PREFIX + "/*", handlerOptions, null);
cluster.addComponent(handler);
// We need to include a dummy implementation of the previous restapi handler (using the same class name).
// The internal legacy test framework requires that the name of the old handler is listed in /ApplicationStatus.
- var oldHandlerDummy = handlerComponentSpecification("com.yahoo.document.restapi.resource.RestApi");
+ var oldHandlerDummy = createHandler("com.yahoo.document.restapi.resource.RestApi", null);
cluster.addComponent(oldHandlerDummy);
}
public boolean ignoreUndefinedFields() { return ignoreUndefinedFields; }
- private static Handler<AbstractConfigProducer<?>> newVespaClientHandler(
- String componentId,
- String bindingSuffix,
- HandlerOptions handlerOptions) {
- Handler<AbstractConfigProducer<?>> handler = handlerComponentSpecification(componentId);
+ private static Handler newVespaClientHandler(String componentId,
+ String bindingSuffix,
+ HandlerOptions handlerOptions,
+ Threadpool executor) {
+ Handler handler = createHandler(componentId, executor);
if (handlerOptions.bindings.isEmpty()) {
handler.addServerBindings(
SystemBindingPattern.fromHttpPath(bindingSuffix),
@@ -81,9 +79,9 @@ public class ContainerDocumentApi {
return handler;
}
- private static Handler<AbstractConfigProducer<?>> handlerComponentSpecification(String className) {
- return new Handler<>(new ComponentModel(
- BundleInstantiationSpecification.getFromStrings(className, null, "vespaclient-container-plugin"), ""));
+ private static Handler createHandler(String className, Threadpool executor) {
+ return new Handler(new ComponentModel(className, null, "vespaclient-container-plugin"),
+ executor);
}
public static final class HandlerOptions {
@@ -104,12 +102,10 @@ public class ContainerDocumentApi {
}
@Override
- public void getConfig(ContainerThreadpoolConfig.Builder builder) {
- super.getConfig(builder);
-
- // User options overrides below configuration
- if (hasUserOptions()) return;
- builder.maxThreads(-4).minThreads(-4).queueSize(500);
+ protected void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder) {
+ builder.maxThreads(-4)
+ .minThreads(-4)
+ .queueSize(500);
}
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java
index 937d7cf58d3..e316f826ad6 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java
@@ -147,7 +147,7 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat
}
private void addMetricsHandler(String handlerClass, BindingPattern rootBinding, BindingPattern innerBinding) {
- Handler<AbstractConfigProducer<?>> handler = new Handler<>(
+ Handler handler = new Handler(
new ComponentModel(handlerClass, null, null, null));
handler.addServerBindings(rootBinding, innerBinding);
addComponent(handler);
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java
index 63c323bfdaf..3d6332a9773 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java
@@ -76,7 +76,7 @@ public abstract class Container extends AbstractService implements
private final boolean dumpHeapOnShutdownTimeout;
private final double shutdownTimeoutS;
- private final ComponentGroup<Handler<?>> handlers = new ComponentGroup<>(this, "handler");
+ private final ComponentGroup<Handler> handlers = new ComponentGroup<>(this, "handler");
private final ComponentGroup<Component<?, ?>> components = new ComponentGroup<>(this, "components");
private final JettyHttpServer defaultHttpServer;
@@ -113,7 +113,7 @@ public abstract class Container extends AbstractService implements
/** True if this container is retired (slated for removal) */
public boolean isRetired() { return retired; }
- public ComponentGroup<Handler<?>> getHandlers() {
+ public ComponentGroup<Handler> getHandlers() {
return handlers;
}
@@ -129,7 +129,7 @@ public abstract class Container extends AbstractService implements
addComponent(new SimpleComponent(new ComponentModel(idSpec, classSpec, bundleSpec)));
}
- public final void addHandler(Handler<?> h) {
+ public final void addHandler(Handler h) {
handlers.addComponent(h);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
index 2385b5b3812..45fde57fcc7 100755
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java
@@ -142,6 +142,7 @@ public abstract class ContainerCluster<CONTAINER extends Container>
private ContainerDocproc containerDocproc;
private ContainerDocumentApi containerDocumentApi;
private SecretStore secretStore;
+ private final ContainerThreadpool defaultHandlerThreadpool = new Handler.DefaultHandlerThreadpool();
private boolean rpcServerEnabled = true;
private boolean httpServerEnabled = true;
@@ -181,6 +182,7 @@ public abstract class ContainerCluster<CONTAINER extends Container>
addCommonVespaBundles();
addSimpleComponent(AccessLog.class);
addComponent(new DefaultThreadpoolProvider(this, defaultPoolNumThreads));
+ addComponent(defaultHandlerThreadpool);
addSimpleComponent(com.yahoo.concurrent.classlock.ClassLocking.class);
addSimpleComponent("com.yahoo.container.jdisc.metric.MetricConsumerProviderProvider");
addSimpleComponent("com.yahoo.container.jdisc.metric.MetricProvider");
@@ -217,14 +219,14 @@ public abstract class ContainerCluster<CONTAINER extends Container>
}
public void addMetricStateHandler() {
- Handler<AbstractConfigProducer<?>> stateHandler = new Handler<>(
+ Handler stateHandler = new Handler(
new ComponentModel(STATE_HANDLER_CLASS, null, null, null));
stateHandler.addServerBindings(STATE_HANDLER_BINDING_1, STATE_HANDLER_BINDING_2);
addComponent(stateHandler);
}
public void addDefaultRootHandler() {
- Handler<AbstractConfigProducer<?>> handler = new Handler<>(
+ Handler handler = new Handler(
new ComponentModel(BundleInstantiationSpecification.getFromStrings(
BINDINGS_OVERVIEW_HANDLER_CLASS, null, null), null)); // null bundle, as the handler is in container-disc
handler.addServerBindings(ROOT_HANDLER_BINDING);
@@ -232,7 +234,7 @@ public abstract class ContainerCluster<CONTAINER extends Container>
}
public void addApplicationStatusHandler() {
- Handler<AbstractConfigProducer<?>> statusHandler = new Handler<>(
+ Handler statusHandler = new Handler(
new ComponentModel(BundleInstantiationSpecification.getFromStrings(
APPLICATION_STATUS_HANDLER_CLASS, null, null), null)); // null bundle, as the handler is in container-disc
statusHandler.addServerBindings(SystemBindingPattern.fromHttpPath("/ApplicationStatus"));
@@ -240,13 +242,22 @@ public abstract class ContainerCluster<CONTAINER extends Container>
}
public void addVipHandler() {
- Handler<?> vipHandler = Handler.fromClassName(FileStatusHandlerComponent.CLASS);
+ Handler vipHandler = Handler.fromClassName(FileStatusHandlerComponent.CLASS);
vipHandler.addServerBindings(VIP_HANDLER_BINDING);
addComponent(vipHandler);
}
public final void addComponent(Component<?, ?> component) {
componentGroup.addComponent(component);
+ if (component instanceof Handler handler) {
+ ensureHandlerHasThreadpool(handler);
+ }
+ }
+
+ private void ensureHandlerHasThreadpool(Handler handler) {
+ if (! handler.hasCustomThreadPool) {
+ handler.inject(defaultHandlerThreadpool);
+ }
}
public final void addSimpleComponent(String idSpec, String classSpec, String bundleSpec) {
@@ -306,10 +317,8 @@ public abstract class ContainerCluster<CONTAINER extends Container>
this.processingChains = processingChains;
// Cannot use the class object for ProcessingHandler, because its superclass is not accessible
- ProcessingHandler<?> processingHandler = new ProcessingHandler<>(
- processingChains,
- "com.yahoo.processing.handler.ProcessingHandler",
- null);
+ ProcessingHandler<?> processingHandler = new ProcessingHandler<>(processingChains,
+ "com.yahoo.processing.handler.ProcessingHandler");
for (BindingPattern binding: serverBindings)
processingHandler.addServerBindings(binding);
@@ -368,9 +377,8 @@ public abstract class ContainerCluster<CONTAINER extends Container>
return containerDocproc.getChains();
}
- @SuppressWarnings("unchecked")
- public Collection<Handler<?>> getHandlers() {
- return (Collection<Handler<?>>)(Collection)componentGroup.getComponents(Handler.class);
+ public Collection<Handler> getHandlers() {
+ return componentGroup.getComponents(Handler.class);
}
public void setSecretStore(SecretStore secretStore) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java
index cb8e6ba85ff..088465f56b1 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerModelEvaluation.java
@@ -63,8 +63,8 @@ public class ContainerModelEvaluation implements
rankProfileList.getConfig(builder);
}
- public static Handler<?> getHandler() {
- Handler<?> handler = new Handler<>(new ComponentModel(REST_HANDLER_NAME, null, EVALUATION_BUNDLE_NAME));
+ public static Handler getHandler() {
+ Handler handler = new Handler(new ComponentModel(REST_HANDLER_NAME, null, EVALUATION_BUNDLE_NAME));
handler.addServerBindings(
SystemBindingPattern.fromHttpPath(REST_BINDING_PATH),
SystemBindingPattern.fromHttpPath(REST_BINDING_PATH + "/*"));
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
index 489e4cc135a..fbd7bc9fe56 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerThreadpool.java
@@ -17,7 +17,7 @@ import java.util.Optional;
*
* @author bjorncs
*/
-public class ContainerThreadpool extends SimpleComponent implements ContainerThreadpoolConfig.Producer {
+public abstract class ContainerThreadpool extends SimpleComponent implements ContainerThreadpoolConfig.Producer {
private final String name;
private final UserOptions userOptions;
@@ -32,8 +32,13 @@ public class ContainerThreadpool extends SimpleComponent implements ContainerThr
this.userOptions = userOptions;
}
+ // Must be implemented by subclasses to set values that may be overridden by user options.
+ protected abstract void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder);
+
@Override
public void getConfig(ContainerThreadpoolConfig.Builder builder) {
+ setDefaultConfigValues(builder);
+
builder.name(this.name);
if (userOptions != null) {
builder.maxThreads(userOptions.maxThreads);
@@ -42,9 +47,6 @@ public class ContainerThreadpool extends SimpleComponent implements ContainerThr
}
}
- protected Optional<UserOptions> userOptions() { return Optional.ofNullable(userOptions); }
- protected boolean hasUserOptions() { return userOptions().isPresent(); }
-
public static class UserOptions {
private final int maxThreads;
private final int minThreads;
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java
index 76124b14209..e4a5c2cd440 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/DiscBindingsConfigGenerator.java
@@ -14,16 +14,16 @@ import static java.util.stream.Collectors.toList;
*/
public class DiscBindingsConfigGenerator {
- public static Map<String, Handlers.Builder> generate(Collection<? extends Handler<?>> handlers) {
+ public static Map<String, Handlers.Builder> generate(Collection<? extends Handler> handlers) {
Map<String, Handlers.Builder> handlerBuilders = new LinkedHashMap<>();
- for (Handler<?> handler : handlers) {
+ for (Handler handler : handlers) {
handlerBuilders.putAll(generate(handler));
}
return handlerBuilders;
}
- public static <T extends Handler<?>> Map<String, Handlers.Builder> generate(T handler) {
+ public static <T extends Handler> Map<String, Handlers.Builder> generate(T handler) {
if (handler.getServerBindings().isEmpty() && handler.getClientBindings().isEmpty())
return Collections.emptyMap();
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
index 8ffdccae896..9f2bfe9251b 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/Handler.java
@@ -1,8 +1,9 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.component;
-import com.yahoo.config.model.producer.AbstractConfigProducer;
+import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
+import com.yahoo.vespa.model.container.ContainerThreadpool;
import java.util.ArrayList;
import java.util.Arrays;
@@ -15,22 +16,35 @@ import java.util.Set;
* Models a jdisc RequestHandler (including ClientProvider).
* RequestHandlers always have at least one server binding,
* while ClientProviders have at least one client binding.
- * <p>
- * Note that this is also used to model vespa handlers (which do not have any bindings)
*
* @author gjoranv
*/
-public class Handler<CHILD extends AbstractConfigProducer<?>> extends Component<CHILD, ComponentModel> {
+public class Handler extends Component<Component<?, ?>, ComponentModel> {
private final Set<BindingPattern> serverBindings = new LinkedHashSet<>();
private final List<BindingPattern> clientBindings = new ArrayList<>();
+ public final boolean hasCustomThreadPool;
+
public Handler(ComponentModel model) {
+ this(model, null);
+ }
+
+ public Handler(ComponentModel model, ContainerThreadpool threadpool) {
super(model);
+
+ // The default threadpool is always added to the cluster, so cannot be added here.
+ if (threadpool != null) {
+ hasCustomThreadPool = true;
+ addComponent(threadpool);
+ inject(threadpool);
+ } else {
+ hasCustomThreadPool = false;
+ }
}
- public static Handler<AbstractConfigProducer<?>> fromClassName(String className) {
- return new Handler<>(new ComponentModel(className, null, null, null));
+ public static Handler fromClassName(String className) {
+ return new Handler(new ComponentModel(className, null, null, null));
}
public void addServerBindings(BindingPattern... bindings) {
@@ -53,4 +67,24 @@ public class Handler<CHILD extends AbstractConfigProducer<?>> extends Component<
return Collections.unmodifiableList(clientBindings);
}
+
+ /**
+ * The default threadpool for all handlers, except those that declare their own, e.g. SearchHandler.
+ */
+ public static class DefaultHandlerThreadpool extends ContainerThreadpool {
+
+ public DefaultHandlerThreadpool() {
+ super("default-handler-common", null);
+ }
+
+ @Override
+ public void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder) {
+ builder.maxThreadExecutionTimeSeconds(190)
+ .keepAliveTime(5.0)
+ .maxThreads(-2)
+ .minThreads(-2)
+ .queueSize(-40);
+ }
+ }
+
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/component/chain/ProcessingHandler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/component/chain/ProcessingHandler.java
index 3f68a0a2709..e0bbc2d755d 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/component/chain/ProcessingHandler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/component/chain/ProcessingHandler.java
@@ -4,7 +4,7 @@ package com.yahoo.vespa.model.container.component.chain;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.core.ChainsConfig;
import com.yahoo.osgi.provider.model.ComponentModel;
-import com.yahoo.config.model.producer.AbstractConfigProducer;
+import com.yahoo.vespa.model.container.ContainerThreadpool;
import com.yahoo.vespa.model.container.component.Handler;
@@ -14,21 +14,17 @@ import com.yahoo.vespa.model.container.component.Handler;
* @author gjoranv
*/
public class ProcessingHandler<CHAINS extends Chains<?>>
- extends Handler<AbstractConfigProducer<?>>
+ extends Handler
implements ChainsConfig.Producer {
protected final CHAINS chains;
public ProcessingHandler(CHAINS chains, String handlerClass) {
- this(chains, BundleInstantiationSpecification.getInternalProcessingSpecificationFromStrings(handlerClass, null));
+ this(chains, BundleInstantiationSpecification.getInternalProcessingSpecificationFromStrings(handlerClass, null), null);
}
- public ProcessingHandler(CHAINS chains, String handlerClass, String bundle) {
- this(chains, BundleInstantiationSpecification.getFromStrings(handlerClass, null, bundle));
- }
-
- private ProcessingHandler(CHAINS chains, BundleInstantiationSpecification spec) {
- super(new ComponentModel(spec, null));
+ public ProcessingHandler(CHAINS chains, BundleInstantiationSpecification spec, ContainerThreadpool threadpool) {
+ super(new ComponentModel(spec, null), threadpool);
this.chains = chains;
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/docproc/MbusClient.java b/config-model/src/main/java/com/yahoo/vespa/model/container/docproc/MbusClient.java
index 28a0748be26..0efcd8df37f 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/docproc/MbusClient.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/docproc/MbusClient.java
@@ -6,13 +6,12 @@ import com.yahoo.component.ComponentSpecification;
import com.yahoo.container.jdisc.config.SessionConfig;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.osgi.provider.model.ComponentModel;
-import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.vespa.model.container.component.Handler;
/**
* @author Einar M R Rosenvinge
*/
-public class MbusClient extends Handler<AbstractConfigProducer<?>> implements SessionConfig.Producer {
+public class MbusClient extends Handler implements SessionConfig.Producer {
private static final ComponentSpecification CLASSNAME =
ComponentSpecification.fromString("com.yahoo.container.jdisc.messagebus.MbusClientProvider");
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java b/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java
index d85f00a5bb2..3ee0414bf32 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/http/AccessControl.java
@@ -51,7 +51,7 @@ public class AccessControl {
private final String domain;
private ClientAuthentication clientAuthentication = ClientAuthentication.need;
private final Set<BindingPattern> excludeBindings = new LinkedHashSet<>();
- private Collection<Handler<?>> handlers = Collections.emptyList();
+ private Collection<Handler> handlers = Collections.emptyList();
public Builder(String domain) {
this.domain = domain;
}
@@ -79,12 +79,12 @@ public class AccessControl {
public final String domain;
public final ClientAuthentication clientAuthentication;
private final Set<BindingPattern> excludedBindings;
- private final Collection<Handler<?>> handlers;
+ private final Collection<Handler> handlers;
private AccessControl(String domain,
ClientAuthentication clientAuthentication,
Set<BindingPattern> excludedBindings,
- Collection<Handler<?>> handlers) {
+ Collection<Handler> handlers) {
this.domain = domain;
this.clientAuthentication = clientAuthentication;
this.excludedBindings = Collections.unmodifiableSet(excludedBindings);
@@ -119,7 +119,7 @@ public class AccessControl {
public Set<BindingPattern> excludedBindings() { return excludedBindings; }
/** all handlers (that are known by the access control components) **/
- public Collection<Handler<?>> handlers() { return handlers; }
+ public Collection<Handler> handlers() { return handlers; }
public static boolean hasHandlerThatNeedsProtection(ApplicationContainerCluster cluster) {
return cluster.getHandlers().stream()
@@ -135,7 +135,7 @@ public class AccessControl {
for (BindingPattern excludedBinding : excludedBindings) {
http.getBindings().add(createAccessControlExcludedBinding(excludedBinding));
}
- for (Handler<?> handler : handlers) {
+ for (Handler handler : handlers) {
if (isExcludedHandler(handler)) {
for (BindingPattern binding : handler.getServerBindings()) {
http.getBindings().add(createAccessControlExcludedBinding(binding));
@@ -188,9 +188,9 @@ public class AccessControl {
private static Chain<Filter> createChain(ComponentId id) { return new Chain<>(FilterChains.emptyChainSpec(id)); }
- private static boolean isExcludedHandler(Handler<?> handler) { return EXCLUDED_HANDLERS.contains(handler.getClassId().getName()); }
+ private static boolean isExcludedHandler(Handler handler) { return EXCLUDED_HANDLERS.contains(handler.getClassId().getName()); }
- private static boolean hasNonMbusBinding(Handler<?> handler) {
+ private static boolean hasNonMbusBinding(Handler handler) {
return handler.getServerBindings().stream().anyMatch(binding -> ! binding.scheme().equals("mbus"));
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java
index 7087cabafc1..c6b0eb28ed3 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.search;
-import com.yahoo.config.model.producer.AbstractConfigProducer;
import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.vespa.model.container.component.Handler;
@@ -10,7 +9,7 @@ import com.yahoo.vespa.model.container.component.Handler;
/**
* @author Henrik Høiness
*/
-public class GUIHandler extends Handler<AbstractConfigProducer<?>> {
+public class GUIHandler extends Handler {
public static final String BUNDLE = "container-search-gui";
public static final String CLASS = "com.yahoo.search.query.gui.GUIHandler";
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
index 1c47f1d7c9c..956d7e5c366 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java
@@ -222,7 +222,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
}
if (deployState.zone().system().isPublic()) {
BindingPattern bindingPattern = SystemBindingPattern.fromHttpPath("/validate-secret-store");
- Handler<AbstractConfigProducer<?>> handler = new Handler<>(
+ Handler handler = new Handler(
new ComponentModel("com.yahoo.jdisc.cloud.aws.AwsParameterStoreValidationHandler", null, "jdisc-cloud-aws", null));
handler.addServerBindings(bindingPattern);
cluster.addComponent(handler);
@@ -897,7 +897,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> {
}
private void addGUIHandler(ApplicationContainerCluster cluster) {
- Handler<?> guiHandler = new GUIHandler();
+ Handler guiHandler = new GUIHandler();
guiHandler.addServerBindings(SystemBindingPattern.fromHttpPath(GUIHandler.BINDING_PATH));
cluster.addComponent(guiHandler);
}
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
index 54d943f498a..6b0bf8a67b9 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/SearchHandler.java
@@ -1,6 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.xml;
+import com.yahoo.container.bundle.BundleInstantiationSpecification;
import com.yahoo.container.handler.threadpool.ContainerThreadpoolConfig;
import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.ContainerThreadpool;
@@ -11,6 +12,8 @@ import com.yahoo.vespa.model.container.search.searchchain.SearchChains;
import java.util.List;
+import static com.yahoo.container.bundle.BundleInstantiationSpecification.getInternalHandlerSpecificationFromStrings;
+
/**
* Component definition for {@link com.yahoo.search.handler.SearchHandler}
*
@@ -19,38 +22,32 @@ import java.util.List;
class SearchHandler extends ProcessingHandler<SearchChains> {
static final String HANDLER_CLASS = com.yahoo.search.handler.SearchHandler.class.getName();
+ static final BundleInstantiationSpecification HANDLER_SPEC = getInternalHandlerSpecificationFromStrings(HANDLER_CLASS, null);
static final BindingPattern DEFAULT_BINDING = SystemBindingPattern.fromHttpPath("/search/*");
SearchHandler(ApplicationContainerCluster cluster,
List<BindingPattern> bindings,
ContainerThreadpool.UserOptions threadpoolOptions) {
- super(cluster.getSearchChains(), HANDLER_CLASS);
+ super(cluster.getSearchChains(), HANDLER_SPEC, new Threadpool(threadpoolOptions));
bindings.forEach(this::addServerBindings);
- Threadpool threadpool = new Threadpool(cluster, threadpoolOptions);
- inject(threadpool);
- addComponent(threadpool);
}
+
private static class Threadpool extends ContainerThreadpool {
- private final ApplicationContainerCluster cluster;
- Threadpool(ApplicationContainerCluster cluster, UserOptions options) {
+ Threadpool(UserOptions options) {
super("search-handler", options);
- this.cluster = cluster;
}
@Override
- public void getConfig(ContainerThreadpoolConfig.Builder builder) {
- super.getConfig(builder);
-
- builder.maxThreadExecutionTimeSeconds(190);
- builder.keepAliveTime(5.0);
-
- // User options overrides below configuration
- if (hasUserOptions()) return;
- builder.maxThreads(-2).minThreads(-2).queueSize(-40);
+ public void setDefaultConfigValues(ContainerThreadpoolConfig.Builder builder) {
+ builder.maxThreadExecutionTimeSeconds(190)
+ .keepAliveTime(5.0)
+ .maxThreads(-2)
+ .minThreads(-2)
+ .queueSize(-40);
}
-
}
+
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerClusterTest.java
index 7bf08461df7..d50aedeafa0 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerClusterTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerClusterTest.java
@@ -70,7 +70,7 @@ public class MetricsProxyContainerClusterTest {
@Test
public void http_handlers_are_set_up() {
VespaModel model = getModel(servicesWithAdminOnly(), self_hosted);
- Collection<Handler<?>> handlers = model.getAdmin().getMetricsProxyCluster().getHandlers();
+ Collection<Handler> handlers = model.getAdmin().getMetricsProxyCluster().getHandlers();
Collection<ComponentSpecification> handlerClasses = handlers.stream().map(Component::getClassId).collect(toList());
assertTrue(handlerClasses.contains(ComponentSpecification.fromString(MetricsV1Handler.class.getName())));
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java
index 81b6de8f2ee..d9659cf92d4 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/AccessLogTest.java
@@ -89,7 +89,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase {
assertNotNull(getVespaAccessLog("default"));
{ // vespa
- Component<?, ?> accessLogComponent = getContainerComponent("default", VespaAccessLog.class.getName());
+ Component<?, ?> accessLogComponent = getComponent("default", VespaAccessLog.class.getName());
assertNotNull(accessLogComponent);
assertEquals(VespaAccessLog.class.getName(), accessLogComponent.getClassId().getName(), VespaAccessLog.class.getName());
AccessLogConfig config = root.getConfig(AccessLogConfig.class, "default/component/com.yahoo.container.logging.VespaAccessLog");
@@ -101,7 +101,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase {
}
{ // json
- Component<?, ?> accessLogComponent = getContainerComponent("default", JSONAccessLog.class.getName());
+ Component<?, ?> accessLogComponent = getComponent("default", JSONAccessLog.class.getName());
assertNotNull(accessLogComponent);
assertEquals(JSONAccessLog.class.getName(), accessLogComponent.getClassId().getName(), JSONAccessLog.class.getName());
AccessLogConfig config = root.getConfig(AccessLogConfig.class, "default/component/com.yahoo.container.logging.JSONAccessLog");
@@ -124,7 +124,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase {
nodesXml,
"</container>" );
createModel(root, clusterElem);
- Component<?, ?> connectionLogComponent = getContainerComponent("default", FileConnectionLog.class.getName());
+ Component<?, ?> connectionLogComponent = getComponent("default", FileConnectionLog.class.getName());
assertNotNull(connectionLogComponent);
ConnectionLogConfig config = root.getConfig(ConnectionLogConfig.class, "default/component/com.yahoo.container.logging.FileConnectionLog");
assertEquals("default", config.cluster());
@@ -140,7 +140,7 @@ public class AccessLogTest extends ContainerModelBuilderTestBase {
nodesXml,
"</container>" );
createModel(root, clusterElem);
- Component<?, ?> fileConnectionLogComponent = getContainerComponent("default", FileConnectionLog.class.getName());
+ Component<?, ?> fileConnectionLogComponent = getComponent("default", FileConnectionLog.class.getName());
assertNull(fileConnectionLogComponent);
}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java
index ca0b4681e51..3cab01fd038 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerDocumentApiBuilderTest.java
@@ -30,11 +30,11 @@ import static org.junit.Assert.assertTrue;
*/
public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBase {
- private Map<String, Handler<?>> getHandlers(String clusterName) {
+ private Map<String, Handler> getHandlers(String clusterName) {
ContainerCluster<?> cluster = (ContainerCluster<?>) root.getChildren().get(clusterName);
- Map<String, Handler<?>> handlerMap = new HashMap<>();
- Collection<Handler<?>> handlers = cluster.getHandlers();
- for (Handler<?> handler : handlers) {
+ Map<String, Handler> handlerMap = new HashMap<>();
+ Collection<Handler> handlers = cluster.getHandlers();
+ for (Handler handler : handlers) {
assertFalse(handlerMap.containsKey(handler.getComponentId().toString())); //die on overwrites
handlerMap.put(handler.getComponentId().toString(), handler);
}
@@ -56,7 +56,7 @@ public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBa
}
private void verifyCustomBindings(String id) {
- Handler<?> handler = getHandlers("cluster1").get(id);
+ Handler handler = getHandlers("cluster1").get(id);
assertTrue(handler.getServerBindings().contains(UserBindingPattern.fromHttpPath("/document-api/reserved-for-internal-use/feedapi")));
assertTrue(handler.getServerBindings().contains(UserBindingPattern.fromHttpPath("/document-api/reserved-for-internal-use/feedapi/")));
@@ -73,7 +73,7 @@ public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBa
"</container>");
createModel(root, elem);
- Map<String, Handler<?>> handlerMap = getHandlers("cluster1");
+ Map<String, Handler> handlerMap = getHandlers("cluster1");
assertNotNull(handlerMap.get("com.yahoo.container.handler.VipStatusHandler"));
assertNotNull(handlerMap.get("com.yahoo.container.handler.observability.ApplicationStatusHandler"));
@@ -110,8 +110,8 @@ public class ContainerDocumentApiBuilderTest extends ContainerModelBuilderTestBa
"</container>");
root = new MockRoot("root", new MockApplicationPackage.Builder().build());
createModel(root, elem);
- Map<String, Handler<?>> handlers = getHandlers("cluster1");
- Handler<?> feedApiHandler = handlers.get("com.yahoo.vespa.http.server.FeedHandler");
+ Map<String, Handler> handlers = getHandlers("cluster1");
+ Handler feedApiHandler = handlers.get("com.yahoo.vespa.http.server.FeedHandler");
Set<String> injectedComponentIds = feedApiHandler.getInjectedComponentIds();
assertTrue(injectedComponentIds.contains("threadpool@feedapi-handler"));
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java
index 3a241d9607f..2ab81a7a4bb 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTest.java
@@ -21,7 +21,6 @@ import com.yahoo.config.provision.Flavor;
import com.yahoo.config.provision.RegionName;
import com.yahoo.config.provision.Zone;
import com.yahoo.config.provisioning.FlavorsConfig;
-import com.yahoo.container.ComponentsConfig;
import com.yahoo.container.QrConfig;
import com.yahoo.container.core.ChainsConfig;
import com.yahoo.container.core.VipStatusConfig;
@@ -42,6 +41,7 @@ import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.ContainerModelEvaluation;
import com.yahoo.vespa.model.container.component.Component;
+import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.content.utils.ContentClusterUtils;
import com.yahoo.vespa.model.test.VespaModelTester;
import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg;
@@ -60,19 +60,14 @@ import java.util.stream.Collectors;
import static com.yahoo.config.model.test.TestUtil.joinLines;
import static com.yahoo.test.LinePatternMatcher.containsLineWithPattern;
import static com.yahoo.vespa.defaults.Defaults.getDefaults;
-import static com.yahoo.vespa.model.container.ContainerCluster.ROOT_HANDLER_BINDING;
-import static com.yahoo.vespa.model.container.ContainerCluster.STATE_HANDLER_BINDING_1;
-import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -198,6 +193,17 @@ public class ContainerModelBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
+ public void builtin_handlers_get_default_threadpool() {
+ createBasicContainerModel();
+
+ Handler h1 = getHandler("default", ApplicationStatusHandler.class.getName());
+ assertTrue(h1.getInjectedComponentIds().contains("threadpool@default-handler-common"));
+
+ Handler h2 = getHandler("default", BindingsOverviewHandler.class.getName());
+ assertTrue(h2.getInjectedComponentIds().contains("threadpool@default-handler-common"));
+ }
+
+ @Test
public void verify_bindings_for_builtin_handlers() {
createBasicContainerModel();
JdiscBindingsConfig config = root.getConfig(JdiscBindingsConfig.class, "default/container.0");
@@ -216,68 +222,6 @@ public class ContainerModelBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
- public void default_root_handler_binding_can_be_stolen_by_user_configured_handler() {
- Element clusterElem = DomBuilderTest.parse(
- "<container id='default' version='1.0'>" +
- " <handler id='userRootHandler'>" +
- " <binding>" + ROOT_HANDLER_BINDING.patternString() + "</binding>" +
- " </handler>" +
- "</container>");
- createModel(root, clusterElem);
-
- // The handler is still set up.
- ComponentsConfig.Components userRootHandler = getComponent(componentsConfig(), BindingsOverviewHandler.class.getName());
- assertNotNull(userRootHandler);
-
- // .. but it has no bindings
- var discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default");
- assertNull(discBindingsConfig.handlers(BindingsOverviewHandler.class.getName()));
- }
-
- @Test
- public void reserved_binding_cannot_be_stolen_by_user_configured_handler() {
- Element clusterElem = DomBuilderTest.parse(
- "<container id='default' version='1.0'>" +
- " <handler id='userHandler'>" +
- " <binding>" + STATE_HANDLER_BINDING_1.patternString() + "</binding>" +
- " </handler>" +
- "</container>");
- try {
- createModel(root, clusterElem);
- fail("Expected exception when stealing a reserved binding.");
- } catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("Binding 'http://*/state/v1' is a reserved Vespa binding " +
- "and cannot be used by handler: userHandler"));
- }
- }
-
- @Test
- public void handler_bindings_are_included_in_discBindings_config() {
- createClusterWithJDiscHandler();
- String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString();
- assertThat(discBindingsConfig, containsString(".serverBindings[0] \"http://*/binding0\""));
- assertThat(discBindingsConfig, containsString(".serverBindings[1] \"http://*/binding1\""));
- }
-
- @Test
- public void handlers_are_included_in_components_config() {
- createClusterWithJDiscHandler();
- assertThat(componentsConfig().toString(), containsString(".id \"discHandler\""));
- }
-
- private void createClusterWithJDiscHandler() {
- Element clusterElem = DomBuilderTest.parse(
- "<container id='default' version='1.0'>",
- " <handler id='discHandler'>",
- " <binding>http://*/binding0</binding>",
- " <binding>http://*/binding1</binding>",
- " </handler>",
- "</container>");
-
- createModel(root, clusterElem);
- }
-
- @Test
public void processing_handler_bindings_can_be_overridden() {
Element clusterElem = DomBuilderTest.parse(
"<container id='default' version='1.0'>",
@@ -375,20 +319,6 @@ public class ContainerModelBuilderTest extends ContainerModelBuilderTestBase {
}
@Test
- public void nested_components_are_injected_to_handlers() {
- Element clusterElem = DomBuilderTest.parse(
- "<container id='default' version='1.0'>",
- " <handler id='myHandler'>",
- " <component id='injected' />",
- " </handler>",
- "</container>");
-
- createModel(root, clusterElem);
- Component<?,?> handler = getContainerComponent("default", "myHandler");
- assertThat(handler.getInjectedComponentIds(), hasItem("injected@myHandler"));
- }
-
- @Test
public void component_includes_are_added() {
VespaModelCreatorWithFilePkg creator = new VespaModelCreatorWithFilePkg("src/test/cfg/application/include_dirs");
VespaModel model = creator.create(true);
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
index 3d7b17d37e0..dc831ef863d 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilderTestBase.java
@@ -13,6 +13,7 @@ import com.yahoo.vespa.model.container.ApplicationContainerCluster;
import com.yahoo.vespa.model.container.ContainerCluster;
import com.yahoo.vespa.model.container.ContainerModel;
import com.yahoo.vespa.model.container.component.Component;
+import com.yahoo.vespa.model.container.component.Handler;
import com.yahoo.vespa.model.container.search.ContainerSearch;
import org.junit.Before;
import org.w3c.dom.Element;
@@ -94,7 +95,7 @@ public abstract class ContainerModelBuilderTestBase {
return root.getConfig(ComponentsConfig.class, "default");
}
- protected ComponentsConfig.Components getComponent(ComponentsConfig componentsConfig, String id) {
+ protected ComponentsConfig.Components getComponentInConfig(ComponentsConfig componentsConfig, String id) {
for (ComponentsConfig.Components component : componentsConfig.components()) {
if (component.id().equals(id))
return component;
@@ -106,11 +107,18 @@ public abstract class ContainerModelBuilderTestBase {
return (ApplicationContainerCluster) root.getChildren().get(clusterId);
}
- public Component<?, ?> getContainerComponent(String clusterId, String componentId) {
+ public Component<?, ?> getComponent(String clusterId, String componentId) {
return getContainerCluster(clusterId).getComponentsMap().get(
ComponentId.fromString(componentId));
}
+ public Handler getHandler(String clusterId, String componentId) {
+ Component<?,?> component = getComponent(clusterId, componentId);
+ if (! (component instanceof Handler))
+ throw new RuntimeException("Component is not a handler: " + componentId);
+ return (Handler) component;
+ }
+
void assertComponentConfigured(ApplicationContainerCluster cluster, String componentId) {
Component<?, ?> component = cluster.getComponentsMap().get(ComponentId.fromString(componentId));
assertNotNull(component);
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java
new file mode 100644
index 00000000000..42cda0d8034
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/HandlerBuilderTest.java
@@ -0,0 +1,118 @@
+package com.yahoo.vespa.model.container.xml;
+
+import com.yahoo.config.model.builder.xml.test.DomBuilderTest;
+import com.yahoo.container.ComponentsConfig;
+import com.yahoo.container.jdisc.JdiscBindingsConfig;
+import com.yahoo.container.usability.BindingsOverviewHandler;
+import com.yahoo.vespa.model.container.ApplicationContainerCluster;
+import com.yahoo.vespa.model.container.component.Component;
+import com.yahoo.vespa.model.container.component.Handler;
+import org.junit.Test;
+import org.w3c.dom.Element;
+
+import static com.yahoo.vespa.model.container.ContainerCluster.ROOT_HANDLER_BINDING;
+import static com.yahoo.vespa.model.container.ContainerCluster.STATE_HANDLER_BINDING_1;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasItem;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests for container model building with custom handlers.
+ *
+ * @author gjoranv
+ */
+public class HandlerBuilderTest extends ContainerModelBuilderTestBase {
+
+ @Test
+ public void handlers_are_included_in_components_config() {
+ createClusterWithJDiscHandler();
+ assertThat(componentsConfig().toString(), containsString(".id \"discHandler\""));
+ }
+
+ @Test
+ public void handler_bindings_are_included_in_discBindings_config() {
+ createClusterWithJDiscHandler();
+ String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString();
+ assertThat(discBindingsConfig, containsString(".serverBindings[0] \"http://*/binding0\""));
+ assertThat(discBindingsConfig, containsString(".serverBindings[1] \"http://*/binding1\""));
+ }
+
+ @Test
+ public void nested_components_are_injected_to_handlers() {
+ Element clusterElem = DomBuilderTest.parse(
+ "<container id='default' version='1.0'>",
+ " <handler id='myHandler'>",
+ " <component id='injected' />",
+ " </handler>",
+ "</container>");
+
+ createModel(root, clusterElem);
+ Component<?,?> handler = getComponent("default", "myHandler");
+ assertThat(handler.getInjectedComponentIds(), hasItem("injected@myHandler"));
+ }
+
+ @Test
+ public void default_root_handler_binding_can_be_stolen_by_user_configured_handler() {
+ Element clusterElem = DomBuilderTest.parse(
+ "<container id='default' version='1.0'>" +
+ " <handler id='userRootHandler'>" +
+ " <binding>" + ROOT_HANDLER_BINDING.patternString() + "</binding>" +
+ " </handler>" +
+ "</container>");
+ createModel(root, clusterElem);
+
+ // The handler is still set up.
+ ComponentsConfig.Components userRootHandler = getComponentInConfig(componentsConfig(), BindingsOverviewHandler.class.getName());
+ assertNotNull(userRootHandler);
+
+ // .. but it has no bindings
+ var discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default");
+ assertNull(discBindingsConfig.handlers(BindingsOverviewHandler.class.getName()));
+ }
+
+ @Test
+ public void reserved_binding_cannot_be_stolen_by_user_configured_handler() {
+ Element clusterElem = DomBuilderTest.parse(
+ "<container id='default' version='1.0'>" +
+ " <handler id='userHandler'>" +
+ " <binding>" + STATE_HANDLER_BINDING_1.patternString() + "</binding>" +
+ " </handler>" +
+ "</container>");
+ try {
+ createModel(root, clusterElem);
+ fail("Expected exception when stealing a reserved binding.");
+ } catch (IllegalArgumentException e) {
+ assertThat(e.getMessage(), is("Binding 'http://*/state/v1' is a reserved Vespa binding " +
+ "and cannot be used by handler: userHandler"));
+ }
+ }
+
+ @Test
+ public void custom_handler_gets_default_threadpool() {
+ createClusterWithJDiscHandler();
+ ApplicationContainerCluster cluster = (ApplicationContainerCluster)root.getChildren().get("default");
+ Handler handler = cluster.getHandlers().stream()
+ .filter(h -> h.getComponentId().toString().equals("discHandler"))
+ .findAny().orElseThrow();
+
+ assertTrue(handler.getInjectedComponentIds().contains("threadpool@default-handler-common"));
+ }
+
+ private void createClusterWithJDiscHandler() {
+ Element clusterElem = DomBuilderTest.parse(
+ "<container id='default' version='1.0'>",
+ " <handler id='discHandler'>",
+ " <binding>http://*/binding0</binding>",
+ " <binding>http://*/binding1</binding>",
+ " </handler>",
+ "</container>");
+
+ createModel(root, clusterElem);
+ }
+
+}
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ApplicationBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java
index ca59e053a89..c41373b9f85 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/ApplicationBuilderTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java
@@ -31,7 +31,7 @@ import static org.junit.Assert.fail;
/**
* @author gjoranv
*/
-public class ApplicationBuilderTest extends ContainerModelBuilderTestBase {
+public class SearchBuilderTest extends ContainerModelBuilderTestBase {
private ChainsConfig chainsConfig() {
return root.getConfig(ChainsConfig.class, "default/component/com.yahoo.search.handler.SearchHandler");
@@ -53,7 +53,7 @@ public class ApplicationBuilderTest extends ContainerModelBuilderTestBase {
ApplicationContainerCluster cluster = (ApplicationContainerCluster)root.getChildren().get("default");
GUIHandler guiHandler = null;
- for (Handler<?> handler : cluster.getHandlers()) {
+ for (Handler handler : cluster.getHandlers()) {
if (handler instanceof GUIHandler) {
guiHandler = (GUIHandler) handler;
}
@@ -230,12 +230,7 @@ public class ApplicationBuilderTest extends ContainerModelBuilderTestBase {
createModel(root, clusterElem);
- ApplicationContainerCluster cluster = (ApplicationContainerCluster)root.getChildren().get("default");
- Handler<?> searchHandler = cluster.getHandlers().stream()
- .filter(h -> h.getComponentId().toString().equals(SearchHandler.HANDLER_CLASS))
- .findAny()
- .get();
-
+ Handler searchHandler = getHandler("default", SearchHandler.HANDLER_CLASS);
assertTrue(searchHandler.getInjectedComponentIds().contains("threadpool@search-handler"));
ContainerThreadpoolConfig config = root.getConfig(
diff --git a/config-model/src/test/schema-test-files/services.xml b/config-model/src/test/schema-test-files/services.xml
index 4fb81963152..df87d2b9f3d 100644
--- a/config-model/src/test/schema-test-files/services.xml
+++ b/config-model/src/test/schema-test-files/services.xml
@@ -193,6 +193,9 @@
<handler id="jdisc-handler">
<binding>http://*:*/HelloWorld</binding>
<binding>http://*:*/Status</binding>
+ <component id="injected-to-handler">
+ <config name="foo"/>
+ </component>
</handler>
<server id="server-provider">
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
index 11355dee24f..fb7ba1ab39e 100644
--- a/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
+++ b/container-core/src/main/java/com/yahoo/container/jdisc/ThreadedHttpRequestHandler.java
@@ -50,7 +50,7 @@ public abstract class ThreadedHttpRequestHandler extends ThreadedRequestHandler
this(executor, metric, false);
}
- // TODO: move Inject annotation here!
+ // TODO: deprecate this and the Context class. The context component set up in the model does not get a dedicated thread pool.
public ThreadedHttpRequestHandler(Context context) {
this(context.executor, context.metric);
}
diff --git a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
index f8f567e1890..5abb96527bd 100644
--- a/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
+++ b/container-core/src/test/java/com/yahoo/container/di/componentgraph/core/ComponentGraphTest.java
@@ -102,7 +102,7 @@ public class ComponentGraphTest {
}
@Test
- public void component_can_be_injected_into_another_component() {
+ public void component_can_be_explicitly_injected_into_another_component() {
Node injectedComponent = mockComponentNode(SimpleComponent.class);
Node targetComponent = mockComponentNode(ComponentTakingComponent.class);
targetComponent.inject(injectedComponent);
@@ -117,6 +117,22 @@ public class ComponentGraphTest {
ComponentTakingComponent instance = componentGraph.getInstance(ComponentTakingComponent.class);
assertNotNull(instance);
+ assertSame(injectedComponent.instance.get(), instance.injectedComponent);
+ }
+
+ @Test
+ public void explicitly_injected_components_may_be_unused() {
+ Node notUsingInjected = mockComponentNode(SimpleComponent.class);
+ Node injectedComponent = mockComponentNode(SimpleComponent2.class);
+ notUsingInjected.inject(injectedComponent);
+
+ ComponentGraph componentGraph = new ComponentGraph();
+ componentGraph.add(injectedComponent);
+ componentGraph.add(notUsingInjected);
+ componentGraph.complete();
+
+ SimpleComponent instanceNotUsingInjected = componentGraph.getInstance(SimpleComponent.class);
+ assertNotNull(instanceNotUsingInjected);
}
@Test
@@ -514,7 +530,7 @@ public class ComponentGraphTest {
}
public static class ComponentTakingComponent extends AbstractComponent {
- private final SimpleComponent injectedComponent;
+ final SimpleComponent injectedComponent;
public ComponentTakingComponent(SimpleComponent injectedComponent) {
assertNotNull(injectedComponent);