Repository: incubator-zeppelin Updated Branches: refs/heads/master ed1b080c3 -> 566ffd0b9
[ZEPPELIN-715]Provide version information ### What is this PR for? Provides version information from it's REST api, GUI and command line ### What type of PR is it? Feature ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-715 ### How should this be tested? - unit test - runtime checking ### Screenshots (if appropriate) - REST API  - GUI  - Command line  Author: Minwoo Kang <minwoo.k...@outlook.com> Closes #792 from mwkang/ZEPPELIN-715 and squashes the following commits: 6829aaf [Minwoo Kang] [ZEPPELIN-715]Changed the command line arguments d054227 [Minwoo Kang] [ZEPPELIN-715]Provide version information d60f41a [Minwoo Kang] [ZEPPELIN-715]Provide version information (add ASF licenses, fix style) 1b34004 [Minwoo Kang] [ZEPPELIN-715]Provide version information (add ASF licenses) c185a03 [Minwoo Kang] [ZEPPELIN-715]Provide version information (fix style) f5b2e66 [Minwoo Kang] [ZEPPELIN-715]Provide version information Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/566ffd0b Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/566ffd0b Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/566ffd0b Branch: refs/heads/master Commit: 566ffd0b9ce348e1189fbdb8a723967c4ebd5be3 Parents: ed1b080 Author: Minwoo Kang <minwoo.k...@outlook.com> Authored: Thu Mar 24 12:27:18 2016 +0900 Committer: Lee moon soo <m...@apache.org> Committed: Fri Mar 25 21:26:26 2016 -0700 ---------------------------------------------------------------------- bin/common.sh | 12 ++++++ bin/interpreter.sh | 6 ++- bin/zeppelin-daemon.sh | 7 +++- bin/zeppelin.sh | 4 ++ .../apache/zeppelin/rest/ZeppelinRestApi.java | 9 +++++ .../apache/zeppelin/utils/CommandLineUtils.java | 41 ++++++++++++++++++++ zeppelin-web/src/app/home/home.controller.js | 13 ++++++- zeppelin-web/src/app/home/home.html | 2 +- zeppelin-zengine/pom.xml | 9 +++++ .../java/org/apache/zeppelin/util/Util.java | 28 +++++++++++++ .../src/main/resources/project.properties | 19 +++++++++ .../java/org/apache/zeppelin/util/UtilTest.java | 6 +++ 12 files changed, 152 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/bin/common.sh ---------------------------------------------------------------------- diff --git a/bin/common.sh b/bin/common.sh index 542d515..4d575e8 100644 --- a/bin/common.sh +++ b/bin/common.sh @@ -81,6 +81,18 @@ function addJarInDir(){ fi } +ZEPPELIN_COMMANDLINE_MAIN=org.apache.zeppelin.utils.CommandLineUtils + +function getZeppelinVersion(){ + if [[ -d "${ZEPPELIN_HOME}/zeppelin-server/target/classes" ]]; then + ZEPPELIN_CLASSPATH+=":${ZEPPELIN_HOME}/zeppelin-server/target/classes" + fi + addJarInDir "${ZEPPELIN_HOME}/zeppelin-server/target/lib" + CLASSPATH+=":${ZEPPELIN_CLASSPATH}" + $ZEPPELIN_RUNNER -cp $CLASSPATH $ZEPPELIN_COMMANDLINE_MAIN -v + exit 0 +} + # Text encoding for # read/write job into files, # receiving/displaying query/result. http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/bin/interpreter.sh ---------------------------------------------------------------------- diff --git a/bin/interpreter.sh b/bin/interpreter.sh index 62deba1..18e1540 100755 --- a/bin/interpreter.sh +++ b/bin/interpreter.sh @@ -23,7 +23,7 @@ function usage() { echo "usage) $0 -p <port> -d <interpreter dir to load> -l <local interpreter repo dir to load>" } -while getopts "hp:d:l:" o; do +while getopts "hp:d:l:v" o; do case ${o} in h) usage @@ -38,6 +38,10 @@ while getopts "hp:d:l:" o; do l) LOCAL_INTERPRETER_REPO=${OPTARG} ;; + v) + . "${bin}/common.sh" + getZeppelinVersion + ;; esac done http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/bin/zeppelin-daemon.sh ---------------------------------------------------------------------- diff --git a/bin/zeppelin-daemon.sh b/bin/zeppelin-daemon.sh index 56b3c9b..c1d5ef2 100755 --- a/bin/zeppelin-daemon.sh +++ b/bin/zeppelin-daemon.sh @@ -19,7 +19,9 @@ # description: Start and stop daemon script for. # -USAGE="Usage: zeppelin-daemon.sh [--config <conf-dir>] {start|stop|upstart|restart|reload|status}" +USAGE="-e Usage: zeppelin-daemon.sh\n\t + [--config <conf-dir>] {start|stop|upstart|restart|reload|status}\n\t + [--version | -v]" if [[ "$1" == "--config" ]]; then shift @@ -258,6 +260,9 @@ case "${1}" in status) find_zeppelin_process ;; + -v | --version) + getZeppelinVersion + ;; *) echo ${USAGE} esac http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/bin/zeppelin.sh ---------------------------------------------------------------------- diff --git a/bin/zeppelin.sh b/bin/zeppelin.sh index 2fc5303..e93c715 100755 --- a/bin/zeppelin.sh +++ b/bin/zeppelin.sh @@ -39,6 +39,10 @@ bin=$(cd "${bin}">/dev/null; pwd) . "${bin}/common.sh" +if [ "$1" == "--version" ] || [ "$1" == "-v" ]; then + getZeppelinVersion +fi + HOSTNAME=$(hostname) ZEPPELIN_LOGFILE="${ZEPPELIN_LOG_DIR}/zeppelin-${ZEPPELIN_IDENT_STRING}-${HOSTNAME}.log" LOG="${ZEPPELIN_LOG_DIR}/zeppelin-cli-${ZEPPELIN_IDENT_STRING}-${HOSTNAME}.out" http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/ZeppelinRestApi.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/ZeppelinRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/ZeppelinRestApi.java index 9a0b883..ca42e34 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/ZeppelinRestApi.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/ZeppelinRestApi.java @@ -17,6 +17,9 @@ package org.apache.zeppelin.rest; +import org.apache.zeppelin.server.JsonResponse; +import org.apache.zeppelin.util.Util; + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.core.Response; @@ -41,4 +44,10 @@ public class ZeppelinRestApi { public Response getRoot() { return Response.ok().build(); } + + @GET + @Path("version") + public Response getVersion() { + return new JsonResponse<>(Response.Status.OK, "Zeppelin version", Util.getVersion()).build(); + } } http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java new file mode 100644 index 0000000..93b3628 --- /dev/null +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java @@ -0,0 +1,41 @@ +/* + * 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.zeppelin.utils; + +import org.apache.zeppelin.util.Util; + +import java.util.Locale; + +/** + * CommandLine Support Class + */ +public class CommandLineUtils { + public static void main(String[] args) { + if (args.length == 0) { + return; + } + + String usage = args[0].toLowerCase(Locale.US); + switch (usage){ + case "--version": + case "-v": + System.out.println(Util.getVersion()); + break; + default: + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-web/src/app/home/home.controller.js ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/home/home.controller.js b/zeppelin-web/src/app/home/home.controller.js index 6f7f909..e57a983 100644 --- a/zeppelin-web/src/app/home/home.controller.js +++ b/zeppelin-web/src/app/home/home.controller.js @@ -13,7 +13,7 @@ */ 'use strict'; -angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, notebookListDataFactory, websocketMsgSrv, $rootScope, arrayOrderingSrv) { +angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, notebookListDataFactory, websocketMsgSrv, $rootScope, arrayOrderingSrv, $http, baseUrlSrv) { var vm = this; vm.notes = notebookListDataFactory; vm.websocketMsgSrv = websocketMsgSrv; @@ -23,9 +23,20 @@ angular.module('zeppelinWebApp').controller('HomeCtrl', function($scope, noteboo vm.staticHome = false; $scope.isReloading = false; + + var getZeppelinVersion = function() { + $http.get(baseUrlSrv.getRestApiBase() +'/version'). + success(function (data, status, headers, config) { + $scope.zeppelinVersion = data.body; + }). + error(function(data, status, headers, config) { + console.log('Error %o %o', status, data.message); + }); + }; var initHome = function() { websocketMsgSrv.getHomeNotebook(); + getZeppelinVersion(); }; initHome(); http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-web/src/app/home/home.html ---------------------------------------------------------------------- diff --git a/zeppelin-web/src/app/home/home.html b/zeppelin-web/src/app/home/home.html index 8818edc..439dfa6 100644 --- a/zeppelin-web/src/app/home/home.html +++ b/zeppelin-web/src/app/home/home.html @@ -19,7 +19,7 @@ limitations under the License. </div> <div style="margin-top: -380px;"> <h1 class="box-heading" id="welcome"> - Welcome to Zeppelin! + Welcome to Zeppelin! <small>({{zeppelinVersion}})</small> </h1> Zeppelin is web-based notebook that enables interactive data analytics.<br> You can make beautiful data-driven, interactive, collaborative document with SQL, code and even more!<br> http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-zengine/pom.xml ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/pom.xml b/zeppelin-zengine/pom.xml index 33fee21..10a69a4 100644 --- a/zeppelin-zengine/pom.xml +++ b/zeppelin-zengine/pom.xml @@ -222,4 +222,13 @@ </dependency> </dependencies> + + <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java index fc19d0f..f9dec0f 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/util/Util.java @@ -17,14 +17,32 @@ package org.apache.zeppelin.util; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Properties; /** * TODO(moon) : add description. */ public class Util { + private static final String PROJECT_PROPERTIES_VERSION_KEY = "version"; + + private static Properties projectProperties; + + static { + projectProperties = new Properties(); + try { + projectProperties.load(Util.class.getResourceAsStream("/project.properties")); + } catch (IOException e) { + //Fail to read project.properties + } + } public static String[] split(String str, char split) { return split(str, new String[] {String.valueOf(split)}, false); @@ -181,4 +199,14 @@ public class Util { return false; } } + + /** + * Get Zeppelin version + * + * @return Current Zeppelin version + */ + public static String getVersion() { + return StringUtils.defaultIfEmpty(projectProperties.getProperty(PROJECT_PROPERTIES_VERSION_KEY), + StringUtils.EMPTY); + } } http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-zengine/src/main/resources/project.properties ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/resources/project.properties b/zeppelin-zengine/src/main/resources/project.properties new file mode 100644 index 0000000..9716b27 --- /dev/null +++ b/zeppelin-zengine/src/main/resources/project.properties @@ -0,0 +1,19 @@ +# +# 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. +# + +version=${project.version} +artifactId=${project.artifactId} http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/566ffd0b/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java index e96c824..713166d 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/util/UtilTest.java @@ -97,4 +97,10 @@ public class UtilTest extends TestCase { assertEquals("array <STRUCT<STRING>> tags", t[0]); assertEquals("aa", t[2]); } + + public void testGetVersion(){ + String version = Util.getVersion(); + assertNotNull(version); + System.out.println(version); + } }