Skip to content
This repository has been archived by the owner on Mar 15, 2022. It is now read-only.

JBEAP-4963, HAL-1151: Unable to refresh the log viewer page #314

Open
wants to merge 1 commit into
base: 2.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import edu.ycp.cs.dh.acegwt.client.ace.AceEditor;

import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.shared.runtime.logging.store.LogFile;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
Expand All @@ -62,9 +64,11 @@ public class LogFilePanel extends Composite implements LogFilesId {
private final VerticalPanel panel;
private final AceEditor editor;
private final HandlerRegistration resizeHandler;
private final LogFilesPresenter presenter;

public LogFilePanel(final LogFile logFile) {
public LogFilePanel(final LogFile logFile, LogFilesPresenter presenter) {
this.name = logFile.getName();
this.presenter = presenter;

panel = new VerticalPanel();
panel.addStyleName("fill-layout-width");
Expand Down Expand Up @@ -170,11 +174,16 @@ public void onClick(ClickEvent event) {
findNext.getElement().setAttribute("action", "findNext"); // AceEditor action wiring
setId(findNext, BASE_ID + editorId, "next_match");

ToolButton refresh = new ToolButton(Console.CONSTANTS.common_label_refresh(),
event -> presenter.onRefreshLogFile(name));

ToolStrip searchTools = new ToolStrip();
searchTools.addToolWidget(findTextBox);
searchTools.addToolButton(findButton);
searchTools.addToolWidget(findPrev);
searchTools.addToolWidget(findNext);
searchTools.addToolButton(refresh);

searchTools.getElement().getStyle().setPaddingLeft(0, PX);
searchTools.getElement().getStyle().setMarginBottom(0.5, EM);
findTextBox.getElement().getStyle().setWidth(30, EM);
Expand All @@ -188,6 +197,7 @@ public void onClick(ClickEvent event) {
findPrev.getElement().getParentElement().getStyle().setVerticalAlign(MIDDLE);
findNext.getElement().getStyle().setHeight(25, PX);
findNext.getElement().getParentElement().getStyle().setVerticalAlign(MIDDLE);
refresh.getElement().getStyle().setMarginLeft(1, EM);

// next part: rebuild the original search box
FlowPanel searchForm = div("ace_search_form", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
*/
package org.jboss.as.console.client.shared.runtime.logging.files;

import com.google.gwt.core.client.GWT;
import static org.jboss.as.console.client.shared.runtime.logging.store.LogStore.FILE_NAME;
import static org.jboss.as.console.client.shared.runtime.logging.store.LogStore.FILE_SIZE;

import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.View;
Expand All @@ -33,10 +35,11 @@
import org.jboss.as.console.client.core.CircuitPresenter;
import org.jboss.as.console.client.core.HasPresenter;
import org.jboss.as.console.client.core.NameTokens;
import org.jboss.as.console.client.core.UIConstants;
import org.jboss.as.console.client.shared.runtime.logging.store.LogFile;
import org.jboss.as.console.client.shared.runtime.logging.store.LogStore;
import org.jboss.as.console.client.shared.runtime.logging.store.ReadLogFiles;
import org.jboss.as.console.client.shared.runtime.logging.store.ReadLogFilesForRefresh;
import org.jboss.as.console.client.shared.runtime.logging.store.RefreshLogFile;
import org.jboss.as.console.client.shared.runtime.logging.store.SelectLogFile;
import org.jboss.as.console.client.shared.runtime.logging.store.StreamLogFile;
import org.jboss.as.console.client.shared.subsys.RevealStrategy;
Expand Down Expand Up @@ -94,7 +97,7 @@ public LogFilesPresenter(EventBus eventBus, MyView view, MyProxy proxy, RevealSt
this.circuit = circuit;
this.logStore = logStore;
this.hostStore = hostStore;
this.streamingProgress = new StreamingProgress(circuit, logStore, SHOW_STREAM_IN_PROGRESS_TIMEOUT);
this.streamingProgress = new StreamingProgress(logStore, SHOW_STREAM_IN_PROGRESS_TIMEOUT);
}

@Override
Expand All @@ -114,6 +117,15 @@ public void onAction(Action action) {
streamingProgress.done();
getView().open(logStore.getActiveLogFile());

} else if (action instanceof ReadLogFilesForRefresh) {
getView().list(logStore.getLogFiles());
String name = ((ReadLogFilesForRefresh) action).getName();
refreshLogFile(name);

} else if (action instanceof RefreshLogFile) {
streamingProgress.done();
getView().refresh(logStore.getActiveLogFile());

} else if (action instanceof SelectLogFile) {
getView().open(logStore.getActiveLogFile());

Expand Down Expand Up @@ -152,12 +164,45 @@ public void onStreamLogFile(final String logFile, final int fileSize) {
Console.CONSTANTS.downloadingLogFileConfirmation(),
isConfirmed -> {
if (isConfirmed) {
this.circuit.dispatch(new StreamLogFile(logFile));
streamingProgress.monitor(logFile);
}
});
} else {
this.circuit.dispatch(new StreamLogFile(logFile));
streamingProgress.monitor(logFile);
}
}
}

public void onRefreshLogFile(final String logFile) {
circuit.dispatch(new ReadLogFilesForRefresh(logFile));
}

private void refreshLogFile(String name) {
ModelNode fileNode = null;
for (ModelNode node: logStore.getLogFiles()) {
if (node.get(FILE_NAME).asString().equals(name)) {
fileNode = node;
break;
}
}
if (fileNode != null) {
int fileSize = fileNode.get(FILE_SIZE).asInt();
if (fileSize > LOG_FILE_SIZE_THRESHOLD) {
Feedback.confirm(
Console.CONSTANTS.downloadLogFile(),
Console.CONSTANTS.downloadingLogFileConfirmation(),
isConfirmed -> {
if (isConfirmed) {
this.circuit.dispatch(new RefreshLogFile(name));
streamingProgress.monitor(name);
}
});
} else {
this.circuit.dispatch(new RefreshLogFile(name));
streamingProgress.monitor(name);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package org.jboss.as.console.client.shared.runtime.logging.files;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
Expand All @@ -36,9 +35,9 @@
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.UIConstants;
import org.jboss.as.console.client.shared.runtime.logging.store.DownloadLogFile;
import org.jboss.as.console.client.shared.runtime.logging.store.LogStore;
import org.jboss.as.console.client.shared.runtime.logging.store.ReadLogFiles;
import org.jboss.as.console.client.widgets.ContentDescription;
import org.jboss.as.console.mbui.widgets.ModelNodeCellTable;
import org.jboss.ballroom.client.widgets.ContentHeaderLabel;
Expand Down Expand Up @@ -136,6 +135,13 @@ public void onClick(ClickEvent event) {
view.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging/log-file=*", "read-log-file");
setId(view, BASE_ID, "view");
tools.addToolButtonRight(view);

final ToolButton refresh = new ToolButton(Console.CONSTANTS.common_label_refresh(),
event -> circuit.dispatch(new ReadLogFiles()));
refresh.setOperationAddress("/{implicit.host}/{selected.server}/subsystem=logging", "read-resource");
setId(refresh, BASE_ID, "refresh");
tools.addToolButtonRight(refresh);

panel.add(tools);

// table
Expand Down Expand Up @@ -189,6 +195,7 @@ public String getValue(ModelNode node) {
nameColumn.setSortable(true);
sortHandler.setComparator(nameColumn, new NameComparator());
table.addColumn(nameColumn, "Log File Name");
table.getColumnSortList().push(nameColumn);

// column: last modified
TextColumn<ModelNode> lastModifiedColumn = new TextColumn<ModelNode>() {
Expand Down Expand Up @@ -242,7 +249,6 @@ public void list(List<ModelNode> files) {
list.addAll(files);

// Make sure the new values are properly sorted
table.getColumnSortList().push(nameColumn);
ColumnSortEvent.fire(table, table.getColumnSortList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
public class LogFilesTabs extends Composite {

private final DefaultTabLayoutPanel tabLayout;
private final LogFilesPresenter presenter;

public LogFilesTabs(final Dispatcher circuit, LogFilesPresenter presenter) {
this.presenter = presenter;

public LogFilesTabs(final Dispatcher circuit) {
tabLayout = new DefaultTabLayoutPanel(40, Style.Unit.PX, true, true);
tabLayout.addSelectionHandler(event -> {
LogFilePanel logFilePanel = selectedLogFilePanel();
Expand Down Expand Up @@ -67,7 +70,7 @@ public void reset() {

public void open(LogFile logFile) {
if (!tabLayout.contains(logFile.getName())) {
tabLayout.add(new LogFilePanel(logFile), logFile.getName());
tabLayout.add(new LogFilePanel(logFile, presenter), logFile.getName());
}
tabLayout.selectTab(logFile.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setPresenter(LogFilesPresenter presenter) {

@Override
public Widget createWidget() {
logFilesTabs = new LogFilesTabs(circuit);
logFilesTabs = new LogFilesTabs(circuit, presenter);
logFiles = new LogFilesTable(circuit, presenter);
logFilesTabs.add(logFiles.asWidget(), "Log Files");
return logFilesTabs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
package org.jboss.as.console.client.shared.runtime.logging.files;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
Expand All @@ -30,12 +29,9 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.PopupPanel;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.UIConstants;
import org.jboss.as.console.client.shared.patching.ui.Pending;
import org.jboss.as.console.client.shared.runtime.logging.store.LogStore;
import org.jboss.as.console.client.shared.runtime.logging.store.LogStore.PendingStreamingRequest;
import org.jboss.as.console.client.shared.runtime.logging.store.StreamLogFile;
import org.jboss.gwt.circuit.Dispatcher;

import static org.jboss.as.console.client.shared.runtime.logging.files.LogFilesId.BASE_ID;
import static org.jboss.as.console.client.shared.util.IdHelper.WidgetType.BUTTON;
Expand All @@ -50,16 +46,14 @@ public class StreamingProgress extends PopupPanel {
private final static int WIDTH = 360;
private final static int HEIGHT = 200;

private final Dispatcher circuit;
private final int timeout;
private final Button cancel;

private String logFile;
private boolean pending;

public StreamingProgress(final Dispatcher circuit, final LogStore logStore, int timeout) {
public StreamingProgress(final LogStore logStore, int timeout) {
super(false, true);
this.circuit = circuit;
this.timeout = timeout;

setWidth(WIDTH + "px");
Expand Down Expand Up @@ -90,7 +84,6 @@ public void onClick(ClickEvent event) {

public void monitor(final String logFile) {
this.logFile = logFile;
this.circuit.dispatch(new StreamLogFile(logFile));

// deferred show
pending = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class LogStore extends ChangeSupport {
protected int pageSize;

/**
* Flag to pause the {@link LogStore.RefreshLogFile} command
* Flag to pause the {@link RefreshLogFileCmd} command
* when the related log view is no longer visible.
*/
protected boolean pauseFollow;
Expand Down Expand Up @@ -179,6 +179,11 @@ public void onSuccess(DMRResponse result) {
});
}

@Process(actionType = ReadLogFilesForRefresh.class)
public void readLogFilesForRefresh(final Dispatcher.Channel channel) {
readLogFiles(channel);
}

@Process(actionType = OpenLogFile.class)
public void openLogFile(final OpenLogFile action, final Dispatcher.Channel channel) {
final LogFile logFile = states.get(action.getName());
Expand Down Expand Up @@ -222,45 +227,53 @@ public void streamLogFile(final StreamLogFile action, final Dispatcher.Channel c
final LogFile logFile = states.get(action.getName());

if (logFile == null) {
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, encode(streamUrl(action.getName())));
requestBuilder.setHeader("Accept", "text/plain");
requestBuilder.setHeader("Content-Type", "text/plain");
requestBuilder.setIncludeCredentials(true);
try {
// store the request in order to cancel it later
pendingStreamingRequest = new PendingStreamingRequest(action.getName(),
requestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() >= 400) {
channel.nack(new IllegalStateException("Failed to stream log file " +
action.getName() + ": " + response.getStatusCode() + " - " +
response.getStatusText()));
} else {
LogFile newLogFile = new LogFile(action.getName(), response.getText());
newLogFile.setFollow(false);
states.put(action.getName(), newLogFile);
activate(newLogFile);
channel.ack();
}
}

@Override
public void onError(Request request, Throwable exception) {
channel.nack(exception);
}
}), channel);
} catch (RequestException e) {
channel.nack(e);
}

doStreamLogFile(action.getName(), channel);
} else {
// already streamed, just activate
activate(logFile);
channel.ack();
}
}

@Process(actionType = RefreshLogFile.class)
public void refreshLogFile(final RefreshLogFile action, final Dispatcher.Channel channel) {
doStreamLogFile(action.getName(), channel);
}

private void doStreamLogFile(final String fileName, final Dispatcher.Channel channel) {
RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, encode(streamUrl(fileName)));
requestBuilder.setHeader("Accept", "text/plain");
requestBuilder.setHeader("Content-Type", "text/plain");
requestBuilder.setIncludeCredentials(true);
try {
// store the request in order to cancel it later
pendingStreamingRequest = new PendingStreamingRequest(fileName,
requestBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (response.getStatusCode() >= 400) {
channel.nack(new IllegalStateException("Failed to stream log file " +
fileName + ": " + response.getStatusCode() + " - " +
response.getStatusText()));
} else {
LogFile newLogFile = new LogFile(fileName, response.getText());
newLogFile.setFollow(false);
states.put(fileName, newLogFile);
activate(newLogFile);
channel.ack();
}
}

@Override
public void onError(Request request, Throwable exception) {
channel.nack(exception);
}
}), channel);
} catch (RequestException e) {
channel.nack(e);
}
}

@Process(actionType = DownloadLogFile.class)
public void downloadLogFile(final DownloadLogFile action, final Dispatcher.Channel channel) {
Window.open(streamUrl(action.getName()), "", "");
Expand Down Expand Up @@ -501,7 +514,7 @@ protected void activate(LogFile logFile) {
}

private void startFollowing(LogFile logFile) {
scheduler.scheduleFixedDelay(new RefreshLogFile(logFile.getName()), FOLLOW_INTERVAL);
scheduler.scheduleFixedDelay(new RefreshLogFileCmd(logFile.getName()), FOLLOW_INTERVAL);
}

private String streamUrl(final String name) {
Expand Down Expand Up @@ -634,11 +647,11 @@ public void cancel() {

// ------------------------------------------------------ polling

private class RefreshLogFile implements Scheduler.RepeatingCommand {
private class RefreshLogFileCmd implements Scheduler.RepeatingCommand {

private final String name;

private RefreshLogFile(String name) {
private RefreshLogFileCmd(String name) {
this.name = name;
}

Expand Down
Loading