Search in sources :

Example 1 with OptionalBoolean

use of io.datarouter.web.handler.types.optional.OptionalBoolean 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;
}
Also used : Scanner(io.datarouter.scanner.Scanner) ServerTypes(io.datarouter.storage.servertype.ServerTypes) ServerType(io.datarouter.storage.servertype.ServerType) ClusterSettingLogKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogKey) ObjectTool(io.datarouter.util.lang.ObjectTool) DatarouterHtmlEmailService(io.datarouter.web.email.DatarouterHtmlEmailService) ZonedDateTime(java.time.ZonedDateTime) CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) DatarouterClusterSettingRoot(io.datarouter.clustersetting.config.DatarouterClusterSettingRoot) DatarouterSettingTag(io.datarouter.storage.setting.DatarouterSettingTag) ClusterSettingLogAction(io.datarouter.clustersetting.ClusterSettingLogAction) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) ClusterSettingEmailType(io.datarouter.email.type.DatarouterEmailTypes.ClusterSettingEmailType) DatarouterServerTypeDetector(io.datarouter.storage.servertype.DatarouterServerTypeDetector) Map(java.util.Map) J2HtmlDatarouterEmailBuilder(io.datarouter.email.html.J2HtmlDatarouterEmailBuilder) SimpleSettingCategory(io.datarouter.storage.setting.SettingCategory.SimpleSettingCategory) SettingRootFinder(io.datarouter.storage.setting.SettingRoot.SettingRootFinder) ClusterSettingLogByReversedCreatedMsKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogByReversedCreatedMsKey) DatarouterEmailLinkBuilder(io.datarouter.email.email.DatarouterEmailLinkBuilder) ServerTypeDetector(io.datarouter.storage.servertype.ServerTypeDetector) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) Set(java.util.Set) ClusterSettingValidity(io.datarouter.clustersetting.ClusterSettingValidity) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ContainerTag(j2html.tags.ContainerTag) Range(io.datarouter.util.tuple.Range) List(java.util.List) Setting(io.datarouter.storage.setting.Setting) ClusterSettingLogJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingLogJspDto) SettingNode(io.datarouter.storage.setting.SettingNode) Entry(java.util.Map.Entry) Optional(java.util.Optional) DatarouterClusterSettingFiles(io.datarouter.clustersetting.config.DatarouterClusterSettingFiles) DatarouterClusterSettingPaths(io.datarouter.clustersetting.config.DatarouterClusterSettingPaths) SettingNameMatchResult(io.datarouter.clustersetting.service.ClusterSettingSearchService.SettingNameMatchResult) ClusterSettingService(io.datarouter.clustersetting.service.ClusterSettingService) TagCreator.text(j2html.TagCreator.text) SettingJspDto(io.datarouter.clustersetting.web.dto.SettingJspDto) ClusterSettingJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingJspDto) LocalDateTime(java.time.LocalDateTime) DatarouterClusterSettingLogDao(io.datarouter.clustersetting.storage.clustersettinglog.DatarouterClusterSettingLogDao) HashMap(java.util.HashMap) ClusterSettingSearchService(io.datarouter.clustersetting.service.ClusterSettingSearchService) TreeSet(java.util.TreeSet) ClusterSettingScope(io.datarouter.clustersetting.ClusterSettingScope) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) SettingRoot(io.datarouter.storage.setting.SettingRoot) CachedClusterSettingTags(io.datarouter.storage.setting.cached.CachedClusterSettingTags) SettingNodeJspDto(io.datarouter.clustersetting.web.dto.SettingNodeJspDto) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) DatarouterWebPaths(io.datarouter.web.config.DatarouterWebPaths) StandardDatarouterEmailHeaderService(io.datarouter.web.email.StandardDatarouterEmailHeaderService) Mav(io.datarouter.web.handler.mav.Mav) SettingCategory(io.datarouter.storage.setting.SettingCategory) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) DomContent(j2html.tags.DomContent) DatarouterClusterSettingDao(io.datarouter.clustersetting.storage.clustersetting.DatarouterClusterSettingDao) J2HtmlLegendTable(io.datarouter.web.html.j2html.J2HtmlLegendTable) ClusterSettingLog(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog) DateTimeFormatter(java.time.format.DateTimeFormatter) BaseHandler(io.datarouter.web.handler.BaseHandler) Comparator(java.util.Comparator) Pair(io.datarouter.util.tuple.Pair) Mav(io.datarouter.web.handler.mav.Mav) ClusterSettingLogJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingLogJspDto) ClusterSettingLogByReversedCreatedMsKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogByReversedCreatedMsKey) ZonedDateTime(java.time.ZonedDateTime) Range(io.datarouter.util.tuple.Range) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with OptionalBoolean

use of io.datarouter.web.handler.types.optional.OptionalBoolean in project datarouter by hotpads.

the class JobHandler method list.

@Handler
Mav list(OptionalString category, OptionalString keyword, OptionalBoolean enabled, OptionalBoolean disabled) {
    Optional<String> message = params.optional("jobTriggerResponseMessage");
    Mav mav = new Mav(files.jsp.admin.datarouter.job.triggersJsp);
    if (message.isPresent()) {
        mav.put("message", message.get());
    }
    Optional<String> jobCategoryName = category.getOptional();
    boolean hideEnabled = enabled.orElse(false);
    boolean hideDisabled = disabled.orElse(false);
    mav.put("serverName", serverName.get());
    mav.put("categoryRows", getJobCategoryDtos(jobCategoryName));
    LongRunningTaskSummaryDto longRunningTaskSummary = longRunningTaskService.getSummary();
    AtomicInteger rowId = new AtomicInteger();
    List<TriggerJspDto> triggerRows = jobPackageFilter.streamMatches(jobCategoryName.orElse(""), keyword.orElse(""), hideEnabled, hideDisabled).map(jobClass -> jobToTriggerJspDto(rowId.incrementAndGet(), jobClass, longRunningTaskSummary)).collect(Collectors.toList());
    mav.put("triggerRows", triggerRows);
    mav.put("legend", LongRunningTasksHandler.legend().renderFormatted());
    return mav;
}
Also used : Scanner(io.datarouter.scanner.Scanner) LongRunningTaskTrackerFactory(io.datarouter.tasktracker.service.LongRunningTaskTrackerFactory) Date(java.util.Date) JobCategoryTracker(io.datarouter.job.scheduler.JobCategoryTracker) DurationTool(io.datarouter.util.time.DurationTool) LoggerFactory(org.slf4j.LoggerFactory) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ServerName(io.datarouter.storage.config.properties.ServerName) TreeSet(java.util.TreeSet) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) Inject(javax.inject.Inject) LongRunningTaskService(io.datarouter.tasktracker.service.LongRunningTaskService) StringMav(io.datarouter.web.handler.mav.imp.StringMav) LongRunningTasksHandler(io.datarouter.tasktracker.web.LongRunningTasksHandler) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobScheduler(io.datarouter.job.scheduler.JobScheduler) Duration(java.time.Duration) JobStopperService(io.datarouter.job.service.JobStopperService) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) LongRunningTaskSummaryDto(io.datarouter.tasktracker.service.LongRunningTaskService.LongRunningTaskSummaryDto) Logger(org.slf4j.Logger) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) BaseJob(io.datarouter.job.BaseJob) DatarouterJobFiles(io.datarouter.job.config.DatarouterJobFiles) Mav(io.datarouter.web.handler.mav.Mav) Set(java.util.Set) StringTool(io.datarouter.util.string.StringTool) Collectors(java.util.stream.Collectors) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) List(java.util.List) DatarouterJobPaths(io.datarouter.job.config.DatarouterJobPaths) JobPackage(io.datarouter.job.scheduler.JobPackage) BaseHandler(io.datarouter.web.handler.BaseHandler) Optional(java.util.Optional) Require(io.datarouter.util.Require) LongRunningTask(io.datarouter.tasktracker.storage.LongRunningTask) LongRunningTaskHeartBeatStatus(io.datarouter.tasktracker.storage.LongRunningTaskHeartBeatStatus) StringMav(io.datarouter.web.handler.mav.imp.StringMav) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) Mav(io.datarouter.web.handler.mav.Mav) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) LongRunningTaskSummaryDto(io.datarouter.tasktracker.service.LongRunningTaskService.LongRunningTaskSummaryDto) LongRunningTasksHandler(io.datarouter.tasktracker.web.LongRunningTasksHandler) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with OptionalBoolean

use of io.datarouter.web.handler.types.optional.OptionalBoolean in project datarouter by hotpads.

the class S3BucketHandler method index.

@Handler(defaultHandler = true)
public Mav index(@Param(P_client) String client, @Param(P_bucket) String bucket, @Param(P_prefix) OptionalString prefix, @Param(P_after) OptionalString after, @Param(P_offset) OptionalInteger offset, @Param(P_limit) OptionalInteger limit, @Param(P_currentDirectory) OptionalBoolean currentDirectory, @Param(P_delimiter) OptionalString delimiter) {
    var form = new HtmlForm().withMethod("get");
    form.addTextField().withDisplay("Client").withName(P_client).withPlaceholder("theClientName").withValue(client);
    form.addTextField().withDisplay("Bucket").withName(P_bucket).withPlaceholder("the.bucket.name").withValue(bucket);
    form.addTextField().withDisplay("Prefix").withName(P_prefix).withValue(prefix.orElse(""));
    form.addTextField().withDisplay("After").withName(P_after).withValue(after.orElse(""));
    form.addTextField().withDisplay("Offset").withName(P_offset).withValue(offset.orElse(0) + "");
    form.addTextField().withDisplay("Limit").withName(P_limit).withValue(limit.orElse(100) + "");
    form.addTextField().withDisplay("Delimiter").withName(P_delimiter).withValue(delimiter.orElse(""));
    form.addCheckboxField().withDisplay("currentDirectory").withName(P_currentDirectory).withChecked(currentDirectory.orElse(false));
    form.addButton().withDisplay("Submit").withValue("");
    var htmlForm = Bootstrap4FormHtml.render(form).withClass("card card-body bg-light");
    ClientId clientId = clients.getClientId(client);
    DatarouterS3Client s3Client = s3ClientManager.getClient(clientId);
    List<DirectoryDto> objects = s3Client.scanSubdirectories(bucket, prefix.orElse(null), after.orElse(null), delimiter.orElse(null), limit.orElse(100), currentDirectory.orElse(false)).list();
    int sizePadding = sizePadding(objects);
    ContainerTag<?> table = new J2HtmlTable<DirectoryDto>().withClasses("sortable table table-sm table-striped my-4 border").withHtmlColumn("Key", object -> {
        String name = object.name;
        if (object.isDirectory) {
            return td(makePrefixLink(client, bucket, name, "/"));
        }
        return td(name);
    }).withHtmlColumn("Directory", object -> {
        boolean isDirectory = object.isDirectory;
        if (isDirectory) {
            String href = new URIBuilder().setPath(request.getContextPath() + paths.datarouter.clients.awsS3.countObjects.toSlashedString()).addParameter(P_client, client).addParameter(P_bucket, bucket).addParameter(P_prefix, object.name).toString();
            return td(a("true, view count").withHref(href));
        }
        return td(String.valueOf(isDirectory));
    }).withHtmlColumn("Size", object -> {
        String commas = NumberFormatter.addCommas(object.size);
        String padded = StringTool.pad(commas, ' ', sizePadding);
        String escaped = padded.replaceAll(" ", "&nbsp;");
        return td(rawHtml(escaped));
    }).withColumn("Last Modified", object -> object.lastModified).withColumn("Storage Class", object -> object.storageClass).build(objects);
    ContainerTag<?> tableWrapper = table.withStyle("font-family:monospace; font-size:.9em;");
    var content = div(htmlForm, h4(bucket), tableWrapper).withClass("container-fluid my-4");
    return pageFactory.startBuilder(request).withTitle("S3 Bucket").withRequires(DatarouterWebRequireJsV2.SORTTABLE).withContent(content).buildMav();
}
Also used : Scanner(io.datarouter.scanner.Scanner) DatarouterS3Client(io.datarouter.aws.s3.DatarouterS3Client) LoggerFactory(org.slf4j.LoggerFactory) TagCreator.h4(j2html.TagCreator.h4) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) AtomicReference(java.util.concurrent.atomic.AtomicReference) S3ClientManager(io.datarouter.aws.s3.client.S3ClientManager) Inject(javax.inject.Inject) NumberFormatter(io.datarouter.util.number.NumberFormatter) DatarouterWebRequireJsV2(io.datarouter.web.requirejs.DatarouterWebRequireJsV2) ClientId(io.datarouter.storage.client.ClientId) Param(io.datarouter.web.handler.types.Param) Bootstrap4FormHtml(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4FormHtml) OptionalInteger(io.datarouter.web.handler.types.optional.OptionalInteger) J2HtmlTable(io.datarouter.web.html.j2html.J2HtmlTable) DatarouterClients(io.datarouter.storage.client.DatarouterClients) TagCreator.rawHtml(j2html.TagCreator.rawHtml) Logger(org.slf4j.Logger) URIBuilder(org.apache.http.client.utils.URIBuilder) DatarouterAwsS3Paths(io.datarouter.aws.s3.config.DatarouterAwsS3Paths) Mav(io.datarouter.web.handler.mav.Mav) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) ContainerTag(j2html.tags.ContainerTag) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) DirectoryDto(io.datarouter.storage.node.op.raw.read.DirectoryDto) HtmlForm(io.datarouter.web.html.form.HtmlForm) TagCreator.td(j2html.TagCreator.td) BaseHandler(io.datarouter.web.handler.BaseHandler) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) Comparator(java.util.Comparator) TagCreator.div(j2html.TagCreator.div) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) URIBuilder(org.apache.http.client.utils.URIBuilder) DirectoryDto(io.datarouter.storage.node.op.raw.read.DirectoryDto) HtmlForm(io.datarouter.web.html.form.HtmlForm) DatarouterS3Client(io.datarouter.aws.s3.DatarouterS3Client) ClientId(io.datarouter.storage.client.ClientId) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with OptionalBoolean

use of io.datarouter.web.handler.types.optional.OptionalBoolean in project datarouter by hotpads.

the class DatarouterSnapshotBenchmarkHandler method defaultHandler.

@Handler(defaultHandler = true)
public Mav defaultHandler(@Param(P_group) OptionalString optGroup, @Param(P_numEntries) OptionalString optNumEntries, @Param(P_persist) OptionalBoolean optPersist, @Param(P_delete) OptionalBoolean optDelete, @Param(P_submitAction) OptionalString submitAction) {
    SnapshotGroup group = null;
    String errorGroup = null;
    if (optGroup.isPresent()) {
        try {
            group = Require.notNull(groups.getGroup(optGroup.get()));
        } catch (Exception e) {
            errorGroup = "Group not found";
        }
    }
    long numEntries = DEFAULT_NUM_ENTRIES;
    String errorNumEntries = null;
    try {
        numEntries = optNumEntries.map(Long::valueOf).orElse(numEntries);
    } catch (Exception e) {
        errorNumEntries = "Must be an integer (long) number";
    }
    boolean persist = DEFAULT_PERSIST;
    String errorPersist = null;
    try {
        persist = optPersist.map(Boolean::valueOf).orElse(persist);
    } catch (Exception e) {
        errorPersist = "Must be \"true\" or \"false\"";
    }
    boolean delete = DEFAULT_DELETE;
    String errorDelete = null;
    try {
        delete = optDelete.map(Boolean::valueOf).orElse(delete);
    } catch (Exception e) {
        errorDelete = "Must be \"true\" or \"false\"";
    }
    var form = new HtmlForm().withMethod("post");
    form.addTextField().withDisplay("Group").withError(errorGroup).withName(P_group).withPlaceholder("group").withValue(optGroup.orElse(null));
    form.addTextField().withDisplay("Num Entries").withError(errorNumEntries).withName(P_numEntries).withPlaceholder("numEntries").withValue(numEntries + "");
    form.addTextField().withDisplay("Persist").withError(errorPersist).withName(P_persist).withPlaceholder("true").withValue(persist + "");
    form.addTextField().withDisplay("Delete").withError(errorDelete).withName(P_delete).withPlaceholder("true").withValue(persist + "");
    form.addButton().withDisplay("Run").withValue("anything");
    if (submitAction.isEmpty() || form.hasErrors()) {
        return pageFactory.startBuilder(request).withTitle("Datarouter Filesystem - Benchmark").withContent(Html.makeContent(form)).buildMav();
    }
    int numInputThreads = Runtime.getRuntime().availableProcessors();
    int numWriterThreads = Runtime.getRuntime().availableProcessors();
    var benchmark = new SnapshotBenchmark(group, numInputThreads, numWriterThreads, numEntries, 10_000, persist);
    benchmark.execute();
    if (persist && delete) {
        benchmark.cleanup();
    }
    benchmark.shutdown();
    return pageFactory.message(request, "Complete.  See logs for output");
}
Also used : SnapshotBenchmark(io.datarouter.filesystem.snapshot.benchmark.SnapshotBenchmark) HtmlForm(io.datarouter.web.html.form.HtmlForm) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) SnapshotGroup(io.datarouter.filesystem.snapshot.group.SnapshotGroup) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

BaseHandler (io.datarouter.web.handler.BaseHandler)4 OptionalBoolean (io.datarouter.web.handler.types.optional.OptionalBoolean)4 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)4 Scanner (io.datarouter.scanner.Scanner)3 StringTool (io.datarouter.util.string.StringTool)3 Mav (io.datarouter.web.handler.mav.Mav)3 List (java.util.List)3 Inject (javax.inject.Inject)3 ChangelogRecorder (io.datarouter.instrumentation.changelog.ChangelogRecorder)2 DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)2 TagCreator.a (j2html.TagCreator.a)2 ContainerTag (j2html.tags.ContainerTag)2 Comparator (java.util.Comparator)2 Optional (java.util.Optional)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DatarouterS3Client (io.datarouter.aws.s3.DatarouterS3Client)1