AMBARI-21670. Log Search cleanup: all configurations should be spring managed (oleewere)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/555f241c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/555f241c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/555f241c Branch: refs/heads/branch-feature-logsearch-ui Commit: 555f241cf0cf4e8830ce78f069ecca152802410f Parents: f01c32e Author: oleewere <oleew...@gmail.com> Authored: Mon Aug 7 21:12:53 2017 +0200 Committer: oleewere <oleew...@gmail.com> Committed: Mon Aug 7 21:28:42 2017 +0200 ---------------------------------------------------------------------- .../ambari-logsearch-logfeeder/build.properties | 2 +- .../ambari-logsearch-server/build.properties | 2 +- .../ambari-logsearch-server/pom.xml | 427 ++++--------------- ambari-logsearch/ambari-logsearch-server/run.sh | 6 +- .../org/apache/ambari/logsearch/LogSearch.java | 181 +------- .../logsearch/common/ExternalServerClient.java | 24 +- .../logsearch/common/LogSearchConstants.java | 2 +- .../logsearch/common/PropertiesHelper.java | 124 ------ .../logsearch/common/XMLPropertiesHelper.java | 79 ---- .../ambari/logsearch/conf/ApiDocConfig.java | 4 +- .../logsearch/conf/ApplicationConfig.java | 2 - .../conf/LogSearchConfigMapHolder.java | 61 +++ .../logsearch/conf/LogSearchHttpConfig.java | 83 ++++ .../conf/LogSearchJerseyResourceConfig.java | 37 ++ .../logsearch/conf/LogSearchServletConfig.java | 95 +++++ .../logsearch/conf/LogSearchSpnegoConfig.java | 173 ++++++++ .../logsearch/conf/LogSearchSslConfig.java | 86 ++++ .../ambari/logsearch/conf/SecurityConfig.java | 3 + .../conf/StaticResourceConfiguration.java | 49 +++ .../configurer/LogSearchConfigConfigurer.java | 10 +- .../logsearch/configurer/SslConfigurer.java | 363 ++++++++++++++++ .../apache/ambari/logsearch/util/SSLUtil.java | 388 ----------------- .../apache/ambari/logsearch/util/WebUtil.java | 65 --- .../LogsearchKRBAuthenticationFilter.java | 107 +---- .../web/listener/LogSearchSessionListener.java | 4 +- .../logsearch/web/security/LdapProperties.java | 365 ---------------- .../web/security/LdapPropertyName.java | 58 --- .../ambari/logsearch/web/security/LdapUtil.java | 115 ----- ...LogsearchAbstractAuthenticationProvider.java | 2 +- .../LogsearchAuthenticationProvider.java | 4 - .../LogsearchLdapAuthenticationProvider.java | 187 -------- .../LogsearchLdapBindAuthenticator.java | 46 -- .../src/main/resources/default.properties | 1 - .../src/main/resources/log4j.xml | 118 ++--- .../src/main/resources/logsearch-admin-site.xml | 116 ----- .../src/main/resources/logsearch.properties | 6 +- .../src/main/resources/swagger/swagger.html | 36 +- .../src/main/scripts/run.sh | 3 +- .../LogsearchAuthenticationProviderTest.java | 68 +-- ...LogsearchLdapAuthenticationProviderTest.java | 61 --- .../ambari-logsearch-web/build.properties | 2 +- ambari-logsearch/ambari-logsearch-web/pom.xml | 4 +- ambari-logsearch/docker/logsearch-docker.sh | 4 +- .../docker/test-config/logsearch/log4j.xml | 35 +- .../test-config/logsearch/logsearch-env.sh | 5 +- .../logsearch/logsearch-https.properties | 1 + .../LoggingRequestHelperFactoryImpl.java | 19 +- .../server/upgrade/UpgradeCatalog300.java | 28 +- .../common-services/LOGSEARCH/0.5.0/alerts.json | 6 +- .../0.5.0/configuration/logsearch-env.xml | 14 - .../configuration/logsearch-properties.xml | 21 + .../LOGSEARCH/0.5.0/package/scripts/params.py | 13 +- .../0.5.0/properties/logsearch-env.sh.j2 | 2 - .../LOGSEARCH/0.5.0/quicklinks/quicklinks.json | 10 +- .../LoggingRequestHelperFactoryImplTest.java | 10 +- .../stacks/2.4/LOGSEARCH/test_logsearch.py | 2 + .../test/python/stacks/2.4/configs/default.json | 5 +- .../configs/services/logsearch_properties.js | 97 +++-- 58 files changed, 1339 insertions(+), 2502 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-logfeeder/build.properties ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-logfeeder/build.properties b/ambari-logsearch/ambari-logsearch-logfeeder/build.properties index 46979e5..013ba2e 100644 --- a/ambari-logsearch/ambari-logsearch-logfeeder/build.properties +++ b/ambari-logsearch/ambari-logsearch-logfeeder/build.properties @@ -15,4 +15,4 @@ app.pkg.dir=${app.work.dir}/pkg app.dev.war.dir=${app.work.dir}/webapps/logsearch app.war.name=logsearch.war -app.target.dir=${builddir}/target/classes/webapps/app \ No newline at end of file +app.target.dir=${builddir}/target/classes/static \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/build.properties ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/build.properties b/ambari-logsearch/ambari-logsearch-server/build.properties index 1cd118a..4e49489 100644 --- a/ambari-logsearch/ambari-logsearch-server/build.properties +++ b/ambari-logsearch/ambari-logsearch-server/build.properties @@ -20,4 +20,4 @@ app.pkg.dir=${app.work.dir}/pkg app.dev.war.dir=${app.work.dir}/webapps/logsearch app.war.name=logsearch.war -app.target.dir=${builddir}/target/classes/webapps/app \ No newline at end of file +app.target.dir=${builddir}/target/classes/static \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/pom.xml ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/pom.xml b/ambari-logsearch/ambari-logsearch-server/pom.xml index 4db1f61..c0ae16e 100755 --- a/ambari-logsearch/ambari-logsearch-server/pom.xml +++ b/ambari-logsearch/ambari-logsearch-server/pom.xml @@ -27,17 +27,17 @@ <url>http://maven.apache.org</url> <name>Ambari Logsearch Server</name> <properties> - <spring.version>4.2.5.RELEASE</spring.version> - <spring.security.version>4.0.4.RELEASE</spring.security.version> + <spring.version>4.3.10.RELEASE</spring.version> + <spring.security.version>4.2.3.RELEASE</spring.security.version> <spring.ldap.version>2.0.4.RELEASE</spring.ldap.version> - <jersey.version>2.23.2</jersey.version> - <jetty-version>9.2.11.v20150529</jetty-version> - <swagger.version>1.5.8</swagger.version> + <jersey.version>2.25.1</jersey.version> + <jetty.version>9.4.6.v20170531</jetty.version> + <swagger.version>1.5.16</swagger.version> <spring-data-solr.version>2.0.2.RELEASE</spring-data-solr.version> <jjwt.version>0.6.0</jjwt.version> + <spring-boot.version>1.5.6.RELEASE</spring-boot.version> </properties> <profiles> - <!-- Dev Profile Start --> <profile> <id>dev</id> <activation> @@ -67,24 +67,18 @@ <target>${jdk.version}</target> </configuration> </plugin> - <!-- Exec main class plugin --> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${spring-boot.version}</version> <executions> <execution> <goals> - <goal>java</goal> + <goal>repackage</goal> </goals> </execution> </executions> - <configuration> - <mainClass>org.apache.ambari.logsearch.LogSearch</mainClass> - <!-- <arguments> <argument></argument> </arguments> --> - </configuration> </plugin> - <!-- copy-dependencies --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> @@ -103,7 +97,7 @@ <artifactId>ambari-logsearch-web</artifactId> <version>${project.version}</version> <outputDirectory>${project.build.outputDirectory}/</outputDirectory> - <includes>webapps/**</includes> + <includes>static/**</includes> </artifactItem> </artifactItems> </configuration> @@ -126,8 +120,6 @@ </execution> </executions> </plugin> - <!-- - --> - <!-- ant pacakge --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> @@ -137,7 +129,6 @@ <phase>package</phase> <configuration> <target> - <!-- <taskdef resource="build.properties" classpathref="maven.plugin.classpath" /> --> <ant antfile="build.xml"> <target name="package"/> </ant> @@ -168,243 +159,6 @@ </execution> </executions> </plugin> - <!-- /ant package --> - </plugins> - </build> - </profile> - <!-- Dev Profile End --> - <!-- Production Profile Start --> - <profile> - <id>production</id> - <build> - <finalName>LogSearch</finalName> - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.0</version> - </plugin> - <plugin> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.8</version> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.0</version> - <configuration> - <source>${jdk.version}</source> - <target>${jdk.version}</target> - </configuration> - </plugin> - <!-- Exec main class plugin --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.ambari.logsearch.LogSearch</mainClass> - <!-- <arguments> <argument></argument> </arguments> --> - </configuration> - </plugin> - <!-- copy-dependencies --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.8</version> - <executions> - <execution> - <id>copy-dependencies</id> - <phase>package</phase> - <goals> - <goal>copy-dependencies</goal> - </goals> - <configuration> - <artifactItems>*</artifactItems> - <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename> - <outputDirectory>${basedir}/target/libs</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - </configuration> - </execution> - </executions> - </plugin> - <!-- - --> - <!-- ant pacakge --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-antrun-plugin</artifactId> - <version>1.7</version> - <executions> - <execution> - <phase>package</phase> - <configuration> - <target> - <!-- <taskdef resource="build.properties" classpathref="maven.plugin.classpath" /> --> - <ant antfile="build.xml"> - <target name="package"/> - </ant> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - <!-- <execution> - <id>Packag Install</id> - <phase>generate-resources</phase> - <configuration> - <target> - <exec executable="npm"> - <arg value="install" /> - </exec> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - <execution> - <id>Js Packaging</id> - <phase>generate-resources</phase> - <configuration> - <target> - <exec executable="gulp"> - <arg value="minify-css" /> - </exec> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> --> - </executions> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>**/*</exclude> - </excludes> - </configuration> - <executions> - <execution> - <phase>test</phase> - <goals> - <goal>check</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - <!-- Production Profile End --> - <profile> - <id>skipMinify</id> - <activation> - <activeByDefault>false</activeByDefault> - </activation> - <build> - <finalName>LogSearch</finalName> - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.0</version> - </plugin> - <plugin> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.8</version> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.0</version> - <configuration> - <source>${jdk.version}</source> - <target>${jdk.version}</target> - </configuration> - </plugin> - <!-- Exec main class plugin --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <goals> - <goal>java</goal> - </goals> - </execution> - </executions> - <configuration> - <mainClass>org.apache.ambari.logsearch.LogSearch</mainClass> - <!-- <arguments> <argument></argument> </arguments> --> - </configuration> - </plugin> - <!-- copy-dependencies --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>2.8</version> - <executions> - <execution> - <id>copy-dependencies</id> - <phase>package</phase> - <goals> - <goal>copy-dependencies</goal> - </goals> - <configuration> - <artifactItems>*</artifactItems> - <outputAbsoluteArtifactFilename>true</outputAbsoluteArtifactFilename> - <outputDirectory>${basedir}/target/libs</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - </configuration> - </execution> - </executions> - </plugin> - <!-- - --> - <!-- ant pacakge --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-antrun-plugin</artifactId> - <version>1.7</version> - <executions> - <execution> - <phase>package</phase> - <configuration> - <target> - <!-- <taskdef resource="build.properties" classpathref="maven.plugin.classpath" - /> --> - <ant antfile="build.xml"> - <target name="package"/> - </ant> - </target> - </configuration> - <goals> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> </plugins> </build> </profile> @@ -455,62 +209,88 @@ </dependency> <dependency> - <groupId>org.springframework.ldap</groupId> - <artifactId>spring-ldap-core</artifactId> - <version>${spring.ldap.version}</version> + <groupId>org.springframework.security.kerberos</groupId> + <artifactId>spring-security-kerberos-core</artifactId> + <version>1.0.1.RELEASE</version> </dependency> <dependency> - <groupId>org.springframework.security</groupId> - <artifactId>spring-security-ldap</artifactId> - <version>${spring.security.version}</version> + <groupId>org.springframework.security.kerberos</groupId> + <artifactId>spring-security-kerberos-web</artifactId> + <version>1.0.1.RELEASE</version> </dependency> <dependency> - <groupId>org.glassfish.jersey.ext</groupId> - <artifactId>jersey-spring3</artifactId> - <version>2.23.2</version> + <groupId>org.springframework.security.kerberos</groupId> + <artifactId>spring-security-kerberos-client</artifactId> + <version>1.0.1.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + <version>${spring-boot.version}</version> <exclusions> <exclusion> - <groupId>org.springframework</groupId> - <artifactId>*</artifactId> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> - <groupId>org.glassfish.jersey.connectors</groupId> - <artifactId>jersey-apache-connector</artifactId> - <version>${jersey.version}</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-log4j</artifactId> + <version>1.3.8.RELEASE</version> </dependency> <dependency> - <groupId>org.glassfish.jersey.core</groupId> - <artifactId>jersey-client</artifactId> - <version>${jersey.version}</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + <version>${spring-boot.version}</version> </dependency> <dependency> - <groupId>org.glassfish.jersey.media</groupId> - <artifactId>jersey-media-json-jettison</artifactId> - <version>${jersey.version}</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-security</artifactId> + <version>${spring-boot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jetty</artifactId> + <version>${spring-boot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-jersey</artifactId> + <version>${spring-boot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-freemarker</artifactId> + <version>${spring-boot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-autoconfigure</artifactId> + <version>${spring-boot.version}</version> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <version>${spring-boot.version}</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> - <artifactId>jersey-media-json-jackson</artifactId> + <artifactId>jersey-media-json-jettison</artifactId> <version>${jersey.version}</version> </dependency> <dependency> - <groupId>org.glassfish.jersey.core</groupId> - <artifactId>jersey-common</artifactId> - <version>${jersey.version}</version> + <artifactId>guava</artifactId> + <groupId>com.google.guava</groupId> + <version>20.0</version> </dependency> + <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.17</version> - </dependency> - <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>${solr.version}</version> @@ -582,6 +362,10 @@ <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> </exclusion> + <exclusion> + <artifactId>guava</artifactId> + <groupId>com.google.guava</groupId> + </exclusion> </exclusions> </dependency> <dependency> @@ -624,6 +408,10 @@ <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> + <exclusion> + <artifactId>guava</artifactId> + <groupId>com.google.guava</groupId> + </exclusion> </exclusions> </dependency> <dependency> @@ -645,68 +433,6 @@ <artifactId>commons-lang</artifactId> </dependency> <dependency> - <groupId>org.springframework.security.kerberos</groupId> - <artifactId>spring-security-kerberos-core</artifactId> - <version>1.0.1.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework.security.kerberos</groupId> - <artifactId>spring-security-kerberos-web</artifactId> - <version>1.0.1.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework.security.kerberos</groupId> - <artifactId>spring-security-kerberos-client</artifactId> - <version>1.0.1.RELEASE</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-security</artifactId> - <version>${jetty-version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-server</artifactId> - <version>${jetty-version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-servlet</artifactId> - <version>${jetty-version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-servlets</artifactId> - <version>${jetty-version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-util</artifactId> - <version>${jetty-version}</version> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-webapp</artifactId> - <version>${jetty-version}</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>*</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-annotations</artifactId> - <version>${jetty-version}</version> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>*</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>3.2.4</version> @@ -753,11 +479,6 @@ <version>${spring.version}</version> </dependency> <dependency> - <groupId>org.freemarker</groupId> - <artifactId>freemarker</artifactId> - <version>2.3.20</version> - </dependency> - <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jjwt.version}</version> http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/run.sh ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/run.sh b/ambari-logsearch/ambari-logsearch-server/run.sh index ea89947..765fe6c 100755 --- a/ambari-logsearch/ambari-logsearch-server/run.sh +++ b/ambari-logsearch/ambari-logsearch-server/run.sh @@ -17,8 +17,4 @@ echo " ââââââââââââââââââââââââââ âââââââââââââââââââ ââââââ ââââââââââââââ âââ ââââââââ âââââââ âââââââ âââââââââââââââââââ ââââââ âââ ââââââââââ âââ " -cd .. -mvn clean compile package -Pdev -cd ambari-logsearch-server -#mvn exec:java -Pdev -java -cp target/libs/*:target/classes/ org.apache.ambari.logsearch.LogSearch +mvn spring-boot:run http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java index b1517df..39343c7 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/LogSearch.java @@ -18,169 +18,30 @@ */ package org.apache.ambari.logsearch; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.EnumSet; - -import org.apache.ambari.logsearch.common.ManageStartEndTime; -import org.apache.ambari.logsearch.common.PropertiesHelper; -import org.apache.ambari.logsearch.conf.ApplicationConfig; -import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; -import org.apache.ambari.logsearch.util.SSLUtil; -import org.apache.ambari.logsearch.util.WebUtil; -import org.apache.ambari.logsearch.web.listener.LogSearchSessionListener; -import org.apache.commons.lang.StringUtils; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.HttpConfiguration; -import org.eclipse.jetty.server.HttpConnectionFactory; -import org.eclipse.jetty.server.SecureRequestCustomizer; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.SslConnectionFactory; -import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceCollection; -import org.eclipse.jetty.util.ssl.SslContextFactory; -import org.eclipse.jetty.webapp.WebAppContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.request.RequestContextListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.filter.DelegatingFilterProxy; - -import javax.servlet.DispatcherType; - -import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; -import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_SESSION_ID; - -public class LogSearch { - private static final Logger LOG = LoggerFactory.getLogger(LogSearch.class); - - @LogSearchPropertyDescription( - name = "logsearch.protocol", - description = "Log Search Protocol (http or https)", - examples = {"http", "https"}, - defaultValue = "http", - sources = {LOGSEARCH_PROPERTIES_FILE} - ) - private static final String LOGSEARCH_PROTOCOL_PROP = "logsearch.protocol"; - private static final String HTTPS_PROTOCOL = "https"; - private static final String HTTP_PROTOCOL = "http"; - private static final String HTTPS_PORT = "61889"; - private static final String HTTP_PORT = "61888"; - - private static final String ROOT_CONTEXT = "/"; - private static final Integer SESSION_TIMEOUT = 60 * 30; - - public static void main(String[] argv) { - LogSearch logSearch = new LogSearch(); - ManageStartEndTime.manage(); - try { - logSearch.run(argv); - } catch (Throwable e) { - LOG.error("Error running logsearch server", e); - } +import org.springframework.boot.Banner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration; +import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.system.ApplicationPidFileWriter; + +@SpringBootApplication( + scanBasePackages = {"org.apache.ambari.logsearch"}, + exclude = { + RepositoryRestMvcAutoConfiguration.class, + WebMvcAutoConfiguration.class } +) +public class LogSearch { - public void run(String[] argv) throws Exception { - SSLUtil.ensureStorePasswords(); - SSLUtil.loadKeystore(); - - Server server = buildSever(argv); - HandlerList handlers = new HandlerList(); - handlers.addHandler(createSwaggerContext()); - handlers.addHandler(createBaseWebappContext()); - - server.setHandler(handlers); - server.start(); - - LOG.debug("============================Server Dump======================================="); - LOG.debug(server.dump()); - LOG.debug("=============================================================================="); - server.join(); - } - - public Server buildSever(String argv[]) { - Server server = new Server(); - boolean portSpecified = argv.length > 0; - String protcolProperty = PropertiesHelper.getProperty(LOGSEARCH_PROTOCOL_PROP,HTTP_PROTOCOL); - HttpConfiguration httpConfiguration = new HttpConfiguration(); - httpConfiguration.setRequestHeaderSize(65535); - if (StringUtils.isEmpty(protcolProperty)) { - protcolProperty = HTTP_PROTOCOL; - } - String port = null; - if (HTTPS_PROTOCOL.equals(protcolProperty) && SSLUtil.isKeyStoreSpecified()) { - LOG.info("Building https server..........."); - port = portSpecified ? argv[0] : HTTPS_PORT; - WebUtil.checkPort(Integer.parseInt(port)); - httpConfiguration.addCustomizer(new SecureRequestCustomizer()); - SslContextFactory sslContextFactory = SSLUtil.getSslContextFactory(); - ServerConnector sslConnector = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory, "http/1.1"), - new HttpConnectionFactory(httpConfiguration)); - sslConnector.setPort(Integer.parseInt(port)); - server.setConnectors(new Connector[] { sslConnector }); - } else { - LOG.info("Building http server..........."); - port = portSpecified ? argv[0] : HTTP_PORT; - WebUtil.checkPort(Integer.parseInt(port)); - ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration)); - connector.setPort(Integer.parseInt(port)); - server.setConnectors(new Connector[] { connector }); - } - URI logsearchURI = URI.create(String.format("%s://0.0.0.0:%s", protcolProperty, port)); - LOG.info("Starting logsearch server URI=" + logsearchURI); - return server; - } - - private WebAppContext createBaseWebappContext() throws MalformedURLException { - URI webResourceBase = WebUtil.findWebResourceBase(); - WebAppContext context = new WebAppContext(); - context.setBaseResource(Resource.newResource(webResourceBase)); - context.setContextPath(ROOT_CONTEXT); - context.setParentLoaderPriority(true); - context.addEventListener(new LogSearchSessionListener()); - - // Configure Spring - context.addEventListener(new ContextLoaderListener()); - context.addEventListener(new RequestContextListener()); - context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class)); - context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); - context.setInitParameter("contextConfigLocation", ApplicationConfig.class.getName()); - - // Configure Jersey - ServletHolder jerseyServlet = context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class, "/api/v1/*"); - jerseyServlet.setInitOrder(1); - jerseyServlet.setInitParameter("jersey.config.server.provider.packages","org.apache.ambari.logsearch.rest"); - - context.getSessionHandler().getSessionManager().setMaxInactiveInterval(SESSION_TIMEOUT); - context.getSessionHandler().getSessionManager().getSessionCookieConfig().setName(LOGSEARCH_SESSION_ID); + public static void main(String[] args) { - return context; + String pidFile = System.getenv("PID_FILE") == null ? "logsearch.pid" : System.getenv("PID_FILE"); + new SpringApplicationBuilder(LogSearch.class) + .bannerMode(Banner.Mode.OFF) + .listeners(new ApplicationPidFileWriter(pidFile)) + .web(true) + .run(args); } - private ServletContextHandler createSwaggerContext() throws URISyntaxException { - ResourceHandler resourceHandler = new ResourceHandler(); - ResourceCollection resources = new ResourceCollection(new String[] { - LogSearch.class.getClassLoader() - .getResource("META-INF/resources/webjars/swagger-ui/2.1.0") - .toURI().toString(), - LogSearch.class.getClassLoader() - .getResource("swagger") - .toURI().toString() - }); - resourceHandler.setBaseResource(resources); - resourceHandler.setWelcomeFiles(new String[]{"swagger.html"}); // rewrite index.html from swagger-ui webjar - ServletContextHandler context = new ServletContextHandler(); - context.setContextPath("/docs/"); - context.setHandler(resourceHandler); - return context; - } } http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java index df00c15..c6a1379 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/ExternalServerClient.java @@ -25,7 +25,7 @@ import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.apache.ambari.logsearch.conf.AuthPropsConfig; -import org.apache.ambari.logsearch.util.SSLUtil; +import org.apache.ambari.logsearch.configurer.SslConfigurer; import org.apache.commons.httpclient.auth.InvalidCredentialsException; import org.apache.log4j.Logger; import org.glassfish.jersey.client.JerseyClient; @@ -38,15 +38,11 @@ import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; @Named public class ExternalServerClient { + @Inject + private SslConfigurer sslConfigurer; + private static Logger LOG = Logger.getLogger(ExternalServerClient.class); - private static final ThreadLocal<JerseyClient> localJerseyClient = new ThreadLocal<JerseyClient>() { - @Override - protected JerseyClient initialValue() { - return SSLUtil.isKeyStoreSpecified() ? - new JerseyClientBuilder().sslContext(SSLUtil.getSSLContext()).build() : - JerseyClientBuilder.createClient(); - } - }; + private ThreadLocal<JerseyClient> localJerseyClient; @Inject private AuthPropsConfig authPropsConfig; @@ -55,6 +51,16 @@ public class ExternalServerClient { * Send GET request to an external server */ public Object sendGETRequest(String loginUrl, Class<?> klass, String username, String password) throws Exception { + if (localJerseyClient == null) { + localJerseyClient = new ThreadLocal<JerseyClient>() { + @Override + protected JerseyClient initialValue() { + return sslConfigurer.isKeyStoreSpecified() ? + new JerseyClientBuilder().sslContext(sslConfigurer.getSSLContext()).build() : + JerseyClientBuilder.createClient(); + } + }; + } String url = authPropsConfig.getExternalAuthHostUrl() + loginUrl; JerseyClient client = localJerseyClient.get(); HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basicBuilder() http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java index a018dda..c316346 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/LogSearchConstants.java @@ -21,8 +21,8 @@ package org.apache.ambari.logsearch.common; public class LogSearchConstants { + public static final String LOGSEARCH_APPLICATION_NAME = "logsearch"; public static final String LOGSEARCH_PROPERTIES_FILE = "logsearch.properties"; - public static final String LOGSEARCH_SESSION_ID = "LOGSEARCHSESSIONID"; // Log Levels http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java deleted file mode 100644 index 3505fe2..0000000 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/PropertiesHelper.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.ambari.logsearch.common; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; - -public class PropertiesHelper extends PropertyPlaceholderConfigurer { - private static final Logger logger = LoggerFactory.getLogger(PropertiesHelper.class); - - private static final String LOGSEARCH_PROP_FILE="logsearch.properties"; - - private static Map<String, String> propertiesMap; - public static Map<String, String> getProperties() { - return propertiesMap; - } - - private PropertiesHelper() { - } - - static { - propertiesMap = new HashMap<String, String>(); - Properties properties = new Properties(); - URL fileCompleteUrl = Thread.currentThread().getContextClassLoader().getResource(LOGSEARCH_PROP_FILE); - FileInputStream fileInputStream = null; - try { - File file = new File(fileCompleteUrl.toURI()); - fileInputStream = new FileInputStream(file.getAbsoluteFile()); - properties.load(fileInputStream); - } catch (IOException | URISyntaxException e) { - logger.error("error loading prop for protocol config",e); - } finally { - if (fileInputStream != null) { - try { - fileInputStream.close(); - } catch (IOException e) { - } - } - } - for (String key : properties.stringPropertyNames()) { - String value = properties.getProperty(key); - propertiesMap.put(key, value); - } - } - - @Override - protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException { - super.processProperties(beanFactory, props); - - propertiesMap = new HashMap<String, String>(); - - // First add the system properties - Set<Object> keySet = System.getProperties().keySet(); - for (Object key : keySet) { - String keyStr = key.toString(); - propertiesMap.put(keyStr, System.getProperties().getProperty(keyStr).trim()); - } - - // add our properties now - keySet = props.keySet(); - for (Object key : keySet) { - String keyStr = key.toString(); - propertiesMap.put(keyStr, props.getProperty(keyStr).trim()); - } - } - - public static String getProperty(String key, String defaultValue) { - if (key == null) { - return null; - } - String rtrnVal = propertiesMap.get(key); - if (rtrnVal == null) { - rtrnVal = defaultValue; - } - return rtrnVal; - } - - public static String getProperty(String key) { - if (key == null) { - return null; - } - return propertiesMap.get(key); - } - - public static boolean getBooleanProperty(String key, boolean defaultValue) { - if (key == null) { - return defaultValue; - } - String value = getProperty(key); - if (value == null) { - return defaultValue; - } - return Boolean.parseBoolean(value); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java deleted file mode 100644 index 690a60f..0000000 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/common/XMLPropertiesHelper.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.ambari.logsearch.common; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.apache.log4j.Logger; -import org.springframework.util.DefaultPropertiesPersister; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -public class XMLPropertiesHelper extends DefaultPropertiesPersister { - private static Logger logger = Logger.getLogger(XMLPropertiesHelper.class); - - public XMLPropertiesHelper() { - } - - @Override - public void loadFromXml(Properties properties, InputStream inputStream) - throws IOException { - try { - DocumentBuilderFactory xmlDocumentBuilderFactory = DocumentBuilderFactory.newInstance(); - xmlDocumentBuilderFactory.setIgnoringComments(true); - xmlDocumentBuilderFactory.setNamespaceAware(true); - DocumentBuilder xmlDocumentBuilder = xmlDocumentBuilderFactory.newDocumentBuilder(); - Document xmlDocument = xmlDocumentBuilder.parse(inputStream); - if (xmlDocument != null) { - xmlDocument.getDocumentElement().normalize(); - NodeList nList = xmlDocument.getElementsByTagName("property"); - if (nList != null) { - for (int temp = 0; temp < nList.getLength(); temp++) { - Node nNode = nList.item(temp); - if (nNode.getNodeType() == Node.ELEMENT_NODE) { - Element eElement = (Element) nNode; - String propertyName = ""; - String propertyValue = ""; - if (eElement.getElementsByTagName("name") != null && eElement.getElementsByTagName("name").item(0) != null) { - propertyName = eElement.getElementsByTagName("name").item(0).getTextContent().trim(); - } - if (eElement.getElementsByTagName("value") != null && eElement.getElementsByTagName("value").item(0) != null) { - propertyValue = eElement.getElementsByTagName("value").item(0).getTextContent().trim(); - } - if (propertyName != null && !propertyName.isEmpty()) { - properties.put(propertyName, propertyValue); - } - } - } - } - } - } catch (Exception e) { - logger.error("Error loading xml properties ", e); - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java index 1e61f22..2658bcb 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApiDocConfig.java @@ -23,6 +23,7 @@ import io.swagger.jaxrs.listing.SwaggerSerializers; import io.swagger.models.Info; import io.swagger.models.License; +import org.apache.ambari.logsearch.rest.ServiceLogsResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -34,7 +35,6 @@ public class ApiDocConfig { private static final String TITLE = "Log Search REST API"; private static final String LICENSE = "Apache 2.0"; private static final String LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.html"; - private static final String RESOURCE_PACKAGE = "org.apache.ambari.logsearch.rest"; private static final String BASE_PATH = "/api/v1"; @Bean @@ -53,7 +53,7 @@ public class ApiDocConfig { beanConfig.setLicenseUrl(LICENSE_URL); beanConfig.setScan(true); beanConfig.setVersion(VERSION); - beanConfig.setResourcePackage(RESOURCE_PACKAGE); + beanConfig.setResourcePackage(ServiceLogsResource.class.getPackage().getName()); License license = new License(); license.setName(LICENSE); http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java index 756252d..3d30c2a 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/ApplicationConfig.java @@ -20,7 +20,6 @@ package org.apache.ambari.logsearch.conf; import freemarker.template.TemplateException; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.ConversionServiceFactoryBean; @@ -32,7 +31,6 @@ import java.io.IOException; import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; @Configuration -@ComponentScan("org.apache.ambari.logsearch") @PropertySource(value = {"classpath:default.properties", "classpath:"+ LOGSEARCH_PROPERTIES_FILE}) public class ApplicationConfig { http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigMapHolder.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigMapHolder.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigMapHolder.java new file mode 100644 index 0000000..29d60b2 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchConfigMapHolder.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.PropertySource; +import org.springframework.web.context.support.StandardServletEnvironment; + +import javax.inject.Inject; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + +@Configuration +public class LogSearchConfigMapHolder { + + @Inject + private Environment environment; + + private Map<String, String> logsearchProperties = new HashMap<>(); + + public Map<String, String> getLogsearchProperties() { + if (logsearchProperties.isEmpty()) { + PropertySource propertySource = ((StandardServletEnvironment) environment) + .getPropertySources().get("class path resource [" + LOGSEARCH_PROPERTIES_FILE + "]"); + setLogsearchProperties(stringifyValues(((MapPropertySource) propertySource).getSource())); + } + return logsearchProperties; + } + + public void setLogsearchProperties(Map<String, String> logsearchProperties) { + this.logsearchProperties = logsearchProperties; + } + + private Map<String, String> stringifyValues(Map<String, Object> vars) { + return vars.entrySet() + .stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> (String) e.getValue())); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpConfig.java new file mode 100644 index 0000000..4a7280d --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchHttpConfig.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + +@Configuration +public class LogSearchHttpConfig { + + @LogSearchPropertyDescription( + name = "logsearch.http.port", + description = "Log Search http port", + examples = {"61888", "8888"}, + defaultValue = "61888", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.http.port:61888}") + private int httpPort; + + @LogSearchPropertyDescription( + name = "logsearch.https.port", + description = "Log Search https port", + examples = {"61889", "8889"}, + defaultValue = "61889", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.https.port:61889}") + private int httpsPort; + + @LogSearchPropertyDescription( + name = "logsearch.protocol", + description = "Log Search Protocol (http or https)", + examples = {"http", "https"}, + defaultValue = "http", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.protocol:http}") + private String protocol; + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public int getHttpPort() { + return httpPort; + } + + public void setHttpPort(int httpPort) { + this.httpPort = httpPort; + } + + public int getHttpsPort() { + return httpsPort; + } + + public void setHttpsPort(int httpsPort) { + this.httpsPort = httpsPort; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchJerseyResourceConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchJerseyResourceConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchJerseyResourceConfig.java new file mode 100644 index 0000000..c420a24 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchJerseyResourceConfig.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.apache.ambari.logsearch.rest.ServiceLogsResource; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; + +import javax.ws.rs.ApplicationPath; + +@ApplicationPath("/api/v1") +public class LogSearchJerseyResourceConfig extends ResourceConfig { + + public LogSearchJerseyResourceConfig() { + packages(ServiceLogsResource.class.getPackage().getName()); + register(JacksonFeature.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchServletConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchServletConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchServletConfig.java new file mode 100644 index 0000000..a7a27da --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchServletConfig.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.apache.ambari.logsearch.configurer.SslConfigurer; +import org.apache.ambari.logsearch.web.listener.LogSearchSessionListener; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.glassfish.jersey.servlet.ServletContainer; +import org.glassfish.jersey.servlet.ServletProperties; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; +import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer; +import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; +import org.springframework.boot.context.embedded.jetty.JettyServerCustomizer; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.inject.Inject; +import javax.servlet.http.HttpSessionListener; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_APPLICATION_NAME; +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_SESSION_ID; + +@Configuration +public class LogSearchServletConfig { + + private static final Integer SESSION_TIMEOUT = 60 * 30; + + @Inject + private ServerProperties serverProperties; + + @Inject + private LogSearchHttpConfig logSearchHttpConfig; + + @Inject + private SslConfigurer sslConfigurer; + + @Bean + public HttpSessionListener httpSessionListener() { + return new LogSearchSessionListener(); + } + + @Bean + public ServletRegistrationBean jerseyServlet() { + ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(), "/api/v1/*"); + registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, LogSearchJerseyResourceConfig.class.getName()); + return registration; + } + + @Bean + public EmbeddedServletContainerFactory containerFactory() { + final JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory = new JettyEmbeddedServletContainerFactory() { + @Override + protected JettyEmbeddedServletContainer getJettyEmbeddedServletContainer(Server server) { + return new JettyEmbeddedServletContainer(server); + } + }; + jettyEmbeddedServletContainerFactory.setSessionTimeout(SESSION_TIMEOUT); + serverProperties.getSession().getCookie().setName(LOGSEARCH_SESSION_ID); + serverProperties.setDisplayName(LOGSEARCH_APPLICATION_NAME); + if ("https".equals(logSearchHttpConfig.getProtocol())) { + sslConfigurer.ensureStorePasswords(); + sslConfigurer.loadKeystore(); + jettyEmbeddedServletContainerFactory.addServerCustomizers((JettyServerCustomizer) server -> { + SslContextFactory sslContextFactory = sslConfigurer.getSslContextFactory(); + ServerConnector sslConnector = new ServerConnector(server, sslContextFactory); + sslConnector.setPort(logSearchHttpConfig.getHttpsPort()); + server.setConnectors(new Connector[]{sslConnector}); + }); + } else { + jettyEmbeddedServletContainerFactory.setPort(logSearchHttpConfig.getHttpPort()); + } + return jettyEmbeddedServletContainerFactory; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSpnegoConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSpnegoConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSpnegoConfig.java new file mode 100644 index 0000000..16326a6 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSpnegoConfig.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + +@Configuration +public class LogSearchSpnegoConfig { + + @LogSearchPropertyDescription( + name = "logsearch.hadoop.security.auth_to_local", + description = "Rules that will be applied on authentication names and map them into local usernames.", + examples = {"RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//", "DEFAULT"}, + defaultValue = "DEFAULT", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.hadoop.security.auth_to_local:DEFAULT}") + private String nameRules; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.token.valid.seconds", + description = "Kerberos token validity in seconds.", + examples = {"30"}, + defaultValue = "30", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.admin.kerberos.token.valid.seconds:30}") + private String tokenValid; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.cookie.domain", + description = "Domain for Kerberos cookie.", + examples = {"c6401.ambari.apache.org", "localhost"}, + defaultValue = "localhost", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.admin.kerberos.cookie.domain:localhost}") + private String cookieDomain; + + @LogSearchPropertyDescription( + name = "logsearch.admin.kerberos.cookie.path", + description = "Cookie path of the kerberos cookie", + examples = {"/"}, + defaultValue = "/", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.admin.kerberos.cookie.path:/}") + private String cookiePath; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.principal", + description = "Principal for SPNEGO authentication for Http requests", + examples = {"myu...@example.com"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.spnego.kerberos.principal:}") + private String principal; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.keytab", + description = "Keytab for SPNEGO authentication for Http requests.", + examples = {"/etc/security/keytabs/mykeytab.keytab"}, + defaultValue = "", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.spnego.kerberos.keytab:}") + private String keyTab; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.host", + description = "", + examples = {"c6401.ambari.apache.org", "localhost"}, + defaultValue = "localhost", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.spnego.kerberos.host:localhost}") + private String hostName; + + @LogSearchPropertyDescription( + name = "logsearch.spnego.kerberos.enabled", + description = "Enable SPNEGO based authentication for Log Search Server.", + examples = {"true", "false"}, + defaultValue = "false", + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.spnego.kerberos.enabled:false}") + private boolean kerberosEnabled; + + public String getNameRules() { + return nameRules; + } + + public void setNameRules(String nameRules) { + this.nameRules = nameRules; + } + + public String getTokenValid() { + return tokenValid; + } + + public void setTokenValid(String tokenValid) { + this.tokenValid = tokenValid; + } + + public String getCookieDomain() { + return cookieDomain; + } + + public void setCookieDomain(String cookieDomain) { + this.cookieDomain = cookieDomain; + } + + public String getCookiePath() { + return cookiePath; + } + + public void setCookiePath(String cookiePath) { + this.cookiePath = cookiePath; + } + + public String getPrincipal() { + return principal; + } + + public void setPrincipal(String principal) { + this.principal = principal; + } + + public String getKeyTab() { + return keyTab; + } + + public void setKeyTab(String keyTab) { + this.keyTab = keyTab; + } + + public String getHostName() { + return hostName; + } + + public void setHostName(String hostName) { + this.hostName = hostName; + } + + public boolean isKerberosEnabled() { + return kerberosEnabled; + } + + public void setKerberosEnabled(boolean kerberosEnabled) { + this.kerberosEnabled = kerberosEnabled; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java new file mode 100644 index 0000000..afa2293 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/LogSearchSslConfig.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.apache.ambari.logsearch.config.api.LogSearchPropertyDescription; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +import static org.apache.ambari.logsearch.common.LogSearchConstants.LOGSEARCH_PROPERTIES_FILE; + +@Configuration +public class LogSearchSslConfig { + + public static final String LOGSEARCH_CERT_DEFAULT_FOLDER = "/etc/ambari-logsearch-portal/conf/keys"; + public static final String LOGSEARCH_CERT_DEFAULT_ALGORITHM = "sha256WithRSA"; + public static final String CREDENTIAL_STORE_PROVIDER_PATH = "hadoop.security.credential.provider.path"; + + @LogSearchPropertyDescription( + name = "logsearch.cert.algorithm", + description = "Algorithm to generate certificates for SSL (if needed).", + examples = {"sha256WithRSA"}, + defaultValue = LOGSEARCH_CERT_DEFAULT_ALGORITHM, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.cert.algorithm:" + LOGSEARCH_CERT_DEFAULT_ALGORITHM + "}") + private String certAlgorithm; + + @LogSearchPropertyDescription( + name = "logsearch.cert.folder.location", + description = "Folder where the generated certificates (SSL) will be located. Make sure the user of Log Search Server can access it.", + examples = {"/etc/mypath/keys"}, + defaultValue = LOGSEARCH_CERT_DEFAULT_FOLDER, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${logsearch.cert.folder.location:" + LOGSEARCH_CERT_DEFAULT_FOLDER + "}") + private String certFolder; + + @LogSearchPropertyDescription( + name = CREDENTIAL_STORE_PROVIDER_PATH, + description = "Path to interrogate for protected credentials. (see: https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/CredentialProviderAPI.html)", + examples = {"localjceks://file/home/mypath/my.jceks"}, + sources = {LOGSEARCH_PROPERTIES_FILE} + ) + @Value("${hadoop.security.credential.provider.path:}") + private String credentialStoreProviderPath; + + public String getCertAlgorithm() { + return certAlgorithm; + } + + public void setCertAlgorithm(String certAlgorithm) { + this.certAlgorithm = certAlgorithm; + } + + public String getCertFolder() { + return certFolder; + } + + public void setCertFolder(String certFolder) { + this.certFolder = certFolder; + } + + public String getCredentialStoreProviderPath() { + return credentialStoreProviderPath; + } + + public void setCredentialStoreProviderPath(String credentialStoreProviderPath) { + this.credentialStoreProviderPath = credentialStoreProviderPath; + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java index 5207dd0..2758388 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java @@ -190,6 +190,9 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public RequestMatcher requestMatcher() { List<RequestMatcher> matchers = Lists.newArrayList(); + matchers.add(new AntPathRequestMatcher("/docs/**")); + matchers.add(new AntPathRequestMatcher("/swagger-ui/**")); + matchers.add(new AntPathRequestMatcher("/swagger.html")); matchers.add(new AntPathRequestMatcher("/login.html")); matchers.add(new AntPathRequestMatcher("/logout.html")); matchers.add(new AntPathRequestMatcher("/styles/**")); http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/StaticResourceConfiguration.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/StaticResourceConfiguration.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/StaticResourceConfiguration.java new file mode 100644 index 0000000..bf03aa7 --- /dev/null +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/conf/StaticResourceConfiguration.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ambari.logsearch.conf; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@EnableWebMvc +@Configuration +public class StaticResourceConfiguration extends WebMvcConfigurerAdapter { + + private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { + "classpath:/static/", "classpath:/swagger/","classpath:META-INF/resources/webjars/" + }; + + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("/**") + .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS); + } + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName( + "forward:/index.html"); + registry.addViewController("/docs").setViewName( + "forward:/swagger.html"); + } + +} http://git-wip-us.apache.org/repos/asf/ambari/blob/555f241c/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java index 23b7430..baf5adb 100644 --- a/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java +++ b/ambari-logsearch/ambari-logsearch-server/src/main/java/org/apache/ambari/logsearch/configurer/LogSearchConfigConfigurer.java @@ -23,7 +23,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; -import org.apache.ambari.logsearch.common.PropertiesHelper; +import org.apache.ambari.logsearch.conf.LogSearchConfigMapHolder; import org.apache.ambari.logsearch.conf.global.LogSearchConfigState; import org.apache.ambari.logsearch.config.api.LogSearchConfigFactory; import org.apache.ambari.logsearch.config.api.LogSearchConfigServer; @@ -44,7 +44,10 @@ public class LogSearchConfigConfigurer implements Configurer { @Inject private LogSearchConfigState logSearchConfigState; - + + @Inject + private LogSearchConfigMapHolder logSearchConfigMapHolder; + @PostConstruct @Override public void start() { @@ -54,7 +57,7 @@ public class LogSearchConfigConfigurer implements Configurer { logger.info("Started thread to set up log search config"); while (true) { try { - logSearchConfig = LogSearchConfigFactory.createLogSearchConfigServer(PropertiesHelper.getProperties(), + logSearchConfig = LogSearchConfigFactory.createLogSearchConfigServer(logSearchConfigMapHolder.getLogsearchProperties(), LogSearchConfigServerZK.class); logSearchConfigState.setLogSearchConfigAvailable(true); break; @@ -68,4 +71,5 @@ public class LogSearchConfigConfigurer implements Configurer { setupThread.setDaemon(true); setupThread.start(); } + }