use of io.datarouter.webappinstance.storage.webappinstance.WebappInstance in project datarouter by hotpads.
the class ClusterSettingService method scanClusterSettingAndValidityWithPrefix.
public Scanner<ClusterSettingAndValidityJspDto> scanClusterSettingAndValidityWithPrefix(String prefix) {
WebappInstance currentWebappInstance = webappInstanceDao.get(webappInstanceService.buildCurrentWebappInstanceKey());
Range<ClusterSettingKey> range = prefix == null ? Range.everything() : KeyRangeTool.forPrefixWithWildcard(prefix, name -> new ClusterSettingKey(name, null, null, null));
return clusterSettingDao.scan(range).map(setting -> {
ClusterSettingValidity validity = getValidityForWebappInstance(setting, currentWebappInstance);
return new ClusterSettingAndValidityJspDto(setting, validity);
});
}
use of io.datarouter.webappinstance.storage.webappinstance.WebappInstance in project datarouter by hotpads.
the class WebappInstanceAlertJob method run.
@Override
public void run(TaskTracker tracker) {
WebappInstance webappInstance = webappInstanceService.buildCurrentWebappInstance();
Instant build = webappInstance.getBuildInstant();
DatarouterDuration buildAge = DatarouterDuration.age(build);
if (buildAge.isLongerThan(settings.staleWebappInstanceThreshold.get())) {
sendEmail(webappInstance, buildAge);
}
}
use of io.datarouter.webappinstance.storage.webappinstance.WebappInstance in project datarouter by hotpads.
the class WebappInstanceAlertJob method makeContent.
private ContainerTag<?> makeContent(WebappInstance webappInstance, DatarouterDuration buildAge) {
ZoneId zoneId = defaultDistributionListZoneId.get();
var rows = List.of(new Twin<>("webapp", webappInstance.getKey().getWebappName()), new Twin<>("build date", ZonedDateFormatterTool.formatInstantWithZone(webappInstance.getBuildInstant(), zoneId)), new Twin<>("build age", buildAge.toString()), new Twin<>("startup date", ZonedDateFormatterTool.formatInstantWithZone(webappInstance.getStartupInstant(), zoneId)), new Twin<>("commitId", webappInstance.getCommitId()));
return new J2HtmlEmailTable<Twin<String>>().withColumn(new J2HtmlEmailTableColumn<>(null, row -> makeDivBoldRight(row.getLeft()))).withColumn(new J2HtmlEmailTableColumn<>(null, row -> text(row.getRight()))).build(rows);
}
use of io.datarouter.webappinstance.storage.webappinstance.WebappInstance in project datarouter by hotpads.
the class WebappInstanceService method updateWebappInstanceTable.
public WebappInstance updateWebappInstanceTable() {
String buildId = buildProperties.getBuildId();
String commitId = gitProperties.getIdAbbrev().orElse(GitProperties.UNKNOWN_STRING);
Counters.inc("App heartbeat " + serverType.getServerTypeString());
Counters.inc("App heartbeat type-build " + serverType.getServerTypeString() + " " + buildId);
Counters.inc("App heartbeat type-commit " + serverType.getServerTypeString() + " " + commitId);
Counters.inc("App heartbeat build " + buildId);
Counters.inc("App heartbeat commit " + commitId);
WebappInstance webappInstance = buildCurrentWebappInstance();
webappInstanceDao.put(webappInstance);
webappInstanceLogDao.put(new WebappInstanceLog(webappInstance));
if (settings.webappInstancePublisher.get()) {
WebappInstanceDto dto = webappInstance.toDto();
webappInstancePublisher.add(dto);
}
return webappInstance;
}
use of io.datarouter.webappinstance.storage.webappinstance.WebappInstance in project datarouter by hotpads.
the class WebappInstanceHandler method view.
@Handler(defaultHandler = true)
public Mav view() {
Mav mav = new Mav(files.jsp.admin.datarouter.webappInstances.webappInstanceJsp);
List<WebappInstance> webappInstances = dao.scan().sort(Comparator.comparing(webappInstance -> webappInstance.getKey().getServerName())).list();
if (webappInstances.isEmpty()) {
return mav;
}
Map<String, String> mostPopularCommitIdByWebapp = webappInstances.stream().collect(Collectors.groupingBy(instance -> instance.getKey().getWebappName(), Collectors.collectingAndThen(Collectors.toList(), instances -> getMostCommonValue(instances, WebappInstance::getCommitId))));
ZoneId zoneId = currentSessionInfoService.getZoneId(request);
var webappStats = new UsageStatsJspDto(webappInstances, instance -> instance.getKey().getWebappName());
var buildIdStats = new UsageStatsJspDto(webappInstances, WebappInstance::getBuildId, Optional.of(buildIdLink.getLinkPrefix()));
var commitIdStats = new UsageStatsJspDto(webappInstances, WebappInstance::getCommitId, Optional.of(commitIdLink.getLinkPrefix()));
var publicIpStats = new UsageStatsJspDto(webappInstances, WebappInstance::getServerPublicIp);
var buildDateStats = new UsageStatsJspDto(webappInstances, webappInstance -> ZonedDateFormatterTool.formatInstantWithZone(webappInstance.getBuildInstant(), zoneId));
var javaVersionStats = new UsageStatsJspDto(webappInstances, WebappInstance::getJavaVersion);
var lastUpdatedStats = new UsageStatsJspDto(webappInstances, WebappInstance::getRefreshedLastInstant);
var servletVersionStats = new UsageStatsJspDto(webappInstances, WebappInstance::getServletContainerVersion);
List<WebappInstanceJspDto> dtos = Scanner.of(webappInstances).map(instance -> new WebappInstanceJspDto(instance, !Objects.equals(buildIdStats.getMostCommon(), instance.getBuildId()), !mostPopularCommitIdByWebapp.get(instance.getKey().getWebappName()).equals(instance.getCommitId()), !javaVersionStats.getMostCommon().equals(instance.getJavaVersion()), !servletVersionStats.getMostCommon().equals(instance.getServletContainerVersion()), buildIdLink.getLinkPrefix(), commitIdLink.getLinkPrefix(), zoneId)).list();
mav.put("webappInstances", dtos);
mav.put("webappStats", webappStats);
mav.put("buildIdStats", buildIdStats);
mav.put("commitIdStats", commitIdStats);
mav.put("publicIpStats", publicIpStats);
mav.put("buildDateStats", buildDateStats);
mav.put("javaVersionStats", javaVersionStats);
mav.put("lastUpdatedStats", lastUpdatedStats);
mav.put("servletVersionStats", servletVersionStats);
mav.put("uri", request.getRequestURI());
mav.put("logPath", paths.datarouter.webappInstanceLog.toSlashedString());
return mav;
}
Aggregations