You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/11/17 10:44:21 UTC
ambari git commit: AMBARI-18909. Log Search - make logsearch rest api
docs as default under /docs/ instead of petstore (oleewere)
Repository: ambari
Updated Branches:
refs/heads/trunk 07bdabdd0 -> 323628c9b
AMBARI-18909. Log Search - make logsearch rest api docs as default under /docs/ instead of petstore (oleewere)
Change-Id: Iadae048f94d71c7e284debabca0d1f8bd54710da
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/323628c9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/323628c9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/323628c9
Branch: refs/heads/trunk
Commit: 323628c9b118beda6591eedd89b15697da9cb036
Parents: 07bdabd
Author: oleewere <ol...@gmail.com>
Authored: Wed Nov 16 18:53:23 2016 +0100
Committer: oleewere <ol...@gmail.com>
Committed: Thu Nov 17 11:37:35 2016 +0100
----------------------------------------------------------------------
.../org/apache/ambari/logsearch/LogSearch.java | 14 ++-
.../ambari/logsearch/conf/SecurityConfig.java | 1 +
.../src/main/resources/swagger/swagger.html | 119 +++++++++++++++++++
3 files changed, 131 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/323628c9/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
index 5a7cf02..d4be790 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
@@ -45,6 +45,7 @@ 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.springframework.web.context.ContextLoaderListener;
@@ -154,9 +155,16 @@ public class LogSearch {
private ServletContextHandler createSwaggerContext() throws URISyntaxException {
ResourceHandler resourceHandler = new ResourceHandler();
- resourceHandler.setResourceBase(LogSearch.class.getClassLoader()
- .getResource("META-INF/resources/webjars/swagger-ui/2.1.0")
- .toURI().toString());
+ 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);
http://git-wip-us.apache.org/repos/asf/ambari/blob/323628c9/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
index 7a6c69c..7ffcedd 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/conf/SecurityConfig.java
@@ -131,6 +131,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
matchers.add(new AntPathRequestMatcher("/scripts/**"));
matchers.add(new AntPathRequestMatcher("/libs/**"));
matchers.add(new AntPathRequestMatcher("/templates/**"));
+ matchers.add(new AntPathRequestMatcher("/images/**"));
matchers.add(new AntPathRequestMatcher("/favicon.ico"));
matchers.add(new AntPathRequestMatcher("/api/v1/public/**"));
matchers.add(new AntPathRequestMatcher("/api/v1/swagger.json"));
http://git-wip-us.apache.org/repos/asf/ambari/blob/323628c9/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
new file mode 100644
index 0000000..e1b052a
--- /dev/null
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/swagger/swagger.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<!--
+ 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.
+-->
+<html>
+<head>
+ <title>Swagger UI</title>
+ <link rel="icon" type="image/png" href="images/favicon-32x32.png" sizes="32x32" />
+ <link rel="icon" type="image/png" href="images/favicon-16x16.png" sizes="16x16" />
+ <link href='css/typography.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
+ <link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
+ <link href='css/print.css' media='print' rel='stylesheet' type='text/css'/>
+ <script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
+ <script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
+ <script src='lib/handlebars-2.0.0.js' type='text/javascript'></script>
+ <script src='lib/underscore-min.js' type='text/javascript'></script>
+ <script src='lib/backbone-min.js' type='text/javascript'></script>
+ <script src='swagger-ui.js' type='text/javascript'></script>
+ <script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
+ <script src='lib/marked.js' type='text/javascript'></script>
+ <script src='lib/swagger-oauth.js' type='text/javascript'></script>
+
+ <script type="text/javascript">
+ $(function () {
+ var url = window.location.search.match(/url=([^&]+)/);
+ if (url && url.length > 1) {
+ url = decodeURIComponent(url[1]);
+ } else {
+ var urlPrefix = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port: '');
+ url = urlPrefix + "/api/v1/swagger.yaml";
+ }
+ window.swaggerUi = new SwaggerUi({
+ url: url,
+ dom_id: "swagger-ui-container",
+ supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
+ onComplete: function(swaggerApi, swaggerUi){
+ if(typeof initOAuth == "function") {
+ initOAuth({
+ clientId: "your-client-id",
+ realm: "your-realms",
+ appName: "your-app-name"
+ });
+ }
+
+ $('pre code').each(function(i, e) {
+ hljs.highlightBlock(e)
+ });
+
+ addApiKeyAuthorization();
+ },
+ onFailure: function(data) {
+ log("Unable to Load SwaggerUI");
+ },
+ docExpansion: "none",
+ apisSorter: "alpha",
+ showRequestHeaders: false
+ });
+
+ function addApiKeyAuthorization(){
+ var key = encodeURIComponent($('#input_apiKey')[0].value);
+ if(key && key.trim() != "") {
+ var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("api_key", key, "query");
+ window.swaggerUi.api.clientAuthorizations.add("api_key", apiKeyAuth);
+ log("added key " + key);
+ }
+ }
+
+ $('#input_apiKey').change(addApiKeyAuthorization);
+
+ // if you have an apiKey you would like to pre-populate on the page for demonstration purposes...
+ /*
+ var apiKey = "myApiKeyXXXX123456789";
+ $('#input_apiKey').val(apiKey);
+ */
+
+ window.swaggerUi.load();
+
+ function log() {
+ if ('console' in window) {
+ console.log.apply(console, arguments);
+ }
+ }
+ });
+ </script>
+</head>
+
+<body class="swagger-section">
+<div id='header'>
+ <div class="swagger-ui-wrap">
+ <a id="logo" href="http://swagger.io">swagger</a>
+ <form id='api_selector'>
+ <div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
+ <div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
+ <div class='input'><a id="explore" href="#">Explore</a></div>
+ </form>
+ </div>
+</div>
+
+<div id="message-bar" class="swagger-ui-wrap"> </div>
+<div id="swagger-ui-container" class="swagger-ui-wrap"></div>
+</body>
+</html>