mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
[ZEPPELIN-2622] Add Zeppelin Git info REST API
This commit is contained in:
parent
43926485cd
commit
75795f1520
6 changed files with 154 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -122,3 +122,6 @@ tramp
|
|||
|
||||
# tmp files
|
||||
/tmp/
|
||||
|
||||
# Git properties
|
||||
**/git.properties
|
||||
|
|
|
|||
|
|
@ -33,6 +33,79 @@ If you work with Apache Zeppelin and find a need for an additional REST API, ple
|
|||
|
||||
## Zeppelin Server REST API list
|
||||
|
||||
### Get Zeppelin version
|
||||
<table class="table-configuration">
|
||||
<col width="200">
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td>This ```GET``` method returns Zeppelin version</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>URL</td>
|
||||
<td>```http://[zeppelin-server]:[zeppelin-port]/api/version```</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Success code</td>
|
||||
<td>200</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Fail code</td>
|
||||
<td> 500 </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON response
|
||||
</td>
|
||||
<td>
|
||||
<pre>
|
||||
{
|
||||
"status": "OK",
|
||||
"message": "Zeppelin version",
|
||||
"body": "0.8.0-SNAPSHOT"
|
||||
}
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Get Zeppelin git info
|
||||
<table class="table-configuration">
|
||||
<col width="200">
|
||||
<tr>
|
||||
<td>Description</td>
|
||||
<td>This ```GET``` method returns Zeppelin Git info</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>URL</td>
|
||||
<td>```http://[zeppelin-server]:[zeppelin-port]/api/git```</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Success code</td>
|
||||
<td>200</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> Fail code</td>
|
||||
<td> 500 </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> sample JSON response
|
||||
</td>
|
||||
<td>
|
||||
<pre>
|
||||
{
|
||||
"status": "OK",
|
||||
"message": "Zeppelin Git Info",
|
||||
"body": [
|
||||
{
|
||||
"commitId": "abc0123",
|
||||
"timestamp": "2017-01-02 03:04:05"
|
||||
}
|
||||
]
|
||||
}
|
||||
</pre>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Change the log level of Zeppelin Server
|
||||
<table class="table-configuration">
|
||||
<col width="200">
|
||||
|
|
|
|||
21
pom.xml
21
pom.xml
|
|
@ -519,6 +519,27 @@
|
|||
<version>${plugin.deploy.version}</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>pl.project13.maven</groupId>
|
||||
<artifactId>git-commit-id-plugin</artifactId>
|
||||
<version>2.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>revision</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<skipPoms>false</skipPoms>
|
||||
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
|
||||
<generateGitPropertiesFile>true</generateGitPropertiesFile>
|
||||
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
|
||||
<failOnNoGitDirectory>false</failOnNoGitDirectory>
|
||||
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!--TODO(alex): make part of the build and reconcile conflicts
|
||||
<plugin>
|
||||
<groupId>com.ning.maven.plugins</groupId>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@ import org.apache.zeppelin.annotation.ZeppelinApi;
|
|||
import org.apache.zeppelin.server.JsonResponse;
|
||||
import org.apache.zeppelin.util.Util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
|
|
@ -59,6 +62,17 @@ public class ZeppelinRestApi {
|
|||
return new JsonResponse<>(Response.Status.OK, "Zeppelin version", Util.getVersion()).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("git")
|
||||
@ZeppelinApi
|
||||
public Response getGitInfo() {
|
||||
Map<String, String> gitInfo = new HashMap<>();
|
||||
gitInfo.put("commitId", Util.getGitCommitId());
|
||||
gitInfo.put("timestamp", Util.getGitTimestamp());
|
||||
|
||||
return new JsonResponse<>(Response.Status.OK, "Zeppelin Git info", gitInfo).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log level for root logger
|
||||
* @param request
|
||||
|
|
|
|||
|
|
@ -27,13 +27,18 @@ import java.util.Properties;
|
|||
*/
|
||||
public class Util {
|
||||
private static final String PROJECT_PROPERTIES_VERSION_KEY = "version";
|
||||
private static final String GIT_PROPERTIES_COMMIT_ID_KEY = "git.commit.id.abbrev";
|
||||
private static final String GIT_PROPERTIES_COMMIT_TS_KEY = "git.commit.time";
|
||||
|
||||
private static Properties projectProperties;
|
||||
private static Properties gitProperties;
|
||||
|
||||
static {
|
||||
projectProperties = new Properties();
|
||||
gitProperties = new Properties();
|
||||
try {
|
||||
projectProperties.load(Util.class.getResourceAsStream("/project.properties"));
|
||||
gitProperties.load(Util.class.getResourceAsStream("/git.properties"));
|
||||
} catch (IOException e) {
|
||||
//Fail to read project.properties
|
||||
}
|
||||
|
|
@ -48,4 +53,24 @@ public class Util {
|
|||
return StringUtils.defaultIfEmpty(projectProperties.getProperty(PROJECT_PROPERTIES_VERSION_KEY),
|
||||
StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Zeppelin Git latest commit id
|
||||
*
|
||||
* @return Latest Zeppelin commit id
|
||||
*/
|
||||
public static String getGitCommitId() {
|
||||
return StringUtils.defaultIfEmpty(gitProperties.getProperty(GIT_PROPERTIES_COMMIT_ID_KEY),
|
||||
StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Zeppelin Git latest commit timestamp
|
||||
*
|
||||
* @return Latest Zeppelin commit timestamp
|
||||
*/
|
||||
public static String getGitTimestamp() {
|
||||
return StringUtils.defaultIfEmpty(gitProperties.getProperty(GIT_PROPERTIES_COMMIT_TS_KEY),
|
||||
StringUtils.EMPTY);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.zeppelin.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class UtilTest {
|
||||
|
||||
@Test
|
||||
public void getVersionTest() {
|
||||
assertNotNull(Util.getVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGitInfoTest() {
|
||||
assertNotNull(Util.getGitCommitId());
|
||||
assertNotNull(Util.getGitTimestamp());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue