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;
}
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;
}
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(" ", " ");
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();
}
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");
}
Aggregations