mirror of
https://github.com/apache/druid.git
synced 2025-02-09 03:24:55 +00:00
server versions with loaded extensions versions
This commit is contained in:
parent
abf417a1c4
commit
95fafe02a7
@ -66,4 +66,18 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -20,12 +20,19 @@
|
|||||||
package io.druid.server;
|
package io.druid.server;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import io.druid.initialization.DruidModule;
|
||||||
|
import io.druid.initialization.Initialization;
|
||||||
|
import io.druid.server.initialization.ExtensionsConfig;
|
||||||
|
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,22 +45,44 @@ public class StatusResource
|
|||||||
public Status doGet()
|
public Status doGet()
|
||||||
{
|
{
|
||||||
return new Status(
|
return new Status(
|
||||||
getMavenVersion("io.druid","druid-server"),
|
getVersion("/druid-server.version"),
|
||||||
|
getVersion("/druid-api.version"),
|
||||||
|
getExtensionVersions(),
|
||||||
new Memory(Runtime.getRuntime())
|
new Memory(Runtime.getRuntime())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMavenVersion(String groupId, String artifactId){
|
/**
|
||||||
|
* Load the extensions list and return the implementation-versions
|
||||||
|
*
|
||||||
|
* @return map of extensions loaded with their respective implementation versions.
|
||||||
|
*/
|
||||||
|
private Map<String, String> getExtensionVersions()
|
||||||
|
{
|
||||||
|
final Injector injector = Initialization.makeStartupInjector();
|
||||||
|
final ExtensionsConfig config = injector.getInstance(ExtensionsConfig.class);
|
||||||
|
final List<DruidModule> druidModules = Initialization.getFromExtensions(config, DruidModule.class);
|
||||||
|
Map<String, String> moduleVersions = new HashMap<>();
|
||||||
|
for (DruidModule module : druidModules) {
|
||||||
|
Package pkg = module.getClass().getPackage();
|
||||||
|
moduleVersions.put(pkg.getImplementationTitle(), pkg.getImplementationVersion());
|
||||||
|
}
|
||||||
|
return moduleVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load properties files from the classpath and return version number
|
||||||
|
*
|
||||||
|
* @param versionFile
|
||||||
|
*
|
||||||
|
* @return version number
|
||||||
|
*/
|
||||||
|
private String getVersion(String versionFile)
|
||||||
|
{
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
InputStream is = StatusResource.class.getClassLoader().getResourceAsStream(
|
InputStream is = StatusResource.class.getResourceAsStream(versionFile);
|
||||||
String.format(
|
|
||||||
"META-INF/maven/%s/%s/pom.properties",
|
|
||||||
groupId,
|
|
||||||
artifactId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (is == null) {
|
if (is == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -65,20 +94,42 @@ public class StatusResource
|
|||||||
return properties.getProperty("version");
|
return properties.getProperty("version");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Status {
|
public static class Status
|
||||||
final String version;
|
{
|
||||||
|
final String serverVersion;
|
||||||
|
final String apiVersion;
|
||||||
|
final Map<String, String> extensionsVersion;
|
||||||
final Memory memory;
|
final Memory memory;
|
||||||
|
|
||||||
public Status(String version, Memory memory)
|
public Status(
|
||||||
|
String serverVersion,
|
||||||
|
String apiVersion,
|
||||||
|
Map<String, String> extensionsVersion,
|
||||||
|
Memory memory
|
||||||
|
)
|
||||||
{
|
{
|
||||||
this.version = version;
|
this.serverVersion = serverVersion;
|
||||||
|
this.apiVersion = apiVersion;
|
||||||
|
this.extensionsVersion = extensionsVersion;
|
||||||
this.memory = memory;
|
this.memory = memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
public String getVersion()
|
public String getServerVersion()
|
||||||
{
|
{
|
||||||
return version;
|
return serverVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public String getApiVersion()
|
||||||
|
{
|
||||||
|
return apiVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public Map<String, String> getExtensionsVersion()
|
||||||
|
{
|
||||||
|
return extensionsVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@ -88,13 +139,15 @@ public class StatusResource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Memory {
|
public static class Memory
|
||||||
|
{
|
||||||
final long maxMemory;
|
final long maxMemory;
|
||||||
final long totalMemory;
|
final long totalMemory;
|
||||||
final long freeMemory;
|
final long freeMemory;
|
||||||
final long usedMemory;
|
final long usedMemory;
|
||||||
|
|
||||||
public Memory(Runtime runtime) {
|
public Memory(Runtime runtime)
|
||||||
|
{
|
||||||
maxMemory = runtime.maxMemory();
|
maxMemory = runtime.maxMemory();
|
||||||
totalMemory = runtime.totalMemory();
|
totalMemory = runtime.totalMemory();
|
||||||
freeMemory = runtime.freeMemory();
|
freeMemory = runtime.freeMemory();
|
||||||
|
3
server/src/main/resources/druid-server.version
Normal file
3
server/src/main/resources/druid-server.version
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version=${pom.version}
|
||||||
|
groupId=${pom.groupId}
|
||||||
|
artifactId=${pom.artifactId}
|
Loading…
x
Reference in New Issue
Block a user