From 3024151767494e99cdc9e3f40ad5aac7758ea94c Mon Sep 17 00:00:00 2001 From: Salvatore Coppola Date: Mon, 8 Jul 2024 09:50:33 +0200 Subject: [PATCH] Added filter fields to journal log. --- kura/org.eclipse.kura.web2/pom.xml | 458 +++++++++--------- .../kura/web/client/ui/device/LogTabUi.java | 30 +- .../kura/web/client/ui/device/LogTabUi.ui.xml | 100 ++-- .../kura/web/server/servlet/LogServlet.java | 37 +- .../web/client/messages/Messages.properties | 2 + .../org/eclipse/kura/web/denali.gwt.xml | 7 +- .../org/eclipse/kura/web/login.gwt.xml | 5 +- 7 files changed, 355 insertions(+), 284 deletions(-) diff --git a/kura/org.eclipse.kura.web2/pom.xml b/kura/org.eclipse.kura.web2/pom.xml index 24c8d1f2646..08a45193787 100644 --- a/kura/org.eclipse.kura.web2/pom.xml +++ b/kura/org.eclipse.kura.web2/pom.xml @@ -1,193 +1,199 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - 4.0.0 + 4.0.0 - - org.eclipse.kura - kura - 5.5.0-SNAPSHOT - + + org.eclipse.kura + kura + 5.5.0-SNAPSHOT + - org.eclipse.kura.web2 - 2.5.0-SNAPSHOT - eclipse-plugin + org.eclipse.kura.web2 + 2.5.0-SNAPSHOT + eclipse-plugin - - ${project.basedir}/.. - - 2.10.0 - UTF-8 - + + ${project.basedir}/.. + + 2.10.0 + UTF-8 + - - - org.eclipse.kura - org.eclipse.kura.web2.ext - 1.5.0-SNAPSHOT - provided - - + + + org.eclipse.kura + org.eclipse.kura.web2.ext + 1.5.0-SNAPSHOT + provided + + + org.gwtbootstrap3 + gwtbootstrap3-extras + 1.0.2 + provided + + - - - - - org.apache.maven.wagon - wagon-ssh - 1.0-beta-6 - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - true - - - - - org.apache.maven.plugins - maven-clean-plugin - 2.4.1 - - - - src/main/webapp/denali - - - src/main/webapp/WEB-INF - - - - - - - org.codehaus.mojo - gwt-maven-plugin - ${gwtVersion} - - - - compile - test - i18n - generateAsync - - - - - - true - -Xmx2048M -Xss1024k -XX:+UseParallelGC - 2 - denali.html - org.eclipse.kura.web.client.messages.Messages - org.eclipse.kura.web.client.messages.ValidationMessages - src/main/webapp - - + + + + + org.apache.maven.wagon + wagon-ssh + 1.0-beta-6 + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + true + + + + + org.apache.maven.plugins + maven-clean-plugin + 2.4.1 + + + + src/main/webapp/denali + + + src/main/webapp/WEB-INF + + + + + + + org.codehaus.mojo + gwt-maven-plugin + ${gwtVersion} + + + + compile + test + i18n + generateAsync + + + + + + true + -Xmx2048M -Xss1024k -XX:+UseParallelGC + 2 + denali.html + org.eclipse.kura.web.client.messages.Messages + org.eclipse.kura.web.client.messages.ValidationMessages + src/main/webapp + + - - - org.apache.maven.plugins - maven-war-plugin - 3.3.2 - - - compile - - exploded - - - - - ${webappDirectory} - - false - META-INF/MANIFEST.MF - - - + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + compile + + exploded + + + + + ${webappDirectory} + + false + META-INF/MANIFEST.MF + + + - - net.alchim31.maven - yuicompressor-maven-plugin - 1.5.1 - - true - - - true - src/main/webapp/login.all.js - ${basedir}/src/main/resources/org/eclipse/kura/web/js - - extensions.js - - - - true - src/main/webapp/denali.all.js - ${basedir}/src/main/resources/org/eclipse/kura/web/js - - jquery.min.js - lodash.min.js - backbone.min.js - joint.min.js - joint.shapes.devs.js - dnd_helper.js - wires_composer.js - wires_blink.js - extensions.js - - - - true - src/main/webapp/denali.all.css - ${basedir}/src/main/resources/org/eclipse/kura/web/css - - joint.min.css - denali.css - - - - - denali.all.js - login.all.js - denali.all.css - - false - false - src/main/webapp/ - src/main/webapp/ - - - - compress_js_css - process-resources - - compress - - - - + + net.alchim31.maven + yuicompressor-maven-plugin + 1.5.1 + + true + + + true + src/main/webapp/login.all.js + ${basedir}/src/main/resources/org/eclipse/kura/web/js + + extensions.js + + + + true + src/main/webapp/denali.all.js + ${basedir}/src/main/resources/org/eclipse/kura/web/js + + jquery.min.js + lodash.min.js + backbone.min.js + joint.min.js + joint.shapes.devs.js + dnd_helper.js + wires_composer.js + wires_blink.js + extensions.js + + + + true + src/main/webapp/denali.all.css + ${basedir}/src/main/resources/org/eclipse/kura/web/css + + joint.min.css + denali.css + + + + + denali.all.js + login.all.js + denali.all.css + + false + false + src/main/webapp/ + src/main/webapp/ + + + + compress_js_css + process-resources + + compress + + + + org.eclipse.tycho @@ -200,63 +206,63 @@ - - org.eclipse.tycho - tycho-packaging-plugin - - - - src/main/webapp - www/ - - **/WEB-INF/** - **/gwt-unitCache/**/* - **/src/main/resources/**/js/*.js - **/src/main/resources/**/css/*.css - **/src/main/webapp/*.all.js - - - - - - + + org.eclipse.tycho + tycho-packaging-plugin + + + + src/main/webapp + www/ + + **/WEB-INF/** + **/gwt-unitCache/**/* + **/src/main/resources/**/js/*.js + **/src/main/resources/**/css/*.css + **/src/main/webapp/*.all.js + + + + + + - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + - - - - org.apache.maven.plugins - - - maven-war-plugin - - - [2.1.1,) - - - exploded - - - - - - - - - - - - - + + + + org.apache.maven.plugins + + + maven-war-plugin + + + [2.1.1,) + + + exploded + + + + + + + + + + + + + diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java index 769ef6332b3..55a7a4f1dfe 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.java @@ -12,6 +12,7 @@ *******************************************************************************/ package org.eclipse.kura.web.client.ui.device; +import java.time.LocalDate; import java.util.LinkedList; import java.util.List; @@ -35,7 +36,9 @@ import org.gwtbootstrap3.client.ui.ListBox; import org.gwtbootstrap3.client.ui.Panel; import org.gwtbootstrap3.client.ui.Row; - +import org.gwtbootstrap3.extras.datepicker.client.ui.DatePicker; +import com.google.gwt.i18n.client.DateTimeFormat; +import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat; import com.google.gwt.core.client.GWT; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -85,6 +88,14 @@ interface LogTabUiUiBinder extends UiBinder { CheckBox showMoreInfoCheckbox; @UiField Button openNewWindow; + @UiField + DatePicker datePickerJournalFrom; + @UiField + DatePicker datePickerJournalTo; + @UiField + FormLabel datePickerJournalLabelFrom; + @UiField + FormLabel datePickerJournalLabelTo; private static final int CACHE_SIZE_LIMIT = 1500; private final LinkedList logs = new LinkedList<>(); @@ -92,6 +103,8 @@ interface LogTabUiUiBinder extends UiBinder { private boolean autoFollow = true; private boolean initialized = false; + private final DateTimeFormat iso8601DateFormat = DateTimeFormat.getFormat("yyyy-MM-dd"); + private final String nonce = Integer.toString(Random.nextInt()); private static final int DOWNLOAD_COMPLETE_WAIT_TIMEOUT = 5000; @@ -131,8 +144,9 @@ public LogTabUi() { initWidget(uiBinder.createAndBindUi(this)); this.logLabel.setText(MSGS.logDownload()); + this.datePickerJournalLabelFrom.setText(MSGS.logDateFrom()); + this.datePickerJournalLabelTo.setText(MSGS.logDateTo()); - this.execute.setText(MSGS.download()); this.execute.addClickHandler( event -> LogTabUi.this.gwtXSRFService.generateSecurityToken(new AsyncCallback() { @@ -144,7 +158,17 @@ public void onFailure(Throwable ex) { @Override public void onSuccess(GwtXSRFToken token) { final StringBuilder sbUrl = new StringBuilder(); - sbUrl.append("/log?nonce=").append(LogTabUi.this.nonce); + sbUrl.append("/log?nonce=") // + .append(LogTabUi.this.nonce); + if (datePickerJournalFrom.getValue() != null) { + sbUrl.append("&dateJournalFrom=") + .append(iso8601DateFormat.format(datePickerJournalFrom.getValue())); + } + if (datePickerJournalTo.getValue() != null) { + sbUrl.append("&dateJournalTo=") + .append(iso8601DateFormat.format(datePickerJournalTo.getValue())); + } + DownloadHelper.instance().startDownload(token, sbUrl.toString()); EntryClassUi.showWaitModal(); diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.ui.xml b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.ui.xml index d0f09e464b4..7fd7b86ace3 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.ui.xml +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/client/ui/device/LogTabUi.ui.xml @@ -2,71 +2,83 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:gwt="urn:import:org.gwtbootstrap3.client.ui.gwt" + xmlns:b2="urn:import:org.gwtbootstrap3.extras.datepicker.client.ui"> .important { - font-weight: bold; + font-weight: bold; } .download-label-text { - vertical-align : middle; - margin: 5px; + vertical-align : middle; + margin: 5px; } .log-area { - width: 100%; + width: 100%; } .open-window-btn { - float: right; + float: right; } - - - - - - - - Show errors stacktrace - Show additional info - - - New window - - - - - - - - - - - - - Download - - - - - - + + + + + + + + Show errors stacktrace + Show additional info + + + New window + + + + + + + + + + + + + + Download + + + + + + + + + + + + + + - + - \ No newline at end of file + diff --git a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/servlet/LogServlet.java b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/servlet/LogServlet.java index d2d7fcf515d..af5c6c996ef 100644 --- a/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/servlet/LogServlet.java +++ b/kura/org.eclipse.kura.web2/src/main/java/org/eclipse/kura/web/server/servlet/LogServlet.java @@ -22,9 +22,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import java.util.zip.ZipEntry; @@ -49,6 +52,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.gwt.i18n.client.LocaleInfo; + public class LogServlet extends AuditServlet { private static final long serialVersionUID = 3969980124054250070L; @@ -112,16 +117,25 @@ protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse } }); + String dateJournalFrom = httpServletRequest.getParameter("dateJournalFrom"); + String dateJournalTo = httpServletRequest.getParameter("dateJournalTo"); + + Optional fromDate = dateJournalFrom != null ? Optional.of(LocalDate.parse(dateJournalFrom)) + : Optional.empty(); + Optional toDate = dateJournalTo != null ? Optional.of(LocalDate.parse(dateJournalTo)) + : Optional.empty(); + ; + String outputFields = ss.getProperties().getProperty("kura.log.download.journal.fields", "SYSLOG_IDENTIFIER,PRIORITY,MESSAGE,STACKTRACE"); - if (writeJournalLog(pes, outputFields, KURA_JOURNAL_LOG_FILE, "kura")) { + if (writeJournalLog(pes, outputFields, KURA_JOURNAL_LOG_FILE, "kura", fromDate, toDate)) { fileList.add(new File(KURA_JOURNAL_LOG_FILE)); } else { logger.warn("Error producing: {}", KURA_JOURNAL_LOG_FILE); } - if (writeJournalLog(pes, outputFields, SYSTEM_JOURNAL_LOG_FILE)) { + if (writeJournalLog(pes, outputFields, SYSTEM_JOURNAL_LOG_FILE, fromDate, toDate)) { fileList.add(new File(SYSTEM_JOURNAL_LOG_FILE)); } else { logger.warn("Error producing: {}", SYSTEM_JOURNAL_LOG_FILE); @@ -180,12 +194,13 @@ private void zipFile(byte[] bytes, ZipOutputStream zos, File file) throws IOExce } } - private boolean writeJournalLog(PrivilegedExecutorService pes, String outputFields, String outputFile) { - return writeJournalLog(pes, outputFields, outputFile, null); + private boolean writeJournalLog(PrivilegedExecutorService pes, String outputFields, String outputFile, + Optional from, Optional to) { + return writeJournalLog(pes, outputFields, outputFile, null, from, to); } - private boolean writeJournalLog(PrivilegedExecutorService pes, String outputFields, String outputFile, - String unit) { + private boolean writeJournalLog(PrivilegedExecutorService pes, String outputFields, String outputFile, String unit, + Optional from, Optional to) { List commandSequence = new ArrayList<>(); @@ -197,6 +212,16 @@ private boolean writeJournalLog(PrivilegedExecutorService pes, String outputFiel commandSequence.add(unit); } + if (from.isPresent()) { + commandSequence.add("-S"); + commandSequence.add(from.get().toString()); + } + + if (to.isPresent()) { + commandSequence.add("-U"); + commandSequence.add(to.get().toString()); + } + commandSequence.add("-o"); commandSequence.add("verbose"); commandSequence.add("--output-fields=" + outputFields); diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties index 39b53f8807c..7a601ded86e 100644 --- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties +++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/client/messages/Messages.properties @@ -886,6 +886,8 @@ pwdWhitespaceCharacters=New password cannot contain whitespace characters pwdEmpty=New password cannot be empty logDownload=Click this button to download all system logs in a single zip file +logDateFrom=Journal Starting Date (inclusive) +logDateTo=Journal Ending Date (exclusive) configurationChangeEventNotification=Another user has modified configuration for {0}. You might see an inconsistent state and a page refresh might be needed to show the latest changes. configurationChangeEventNotificationGeneric=Another user has modified some configuration. You might see an inconsistent state and a page refresh might be needed to show the latest changes. diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/denali.gwt.xml b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/denali.gwt.xml index a878bc68c4b..23c1db691f1 100644 --- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/denali.gwt.xml +++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/denali.gwt.xml @@ -1,7 +1,7 @@ - + @@ -38,6 +38,7 @@ + @@ -52,7 +53,7 @@ - + diff --git a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/login.gwt.xml b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/login.gwt.xml index 089ef6a0e00..724db2eae04 100644 --- a/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/login.gwt.xml +++ b/kura/org.eclipse.kura.web2/src/main/resources/org/eclipse/kura/web/login.gwt.xml @@ -1,7 +1,7 @@ - + @@ -38,6 +38,7 @@ +