From ef539860356ebcfe316ac8adc75aa183ab764ab4 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sun, 9 Jun 2019 23:14:07 +0200 Subject: Deliver search chains config to ExecutionFactory --- .../java/com/yahoo/application/Application.java | 48 +++++++++++----------- .../com/yahoo/application/container/JDisc.java | 5 ++- .../com/yahoo/application/container/Search.java | 2 - .../com/yahoo/application/ApplicationTest.java | 5 ++- 4 files changed, 29 insertions(+), 31 deletions(-) (limited to 'application/src') diff --git a/application/src/main/java/com/yahoo/application/Application.java b/application/src/main/java/com/yahoo/application/Application.java index 64ced48edd3..f7b5174b0e5 100644 --- a/application/src/main/java/com/yahoo/application/Application.java +++ b/application/src/main/java/com/yahoo/application/Application.java @@ -46,7 +46,7 @@ public final class Application implements AutoCloseable { /** * This system property is set to "true" upon creation of an Application. - * This is useful for components which are created by dependendy injection which needs to modify + * This is useful for components which are created by dependendcy injection which needs to modify * their behavior to function without reliance on any processes outside the JVM. */ public static final String vespaLocalProperty = "vespa.local"; @@ -142,6 +142,7 @@ public final class Application implements AutoCloseable { */ @Beta public static class Builder { + private static final ThreadLocal random = new ThreadLocal<>(); private static final String DEFAULT_CHAIN = "default"; @@ -217,7 +218,7 @@ public final class Application implements AutoCloseable { } // copy from com.yahoo.application.ApplicationBuilder - private void createFile(final Path path, final String content) throws IOException { + private void createFile(Path path, String content) throws IOException { Files.createDirectories(path.getParent()); Files.write(path, Utf8.toBytes(content)); } @@ -237,16 +238,15 @@ public final class Application implements AutoCloseable { /** * @param name name of document type (search definition) * @param searchDefinition add this search definition to the application - * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder documentType(final String name, final String searchDefinition) throws IOException { + public Builder documentType(String name, String searchDefinition) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.SD_NAME_SUFFIX); createFile(path, searchDefinition); return this; } - public Builder expressionInclude(final String name, final String searchDefinition) throws IOException { + public Builder expressionInclude(String name, String searchDefinition) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.RANKEXPRESSION_NAME_SUFFIX); createFile(path, searchDefinition); return this; @@ -255,10 +255,9 @@ public final class Application implements AutoCloseable { /** * @param name name of rank expression * @param rankExpressionContent add this rank expression to the application - * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder rankExpression(final String name, final String rankExpressionContent) throws IOException { + public Builder rankExpression(String name, String rankExpressionContent) throws IOException { Path path = nestedResource(ApplicationPackage.SEARCH_DEFINITIONS_DIR, name, ApplicationPackage.RANKEXPRESSION_NAME_SUFFIX); createFile(path, rankExpressionContent); return this; @@ -270,7 +269,7 @@ public final class Application implements AutoCloseable { * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder queryProfile(final String name, final String queryProfile) throws IOException { + public Builder queryProfile(String name, String queryProfile) throws IOException { Path path = nestedResource(ApplicationPackage.QUERY_PROFILES_DIR, name, ".xml"); createFile(path, queryProfile); return this; @@ -282,14 +281,14 @@ public final class Application implements AutoCloseable { * @return builder * @throws java.io.IOException e.g.if file not found */ - public Builder queryProfileType(final String name, final String queryProfileType) throws IOException { + public Builder queryProfileType(String name, String queryProfileType) throws IOException { Path path = nestedResource(ApplicationPackage.QUERY_PROFILE_TYPES_DIR, name, ".xml"); createFile(path, queryProfileType); return this; } // copy from com.yahoo.application.ApplicationBuilder - private Path nestedResource(final com.yahoo.path.Path nestedPath, final String name, final String fileType) { + private Path nestedResource(com.yahoo.path.Path nestedPath, String name, String fileType) { String nameWithoutSuffix = StringUtilities.stripSuffix(name, fileType); return path.resolve(nestedPath.getRelative()).resolve(nameWithoutSuffix + fileType); } @@ -298,7 +297,7 @@ public final class Application implements AutoCloseable { * @param networking enable or disable networking (disabled by default) * @return builder */ - public Builder networking(final Networking networking) { + public Builder networking(Networking networking) { this.networking = networking; return this; } @@ -335,15 +334,14 @@ public final class Application implements AutoCloseable { private void generateXml() throws Exception { try (PrintWriter xml = new PrintWriter(Files.newOutputStream(path.resolve("services.xml")))) { xml.println(""); - //xml.println(""); for (Map.Entry entry : containers.entrySet()) { entry.getValue().build(xml, entry.getKey(), (networking == Networking.enable ? getRandomPort() : -1)); } - //xml.println(""); } } public static class Container { + private final Map>> docprocs = new LinkedHashMap<>(); private final Map>> searchers = new LinkedHashMap<>(); private final List> renderers = new ArrayList<>(); @@ -372,7 +370,7 @@ public final class Application implements AutoCloseable { * @param docproc add this docproc to the default document processing chain * @return builder */ - public Container documentProcessor(final Class docproc) { + public Container documentProcessor(Class docproc) { return documentProcessor(DEFAULT_CHAIN, docproc); } @@ -382,7 +380,7 @@ public final class Application implements AutoCloseable { * @param configs local docproc configs * @return builder */ - public Container documentProcessor(final String chainName, final Class docproc, ConfigInstance... configs) { + public Container documentProcessor(String chainName, Class docproc, ConfigInstance... configs) { return documentProcessor(docproc.getName(), chainName, docproc, configs); } @@ -393,7 +391,7 @@ public final class Application implements AutoCloseable { * @param configs local docproc configs * @return builder */ - public Container documentProcessor(String id, final String chainName, final Class docproc, ConfigInstance... configs) { + public Container documentProcessor(String id, String chainName, Class docproc, ConfigInstance... configs) { List> chain = docprocs.get(chainName); if (chain == null) { chain = new ArrayList<>(); @@ -416,7 +414,7 @@ public final class Application implements AutoCloseable { * @param searcher add this searcher to the default search chain * @return builder */ - public Container searcher(final Class searcher) { + public Container searcher(Class searcher) { return searcher(DEFAULT_CHAIN, searcher); } @@ -426,7 +424,7 @@ public final class Application implements AutoCloseable { * @param configs local searcher configs * @return builder */ - public Container searcher(final String chainName, final Class searcher, ConfigInstance... configs) { + public Container searcher(String chainName, Class searcher, ConfigInstance... configs) { return searcher(searcher.getName(), chainName, searcher, configs); } @@ -437,7 +435,7 @@ public final class Application implements AutoCloseable { * @param configs local searcher configs * @return builder */ - public Container searcher(String id, final String chainName, final Class searcher, ConfigInstance... configs) { + public Container searcher(String id, String chainName, Class searcher, ConfigInstance... configs) { List> chain = searchers.get(chainName); if (chain == null) { chain = new ArrayList<>(); @@ -453,7 +451,7 @@ public final class Application implements AutoCloseable { * @param configs local renderer configs * @return builder */ - public Container renderer(String id, final Class renderer, ConfigInstance... configs) { + public Container renderer(String id, Class renderer, ConfigInstance... configs) { renderers.add(new ComponentItem<>(id, renderer, configs)); return this; } @@ -463,7 +461,7 @@ public final class Application implements AutoCloseable { * @param handler the handler class * @return builder */ - public Container handler(final String binding, final Class handler) { + public Container handler(String binding, Class handler) { handlers.add(new ComponentItem<>(binding, handler)); return this; } @@ -473,7 +471,7 @@ public final class Application implements AutoCloseable { * @param client the client class * @return builder */ - public Container client(final String binding, final Class client) { + public Container client(String binding, Class client) { clients.add(new ComponentItem<>(binding, client)); return this; } @@ -483,7 +481,7 @@ public final class Application implements AutoCloseable { * @param server the server class * @return builder */ - public Container server(final String id, final Class server) { + public Container server(String id, Class server) { servers.add(new ComponentItem<>(id, server)); return this; } @@ -492,7 +490,7 @@ public final class Application implements AutoCloseable { * @param component make this component available to the container * @return builder */ - public Container component(final Class component) { + public Container component(Class component) { return component(component.getName(), component, (ConfigInstance) null); } @@ -500,7 +498,7 @@ public final class Application implements AutoCloseable { * @param component make this component available to the container * @return builder */ - public Container component(String id, final Class component, ConfigInstance... configs) { + public Container component(String id, Class component, ConfigInstance... configs) { components.add(new ComponentItem<>(id, component, configs)); return this; } diff --git a/application/src/main/java/com/yahoo/application/container/JDisc.java b/application/src/main/java/com/yahoo/application/container/JDisc.java index 45c7b66ac5e..10ff84d3ede 100644 --- a/application/src/main/java/com/yahoo/application/container/JDisc.java +++ b/application/src/main/java/com/yahoo/application/container/JDisc.java @@ -21,6 +21,7 @@ import com.yahoo.jdisc.handler.RequestHandler; import com.yahoo.jdisc.test.TestDriver; import com.yahoo.processing.handler.ProcessingHandler; import com.yahoo.search.handler.SearchHandler; +import com.yahoo.search.searchchain.ExecutionFactory; import java.nio.file.Path; @@ -41,7 +42,7 @@ public final class JDisc implements AutoCloseable { @SuppressWarnings("unused") private final StandaloneContainerApplication application; - private final Container container = Container.get(); // TODO: This is indeed temporary ... *3 years later* Indeed. + private final Container container = Container.get(); // TODO: This is indeed temporary ... *3 years later* indeed. private final Path path; private final boolean deletePathWhenClosing; @@ -55,7 +56,7 @@ public final class JDisc implements AutoCloseable { application = (StandaloneContainerApplication) testDriver.application(); } - private Module bindings(final Path path, final ConfigModelRepo configModelRepo, final Networking networking) { + private Module bindings(Path path, ConfigModelRepo configModelRepo, Networking networking) { return new AbstractModule() { @Override protected void configure() { diff --git a/application/src/main/java/com/yahoo/application/container/Search.java b/application/src/main/java/com/yahoo/application/container/Search.java index f0a61bc6c10..0e241c27949 100644 --- a/application/src/main/java/com/yahoo/application/container/Search.java +++ b/application/src/main/java/com/yahoo/application/container/Search.java @@ -41,7 +41,6 @@ public final class Search extends ProcessingBase { } @Override - @SuppressWarnings("deprecation") protected ListenableFuture doProcessAndRender(ComponentSpecification chainSpec, Query request, Renderer renderer, @@ -51,7 +50,6 @@ public final class Search extends ProcessingBase { } @Override - @SuppressWarnings("deprecation") protected Renderer doGetRenderer(ComponentSpecification spec) { return handler.getRendererCopy(spec); } diff --git a/application/src/test/java/com/yahoo/application/ApplicationTest.java b/application/src/test/java/com/yahoo/application/ApplicationTest.java index 3227b579832..b6e59f7d4cd 100644 --- a/application/src/test/java/com/yahoo/application/ApplicationTest.java +++ b/application/src/test/java/com/yahoo/application/ApplicationTest.java @@ -61,8 +61,9 @@ public class ApplicationTest { try (Application application = Application.fromApplicationPackage(new File("src/test/app-packages/withcontent"), Networking.disable)) { Result result = application.getJDisc("default").search().process(new ComponentSpecification("default"), - new Query("?query=substring:foobar&tracelevel=3")); - assertEquals("AND substring:fo substring:oo substring:ob substring:ba substring:ar", result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString()); + new Query("?query=substring:foobar&tracelevel=3")); + assertEquals("AND substring:fo substring:oo substring:ob substring:ba substring:ar", + result.hits().get("hasQuery").getQuery().getModel().getQueryTree().toString()); } } -- cgit v1.2.3