mirror of https://github.com/apache/druid.git
implementing comments from review
This commit is contained in:
parent
65facc935d
commit
3752122a7b
|
@ -84,6 +84,7 @@ import java.net.URI;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -101,21 +102,23 @@ public class Initialization
|
|||
"io.druid",
|
||||
"com.metamx.druid"
|
||||
);
|
||||
private static List loadedDruidModules = Lists.newArrayList();
|
||||
private final static Map<Class, Set> extensionsMap = Maps.<Class, Set>newHashMap();
|
||||
|
||||
/**
|
||||
* @return List of {@link DruidModule}, once loaded.
|
||||
*/
|
||||
public static List getLoadedDruidModules()
|
||||
* @param clazz Module class
|
||||
* @param <T>
|
||||
* @return Returns the set of modules loaded.
|
||||
*/
|
||||
public static<T> Set<T> getLoadedModules(Class<T> clazz)
|
||||
{
|
||||
return loadedDruidModules;
|
||||
return extensionsMap.get(clazz);
|
||||
}
|
||||
|
||||
|
||||
public synchronized static <T> List<T> getFromExtensions(ExtensionsConfig config, Class<T> clazz)
|
||||
public synchronized static <T> Collection<T> getFromExtensions(ExtensionsConfig config, Class<T> clazz)
|
||||
{
|
||||
final TeslaAether aether = getAetherClient(config);
|
||||
List<T> retVal = Lists.newArrayList();
|
||||
Set<T> retVal = Sets.newHashSet();
|
||||
|
||||
if (config.searchCurrentClassloader()) {
|
||||
for (T module : ServiceLoader.load(clazz, Initialization.class.getClassLoader())) {
|
||||
|
@ -141,9 +144,8 @@ public class Initialization
|
|||
}
|
||||
}
|
||||
|
||||
if (clazz.equals(DruidModule.class)){
|
||||
loadedDruidModules.addAll(retVal);
|
||||
}
|
||||
// update the map with currently loaded modules
|
||||
extensionsMap.put(clazz, retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.ws.rs.Path;
|
|||
import javax.ws.rs.Produces;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -39,35 +40,7 @@ public class StatusResource
|
|||
@Produces("application/json")
|
||||
public Status doGet()
|
||||
{
|
||||
return getStatus();
|
||||
}
|
||||
|
||||
public static Status getStatus()
|
||||
{
|
||||
return new Status(
|
||||
Initialization.class.getPackage().getImplementationVersion(),
|
||||
getExtensionVersions(),
|
||||
new Memory(Runtime.getRuntime())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the unique extensions and return their implementation-versions
|
||||
*
|
||||
* @return map of extensions loaded with their respective implementation versions.
|
||||
*/
|
||||
private static List<ModuleVersion> getExtensionVersions()
|
||||
{
|
||||
final List<DruidModule> druidModules = Initialization.getLoadedDruidModules();
|
||||
|
||||
List<ModuleVersion> moduleVersions = new ArrayList<>();
|
||||
for (DruidModule module : druidModules) {
|
||||
String artifact = module.getClass().getPackage().getImplementationTitle();
|
||||
String version = module.getClass().getPackage().getImplementationVersion();
|
||||
|
||||
moduleVersions.add(new ModuleVersion(module.getClass().getCanonicalName(), artifact, version));
|
||||
}
|
||||
return moduleVersions;
|
||||
return new Status();
|
||||
}
|
||||
|
||||
public static class Status
|
||||
|
@ -76,13 +49,11 @@ public class StatusResource
|
|||
final List<ModuleVersion> modules;
|
||||
final Memory memory;
|
||||
|
||||
public Status(
|
||||
String version, List<ModuleVersion> modules, Memory memory
|
||||
)
|
||||
public Status()
|
||||
{
|
||||
this.version = version;
|
||||
this.modules = modules;
|
||||
this.memory = memory;
|
||||
this.version = Status.class.getPackage().getImplementationVersion();
|
||||
this.modules = getExtensionVersions();
|
||||
this.memory = new Memory(Runtime.getRuntime());
|
||||
}
|
||||
|
||||
@JsonProperty
|
||||
|
@ -121,6 +92,25 @@ public class StatusResource
|
|||
}
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the unique extensions and return their implementation-versions
|
||||
*
|
||||
* @return map of extensions loaded with their respective implementation versions.
|
||||
*/
|
||||
private List<ModuleVersion> getExtensionVersions()
|
||||
{
|
||||
final Set<DruidModule> druidModules = Initialization.getLoadedModules(DruidModule.class);
|
||||
List<ModuleVersion> moduleVersions = new ArrayList<>();
|
||||
for (DruidModule module : druidModules) {
|
||||
String artifact = module.getClass().getPackage().getImplementationTitle();
|
||||
String version = module.getClass().getPackage().getImplementationVersion();
|
||||
|
||||
moduleVersions.add(new ModuleVersion(module.getClass().getCanonicalName(), artifact, version));
|
||||
}
|
||||
return moduleVersions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
|
|
|
@ -30,6 +30,7 @@ import io.druid.server.initialization.ExtensionsConfig;
|
|||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -75,7 +76,7 @@ public class Main
|
|||
|
||||
final Injector injector = Initialization.makeStartupInjector();
|
||||
final ExtensionsConfig config = injector.getInstance(ExtensionsConfig.class);
|
||||
final List<CliCommandCreator> extensionCommands = Initialization.getFromExtensions(config, CliCommandCreator.class);
|
||||
final Collection<CliCommandCreator> extensionCommands = Initialization.getFromExtensions(config, CliCommandCreator.class);
|
||||
|
||||
for (CliCommandCreator creator : extensionCommands) {
|
||||
creator.addCommands(builder);
|
||||
|
|
|
@ -31,6 +31,6 @@ public class Version implements Runnable
|
|||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.println(StatusResource.getStatus());
|
||||
System.out.println(new StatusResource.Status());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue