Search in sources :

Example 1 with HtmlForm

use of io.datarouter.web.html.form.HtmlForm in project datarouter by hotpads.

the class EditChangelogHandler method edit.

@Handler(defaultHandler = true)
public Mav edit(@Param(P_reversedDateMs) Long reversedDateMs, @Param(P_changelogType) String changelogType, @Param(P_name) String name, @Param(P_note) OptionalString note, @Param(P_submitAction) OptionalString submitAction) {
    ChangelogKey key = new ChangelogKey(reversedDateMs, changelogType, name);
    Changelog changelog = dao.get(key);
    var table = new J2HtmlLegendTable().withClass("table table-sm border table-striped").withSingleRow(false).withEntry("Date", getDate(changelog)).withEntry("Changelog Type", changelog.getKey().getChangelogType()).withEntry("Name", changelog.getKey().getName()).withEntry("Action", changelog.getAction()).withEntry("Username", changelog.getUsername()).withEntry("Comment", Optional.ofNullable(changelog.getComment()).orElse("")).withEntry("Note", Optional.ofNullable(changelog.getNote()).orElse("")).build();
    var form = new HtmlForm().withMethod("post");
    form.addTextAreaField().withDisplay("Note (Optional)").withName(P_note).withPlaceholder(Optional.ofNullable(changelog.getNote()).orElse("")).withValue(note.orElse(null));
    form.addButton().withDisplay("update").withValue("anything");
    if (submitAction.isEmpty() || form.hasErrors()) {
        return pageFactory.startBuilder(request).withTitle("Manual Changelog").withContent(Html.makeContent(table, form)).buildMav();
    }
    note.ifPresent(newNote -> {
        changelog.setNote(newNote);
        ChangelogDto dto = changelog.toDto(serviceName.get());
        recorder.update(dto);
    });
    return pageFactory.preformattedMessage(request, "Updated changelog entry.");
}
Also used : ChangelogKey(io.datarouter.changelog.storage.ChangelogKey) ChangelogDto(io.datarouter.instrumentation.changelog.ChangelogDto) HtmlForm(io.datarouter.web.html.form.HtmlForm) Changelog(io.datarouter.changelog.storage.Changelog) J2HtmlLegendTable(io.datarouter.web.html.j2html.J2HtmlLegendTable) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with HtmlForm

use of io.datarouter.web.html.form.HtmlForm in project datarouter by hotpads.

the class CreateUserFormHtml method makeForm.

private HtmlForm makeForm() {
    var form = new HtmlForm().withMethod("post");
    form.addEmailField().withName(authenticationConfig.getUsernameParam()).withDisplay("Email").withPlaceholder("you@email.com").required();
    form.addPasswordField().withName(authenticationConfig.getPasswordParam()).withDisplay("Password").required();
    form.addSelectField().withName(authenticationConfig.getUserRolesParam()).withDisplay("Roles").withValues(roles).multiple();
    form.addButton().withDisplay("Submit").withValue(submitAction);
    return form;
}
Also used : HtmlForm(io.datarouter.web.html.form.HtmlForm)

Example 3 with HtmlForm

use of io.datarouter.web.html.form.HtmlForm 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 HtmlForm

use of io.datarouter.web.html.form.HtmlForm in project datarouter by hotpads.

the class LoadTestGetHandler method get.

@Handler(defaultHandler = true)
private Mav get(@Param(P_num) OptionalString num, @Param(P_max) OptionalString max, @Param(P_numThreads) OptionalString numThreads, @Param(P_batchSize) OptionalString batchSize, @Param(P_logPeriod) OptionalString logPeriod, @Param(P_submitAction) OptionalString submitAction) {
    var form = new HtmlForm().withMethod("post");
    form.addTextField().withDisplay("Num").withName(P_num).withPlaceholder("100,000").withValue(num.orElse(null));
    form.addTextField().withDisplay("Max").withName(P_max).withPlaceholder("10").withValue(max.orElse(null));
    form.addTextField().withDisplay("Num Threads").withName(P_numThreads).withPlaceholder("10").withValue(numThreads.orElse(null));
    form.addTextField().withDisplay("Batch Size").withName(P_batchSize).withPlaceholder("100").withValue(batchSize.orElse(null));
    form.addTextField().withDisplay("Log Period").withName(P_logPeriod).withPlaceholder("1,0000").withValue(logPeriod.orElse(null));
    form.addButton().withDisplay("Run Get").withValue("anything");
    if (submitAction.isEmpty() || form.hasErrors()) {
        return pageFactory.startBuilder(request).withTitle("Load Test - Get").withContent(Html.makeContent(form)).buildMav();
    }
    PhaseTimer timer = new PhaseTimer("get");
    // params
    int pNum = num.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_NUM);
    int pMax = max.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(pNum);
    int pNumThreads = numThreads.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_NUM_THREADS);
    int pBatchSize = batchSize.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_BATCH_SIZE);
    int pLogPeriod = logPeriod.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_LOG_PERIOD);
    // tracking
    AtomicInteger rowCounter = new AtomicInteger(0);
    AtomicLong lastBatchFinished = new AtomicLong(System.nanoTime());
    // execute
    int numBatches = LoadTestTool.numBatches(pNum, pBatchSize);
    ExecutorService executor = Executors.newFixedThreadPool(pNumThreads);
    Scanner.of(IntStream.range(0, numBatches).mapToObj(Integer::valueOf)).map(batchId -> LoadTestTool.makeRandomIdBatch(pNum, pMax, pBatchSize, batchId)).map(ids -> new GetBatchCallable(dao.getReaderNode(), ids, pLogPeriod, rowCounter, lastBatchFinished)).parallel(new ParallelScannerContext(executor, pNumThreads, true)).forEach(CallableTool::callUnchecked);
    ExecutorServiceTool.shutdown(executor, Duration.ofSeconds(5));
    timer.add("got " + rowCounter.get());
    var message = div(h2("Load Test Get Results"), div(h3("Results"), dl(dt("Total Time"), dd(timer.getElapsedString()), dt("Rows per second"), dd(timer.getItemsPerSecond(rowCounter.get()) + ""))), div(h3("Params"), dl(dt("Num"), dd(pNum + ""), dt("Max"), dd(pMax + ""), dt("Num Threads"), dd(pNumThreads + ""), dt("Batch Size"), dd(pBatchSize + ""), dt("Log Period"), dd(pLogPeriod + "")))).withClass("container");
    logger.warn("total={}, rps={}, num={}, max={}, numThreads={} batchSize={}, logPeriod={}", timer.getElapsedString(), timer.getItemsPerSecond(rowCounter.get()), pNum, pMax, pNumThreads, pBatchSize, pLogPeriod);
    return pageFactory.message(request, message);
}
Also used : IntStream(java.util.stream.IntStream) Scanner(io.datarouter.scanner.Scanner) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) TagCreator.dd(j2html.TagCreator.dd) LoggerFactory(org.slf4j.LoggerFactory) TagCreator.h3(j2html.TagCreator.h3) Callable(java.util.concurrent.Callable) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) TagCreator.h2(j2html.TagCreator.h2) TagCreator.dl(j2html.TagCreator.dl) Inject(javax.inject.Inject) NumberFormatter(io.datarouter.util.number.NumberFormatter) ExecutorServiceTool(io.datarouter.util.concurrent.ExecutorServiceTool) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TagCreator.br(j2html.TagCreator.br) TagCreator.dt(j2html.TagCreator.dt) Duration(java.time.Duration) Param(io.datarouter.web.handler.types.Param) Bootstrap4FormHtml(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4FormHtml) ExecutorService(java.util.concurrent.ExecutorService) PhaseTimer(io.datarouter.util.timer.PhaseTimer) Logger(org.slf4j.Logger) Mav(io.datarouter.web.handler.mav.Mav) RandomValue(io.datarouter.loadtest.storage.RandomValue) StringTool(io.datarouter.util.string.StringTool) Executors(java.util.concurrent.Executors) ContainerTag(j2html.tags.ContainerTag) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) LoadTestTool(io.datarouter.loadtest.util.LoadTestTool) HtmlForm(io.datarouter.web.html.form.HtmlForm) BaseHandler(io.datarouter.web.handler.BaseHandler) LoadTestGetDao(io.datarouter.loadtest.service.LoadTestGetDao) CallableTool(io.datarouter.util.concurrent.CallableTool) Bootstrap4PageFactory(io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory) RandomValueKey(io.datarouter.loadtest.storage.RandomValueKey) TagCreator.div(j2html.TagCreator.div) MapStorageReader(io.datarouter.storage.node.op.raw.read.MapStorageReader) AtomicLong(java.util.concurrent.atomic.AtomicLong) PhaseTimer(io.datarouter.util.timer.PhaseTimer) HtmlForm(io.datarouter.web.html.form.HtmlForm) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ParallelScannerContext(io.datarouter.scanner.ParallelScannerContext) CallableTool(io.datarouter.util.concurrent.CallableTool) ExecutorService(java.util.concurrent.ExecutorService) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 5 with HtmlForm

use of io.datarouter.web.html.form.HtmlForm in project datarouter by hotpads.

the class LoadTestScanHandler method scan.

@Handler(defaultHandler = true)
private Mav scan(@Param(P_num) OptionalString num, @Param(P_batchSize) OptionalString batchSize, @Param(P_submitAction) OptionalString submitAction) {
    var form = new HtmlForm().withMethod("post");
    form.addTextField().withDisplay("Num").withName(P_num).withPlaceholder("100,000").withValue(num.orElse(null));
    form.addTextField().withDisplay("Batch Size").withName(P_batchSize).withPlaceholder("100").withValue(batchSize.orElse(null));
    form.addButton().withDisplay("Run Scan").withValue("anything");
    if (submitAction.isEmpty() || form.hasErrors()) {
        return pageFactory.startBuilder(request).withTitle("Load Test - Scan").withContent(Html.makeContent(form)).buildMav();
    }
    PhaseTimer timer = new PhaseTimer("scan");
    // params
    int pNum = num.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_NUM);
    int pBatchSize = batchSize.map(StringTool::nullIfEmpty).map(number -> number.replaceAll(",", "")).map(Integer::valueOf).orElse(DEFAULT_BATCH_SIZE);
    // tracking
    AtomicInteger rowCounter = new AtomicInteger(0);
    AtomicLong lastBatchFinished = new AtomicLong(System.nanoTime());
    // execute
    dao.scan(pBatchSize, pNum).forEach(randomValue -> trackEachRow(rowCounter, lastBatchFinished, randomValue));
    timer.add("scanned " + rowCounter.get());
    // results
    DomContent message = div(h2("Load Test Scan Results"), div(h3("Results"), dl(dt("Total Time"), dd(timer.getElapsedString()), dt("Rows per second"), dd(timer.getItemsPerSecond(rowCounter.get()) + ""))), div(h3("Params"), dl(dt("Num"), dd(pNum + ""), dt("Batch Size"), dd(pBatchSize + "")))).withClass("container");
    logger.warn("total={}, rps={}, num={}, batchSize={}", timer.getElapsedString(), timer.getItemsPerSecond(rowCounter.get()), pNum, pBatchSize);
    return pageFactory.message(request, message);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PhaseTimer(io.datarouter.util.timer.PhaseTimer) HtmlForm(io.datarouter.web.html.form.HtmlForm) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DomContent(j2html.tags.DomContent) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

HtmlForm (io.datarouter.web.html.form.HtmlForm)17 BaseHandler (io.datarouter.web.handler.BaseHandler)16 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)13 Mav (io.datarouter.web.handler.mav.Mav)9 Bootstrap4FormHtml (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4FormHtml)9 Bootstrap4PageFactory (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory)9 TagCreator.div (j2html.TagCreator.div)9 List (java.util.List)9 Inject (javax.inject.Inject)9 StringTool (io.datarouter.util.string.StringTool)8 Param (io.datarouter.web.handler.types.Param)8 ContainerTag (j2html.tags.ContainerTag)8 Scanner (io.datarouter.scanner.Scanner)7 TagCreator.br (j2html.TagCreator.br)7 TagCreator.h2 (j2html.TagCreator.h2)7 NumberFormatter (io.datarouter.util.number.NumberFormatter)6 TableSamplerService (io.datarouter.nodewatch.service.TableSamplerService)5 ArrayList (java.util.ArrayList)5 Databean (io.datarouter.model.databean.Databean)4 PrimaryKey (io.datarouter.model.key.primary.PrimaryKey)4