Search in sources :

Example 1 with WebappInstance

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);
    });
}
Also used : Scanner(io.datarouter.scanner.Scanner) DatarouterServerTypeSupplier(io.datarouter.storage.config.properties.DatarouterServerTypeSupplier) ServerTypes(io.datarouter.storage.servertype.ServerTypes) ServerType(io.datarouter.storage.servertype.ServerType) ClusterSettingFinder(io.datarouter.clustersetting.ClusterSettingFinder) CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) DatarouterClusterSettingLogDao(io.datarouter.clustersetting.storage.clustersettinglog.DatarouterClusterSettingLogDao) Singleton(javax.inject.Singleton) DatarouterClusterSettingRoot(io.datarouter.clustersetting.config.DatarouterClusterSettingRoot) ServerName(io.datarouter.storage.config.properties.ServerName) Function(java.util.function.Function) DatarouterSettingTag(io.datarouter.storage.setting.DatarouterSettingTag) ClusterSettingScope(io.datarouter.clustersetting.ClusterSettingScope) ClusterSettingAndValidityJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingAndValidityJspDto) Inject(javax.inject.Inject) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) CachedClusterSettingTags(io.datarouter.storage.setting.cached.CachedClusterSettingTags) Map(java.util.Map) KeyRangeTool(io.datarouter.storage.util.KeyRangeTool) SettingRootFinder(io.datarouter.storage.setting.SettingRoot.SettingRootFinder) ClusterSettingScopeComparator(io.datarouter.clustersetting.ClusterSettingScopeComparator) DefaultSettingValue(io.datarouter.storage.setting.DefaultSettingValue) WebappInstanceService(io.datarouter.webappinstance.service.WebappInstanceService) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) ClusterSettingValidity(io.datarouter.clustersetting.ClusterSettingValidity) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance) StringTool(io.datarouter.util.string.StringTool) Objects(java.util.Objects) Range(io.datarouter.util.tuple.Range) List(java.util.List) EnvironmentName(io.datarouter.storage.config.properties.EnvironmentName) ClusterSettingComparisonTool(io.datarouter.clustersetting.ClusterSettingComparisonTool) DatarouterClusterSettingDao(io.datarouter.clustersetting.storage.clustersetting.DatarouterClusterSettingDao) DatarouterEnvironmentTypeSupplier(io.datarouter.storage.config.properties.DatarouterEnvironmentTypeSupplier) BooleanTool(io.datarouter.util.BooleanTool) Optional(java.util.Optional) DatarouterWebappInstanceDao(io.datarouter.webappinstance.storage.webappinstance.DatarouterWebappInstanceDao) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) ClusterSettingAndValidityJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingAndValidityJspDto) ClusterSettingValidity(io.datarouter.clustersetting.ClusterSettingValidity) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance)

Example 2 with WebappInstance

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);
    }
}
Also used : Instant(java.time.Instant) DatarouterDuration(io.datarouter.util.duration.DatarouterDuration) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance)

Example 3 with WebappInstance

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);
}
Also used : Twin(io.datarouter.util.tuple.Twin) TagCreator.text(j2html.TagCreator.text) TagCreator.body(j2html.TagCreator.body) DatarouterHtmlEmailService(io.datarouter.web.email.DatarouterHtmlEmailService) DatarouterWebappInstanceSettingRoot(io.datarouter.webappinstance.config.DatarouterWebappInstanceSettingRoot) J2HtmlEmailTableColumn(io.datarouter.email.html.J2HtmlEmailTable.J2HtmlEmailTableColumn) DatarouterWebappInstancePaths(io.datarouter.webappinstance.config.DatarouterWebappInstancePaths) Inject(javax.inject.Inject) WebappInstanceService(io.datarouter.webappinstance.service.WebappInstanceService) ServerTypeDetector(io.datarouter.storage.servertype.ServerTypeDetector) J2HtmlEmailTable(io.datarouter.email.html.J2HtmlEmailTable) BaseJob(io.datarouter.job.BaseJob) StandardDatarouterEmailHeaderService(io.datarouter.web.email.StandardDatarouterEmailHeaderService) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance) Instant(java.time.Instant) DatarouterDuration(io.datarouter.util.duration.DatarouterDuration) ZoneId(java.time.ZoneId) ContainerTag(j2html.tags.ContainerTag) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) DefaultEmailDistributionListZoneId(io.datarouter.web.config.properties.DefaultEmailDistributionListZoneId) WebappInstanceAlertEmailType(io.datarouter.email.type.DatarouterEmailTypes.WebappInstanceAlertEmailType) DomContent(j2html.tags.DomContent) List(java.util.List) TagCreator.div(j2html.TagCreator.div) ZoneId(java.time.ZoneId) DefaultEmailDistributionListZoneId(io.datarouter.web.config.properties.DefaultEmailDistributionListZoneId) J2HtmlEmailTableColumn(io.datarouter.email.html.J2HtmlEmailTable.J2HtmlEmailTableColumn) Twin(io.datarouter.util.tuple.Twin)

Example 4 with WebappInstance

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;
}
Also used : WebappInstanceDto(io.datarouter.instrumentation.webappinstance.WebappInstanceDto) WebappInstanceLog(io.datarouter.webappinstance.storage.webappinstancelog.WebappInstanceLog) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance)

Example 5 with 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;
}
Also used : TagCreator.text(j2html.TagCreator.text) Scanner(io.datarouter.scanner.Scanner) CurrentUserSessionInfoService(io.datarouter.web.user.session.CurrentUserSessionInfoService) DateTool(io.datarouter.util.DateTool) Date(java.util.Date) DatarouterWebappInstanceFiles(io.datarouter.webappinstance.config.DatarouterWebappInstanceFiles) DatarouterWebappInstancePaths(io.datarouter.webappinstance.config.DatarouterWebappInstancePaths) Function(java.util.function.Function) Inject(javax.inject.Inject) OneTimeLoginService(io.datarouter.webappinstance.service.OneTimeLoginService) Duration(java.time.Duration) Map(java.util.Map) TagCreator.ul(j2html.TagCreator.ul) WebappInstanceUpdateJob(io.datarouter.webappinstance.job.WebappInstanceUpdateJob) TagCreator.span(j2html.TagCreator.span) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.strong(j2html.TagCreator.strong) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance) Instant(java.time.Instant) TagCreator.a(j2html.TagCreator.a) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ContainerTag(j2html.tags.ContainerTag) Objects(java.util.Objects) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) List(java.util.List) BaseHandler(io.datarouter.web.handler.BaseHandler) TagCreator.li(j2html.TagCreator.li) Entry(java.util.Map.Entry) Optional(java.util.Optional) WebappInstanceCommitIdLink(io.datarouter.webappinstance.service.WebappInstanceCommitIdLink) Comparator(java.util.Comparator) WebappInstanceBuildIdLink(io.datarouter.webappinstance.service.WebappInstanceBuildIdLink) DatarouterWebappInstanceDao(io.datarouter.webappinstance.storage.webappinstance.DatarouterWebappInstanceDao) Session(io.datarouter.web.user.session.service.Session) Mav(io.datarouter.web.handler.mav.Mav) ZoneId(java.time.ZoneId) WebappInstance(io.datarouter.webappinstance.storage.webappinstance.WebappInstance) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

WebappInstance (io.datarouter.webappinstance.storage.webappinstance.WebappInstance)6 Instant (java.time.Instant)4 List (java.util.List)3 Inject (javax.inject.Inject)3 Scanner (io.datarouter.scanner.Scanner)2 DatarouterDuration (io.datarouter.util.duration.DatarouterDuration)2 ZonedDateFormatterTool (io.datarouter.util.time.ZonedDateFormatterTool)2 WebappInstanceService (io.datarouter.webappinstance.service.WebappInstanceService)2 ClusterSettingComparisonTool (io.datarouter.clustersetting.ClusterSettingComparisonTool)1 ClusterSettingFinder (io.datarouter.clustersetting.ClusterSettingFinder)1 ClusterSettingScope (io.datarouter.clustersetting.ClusterSettingScope)1 ClusterSettingScopeComparator (io.datarouter.clustersetting.ClusterSettingScopeComparator)1 ClusterSettingValidity (io.datarouter.clustersetting.ClusterSettingValidity)1 DatarouterClusterSettingRoot (io.datarouter.clustersetting.config.DatarouterClusterSettingRoot)1 ClusterSetting (io.datarouter.clustersetting.storage.clustersetting.ClusterSetting)1 ClusterSettingKey (io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey)1 DatarouterClusterSettingDao (io.datarouter.clustersetting.storage.clustersetting.DatarouterClusterSettingDao)1 DatarouterClusterSettingLogDao (io.datarouter.clustersetting.storage.clustersettinglog.DatarouterClusterSettingLogDao)1 ClusterSettingAndValidityJspDto (io.datarouter.clustersetting.web.dto.ClusterSettingAndValidityJspDto)1 J2HtmlEmailTable (io.datarouter.email.html.J2HtmlEmailTable)1