use of io.datarouter.web.handler.mav.Mav in project datarouter by hotpads.
the class LoggingSettingsHandler method showForm.
@Handler(defaultHandler = true)
protected Mav showForm() {
Mav mav = new Mav(files.jsp.datarouter.loggerConfig.loggingJsp);
mav.put("rootLogger", log4j2Configurator.getRootLoggerConfig());
mav.put("levels", LEVELS);
mav.put("currentUserEmail", getCurrentUsername());
Map<String, LoggerConfig> configs = log4j2Configurator.getConfigs();
List<String> names = Scanner.of(configs.values()).map(LoggerConfig::getName).list();
Map<String, io.datarouter.loggerconfig.storage.loggerconfig.LoggerConfig> configsWithMetadata = loggerConfigDao.getLoggerConfigs(names);
Map<String, LoggerConfigMetadata> mergedConfigs = new TreeMap<>();
Map<LoggerConfigMetadata, Collection<String>> appenderMap = new HashMap<>();
for (LoggerConfig config : configs.values()) {
String name = config.getName();
io.datarouter.loggerconfig.storage.loggerconfig.LoggerConfig configWithMetadata = configsWithMetadata.get(name);
String email;
Instant lastUpdated = null;
Integer ttlMinutes = null;
boolean canDelete = true;
if (configWithMetadata != null) {
email = configWithMetadata.getEmail();
lastUpdated = configWithMetadata.getLastUpdated();
ttlMinutes = Optional.ofNullable(configWithMetadata.getTtlMillis()).map(Duration::ofMillis).map(Duration::toMinutes).map(Long::intValue).orElse(null);
} else {
email = DEFAULT_EMAIL;
canDelete = false;
}
var mergedLoggerConfig = new LoggerConfigMetadata(config, email, lastUpdated, canDelete, ttlMinutes, getUserZoneId());
mergedConfigs.put(name, mergedLoggerConfig);
appenderMap.put(mergedLoggerConfig, config.getAppenders().keySet());
}
mav.put("appenderMap", appenderMap);
mav.put("configs", mergedConfigs);
mav.put("appenders", log4j2Configurator.getAppenders());
return mav;
}
use of io.datarouter.web.handler.mav.Mav in project datarouter by hotpads.
the class LoggingSettingsHandler method editFileAppender.
@Handler
private Mav editFileAppender() {
String action = params.optional("action").orElse(null);
String name = params.optional("name").orElse(null);
if ("Create".equals(action)) {
String pattern = params.required("layout");
String fileName = params.required("fileName");
log4j2Configurator.addFileAppender(name, fileName, pattern);
fileAppenderDao.createAndputFileAppender(name, pattern, fileName);
preventSecondApply();
return getRedirectMav();
}
Mav mav = new Mav(files.jsp.datarouter.loggerConfig.fileAppenderJsp);
mav.put("name", name);
if (name != null) {
FileAppender appender = (FileAppender) log4j2Configurator.getAppender(name);
Layout<? extends Serializable> layout = appender.getLayout();
mav.put("layout", layout);
mav.put("fileName", appender.getFileName());
} else {
mav.put("layout", BaseLog4j2Configuration.DEFAULT_PATTERN);
}
recordChangelog("FileAppender", name, action);
return mav;
}
use of io.datarouter.web.handler.mav.Mav in project datarouter by hotpads.
the class ClusterSettingsHandler method browseSettings.
@Handler
public Mav browseSettings(OptionalString name) {
Mav mav = new Mav(files.jsp.admin.datarouter.setting.browseSettingsJsp);
String path = servletContext.getContextPath() + paths.datarouter.settings.customSettings.toSlashedString();
mav.put("customSettingsPath", path);
String requestedNodeName = name.orElse(settingRootFinder.getName());
mav.put("nodeName", name.orElse(""));
Map<SimpleSettingCategory, Set<SettingNodeJspDto>> categoryMap = new LinkedHashMap<>();
for (Entry<SimpleSettingCategory, Set<SettingRoot>> entry : settingRootFinder.getRootNodesByCategory().entrySet()) {
var nodes = entry.getValue().stream().map(SettingNodeJspDto::new).collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SettingNodeJspDto::getShortName))));
categoryMap.put(entry.getKey(), nodes);
}
Optional<String> currentCategory = settingRootFinder.getRootNodesByCategory().entrySet().stream().findFirst().map(Entry::getKey).map(SimpleSettingCategory::getDisplay);
mav.put("currentCategory", currentCategory.orElse(""));
mav.put("categoryMap", categoryMap);
mav.put("serverTypeOptions", serverTypes.getHtmlSelectOptionsVarNames());
Optional<SettingNode> node = getSettingNode(requestedNodeName);
// if the node was not found, get the most recent ancestor to search its settings list
boolean trySearchingForSpecificSetting = node.isEmpty();
if (trySearchingForSpecificSetting) {
node = getMostRecentAncestorSettingNode(requestedNodeName);
}
if (node.isEmpty()) {
return mav;
}
node.ifPresent(settingNode -> {
String rootName = StringTool.getStringBeforeFirstOccurrence('.', settingNode.getName());
settingRootFinder.getRootNodesSortedByShortName().stream().filter(rootNode -> rootNode.getShortName().equals(rootName)).findFirst().map(SettingRoot.class::cast).map(SettingRoot::getSettingCategory).map(SettingCategory::getDisplay).ifPresent(category -> mav.put("currentCategory", category));
mav.put("currentRootName", rootName);
});
mav.put("ancestors", Scanner.of(settingRootFinder.getDescendants(node.get().getName())).map(SettingNodeJspDto::new).list());
mav.put("currentRootName", node.get().getName().substring(0, node.get().getName().indexOf('.')));
mav.put("children", Scanner.of(node.get().getListChildren()).map(SettingNodeJspDto::new).list());
List<CachedSetting<?>> settingsList = node.get().getListSettings();
if (trySearchingForSpecificSetting) {
settingsList = settingsList.stream().filter(setting -> setting.getName().equals(requestedNodeName)).collect(Collectors.toList());
}
Map<String, List<ClusterSettingJspDto>> customSettingsByName = new HashMap<>();
for (CachedSetting<?> setting : settingsList) {
ClusterSettingKey settingKey = new ClusterSettingKey(setting.getName(), null, null, null);
List<ClusterSetting> settingsInDb = clusterSettingDao.scanWithPrefix(settingKey).list();
Optional<ClusterSetting> mostSpecificSetting = clusterSettingService.getMostSpecificClusterSetting(settingsInDb);
boolean isActive = setting.getMostSpecificDatabeanValue().isPresent();
Scanner.of(settingsInDb).map(settingFromDb -> {
boolean isWinner = mostSpecificSetting.isPresent() && settingFromDb.equals(mostSpecificSetting.get());
ClusterSettingJspDto jspDto = new ClusterSettingJspDto(settingFromDb, isActive, isWinner);
return jspDto;
}).flush(customSettings -> customSettingsByName.put(setting.getName(), customSettings));
}
mav.put("listSettings", Scanner.of(settingsList).map(SettingJspDto::new).list());
mav.put("mightBeDevelopment", datarouterServerTypeDetector.mightBeDevelopment());
mav.put("mapListsCustomSettings", customSettingsByName);
return mav;
}
use of io.datarouter.web.handler.mav.Mav in project datarouter by hotpads.
the class ClusterSettingsHandler method customSettings.
@Handler
public Mav customSettings(OptionalString prefix) {
Mav mav = new Mav(files.jsp.admin.datarouter.setting.editSettingsJsp);
mav.put("serverTypeOptions", serverTypes.getHtmlSelectOptionsVarNames());
mav.put("validities", buildLegend());
clusterSettingService.scanClusterSettingAndValidityWithPrefix(prefix.orElse(null)).flush(settings -> mav.put("rows", settings));
boolean mightBeDevelopment = datarouterServerTypeDetector.mightBeDevelopment();
mav.put("mightBeDevelopment", mightBeDevelopment);
if (mightBeDevelopment) {
mav.put("settingTagFilePath", CachedClusterSettingTags.getConfigFilePath());
List<DatarouterSettingTag> tags = cachedClusterSettingTags.get();
mav.put("settingTagValues", tags.stream().map(DatarouterSettingTag::getPersistentString).collect(Collectors.joining(",")));
}
return mav;
}
use of io.datarouter.web.handler.mav.Mav in project datarouter by hotpads.
the class ClusterSettingsHandler method logsForAll.
@Handler
public Mav logsForAll(OptionalString explicitStartIso, OptionalBoolean inclusiveStart) {
Mav mav = new Mav(files.jsp.admin.datarouter.setting.clusterSettingsLogJsp);
mav.put("showingAllSettings", true);
long startCreatedMs = explicitStartIso.map(isoDate -> LocalDateTime.parse(isoDate, DateTimeFormatter.ISO_LOCAL_DATE_TIME)).map(localDate -> localDate.atZone(ZoneId.systemDefault())).map(ZonedDateTime::toInstant).map(Instant::toEpochMilli).orElseGet(System::currentTimeMillis);
long reverseStartCreatedMs = Long.MAX_VALUE - startCreatedMs;
Range<ClusterSettingLogByReversedCreatedMsKey> range = new Range<>(new ClusterSettingLogByReversedCreatedMsKey(reverseStartCreatedMs, null), inclusiveStart.orElse(false));
clusterSettingLogDao.scanByReversedCreatedMs(range, CLUSTER_SETTING_LOGS_PAGE_SIZE).map(setting -> new ClusterSettingLogJspDto(setting, getUserZoneId())).flush(logs -> mav.put("logs", logs)).flush(logs -> mav.put("hasNextPage", logs.size() == CLUSTER_SETTING_LOGS_PAGE_SIZE));
mav.put("hasPreviousPage", explicitStartIso.isPresent());
return mav;
}
Aggregations