mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-26 16:30:50 +01:00
Improve server config documentation and cleanup
This commit is contained in:
committed by
René Pfeuffer
parent
abe0a62cb4
commit
d0c43dd9f4
@@ -60,12 +60,12 @@ public class LoggingConfiguration {
|
||||
root.setLevel(Level.valueOf(config.getRootLevel()));
|
||||
configureSpecificLoggers();
|
||||
|
||||
if (config.isEnableFileAppender()) {
|
||||
if (config.isFileAppenderEnabled()) {
|
||||
RollingFileAppender fileAppender = configureFileLogger();
|
||||
root.addAppender(fileAppender);
|
||||
}
|
||||
|
||||
if (config.isEnableConsoleAppender()) {
|
||||
if (config.isConsoleAppenderEnabled()) {
|
||||
ConsoleAppender consoleAppender = configureConsoleLogger();
|
||||
root.addAppender(consoleAppender);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class ServerConfigYaml {
|
||||
private String logDir = "";
|
||||
private String rootLevel = "INFO";
|
||||
private Map<String, String> logger = new HashMap<>();
|
||||
private boolean enableFileAppender = true;
|
||||
private boolean enableConsoleAppender = true;
|
||||
private boolean fileAppenderEnabled = true;
|
||||
private boolean consoleAppenderEnabled = true;
|
||||
|
||||
private LogConfig() {}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ServerConfigYaml {
|
||||
continue;
|
||||
}
|
||||
String[] envLoggerEntryParts = envLoggerEntry.trim().split(":");
|
||||
loggerMap.put(envLoggerEntryParts[0], envLoggerEntryParts[1]);
|
||||
loggerMap.put(envLoggerEntryParts[0].trim(), envLoggerEntryParts[1].trim());
|
||||
}
|
||||
return loggerMap;
|
||||
}
|
||||
@@ -82,20 +82,20 @@ public class ServerConfigYaml {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public boolean isEnableFileAppender() {
|
||||
return getEnvWithDefault("LOG_ENABLE_FILE_APPENDER", enableFileAppender);
|
||||
public boolean isFileAppenderEnabled() {
|
||||
return getEnvWithDefault("LOG_FILE_APPENDER_ENABLED", fileAppenderEnabled);
|
||||
}
|
||||
|
||||
public void setEnableFileAppender(boolean enableFileAppender) {
|
||||
this.enableFileAppender = enableFileAppender;
|
||||
public void setFileAppenderEnabled(boolean fileAppenderEnabled) {
|
||||
this.fileAppenderEnabled = fileAppenderEnabled;
|
||||
}
|
||||
|
||||
public boolean isEnableConsoleAppender() {
|
||||
return getEnvWithDefault("LOG_ENABLE_CONSOLE_APPENDER", enableConsoleAppender);
|
||||
public boolean isConsoleAppenderEnabled() {
|
||||
return getEnvWithDefault("LOG_CONSOLE_APPENDER_ENABLED", consoleAppenderEnabled);
|
||||
}
|
||||
|
||||
public void setEnableConsoleAppender(boolean enableConsoleAppender) {
|
||||
this.enableConsoleAppender = enableConsoleAppender;
|
||||
public void setConsoleAppenderEnabled(boolean consoleAppenderEnabled) {
|
||||
this.consoleAppenderEnabled = consoleAppenderEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@ import sonia.scm.plugin.InstalledPluginDescriptor;
|
||||
import sonia.scm.plugin.PluginException;
|
||||
import sonia.scm.plugin.PluginLoadException;
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.plugin.PluginTransformException;
|
||||
import sonia.scm.plugin.PluginTransformer;
|
||||
import sonia.scm.plugin.PluginsInternal;
|
||||
import sonia.scm.plugin.SmpArchive;
|
||||
import sonia.scm.util.IOUtil;
|
||||
@@ -109,35 +107,12 @@ public final class PluginBootstrap {
|
||||
LOG.info("core plugin extraction is disabled");
|
||||
}
|
||||
uninstallMarkedPlugins(pluginDirectory.toPath());
|
||||
transformIncompatiblePlugins(pluginDirectory.toPath());
|
||||
return PluginsInternal.collectPlugins(classLoaderLifeCycle, pluginDirectory.toPath());
|
||||
} catch (IOException ex) {
|
||||
throw new PluginLoadException("could not load plugins", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void transformIncompatiblePlugins(Path pluginsDirectory) {
|
||||
try (Stream<Path> list = java.nio.file.Files.list(pluginsDirectory)) {
|
||||
list
|
||||
.filter(java.nio.file.Files::isDirectory)
|
||||
.filter(this::isIncompatiblePlugin)
|
||||
.forEach(plugin -> {
|
||||
PluginTransformer.transform(plugin);
|
||||
try {
|
||||
Files.touch(plugin.resolve(InstalledPlugin.COMPATIBILITY_MARKER_FILENAME).toFile());
|
||||
} catch (IOException e) {
|
||||
throw new PluginTransformException("Failed to create marker file for jakarta compatibility", e);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
LOG.warn("error occurred while checking for plugins that should be transformed", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isIncompatiblePlugin(Path path) {
|
||||
return !new File(path.toFile(), InstalledPlugin.COMPATIBILITY_MARKER_FILENAME).exists();
|
||||
}
|
||||
|
||||
private void uninstallMarkedPlugins(Path pluginDirectory) {
|
||||
try (Stream<Path> list = java.nio.file.Files.list(pluginDirectory)) {
|
||||
list
|
||||
|
||||
@@ -54,7 +54,7 @@ public class PluginWizardStartupAction implements InitializationStep {
|
||||
|
||||
@Override
|
||||
public boolean done() {
|
||||
return WebappConfigProvider.resolveAsString("initialPassword").orElse(null) != null || store.getPluginSets().isPresent();
|
||||
return WebappConfigProvider.resolveAsString("initialPassword").isPresent() || store.getPluginSets().isPresent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,7 +70,11 @@ public class ConfigurationResolver {
|
||||
Map<String, String> configurationFile = new HashMap<>();
|
||||
rootNode.fields().forEachRemaining(entry -> {
|
||||
if (entry.getValue().isValueNode()) {
|
||||
configurationFile.put(prefix + entry.getKey(), entry.getValue().asText());
|
||||
if (entry.getValue().isNull()) {
|
||||
configurationFile.put(prefix + entry.getKey(), null);
|
||||
} else {
|
||||
configurationFile.put(prefix + entry.getKey(), entry.getValue().asText());
|
||||
}
|
||||
} else {
|
||||
configurationFile.putAll(readConfigurationFile(entry.getValue(), prefix + entry.getKey() + "."));
|
||||
}
|
||||
|
||||
@@ -44,20 +44,17 @@ import java.util.Objects;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class ExplodedSmp
|
||||
{
|
||||
public final class ExplodedSmp {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExplodedSmp.class);
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param path
|
||||
* @param plugin
|
||||
*/
|
||||
ExplodedSmp(Path path, InstalledPluginDescriptor plugin)
|
||||
{
|
||||
ExplodedSmp(Path path, InstalledPluginDescriptor plugin) {
|
||||
logger.trace("create exploded scm for plugin {} and dependencies {}", plugin.getInformation().getName(), plugin.getDependencies());
|
||||
this.path = path;
|
||||
this.plugin = plugin;
|
||||
@@ -68,16 +65,12 @@ public final class ExplodedSmp
|
||||
/**
|
||||
* Creates a new ExplodedSmp object.
|
||||
*
|
||||
*
|
||||
* @param directory directory containing an extracted SCM-Manager plugin.
|
||||
*
|
||||
* @return ExplodedSmp object
|
||||
*
|
||||
* @throws PluginException if the path does not contain an plugin descriptor
|
||||
* or the plugin descriptor could not be parsed
|
||||
* or the plugin descriptor could not be parsed
|
||||
*/
|
||||
public static ExplodedSmp create(Path directory)
|
||||
{
|
||||
public static ExplodedSmp create(Path directory) {
|
||||
Path desc = directory.resolve(PluginConstants.FILE_DESCRIPTOR);
|
||||
|
||||
return new ExplodedSmp(directory, Plugins.parsePluginDescriptor(desc));
|
||||
@@ -87,6 +80,7 @@ public final class ExplodedSmp
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the exploded smp contains a core plugin
|
||||
*
|
||||
* @return {@code true} for a core plugin
|
||||
* @since 2.30.0
|
||||
*/
|
||||
@@ -98,22 +92,18 @@ public final class ExplodedSmp
|
||||
/**
|
||||
* Returns the path to the plugin directory.
|
||||
*
|
||||
*
|
||||
* @return to plugin directory
|
||||
*/
|
||||
public Path getPath()
|
||||
{
|
||||
public Path getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns parsed plugin descriptor.
|
||||
*
|
||||
*
|
||||
* @return plugin descriptor
|
||||
*/
|
||||
public InstalledPluginDescriptor getPlugin()
|
||||
{
|
||||
public InstalledPluginDescriptor getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@@ -141,24 +131,19 @@ public final class ExplodedSmp
|
||||
/**
|
||||
* Transforms {@link Path} to {@link ExplodedSmp}.
|
||||
*/
|
||||
public static class PathTransformer implements Function<Path, ExplodedSmp>
|
||||
{
|
||||
public static class PathTransformer implements Function<Path, ExplodedSmp> {
|
||||
|
||||
/**
|
||||
* Transforms {@link Path} to {@link ExplodedSmp}. The path must contain an
|
||||
* extracted SCM-Manager plugin.
|
||||
*
|
||||
*
|
||||
* @param directory directory containing exploded plugin
|
||||
*
|
||||
* @return exploded smp object
|
||||
*
|
||||
* @throws PluginException if the path does not contain an extracted
|
||||
* SCM-Manager plugin.
|
||||
* SCM-Manager plugin.
|
||||
*/
|
||||
@Override
|
||||
public ExplodedSmp apply(Path directory)
|
||||
{
|
||||
public ExplodedSmp apply(Path directory) {
|
||||
return ExplodedSmp.create(directory);
|
||||
}
|
||||
}
|
||||
@@ -166,9 +151,13 @@ public final class ExplodedSmp
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** directory */
|
||||
/**
|
||||
* directory
|
||||
*/
|
||||
private final Path path;
|
||||
|
||||
/** plugin object */
|
||||
/**
|
||||
* plugin object
|
||||
*/
|
||||
private final InstalledPluginDescriptor plugin;
|
||||
}
|
||||
|
||||
@@ -174,13 +174,22 @@ public final class PluginProcessor
|
||||
Set<ExplodedSmp> installedPlugins = findInstalledPlugins();
|
||||
logger.debug("found {} installed plugins", installedPlugins.size());
|
||||
|
||||
for (ExplodedSmp installedPlugin : installedPlugins) {
|
||||
if (installedPlugin.getPlugin().getScmVersion() < 3) {
|
||||
logger.debug("start jakarta transformation of already installed plugin: {}", installedPlugin.getPlugin().getInformation().getName());
|
||||
PluginTransformer.transform(installedPlugin.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
Set<ExplodedSmp> newlyInstalledPlugins = installPending(installedPlugins);
|
||||
logger.debug("finished installation of {} plugins", newlyInstalledPlugins.size());
|
||||
|
||||
for (ExplodedSmp newInstalledSmp : newlyInstalledPlugins) {
|
||||
PluginTransformer.transform(newInstalledSmp.getPath());
|
||||
if (newInstalledSmp.getPlugin().getScmVersion() < 3) {
|
||||
logger.debug("start jakarta transformation of newly installed smp: {}", newInstalledSmp.getPlugin().getInformation().getName());
|
||||
PluginTransformer.transform(newInstalledSmp.getPath());
|
||||
}
|
||||
}
|
||||
logger.debug("finished jakarta transformation of {} plugins", newlyInstalledPlugins.size());
|
||||
|
||||
Set<ExplodedSmp> plugins = concat(installedPlugins, newlyInstalledPlugins);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class PluginTree {
|
||||
|
||||
private static final int SCM_VERSION = 2;
|
||||
private static final int SCM_VERSION = 3;
|
||||
|
||||
/**
|
||||
* the logger for PluginTree
|
||||
@@ -72,16 +72,6 @@ public final class PluginTree {
|
||||
|
||||
private void checkIfSupported(ExplodedSmp smp) {
|
||||
InstalledPluginDescriptor plugin = smp.getPlugin();
|
||||
|
||||
if (plugin.getScmVersion() != SCM_VERSION) {
|
||||
throw new PluginException(
|
||||
String.format(
|
||||
"scm version %s of plugin %s does not match, required is version %s",
|
||||
plugin.getScmVersion(), plugin.getInformation().getId(), SCM_VERSION
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
checkIfConditionsMatch(smp, plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,9 @@ import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class PluginsInternal
|
||||
{
|
||||
public final class PluginsInternal {
|
||||
|
||||
/**
|
||||
* the logger for PluginsInternal
|
||||
@@ -51,30 +49,27 @@ public final class PluginsInternal
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(PluginsInternal.class);
|
||||
|
||||
private PluginsInternal() {}
|
||||
private PluginsInternal() {
|
||||
}
|
||||
|
||||
public static Set<InstalledPlugin> collectPlugins(ClassLoaderLifeCycle classLoaderLifeCycle,
|
||||
Path directory)
|
||||
throws IOException
|
||||
{
|
||||
throws IOException {
|
||||
PluginProcessor processor = new PluginProcessor(classLoaderLifeCycle, directory);
|
||||
|
||||
return processor.collectPlugins(classLoaderLifeCycle.getBootstrapClassLoader());
|
||||
}
|
||||
|
||||
public static File createPluginDirectory(File parent, InstalledPluginDescriptor plugin)
|
||||
{
|
||||
public static File createPluginDirectory(File parent, InstalledPluginDescriptor plugin) {
|
||||
PluginInformation info = plugin.getInformation();
|
||||
|
||||
return new File(parent, info.getName());
|
||||
}
|
||||
|
||||
public static void extract(SmpArchive archive, String checksum,
|
||||
File directory, File checksumFile, boolean core)
|
||||
throws IOException
|
||||
{
|
||||
if (directory.exists())
|
||||
{
|
||||
File directory, File checksumFile, boolean core)
|
||||
throws IOException {
|
||||
if (directory.exists()) {
|
||||
logger.debug("delete directory {} for plugin extraction",
|
||||
archive.getPlugin().getInformation().getName(false));
|
||||
IOUtil.delete(directory);
|
||||
@@ -87,31 +82,25 @@ public final class PluginsInternal
|
||||
archive.extract(directory);
|
||||
Files.write(checksum, checksumFile, Charsets.UTF_8);
|
||||
|
||||
if (core)
|
||||
{
|
||||
if (!new File(directory, PluginConstants.FILE_CORE).createNewFile())
|
||||
{
|
||||
if (core) {
|
||||
if (!new File(directory, PluginConstants.FILE_CORE).createNewFile()) {
|
||||
throw new IOException("could not create core plugin marker");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterable<InstalledPluginDescriptor> unwrap(Iterable<InstalledPlugin> wrapped)
|
||||
{
|
||||
public static Iterable<InstalledPluginDescriptor> unwrap(Iterable<InstalledPlugin> wrapped) {
|
||||
return Iterables.transform(wrapped, new Unwrap());
|
||||
}
|
||||
|
||||
public static File getChecksumFile(File pluginDirectory)
|
||||
{
|
||||
public static File getChecksumFile(File pluginDirectory) {
|
||||
return new File(pluginDirectory, PluginConstants.FILE_CHECKSUM);
|
||||
}
|
||||
|
||||
private static class Unwrap implements Function<InstalledPlugin, InstalledPluginDescriptor>
|
||||
{
|
||||
private static class Unwrap implements Function<InstalledPlugin, InstalledPluginDescriptor> {
|
||||
|
||||
@Override
|
||||
public InstalledPluginDescriptor apply(InstalledPlugin wrapper)
|
||||
{
|
||||
@Override
|
||||
public InstalledPluginDescriptor apply(InstalledPlugin wrapper) {
|
||||
return wrapper.getDescriptor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DefaultCentralWorkQueue implements CentralWorkQueue, Closeable {
|
||||
|
||||
@Inject
|
||||
public DefaultCentralWorkQueue(
|
||||
@ConfigValue(key = "centralWorkQueue.workers", defaultValue = "8", description = "") Integer workers,
|
||||
@ConfigValue(key = "centralWorkQueue.workers", defaultValue = "0", description = "Sets the number of threads for the central work queue. If set to 0, the default will be used.") Integer workers,
|
||||
Injector injector,
|
||||
Persistence persistence,
|
||||
MeterRegistry meterRegistry
|
||||
|
||||
@@ -34,11 +34,8 @@ public class ThreadCountProvider implements IntSupplier {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ThreadCountProvider.class);
|
||||
|
||||
@VisibleForTesting
|
||||
static final String PROPERTY = "scm.central-work-queue.workers";
|
||||
|
||||
private final IntSupplier cpuCountProvider;
|
||||
private final Integer workers;
|
||||
private final int workers;
|
||||
|
||||
public ThreadCountProvider(Integer workers) {
|
||||
this(() -> Runtime.getRuntime().availableProcessors(), workers);
|
||||
@@ -47,18 +44,24 @@ public class ThreadCountProvider implements IntSupplier {
|
||||
@VisibleForTesting
|
||||
ThreadCountProvider(IntSupplier cpuCountProvider, Integer workers) {
|
||||
this.cpuCountProvider = cpuCountProvider;
|
||||
this.workers = workers;
|
||||
this.workers = sanitizeWorkerCount(workers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAsInt() {
|
||||
if (isInvalid(workers)) {
|
||||
return workers;
|
||||
}
|
||||
|
||||
private int sanitizeWorkerCount(Integer workers) {
|
||||
if (workers == null || workers == 0) {
|
||||
return deriveFromCPUCount();
|
||||
} else if (isInvalid(workers)) {
|
||||
LOG.warn(
|
||||
"config value {} contains a invalid value {}, fall back and derive worker count from cpu count",
|
||||
"central-work-queue.workers", workers
|
||||
"config value 'centralWorkQueue.workers' contains an invalid value {}, fall back and derive worker count from cpu count", workers
|
||||
);
|
||||
return deriveFromCPUCount();
|
||||
}
|
||||
LOG.debug("using {} workers for central work queue", workers);
|
||||
return workers;
|
||||
}
|
||||
|
||||
@@ -69,8 +72,10 @@ public class ThreadCountProvider implements IntSupplier {
|
||||
private int deriveFromCPUCount() {
|
||||
int cpus = cpuCountProvider.getAsInt();
|
||||
if (cpus > 1) {
|
||||
LOG.debug("using 4 workers for central work queue");
|
||||
return 4;
|
||||
}
|
||||
LOG.debug("using 2 workers for central work queue");
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user