Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/2204#discussion_r128368272
--- Diff:
storm-webapp/src/main/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogPageHandler.java
---
@@ -0,0 +1,467 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.storm.daemon.logviewer.handler;
+
+import static j2html.TagCreator.a;
+import static j2html.TagCreator.body;
+import static j2html.TagCreator.div;
+import static j2html.TagCreator.form;
+import static j2html.TagCreator.h3;
+import static j2html.TagCreator.head;
+import static j2html.TagCreator.html;
+import static j2html.TagCreator.input;
+import static j2html.TagCreator.link;
+import static j2html.TagCreator.p;
+import static j2html.TagCreator.pre;
+import static j2html.TagCreator.select;
+import static j2html.TagCreator.text;
+import static j2html.TagCreator.title;
+import static java.util.stream.Collectors.toCollection;
+import static java.util.stream.Collectors.toList;
+import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
+
+import j2html.TagCreator;
+import j2html.tags.DomContent;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.zip.GZIPInputStream;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.storm.daemon.logviewer.LogviewerConstant;
+import org.apache.storm.daemon.logviewer.utils.DirectoryCleaner;
+import org.apache.storm.daemon.logviewer.utils.LogviewerResponseBuilder;
+import org.apache.storm.daemon.logviewer.utils.ResourceAuthorizer;
+import org.apache.storm.daemon.logviewer.utils.WorkerLogs;
+import org.apache.storm.daemon.utils.StreamUtil;
+import org.apache.storm.daemon.utils.UrlBuilder;
+import org.apache.storm.ui.InvalidRequestException;
+import org.apache.storm.ui.UIHelpers;
+import org.apache.storm.utils.ConfigUtils;
+import org.apache.storm.utils.ServerUtils;
+import org.apache.storm.utils.Utils;
+import org.jooq.lambda.Unchecked;
+
+public class LogviewerLogPageHandler {
+ private final String logRoot;
+ private final String daemonLogRoot;
+ private final WorkerLogs workerLogs;
+ private final ResourceAuthorizer resourceAuthorizer;
+
+ /**
+ * Constructor.
+ *
+ * @param logRoot root worker log directory
+ * @param daemonLogRoot root daemon log directory
+ * @param workerLogs {@link WorkerLogs}
+ * @param resourceAuthorizer {@link ResourceAuthorizer}
+ */
+ public LogviewerLogPageHandler(String logRoot, String daemonLogRoot,
+ WorkerLogs workerLogs,
+ ResourceAuthorizer resourceAuthorizer) {
+ this.logRoot = logRoot;
+ this.daemonLogRoot = daemonLogRoot;
+ this.workerLogs = workerLogs;
+ this.resourceAuthorizer = resourceAuthorizer;
+ }
+
+ /**
+ * Enumerate worker log files for given criteria.
+ *
+ * @param user username
+ * @param port worker's port, null for all workers
+ * @param topologyId topology ID, null for all topologies
+ * @param callback callback for JSONP
+ * @param origin origin
+ * @return list of worker logs for given criteria
+ */
+ public Response listLogFiles(String user, Integer port, String
topologyId, String callback, String origin) throws IOException {
+ List<File> fileResults = null;
+ if (topologyId == null) {
+ if (port == null) {
+ fileResults = workerLogs.getAllLogsForRootDir();
+ } else {
+ fileResults = new ArrayList<>();
+
+ File[] logRootFiles = new File(logRoot).listFiles();
+ if (logRootFiles != null) {
+ for (File topoDir : logRootFiles) {
+ File[] topoDirFiles = topoDir.listFiles();
+ if (topoDirFiles != null) {
+ for (File portDir : topoDirFiles) {
+ if
(portDir.getName().equals(port.toString())) {
+
fileResults.addAll(DirectoryCleaner.getFilesForDir(portDir));
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ if (port == null) {
+ fileResults = new ArrayList<>();
+
+ File topoDir = new File(logRoot +
Utils.FILE_PATH_SEPARATOR + topologyId);
--- End diff --
nit: I know this is an exact translation, but we could just use `new
File(logRoot, topologyId)`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---