Skip to content

Commit

Permalink
Merge pull request #428 from ZihengSun/master
Browse files Browse the repository at this point in the history
fix the logging issues in separate windows
  • Loading branch information
ZihengSun authored Nov 27, 2023
2 parents 9580e9d + 9c5f1f8 commit 7064479
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>com.gw</groupId>
<artifactId>geoweaver</artifactId>
<version>1.2.3</version>
<version>1.2.5</version>
<name>geoweaver</name>
<description>A lightweight workflow management software for organizing data analysis workflows,
preserving history of every workflow run, and improving scientist producitvity and workflow FAIRness,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gw/database/HistoryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public interface HistoryRepository extends JpaRepository<History, String> {
* @param pid The ID of the process.
* @return A list of history records associated with the specified process ID, excluding 'Skipped' records.
*/
@Query(value = "select * from history where history.history_process = ?1 and history.indicator != 'Skipped' ORDER BY history_begin_time DESC;", nativeQuery = true)
@Query(value = "select * from history where history.history_process = ?1 and history.history_input != 'No code saved' ORDER BY history_begin_time DESC;", nativeQuery = true)
List<History> findByProcessIdIgnoreUnknown(String pid);

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/gw/local/LocalSessionNixImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ public void endWithError(String token, String message) {
this.isClose = true;

if(!BaseTool.isNull(message))
CommandServlet.sendMessageToSocket(token, message);
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+BaseTool.log_separator+message);

CommandServlet.sendMessageToSocket(token, "The process " + this.history.getHistory_id() + " is stopped.");
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+BaseTool.log_separator+
"The process " + this.history.getHistory_id() + " is stopped.");

}

Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/gw/local/LocalSessionOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void endWithCode(String token, int exitvalue) {

ht.saveHistory(h);

this.sendMessage2WebSocket("Exit Code: " + exitvalue);
this.sendMessage2WebSocket(this.history_id + BaseTool.log_separator + "Exit Code: " + exitvalue);
}

/**
Expand Down Expand Up @@ -247,7 +247,7 @@ public void run() {
this.updateStatus("Running", "Running");

// Send a message to the WebSocket indicating that the process has started
this.sendMessage2WebSocket("Process " + this.history_id + " Started");
this.sendMessage2WebSocket(this.history_id + BaseTool.log_separator+ "Process " + this.history_id + " Started");

String line = null; // Initialize a variable to store each line of output

Expand Down Expand Up @@ -296,15 +296,15 @@ public void run() {
} else if (line.contains("==== Geoweaver Bash Output Finished ====")) {
// Handle specific marker lines if present
} else {
log.info("Local thread output >> " + line + " - token: " + token); // Log each line of output
log.info("Local output " + theprocess.pid() + " >> " + line + " - token: " + token); // Log each line of output
logs.append(line).append("\n"); // Append the line to the logs

if (!BaseTool.isNull(wsout) && wsout.isOpen()) {
if (prelog.toString() != null) {
line = prelog.toString() + line;
prelog = new StringBuffer();
}
this.sendMessage2WebSocket(line);
this.sendMessage2WebSocket(this.history_id + BaseTool.log_separator + line);
} else {
prelog.append(line).append("\n"); // Append to the prelog if WebSocket isn't available
}
Expand Down Expand Up @@ -333,6 +333,7 @@ public void run() {
// If the process is available, attempt to stop and get its exit code
if (!BaseTool.isNull(theprocess)) {
try {
log.info("This output thread corresponding process: " + theprocess.pid());
if (theprocess.isAlive()) theprocess.destroy();
this.endWithCode(token, theprocess.exitValue());
} catch (Exception e) {
Expand All @@ -342,18 +343,18 @@ public void run() {
}

// Send a message to the WebSocket indicating that the process has finished
this.sendMessage2WebSocket("The process " + history_id + " is finished.");
this.sendMessage2WebSocket(this.history_id + BaseTool.log_separator+ "The process " + history_id + " is finished.");

// This thread will end by itself when the task is finished; you don't have to close it manually
GeoweaverController.sessionManager.closeByToken(token); // Close the session by token
// GeoweaverController.sessionManager.closeByToken(token); // Close the session by token

log.info("Local session output thread ended");
} catch (Exception e) {
e.printStackTrace();
// Depending on the language, update the status to "Failed"
this.updateStatus(logs.toString() + "\n" + e.getLocalizedMessage(), "Failed");
} finally {
this.sendMessage2WebSocket("======= Process " + this.history_id + " ended");
this.sendMessage2WebSocket(this.history_id + BaseTool.log_separator + "======= Process " + this.history_id + " ended");
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/gw/local/LocalSessionWinImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ public void endWithError(String token, String message) {

this.isClose = true;

CommandServlet.sendMessageToSocket(token, message);
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+BaseTool.log_separator+message);

CommandServlet.sendMessageToSocket(token, "======= Process " + this.history.getHistory_id() + " ended.");
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+BaseTool.log_separator+
"======= Process " + this.history.getHistory_id() + " ended.");

}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/gw/ssh/SSHCmdSessionOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void endWithCode(String token, String history_id, int exitvalue){

log.info("Exit code: " + exitvalue);

CommandServlet.sendMessageToSocket(token, "Exit Code: " + exitvalue);
CommandServlet.sendMessageToSocket(token, history_id+ BaseTool.log_separator + "Exit Code: " + exitvalue);

}

Expand Down Expand Up @@ -146,7 +146,7 @@ public void run() {

updateStatus("Running", "Running"); //initiate the history record

CommandServlet.sendMessageToSocket(token, "Process "+this.history_id+" Started");
CommandServlet.sendMessageToSocket(token, history_id+ BaseTool.log_separator + "Process "+this.history_id+" Started");

String line = null;

Expand Down Expand Up @@ -206,7 +206,7 @@ public void run() {

}

CommandServlet.sendMessageToSocket(token, line);
CommandServlet.sendMessageToSocket(token, history_id+ BaseTool.log_separator+ line);

}else {

Expand All @@ -218,7 +218,7 @@ public void run() {

this.updateStatus(logs.toString(), "Done");

CommandServlet.sendMessageToSocket(token, "The process "+this.history_id+" is finished.");
CommandServlet.sendMessageToSocket(token, history_id+ BaseTool.log_separator + "The process "+this.history_id+" is finished.");


} catch (Exception e) {
Expand All @@ -229,11 +229,11 @@ public void run() {

}finally {

CommandServlet.sendMessageToSocket(token, "======= Process " + this.history_id + " ended");
CommandServlet.sendMessageToSocket(token, history_id+ BaseTool.log_separator + "======= Process " + this.history_id + " ended");

}

GeoweaverController.sessionManager.closeByToken(token);
// GeoweaverController.sessionManager.closeByToken(token);

log.info("SSH session output thread ended");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gw/ssh/SSHLiveSessionOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void run() {

e.printStackTrace();

GeoweaverController.sessionManager.closeByToken(token);
// GeoweaverController.sessionManager.closeByToken(token);

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gw/ssh/SSHSessionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ public void endWithError(String token, String history_id, String message) {

// If the error message is not empty, send it to the associated socket.
if (!BaseTool.isNull(message)) {
CommandServlet.sendMessageToSocket(token, message);
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+ BaseTool.log_separator + message);
}

// Send a message to the socket indicating that the process is stopped.
CommandServlet.sendMessageToSocket(token, "The process " + this.history.getHistory_id() + " is stopped.");
CommandServlet.sendMessageToSocket(token, this.history.getHistory_id()+ BaseTool.log_separator + "The process " + this.history.getHistory_id() + " is stopped.");
}


Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/gw/utils/BaseTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class BaseTool {

public static int BUFFER_SIZE = 20;

public static String log_separator = "*_*";

private String _classpath = null;

Logger logger = LoggerFactory.getLogger(getClass());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/static/js/gw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edu = {

sponsor: "ESIPLab incubator project, NASA ACCESS project, NSF Geoinformatics project, NSF Cybertraining project",

version: "1.2.3",
version: "1.2.5",

author: "open source contributors",

Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/static/js/gw.process.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ GW.process = {
current_pid: null,

last_executed_process_id: null,

process_id: null,

history_id: null,

editOn: false, //false: disable is false, all fields are activated; true: all fields are deactivated.

Expand Down Expand Up @@ -928,6 +932,8 @@ GW.process = {

console.log("history id: " + history_id);

GW.process.history_id = history_id;

$.ajax({

url: "log",
Expand Down Expand Up @@ -1310,6 +1316,10 @@ GW.process = {
var process_id = null;

var process_name = null;

GW.workspace.currentmode = 1;

GW.ssh.process_output_id = "process-log-window"

msg = GW.general.parseResponse(msg);

Expand Down Expand Up @@ -2061,6 +2071,8 @@ GW.process = {
console.log("the process is under execution.");

console.log("history id: " + msg.history_id);

GW.process.history_id = msg.history_id

}else if(msg.ret == "fail"){

Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/static/js/gw.process.sidepanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ GW.process.sidepanel = {

console.log("history id: " + history_id);

GW.process.history_id = history_id;

$.ajax({

url: "log",
Expand All @@ -114,6 +116,8 @@ GW.process.sidepanel = {
msg = GW.general.parseResponse(msg);

msg.code = msg.input;

GW.process.history_id = msg.history_id

GW.process.sidepanel.display(msg);

Expand Down Expand Up @@ -208,6 +212,8 @@ GW.process.sidepanel = {
msg = GW.general.parseResponse(msg);

if("history_output" in msg && msg.history_output!=null){

GW.process.history_id = msg.history_id

msgout = msg.history_output.replaceAll("\n", "<br/>");

Expand Down Expand Up @@ -265,9 +271,12 @@ GW.process.sidepanel = {

GW.process.sidepanel.current_process_category = code_type


GW.ssh.current_process_log_length = 0

GW.workspace.currentmode = 2;

GW.ssh.process_output_id = "prompt-panel-process-log-window"

let code = msg.code;

if(code!=null && code.includes("\\\"")){
Expand Down
32 changes: 26 additions & 6 deletions src/main/resources/static/js/gw.ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,18 @@ GW.ssh = {
var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();

cont_splits = content.split("*_*")

log_history_id = null

if(cont_splits.length>1){
log_history_id = cont_splits[0]
let newArray = cont_splits.slice(1);
content = newArray.join(" ")
}

var style1 = "";
if(content.includes("Start to execute") ){
if(content.includes("Start to execute")){

style1 = "color: blue; font-weight: bold; text-decoration: underline;";

Expand All @@ -261,14 +271,18 @@ GW.ssh = {

$(".dot-flashing").removeClass("visible")
$(".dot-flashing").addClass("invisible")



}else if(content=="disconnected"){
$(".dot-flashing").removeClass("visible")
$(".dot-flashing").addClass("invisible")
}else if(log_history_id == GW.process.history_id){
$(".dot-flashing").removeClass("invisible")
$(".dot-flashing").addClass("visible")
}else{
$(".dot-flashing").removeClass("visible")
$(".dot-flashing").addClass("invisible")
}

var newline = `<p style="line-height:1.1; text-align:left; margin-top: 10px; `+
`margin-bottom: 10px;"><span style="`+
style1+ `">` + content + `</span></p>`;
Expand All @@ -285,7 +299,7 @@ GW.ssh = {
//don't output log to process log if the current executed is workflow
if(GW.process.last_executed_process_id==GW.process.process_id){

if($("#"+GW.ssh.process_output_id).length && GW.workspace.currentmode == 1){
if($("#"+GW.ssh.process_output_id).length){

if(this.current_process_log_length > 5000){

Expand All @@ -295,7 +309,13 @@ GW.ssh = {

}

$("#"+GW.ssh.process_output_id).append(newline);
if(GW.process.history_id == log_history_id){

// only display the log if the current history id is the correct one
$("#"+GW.ssh.process_output_id).append(newline);

}


this.current_process_log_length += 1

Expand Down

0 comments on commit 7064479

Please sign in to comment.