diff options
author | Henrik Høiness <31851923+henrhoi@users.noreply.github.com> | 2018-07-11 16:04:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-11 16:04:45 +0200 |
commit | 343bc34fe8230c9da5489ce60d3849136438a583 (patch) | |
tree | 411a8a1c0cd12a4ce23da642ac6ea04a737ede81 | |
parent | 2e4ddebe0db405d91c0cff6f63118a094101f467 (diff) | |
parent | 06d97034b84a7ec99f196ed9fb2e875431f6f410 (diff) |
Merge pull request #6366 from vespa-engine/henrhoi/adding-gui-handler-when-building-containermodel
Adding handler and binding when services.xml has <search>-field
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | application/pom.xml | 5 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java | 27 | ||||
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java | 11 | ||||
-rw-r--r-- | config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java | 27 | ||||
-rw-r--r-- | container-disc/pom.xml | 1 | ||||
-rw-r--r-- | container-integration-test/.gitignore | 31 | ||||
-rw-r--r-- | container-integration-test/OWNERS | 1 | ||||
-rw-r--r-- | container-integration-test/README | 1 | ||||
-rw-r--r-- | container-integration-test/pom.xml | 44 | ||||
-rw-r--r-- | container-integration-test/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java (renamed from container-search-gui/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java) | 11 | ||||
-rw-r--r-- | container-search-gui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | container-search-gui/pom.xml | 91 | ||||
-rw-r--r-- | container-search-gui/src/main/java/com/yahoo/search/query/gui/GUIHandler.java | 70 | ||||
-rw-r--r-- | pom.xml | 1 |
15 files changed, 244 insertions, 80 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 23dcef6d96d..6c557179750 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ add_subdirectory(container-disc) add_subdirectory(container-jersey2) add_subdirectory(container-messagebus) add_subdirectory(container-search) +add_subdirectory(container-search-gui) add_subdirectory(container-search-and-docproc) add_subdirectory(clustercontroller-apps) add_subdirectory(clustercontroller-apputil) diff --git a/application/pom.xml b/application/pom.xml index db298451a8b..0808f2be58e 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -46,6 +46,11 @@ </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> + <artifactId>container-search-gui</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> <artifactId>zkfacade</artifactId> <version>${project.version}</version> </dependency> 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 new file mode 100644 index 00000000000..025075be8fd --- /dev/null +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/GUIHandler.java @@ -0,0 +1,27 @@ +// Copyright 2018 Yahoo Holdings. 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; + + +/** + * @author Henrik Høiness + */ + +public class GUIHandler extends Handler<AbstractConfigProducer<?>> { + public static final String BUNDLE = "container-search-gui"; + public static final String CLASS = "com.yahoo.search.query.gui.GUIHandler"; + public static final String BINDING = "*/querybuilder/*"; + + public GUIHandler() { + super(new ComponentModel(bundleSpec(CLASS, BUNDLE))); + } + + public static BundleInstantiationSpecification bundleSpec(String className, String bundle) { + return BundleInstantiationSpecification.getFromStrings(className, className, bundle); + } + +} 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 a007c4765c0..d81026c54d1 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 @@ -23,6 +23,7 @@ import com.yahoo.config.provision.NodeType; import com.yahoo.config.provision.Rotation; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.config.MetricDefaultsConfig; +import com.yahoo.osgi.provider.model.ComponentModel; import com.yahoo.search.rendering.RendererRegistry; import com.yahoo.text.XML; import com.yahoo.vespa.defaults.Defaults; @@ -47,6 +48,7 @@ import com.yahoo.vespa.model.container.IdentityProvider; import com.yahoo.vespa.model.container.SecretStore; import com.yahoo.vespa.model.container.component.Component; import com.yahoo.vespa.model.container.component.FileStatusHandlerComponent; +import com.yahoo.vespa.model.container.component.Handler; import com.yahoo.vespa.model.container.component.chain.ProcessingHandler; import com.yahoo.vespa.model.container.docproc.ContainerDocproc; import com.yahoo.vespa.model.container.docproc.DocprocChains; @@ -55,6 +57,7 @@ import com.yahoo.vespa.model.container.http.xml.HttpBuilder; import com.yahoo.vespa.model.container.jersey.xml.RestApiBuilder; import com.yahoo.vespa.model.container.processing.ProcessingChains; import com.yahoo.vespa.model.container.search.ContainerSearch; +import com.yahoo.vespa.model.container.search.GUIHandler; import com.yahoo.vespa.model.container.search.PageTemplates; import com.yahoo.vespa.model.container.search.QueryProfiles; import com.yahoo.vespa.model.container.search.SemanticRules; @@ -378,6 +381,7 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { cluster.setSearch(buildSearch(cluster, searchElement, queryProfiles, semanticRules)); addSearchHandler(cluster, searchElement); + addGUIHandler(cluster); validateAndAddConfiguredComponents(cluster, searchElement, "renderer", ContainerModelBuilder::validateRendererElement); } } @@ -670,6 +674,13 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { cluster.addComponent(searchHandler); } + private void addGUIHandler(ContainerCluster cluster) { + Handler<?> guiHandler = new GUIHandler(); + guiHandler.addServerBindings("http://"+GUIHandler.BINDING, "https://"+GUIHandler.BINDING); + cluster.addComponent(guiHandler); + } + + private String[] serverBindings(Element searchElement, String... defaultBindings) { List<Element> bindings = XML.getChildren(searchElement, "binding"); if (bindings.isEmpty()) diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java index cc8733fc9e2..30f1df6a394 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/container/xml/SearchBuilderTest.java @@ -8,6 +8,8 @@ import com.yahoo.searchdefinition.parser.ParseException; import com.yahoo.vespa.model.VespaModel; import com.yahoo.vespa.model.container.Container; import com.yahoo.vespa.model.container.ContainerCluster; +import com.yahoo.vespa.model.container.component.Handler; +import com.yahoo.vespa.model.container.search.GUIHandler; import com.yahoo.vespa.model.test.utils.ApplicationPackageUtils; import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithMockPkg; import org.junit.Test; @@ -32,6 +34,31 @@ public class SearchBuilderTest extends ContainerModelBuilderTestBase { return root.getConfig(ChainsConfig.class, "default/component/com.yahoo.search.handler.SearchHandler"); } + @Test + public void gui_search_handler_is_always_included_when_search_is_specified() throws Exception{ + Element clusterElem = DomBuilderTest.parse( + "<jdisc id='default' version='1.0'>", + " <search />", + nodesXml, + "</jdisc>"); + + createModel(root, clusterElem); + + String discBindingsConfig = root.getConfig(JdiscBindingsConfig.class, "default").toString(); + assertThat(discBindingsConfig, containsString(GUIHandler.BINDING)); + + ContainerCluster cluster = (ContainerCluster)root.getChildren().get("default"); + + GUIHandler guiHandler = null; + for (Handler<?> handler : cluster.getHandlers()) { + if (handler instanceof GUIHandler) { + guiHandler = (GUIHandler) handler; + } + } + if (guiHandler == null) fail(); + } + + @Test public void search_handler_bindings_can_be_overridden() throws Exception { diff --git a/container-disc/pom.xml b/container-disc/pom.xml index c112466bbd4..ea3425d302d 100644 --- a/container-disc/pom.xml +++ b/container-disc/pom.xml @@ -169,6 +169,7 @@ configdefinitions-jar-with-dependencies.jar, container-jersey2-jar-with-dependencies.jar, container-search-and-docproc-jar-with-dependencies.jar, + container-search-gui-jar-with-dependencies.jar, docprocs-jar-with-dependencies.jar, jdisc-security-filters-jar-with-dependencies.jar, jdisc_http_service-jar-with-dependencies.jar, diff --git a/container-integration-test/.gitignore b/container-integration-test/.gitignore new file mode 100644 index 00000000000..7f4ebc3a7c6 --- /dev/null +++ b/container-integration-test/.gitignore @@ -0,0 +1,31 @@ +.classpath +.project +.settings +/.cache +/.classpath +/.emacs.desktop +/.nbintdb +/.project +/.settings +/.version +/QueryAccessLog* +/accessLog.log +/build +/bundles +/libexec +/nbproject +/pom.xml.build +/prelude.iml +/prelude.ipr +/prelude.iws +/staging +/target +/temp +/testLogFileG.txt +/testLogs +/test_yapache_access_log +/testlogsG +/testng.out.log +/tmp +null.log +tmp diff --git a/container-integration-test/OWNERS b/container-integration-test/OWNERS new file mode 100644 index 00000000000..6faef1015fb --- /dev/null +++ b/container-integration-test/OWNERS @@ -0,0 +1 @@ +gjoranv
\ No newline at end of file diff --git a/container-integration-test/README b/container-integration-test/README new file mode 100644 index 00000000000..c10341c3d8e --- /dev/null +++ b/container-integration-test/README @@ -0,0 +1 @@ +Test for JDisc-components diff --git a/container-integration-test/pom.xml b/container-integration-test/pom.xml new file mode 100644 index 00000000000..4b4d5de21eb --- /dev/null +++ b/container-integration-test/pom.xml @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<!-- Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>6-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + <artifactId>container-integration-test</artifactId> + <packaging>jar</packaging> + <version>6-SNAPSHOT</version> + <dependencies> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-search-gui</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>application</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + </plugin> + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/container-search-gui/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java b/container-integration-test/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java index ec515a1bf4a..5fd73afe800 100644 --- a/container-search-gui/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java +++ b/container-integration-test/src/test/java/com/yahoo/search/query/gui/GUIHandlerTest.java @@ -5,13 +5,12 @@ import com.yahoo.application.Networking; import com.yahoo.application.container.JDisc; import com.yahoo.application.container.handler.Request; import com.yahoo.application.container.handler.Response; + import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; - import java.io.IOException; - +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -25,7 +24,7 @@ public class GUIHandlerTest { @Before public void startContainer() { - container = JDisc.fromServicesXml(servicesXml(), Networking.enable); + container = JDisc.fromServicesXml(servicesXml(), Networking.disable); } @After @@ -64,8 +63,8 @@ public class GUIHandlerTest { private void assertResponse(Request.Method method, String path, String expectedStartString, String expectedContentType, int expectedStatusCode) throws IOException { Response response = container.handleRequest(new Request("http://localhost:8080" + path, new byte[0], method)); - Assert.assertEquals("Status code", expectedStatusCode, response.getStatus()); - Assert.assertEquals(expectedContentType, response.getHeaders().getFirst("Content-Type")); + assertEquals("Status code", expectedStatusCode, response.getStatus()); + assertEquals(expectedContentType, response.getHeaders().getFirst("Content-Type")); if(expectedStartString != null){ assertTrue(response.getBodyAsString().startsWith(expectedStartString)); } diff --git a/container-search-gui/CMakeLists.txt b/container-search-gui/CMakeLists.txt new file mode 100644 index 00000000000..95476154443 --- /dev/null +++ b/container-search-gui/CMakeLists.txt @@ -0,0 +1,2 @@ +# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +install_fat_java_artifact(container-search-gui)
\ No newline at end of file diff --git a/container-search-gui/pom.xml b/container-search-gui/pom.xml index f2ca70dd1f3..f598758e1de 100644 --- a/container-search-gui/pom.xml +++ b/container-search-gui/pom.xml @@ -4,46 +4,55 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>com.yahoo.vespa</groupId> - <artifactId>parent</artifactId> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>6-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + <artifactId>container-search-gui</artifactId> + <packaging>container-plugin</packaging> <version>6-SNAPSHOT</version> - <relativePath>../parent/pom.xml</relativePath> - </parent> - <artifactId>container-search-gui</artifactId> - <packaging>jar</packaging> - <version>6-SNAPSHOT</version> - <dependencies> - <dependency> - <groupId>com.yahoo.vespa</groupId> - <artifactId>application</artifactId> - <version>6-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <compilerArgs> - <arg>-Xlint:all</arg> - <arg>-Xlint:-rawtypes</arg> - <arg>-Xlint:-unchecked</arg> - <arg>-Xlint:-serial</arg> - <arg>-Xlint:-deprecation</arg> - <arg>-Xlint:-dep-ann</arg> - <arg>-Xlint:-cast</arg> - <arg>-Werror</arg> - </compilerArgs> - </configuration> - </plugin> - </plugins> - </build> + <dependencies> + <dependency> + <groupId>com.google.inject</groupId> + <artifactId>guice</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>yolean</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>jdisc_http_service</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>jdisc_core</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>container-core</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + </plugins> + </build> + </project>
\ No newline at end of file diff --git a/container-search-gui/src/main/java/com/yahoo/search/query/gui/GUIHandler.java b/container-search-gui/src/main/java/com/yahoo/search/query/gui/GUIHandler.java index 0f4eebd7fd7..95adbbea3fc 100644 --- a/container-search-gui/src/main/java/com/yahoo/search/query/gui/GUIHandler.java +++ b/container-search-gui/src/main/java/com/yahoo/search/query/gui/GUIHandler.java @@ -5,17 +5,13 @@ import com.google.inject.Inject; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; - - import com.yahoo.search.query.restapi.ErrorResponse; import com.yahoo.yolean.Exceptions; -import java.io.File; + import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.logging.Level; /** @@ -47,75 +43,83 @@ public class GUIHandler extends LoggingRequestHandler { } private HttpResponse handleGET(HttpRequest request) { - com.yahoo.restapi.Path path = new com.yahoo.restapi.Path(request.getUri().getPath()); + com.yahoo.restapi.Path path = new com.yahoo.restapi.Path(request.getUri().getPath()); if (path.matches("/querybuilder/")) { return new FileResponse("_includes/index.html"); } if (!path.matches("/querybuilder/{*}") ) { - return ErrorResponse.notFoundError("Nothing at " + path); + return ErrorResponse.notFoundError("Nothing at path:" + path); } String filepath = path.getRest(); - if (!isValidPath(GUIHandler.class.getClassLoader().getResource("gui").getFile()+"/"+filepath)){ - return ErrorResponse.notFoundError("Nothing at " + path); + if (!isValidPath(filepath)){ + return ErrorResponse.notFoundError("Nothing at path:" + filepath); } return new FileResponse(filepath); } private static boolean isValidPath(String path) { - File file = new File(path); - return file.exists(); + InputStream in = GUIHandler.class.getClassLoader().getResourceAsStream("gui/"+path); + boolean isValid = (in != null); + if(isValid){ + try { in.close(); } catch (IOException e) {/* Problem with closing inputstream */} + } + + return isValid; } private static class FileResponse extends HttpResponse { - private final Path path; + private final String path; public FileResponse(String relativePath) { super(200); - this.path = Paths.get(GUIHandler.class.getClassLoader().getResource("gui").getFile(), relativePath); + this.path = relativePath; } @Override public void render(OutputStream out) throws IOException { - byte[] data = Files.readAllBytes(path); - out.write(data); + InputStream is = GUIHandler.class.getClassLoader().getResourceAsStream("gui/"+this.path); + byte[] buf = new byte[1024]; + int numRead; + while ( (numRead = is.read(buf) ) >= 0) { + out.write(buf, 0, numRead); + } } @Override public String getContentType() { - if (path.toString().endsWith(".css")) { + if (path.endsWith(".css")) { return "text/css"; - } else if (path.toString().endsWith(".js")) { + } else if (path.endsWith(".js")) { return "application/javascript"; - } else if (path.toString().endsWith(".html")) { + } else if (path.endsWith(".html")) { return "text/html"; - }else if (path.toString().endsWith(".php")) { + } else if (path.endsWith(".php")) { return "text/php"; - }else if (path.toString().endsWith(".svg")) { + } else if (path.endsWith(".svg")) { return "image/svg+xml"; - }else if (path.toString().endsWith(".eot")) { + } else if (path.endsWith(".eot")) { return "application/vnd.ms-fontobject"; - }else if (path.toString().endsWith(".ttf")) { + } else if (path.endsWith(".ttf")) { return "font/ttf"; - }else if (path.toString().endsWith(".woff")) { + } else if (path.endsWith(".woff")) { return "font/woff"; - }else if (path.toString().endsWith(".woff2")) { + } else if (path.endsWith(".woff2")) { return "font/woff2"; - }else if (path.toString().endsWith(".otf")) { + } else if (path.endsWith(".otf")) { return "font/otf"; - }else if (path.toString().endsWith(".png")) { + } else if (path.endsWith(".png")) { return "image/png"; - }else if (path.toString().endsWith(".xml")) { + } else if (path.endsWith(".xml")) { return "application/xml"; - }else if (path.toString().endsWith(".ico")) { + } else if (path.endsWith(".ico")) { return "image/x-icon"; - }else if (path.toString().endsWith(".json")) { + } else if (path.endsWith(".json")) { return "application/json"; - }else if (path.toString().endsWith(".ttf")) { + } else if (path.endsWith(".ttf")) { return "font/ttf"; } return "text/html"; } } - -} +}
\ No newline at end of file @@ -56,6 +56,7 @@ <module>container-dev</module> <module>container-di</module> <module>container-disc</module> + <module>container-integration-test</module> <module>container-jersey2</module> <module>container-messagebus</module> <module>container-search-and-docproc</module> |