From 07fdce16f4ec5b4c5771e02412117d84bb294a47 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Fri, 24 Feb 2023 15:10:55 -0800 Subject: [PATCH 01/15] creates a new branch and work on make workbench remember the last simulation --- WorkbenchProject/Cache/hostname.encrypted | Bin 0 -> 43 bytes WorkbenchProject/Cache/username.encrypted | Bin 0 -> 43 bytes WorkbenchProject/Key | Bin 0 -> 23 bytes WorkbenchProject/LastSimulation/simdir | Bin 0 -> 32 bytes .../workbench/script/ScriptManager.java | 18 ++++++++++++++++++ 5 files changed, 18 insertions(+) create mode 100644 WorkbenchProject/Cache/hostname.encrypted create mode 100644 WorkbenchProject/Cache/username.encrypted create mode 100644 WorkbenchProject/Key create mode 100644 WorkbenchProject/LastSimulation/simdir diff --git a/WorkbenchProject/Cache/hostname.encrypted b/WorkbenchProject/Cache/hostname.encrypted new file mode 100644 index 0000000000000000000000000000000000000000..bf3cfd93544cc410a2f9c1c9ff87d4de6c9be38c GIT binary patch literal 43 zcmZ4UmVvdjh=D2EY0YQxA8Z^U511GjDhe1F7z7xZRHwg^OS`&zfyb-DTYPo^J{1o& literal 0 HcmV?d00001 diff --git a/WorkbenchProject/Cache/username.encrypted b/WorkbenchProject/Cache/username.encrypted new file mode 100644 index 0000000000000000000000000000000000000000..1410400e0bc72f1fa2d437abb5f8f8125e6c2e88 GIT binary patch literal 43 zcmZ4UmVvdjh=D2EY0YQxA8Z^U511GjDhe1F7z83-OKzBY>|Y))LrYiZBGr=sO@9y; literal 0 HcmV?d00001 diff --git a/WorkbenchProject/Key b/WorkbenchProject/Key new file mode 100644 index 0000000000000000000000000000000000000000..682d8190081ce18c15bf07ca6bcc128e950b7fda GIT binary patch literal 23 ecmZ4UmVvc|K_EHYwb0uvI5E@L($lom+YA6&X9p_) literal 0 HcmV?d00001 diff --git a/WorkbenchProject/LastSimulation/simdir b/WorkbenchProject/LastSimulation/simdir new file mode 100644 index 0000000000000000000000000000000000000000..8e673646b4ae99fcb0375c5589588f32c0b3bd85 GIT binary patch literal 32 ncmZ4UmVvc|L9$LiJijPADK#%SBRDg+G$*knGe56b-^dsM!L19Z literal 0 HcmV?d00001 diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 123f616..6012a13 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -4,8 +4,10 @@ import com.jcraft.jsch.SftpException; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.ObjectOutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -271,6 +273,13 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat String remoteScriptPath = simDir + "/" + FileManager.getSimpleFilename(scriptPath); String cmd = "mkdir -p " + nListDir; sft.executeCommand(cmd, hostname, lcd.getUsername(), password, true); + FileOutputStream simDirLocation = new FileOutputStream(new File(makeLastSimulationDir() + "\\simdir")); + try { + ObjectOutputStream writeSimDir = new ObjectOutputStream(simDirLocation); + writeSimDir.writeObject(simDir); + } catch (IOException e) { + e.printStackTrace(); + } /* Upload Script */ Date uploadStartTime = new Date(); if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { @@ -644,6 +653,15 @@ public long analyzeScriptOutput(SimulationSpecification simSpec, Simulation simu } return timeCompleted; } + + private String makeLastSimulationDir() { + String lastSim = System.getProperty("user.dir") + "\\LastSimulation"; + File lastSimDirectory = new File(lastSim); + if (!lastSimDirectory.exists() || !lastSimDirectory.isDirectory()) { + lastSimDirectory.mkdir(); + } + return lastSim; + } private String fetchScriptOutputFiles(Simulation simulation, SimulationSpecification simSpec, Path scriptOutputFolder) throws JSchException, SftpException, IOException { From 8a06ee6394b1bdd94bc655a4c77fc6c92d6dc2eb Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Fri, 24 Feb 2023 17:29:29 -0800 Subject: [PATCH 02/15] add the pop up screen when last simulation detected and add the mkdir command to save info for last simulation --- .../workbench/script/ScriptManager.java | 21 +++++++----- .../WorkbenchDashboard.java | 32 ++++++++++++++++++- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 6012a13..3046ccc 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -253,6 +253,17 @@ public boolean runScript(ProvMgr provMgr, SimulationSpecification simSpec, return success; } + private void saveSimDir(String simDir) { + try { + FileOutputStream simDirLocation = new FileOutputStream( + new File(makeLastSimulationDir() + "\\simdir")); + ObjectOutputStream writeSimDir = new ObjectOutputStream(simDirLocation); + writeSimDir.writeObject(simDir); + } catch (IOException e) { + e.printStackTrace(); + } + } + private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulationName, String scriptPath, String[] nListFilenames, String simConfigFilename) throws JSchException, FileNotFoundException, SftpException { @@ -273,13 +284,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat String remoteScriptPath = simDir + "/" + FileManager.getSimpleFilename(scriptPath); String cmd = "mkdir -p " + nListDir; sft.executeCommand(cmd, hostname, lcd.getUsername(), password, true); - FileOutputStream simDirLocation = new FileOutputStream(new File(makeLastSimulationDir() + "\\simdir")); - try { - ObjectOutputStream writeSimDir = new ObjectOutputStream(simDirLocation); - writeSimDir.writeObject(simDir); - } catch (IOException e) { - e.printStackTrace(); - } + saveSimDir(simDir); /* Upload Script */ Date uploadStartTime = new Date(); if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { @@ -653,7 +658,7 @@ public long analyzeScriptOutput(SimulationSpecification simSpec, Simulation simu } return timeCompleted; } - + private String makeLastSimulationDir() { String lastSim = System.getProperty("user.dir") + "\\LastSimulation"; File lastSimDirectory = new File(lastSim); diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 1ffbb9c..152ca86 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -1,10 +1,18 @@ package edu.uwb.braingrid.workbenchdashboard; +import java.awt.FlowLayout; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.logging.FileHandler; import java.util.logging.Logger; + +import javax.swing.JFrame; +import javax.swing.JOptionPane; + import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.image.Image; @@ -15,6 +23,7 @@ import edu.uwb.braingrid.general.LoggerHelper; import edu.uwb.braingrid.workbench.FileManager; import edu.uwb.braingrid.workbench.WorkbenchManager; +import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; import edu.uwb.braingrid.workbenchdashboard.utils.SystemProperties; /** @@ -122,7 +131,7 @@ public void start(Stage primaryStage) throws Exception { primaryStage.setScene(scene); primaryStage.setMaximized(true); primaryStage.show(); - + checkLastSim(); // Exit application on window close primaryStage.setOnCloseRequest(event -> { Platform.exit(); @@ -132,4 +141,25 @@ public void start(Stage primaryStage) throws Exception { // Initialize Workbench Manager WorkbenchManager.getInstance(); } + private void checkLastSim() { + File lastSim = new File(System.getProperty("user.dir") + "\\LastSimulation\\simdir"); + if (lastSim.exists() && lastSim.isFile() && lastSim.length() != 0) { + LOG.info("Last Simulation detected"); + JFrame frame = new JFrame(); + String[] options = {"Resume", "No"}; + int option = JOptionPane.showOptionDialog(frame, + "Do you want to resume last simulation?", "Confirmation", + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, + null, options, options[0]); + if (option == JOptionPane.YES_NO_OPTION) { + try { + FileInputStream readHost = new FileInputStream( + new File(System.getProperty("user.dir") + "\\hostname.encrypted")); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + LoginCredentialsDialog signIn = new LoginCredentialsDialog("bla", true); + } + } + } } From 514b17edd5b54f607f99422b0d38a65bd3bcd316 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:12:31 -0800 Subject: [PATCH 03/15] working on connection to the remote server --- .../workbench/comm/SecureFileTransfer.java | 53 +++++++++++++++++++ .../WorkbenchDashboard.java | 24 +++++++-- 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java index 6d4efd0..b2f4b52 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java @@ -1,5 +1,6 @@ package edu.uwb.braingrid.workbench.comm; +import com.jcraft.jsch.Channel; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.JSch; @@ -7,11 +8,16 @@ import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpProgressMonitor; + +import riotcmd.infer; + +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.util.Date; /** @@ -273,4 +279,51 @@ private boolean readInputStream(InputStream in, ChannelExec cExec) { return success; } // + + /** + * Connects to the last simulation. + * + * @param hostname The name of the host machine to connect to. + * @param username The user's login username. + * @param password The user's login password. + * @param simName The last simulation to connect to. + */ + + public void checkLastSim(String hostname, String username, String password, String simName) { + JSch jsch = new JSch(); + try { + session = jsch.getSession(username, hostname, PORT); + session.setPassword(password); + session.setConfig("StrictHostKeyChecking", "no"); //optional + session.connect(); + + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setInputStream(null); + ((ChannelExec) channel).setCommand("cd WorkbenchSimulations/"); + channel.connect(); + ((ChannelExec) channel).setCommand("ls"); + channel.connect(); + + InputStream in; + try { + in = channel.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + String files; + while ((files = reader.readLine()) != null) { + String[] file = files.split("\\s+"); + for (int i = 0; i < file.length; i++) { + if (file.equals(simName)) { + return; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + } catch (JSchException e) { + e.printStackTrace(); + } + + } } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 152ca86..cb7a25e 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -5,6 +5,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.ObjectInputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.logging.FileHandler; @@ -24,6 +25,7 @@ import edu.uwb.braingrid.workbench.FileManager; import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; +import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import edu.uwb.braingrid.workbenchdashboard.utils.SystemProperties; /** @@ -153,12 +155,28 @@ private void checkLastSim() { null, options, options[0]); if (option == JOptionPane.YES_NO_OPTION) { try { - FileInputStream readHost = new FileInputStream( - new File(System.getProperty("user.dir") + "\\hostname.encrypted")); + FileInputStream readKey = new FileInputStream( + new File(System.getProperty("user.dir") + "\\Key")); + try { + ObjectInputStream readKeyObj = new ObjectInputStream(readKey); + String key; + try { + key = (String) readKeyObj.readObject(); + File hostInfo = new File( + System.getProperty("user.dir") + "\\Cache\\hostname.encrypted"); + SimulationSpecificationDialog tempDiaLog = new SimulationSpecificationDialog(); + String realHostInfo = tempDiaLog.decrypt(key, hostInfo, hostInfo, ""); + LoginCredentialsDialog loginToResume = new + LoginCredentialsDialog(realHostInfo, true); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } } catch (FileNotFoundException e) { e.printStackTrace(); } - LoginCredentialsDialog signIn = new LoginCredentialsDialog("bla", true); } } } From c66f099a7724ac9fc3a9717aaa66e64c4bcd2a92 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Sun, 26 Feb 2023 02:29:26 -0800 Subject: [PATCH 04/15] now the after clicking resume, it can successfully connect to the remote machine and do some operations --- WorkbenchProject/Cache/hostname.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Cache/username.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Key | Bin 23 -> 23 bytes WorkbenchProject/LastSimulation/simName | Bin 0 -> 9 bytes .../workbench/comm/SecureFileTransfer.java | 8 +++++--- .../workbench/script/ScriptManager.java | 17 ++++++++++++++++ .../WorkbenchDashboard.java | 19 ++++++++++++++++-- 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 WorkbenchProject/LastSimulation/simName diff --git a/WorkbenchProject/Cache/hostname.encrypted b/WorkbenchProject/Cache/hostname.encrypted index bf3cfd93544cc410a2f9c1c9ff87d4de6c9be38c..5469d8e1e5681ae395d70a3f6b0898c4261d7dcd 100644 GIT binary patch delta 21 ccmdPao**qS`;fHw3AQ{(cTMfRjzv`m0a4@-3vTk72e{r0{}~22si)$ diff --git a/WorkbenchProject/Cache/username.encrypted b/WorkbenchProject/Cache/username.encrypted index 1410400e0bc72f1fa2d437abb5f8f8125e6c2e88..8f3f47e6c9806212e61bdfb64927e33e4a95c7cd 100644 GIT binary patch delta 21 dcmdPao**so=i0HYuRD*4)N)R`DA#Q!3IJ?|35oy! delta 21 dcmdPao**p{@mg}j)MNkhco|x{Iv1&)1OQsd2^jzY diff --git a/WorkbenchProject/Key b/WorkbenchProject/Key index 682d8190081ce18c15bf07ca6bcc128e950b7fda..2ef881041eda0465603d32cc32d92ade9c8b2aa5 100644 GIT binary patch literal 23 ecmZ4UmVvc|LBQC_-#s&|C@(Z4wA9SZ#RmXc`3Fz{ literal 23 ecmZ4UmVvc|K_EHYwb0uvI5E@L($lom+YA6&X9p_) diff --git a/WorkbenchProject/LastSimulation/simName b/WorkbenchProject/LastSimulation/simName new file mode 100644 index 0000000000000000000000000000000000000000..6dbd8afaeae28fc0d8a4ac6650879e13857544c6 GIT binary patch literal 9 QcmZ4UmVvc|fyu}i01$ivdH?_b literal 0 HcmV?d00001 diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java index b2f4b52..931cba7 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java @@ -299,10 +299,9 @@ public void checkLastSim(String hostname, String username, String password, Stri Channel channel = session.openChannel("exec"); ((ChannelExec) channel).setInputStream(null); - ((ChannelExec) channel).setCommand("cd WorkbenchSimulations/"); - channel.connect(); - ((ChannelExec) channel).setCommand("ls"); + ((ChannelExec) channel).setCommand("cd WorkbenchSimulations/ && ls"); channel.connect(); + channel.disconnect(); InputStream in; try { @@ -313,7 +312,10 @@ public void checkLastSim(String hostname, String username, String password, Stri String[] file = files.split("\\s+"); for (int i = 0; i < file.length; i++) { if (file.equals(simName)) { + System.out.println("yesssssssssssssssssss!"); return; + } else { + System.out.println("noooooooooooooooo!"); } } } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 3046ccc..100e274 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -253,6 +253,10 @@ public boolean runScript(ProvMgr provMgr, SimulationSpecification simSpec, return success; } + private String lastSimLocation() { + return System.getProperty("user.dir") + "\\LastSimulation"; + } + private void saveSimDir(String simDir) { try { FileOutputStream simDirLocation = new FileOutputStream( @@ -264,6 +268,18 @@ private void saveSimDir(String simDir) { } } + private void saveSimName(String simName) { + FileOutputStream simNameLocation; + try { + simNameLocation = new FileOutputStream( + new File(lastSimLocation() + "\\simName")); + ObjectOutputStream writeSimName = new ObjectOutputStream(simNameLocation); + writeSimName.writeObject(simName); + } catch (IOException e) { + e.printStackTrace(); + } + } + private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulationName, String scriptPath, String[] nListFilenames, String simConfigFilename) throws JSchException, FileNotFoundException, SftpException { @@ -285,6 +301,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat String cmd = "mkdir -p " + nListDir; sft.executeCommand(cmd, hostname, lcd.getUsername(), password, true); saveSimDir(simDir); + saveSimName(simulationName); /* Upload Script */ Date uploadStartTime = new Date(); if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index cb7a25e..3859ce7 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -24,6 +24,7 @@ import edu.uwb.braingrid.general.LoggerHelper; import edu.uwb.braingrid.workbench.FileManager; import edu.uwb.braingrid.workbench.WorkbenchManager; +import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import edu.uwb.braingrid.workbenchdashboard.utils.SystemProperties; @@ -133,7 +134,6 @@ public void start(Stage primaryStage) throws Exception { primaryStage.setScene(scene); primaryStage.setMaximized(true); primaryStage.show(); - checkLastSim(); // Exit application on window close primaryStage.setOnCloseRequest(event -> { Platform.exit(); @@ -142,9 +142,16 @@ public void start(Stage primaryStage) throws Exception { // Initialize Workbench Manager WorkbenchManager.getInstance(); + checkLastSim(); } private void checkLastSim() { - File lastSim = new File(System.getProperty("user.dir") + "\\LastSimulation\\simdir"); + String workDir = System.getProperty("user.dir"); + String substr = "\\target"; + if (workDir.endsWith(substr)) { + workDir = workDir.substring(0, workDir.length() - substr.length()); + } + String simPath = workDir + "\\LastSimulation\\simdir"; + File lastSim = new File(simPath); if (lastSim.exists() && lastSim.isFile() && lastSim.length() != 0) { LOG.info("Last Simulation detected"); JFrame frame = new JFrame(); @@ -166,8 +173,16 @@ private void checkLastSim() { System.getProperty("user.dir") + "\\Cache\\hostname.encrypted"); SimulationSpecificationDialog tempDiaLog = new SimulationSpecificationDialog(); String realHostInfo = tempDiaLog.decrypt(key, hostInfo, hostInfo, ""); + FileInputStream readSimlationName = new FileInputStream(new File( + System.getProperty("user.dir") + "\\LastSimulation\\simName")); + ObjectInputStream readSimNameObj = new ObjectInputStream(readSimlationName); + String simName = (String) readSimNameObj.readObject(); LoginCredentialsDialog loginToResume = new LoginCredentialsDialog(realHostInfo, true); + String username = loginToResume.getUsername(); + String password = new String(loginToResume.getPassword()); + SecureFileTransfer fileTransfer = new SecureFileTransfer(); + fileTransfer.checkLastSim(realHostInfo, username, password, simName); } catch (ClassNotFoundException e) { e.printStackTrace(); } From 5f113289e321040a6a5bd449ab97fd524ae4a671 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Sun, 26 Feb 2023 15:55:07 -0800 Subject: [PATCH 05/15] 1. fiexd a bug related to working dir: since the IDE and command line executation has a different working dir, all files will be saved to workbenchproject not target. 2. now the check last simulation can check if the simulation from last time is completed --- WorkbenchProject/Cache/hostname.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Cache/username.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Key | Bin 23 -> 23 bytes .../uwb/braingrid/workbench/FileManager.java | 11 ++++++- .../workbench/comm/SecureFileTransfer.java | 30 +++++++++++++----- .../workbench/script/ScriptManager.java | 13 ++++++-- .../workbench/ui/LoginCredentialsDialog.java | 13 ++++++-- .../ui/SimulationSpecificationDialog.java | 17 +++++++--- .../WorkbenchDashboard.java | 20 +++++++++--- 9 files changed, 83 insertions(+), 21 deletions(-) diff --git a/WorkbenchProject/Cache/hostname.encrypted b/WorkbenchProject/Cache/hostname.encrypted index 5469d8e1e5681ae395d70a3f6b0898c4261d7dcd..a4105951a1c00ffd6b296bf8f3254be6fdc5d400 100644 GIT binary patch delta 21 dcmdPao**soX<3KRmJ&0C;IF6jl*9uj0038H2pa$Z delta 21 ccmdPao**qS`;fHw3AQ{(cTMfRjzv /** @@ -41,8 +50,8 @@ private void initComponents() { hostnameLabel.setText("Hostname: "); usernameLabel.setText("Username: "); - File inputFile = new File(System.getProperty("user.dir") + "\\Cache\\username.encrypted"); - File key = new File(System.getProperty("user.dir") + "\\Key"); + File inputFile = new File(workingDir() + "\\Cache\\username.encrypted"); + File key = new File(workingDir() + "\\Key"); try { FileInputStream keyInput = new FileInputStream(key); ObjectInputStream keyObj; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/SimulationSpecificationDialog.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/SimulationSpecificationDialog.java index c50bd93..8bca0d3 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/SimulationSpecificationDialog.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/SimulationSpecificationDialog.java @@ -588,7 +588,7 @@ private void setRemoteRelatedComponentsEnabled(boolean enabled) { usernameTextField.setEnabled(enabled); passwordField.setEnabled(enabled); //if the cache file exists, autofill the textfield; - File key = new File(System.getProperty("user.dir") + "\\Key"); + File key = new File(workingDir() + "\\Key"); String userPostfix = "\\Cache\\username.encrypted"; String hostnamePostfix = "\\Cache\\hostname.encrypted"; boolean usernameFilled = tryFillTextField(key, userPostfix, "username", usernameTextField); @@ -596,9 +596,18 @@ private void setRemoteRelatedComponentsEnabled(boolean enabled) { hostnamePostfix, "hostname", hostAddressTextField); } + private static String workingDir() { + String dir = System.getProperty("user.dir"); + String target = "\\target"; + if (dir.endsWith(target)) { + dir = dir.substring(0, dir.length() - target.length()); + } + return dir; + } + private boolean tryFillTextField(File key, String location, String fieldName, JTextField fieldToFill) { - File inputFile = new File(System.getProperty("user.dir") + location); + File inputFile = new File(workingDir() + location); FileInputStream keyInput; try { keyInput = new FileInputStream(key); @@ -762,7 +771,7 @@ private void validateUsername() { } private String getCachePath() { - return System.getProperty("user.dir") + "\\Cache"; + return workingDir() + "\\Cache"; } private static final String CHARACTERS @@ -817,7 +826,7 @@ public static String doCrypto(int cipherMode, String key, File inputFile, Cipher cipher = Cipher.getInstance(TRANSFORMATION); cipher.init(cipherMode, secretKey); if (cipherMode == Cipher.ENCRYPT_MODE) { - File keyFile = new File(System.getProperty("user.dir") + "\\Key"); + File keyFile = new File(workingDir() + "\\Key"); FileOutputStream keyOutput = new FileOutputStream(keyFile); ObjectOutputStream keyObj = new ObjectOutputStream(keyOutput); keyObj.writeObject(key); diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 3859ce7..2baf487 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -14,6 +14,8 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; +import org.eclipse.jgit.transport.CredentialItem.Username; + import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.image.Image; @@ -144,8 +146,18 @@ public void start(Stage primaryStage) throws Exception { WorkbenchManager.getInstance(); checkLastSim(); } + + private String workingDir() { + String dir = System.getProperty("user.dir"); + String target = "\\target"; + if (dir.endsWith(target)) { + dir = dir.substring(0, dir.length() - target.length()); + } + return dir; + } + private void checkLastSim() { - String workDir = System.getProperty("user.dir"); + String workDir = workingDir(); String substr = "\\target"; if (workDir.endsWith(substr)) { workDir = workDir.substring(0, workDir.length() - substr.length()); @@ -163,18 +175,18 @@ private void checkLastSim() { if (option == JOptionPane.YES_NO_OPTION) { try { FileInputStream readKey = new FileInputStream( - new File(System.getProperty("user.dir") + "\\Key")); + new File(workingDir() + "\\Key")); try { ObjectInputStream readKeyObj = new ObjectInputStream(readKey); String key; try { key = (String) readKeyObj.readObject(); File hostInfo = new File( - System.getProperty("user.dir") + "\\Cache\\hostname.encrypted"); + workingDir() + "\\Cache\\hostname.encrypted"); SimulationSpecificationDialog tempDiaLog = new SimulationSpecificationDialog(); String realHostInfo = tempDiaLog.decrypt(key, hostInfo, hostInfo, ""); FileInputStream readSimlationName = new FileInputStream(new File( - System.getProperty("user.dir") + "\\LastSimulation\\simName")); + workingDir() + "\\LastSimulation\\simName")); ObjectInputStream readSimNameObj = new ObjectInputStream(readSimlationName); String simName = (String) readSimNameObj.readObject(); LoginCredentialsDialog loginToResume = new From 495f51f07501edc6ace30fc32991607fa0ed117b Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 14:13:03 -0800 Subject: [PATCH 06/15] This version can now keep track of the previous simulation informatiom. Including simulation, provMgv, and the model inside, and can write the model correctly. However, due to the space in my username, it cannot read the model. The problem can be solved by removing the space. --- WorkbenchProject/Cache/hostname.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Cache/username.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Key | Bin 23 -> 23 bytes WorkbenchProject/LastSimulation/message | Bin 0 -> 742 bytes WorkbenchProject/LastSimulation/model.ttl | 108 ++++++++++++++++++ WorkbenchProject/LastSimulation/simulation | Bin 0 -> 1021 bytes WorkbenchProject/LastSimulation/uri | 3 + .../edu/uwb/braingrid/provenance/ProvMgr.java | 47 +++++++- .../braingrid/workbench/WorkbenchManager.java | 29 +++++ .../workbench/comm/SecureFileTransfer.java | 25 +++- .../workbench/model/ScriptHistory.java | 4 +- .../braingrid/workbench/model/Simulation.java | 3 +- .../model/SimulationSpecification.java | 4 +- .../workbench/script/ScriptManager.java | 25 ++++ .../WorkbenchDashboard.java | 33 +++++- 15 files changed, 273 insertions(+), 8 deletions(-) create mode 100644 WorkbenchProject/LastSimulation/message create mode 100644 WorkbenchProject/LastSimulation/model.ttl create mode 100644 WorkbenchProject/LastSimulation/simulation create mode 100644 WorkbenchProject/LastSimulation/uri diff --git a/WorkbenchProject/Cache/hostname.encrypted b/WorkbenchProject/Cache/hostname.encrypted index a4105951a1c00ffd6b296bf8f3254be6fdc5d400..c0764006646f19aa1624e5d216c97aa39865f3cd 100644 GIT binary patch delta 21 dcmdPao**so?vT*AjQH4-e<#(2?Oy3w1ps7m3K;+Z delta 21 dcmdPao**soX<3KRmJ&0C;IF6jl*9uj0038H2pa$Z diff --git a/WorkbenchProject/Cache/username.encrypted b/WorkbenchProject/Cache/username.encrypted index aeb1d2507e4b4295af47b364dc9fd19c906c14bf..afe6c1e7dcc18fda8b9a1c1420f1c7c13641555a 100644 GIT binary patch delta 21 dcmdPao**r7$DikE=>H(Lf6QNbRxGio0{~eZ2;Kky delta 21 dcmdPao**sYG07t{W~bL$hjrT5tp2c{1prXi2%-Q0 diff --git a/WorkbenchProject/Key b/WorkbenchProject/Key index c741d8686a05c7eaf1725aacd8467f7e786f2463..dd8712719c4eb8d8a97f7ff5090bdddc42497b45 100644 GIT binary patch literal 23 ecmZ4UmVvc|K_E0IGc`CMsi4Hm)F?2w+!X*{FbBo} literal 23 ecmZ4UmVvc|LBJy4GRi-_INZs-!Ys-oy8r-My$6v1 diff --git a/WorkbenchProject/LastSimulation/message b/WorkbenchProject/LastSimulation/message new file mode 100644 index 0000000000000000000000000000000000000000..133cfe4ff799600f88915f3fbb2d230308099f97 GIT binary patch literal 742 zcmchV&q~8U5XMFDvQIH5k7?XoG&d;hC;b2SU-gSs!<1zfobN!>aBRAH;l#Jfk-98}?{v`S_w zXipvY>S3*tU_|V!D{HKQ9XKwvp(MUk3D!}F*>~@sd$eokw3w5{psp_|usYRD&$!ab zvaw>zvQ5iwz%E)t6|wWLgK*nyy8-Nc|J8aBZqqUZCbQN3hb(7H)RCzVRO?LaAQ*TX z{iJG2O|&JGYr{xpef?$$4n@g-LUfCbV}zRy{dx?>uIVf?);Sar;T$WF$B?G^(Mc{- Lm`n?hsm#O|UM~v} literal 0 HcmV?d00001 diff --git a/WorkbenchProject/LastSimulation/model.ttl b/WorkbenchProject/LastSimulation/model.ttl new file mode 100644 index 0000000..b463013 --- /dev/null +++ b/WorkbenchProject/LastSimulation/model.ttl @@ -0,0 +1,108 @@ +@prefix rdf: . +@prefix xsd: . +@prefix rdfs: . +@prefix remote: . +@prefix prov: . +@prefix local: . + + + a prov:Entity ; + rdfs:label "script" . + + + a prov:Entity ; + rdfs:label "simulationConfigurationFile" ; + prov:wasGeneratedBy . + + + a prov:Activity ; + rdfs:label "upload" ; + prov:endedAtTime "2023-02-28T08:19:20.003Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-02-28T08:19:19.454Z"^^ ; + prov:used ; + prov:wasAssociatedWith . + + + a prov:Entity ; + rdfs:label "nlist" . + + + a prov:Entity ; + rdfs:label "script" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . + + + a prov:Entity ; + rdfs:label "nlist" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . + + + a prov:Entity ; + rdfs:label "nlist" . + + a prov:Activity ; + rdfs:label "upload" ; + prov:endedAtTime "2023-02-28T08:19:17.839Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-02-28T08:19:17.285Z"^^ ; + prov:used ; + prov:wasAssociatedWith . + + a prov:SoftwareAgent . + + + a prov:Activity ; + rdfs:label "upload" ; + prov:endedAtTime "2023-02-28T08:19:18.918Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-02-28T08:19:18.385Z"^^ ; + prov:used ; + prov:wasAssociatedWith . + + + a prov:Activity ; + rdfs:label "upload" ; + prov:endedAtTime "2023-02-28T08:19:19.454Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-02-28T08:19:18.919Z"^^ ; + prov:used ; + prov:wasAssociatedWith . + + + a prov:Entity ; + rdfs:label "simulationConfigurationFile" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . + + + a prov:Activity ; + rdfs:label "upload" ; + prov:endedAtTime "2023-02-28T08:19:18.385Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-02-28T08:19:17.84Z"^^ ; + prov:used ; + prov:wasAssociatedWith . + + + a prov:Activity ; + prov:generated ; + prov:wasAssociatedWith . + + + a prov:Entity ; + rdfs:label "nlist" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . + + + a prov:Entity ; + rdfs:label "nlist" . + + + a prov:Entity ; + rdfs:label "nlist" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . diff --git a/WorkbenchProject/LastSimulation/simulation b/WorkbenchProject/LastSimulation/simulation new file mode 100644 index 0000000000000000000000000000000000000000..7f8bb283717cfeb55754c1800b536fbc865d740e GIT binary patch literal 1021 zcmb7DJ#W-N5S=^7#}Oq!gea&YK}ozMsYt5JDIp5ZfpR%TM3&In-aBt%?>f8V%N>H0 z`~_NsDESNg01AEpqNPcJ5WfJ%KA)9>BDh+uXWzVe@6D&5Fl7xq6k+CMXTIYbE>+*i z&^goQ#1|@voJ5Brb~-Z2VvbU)H(EdHf2iH9!}Jl%rA8076!&8hx^P|bL?A4>$9%w9 z%vGOt&=BH=3kycrEXHjai#AoA!a3Ajn74tEDeg#%+KdoZT%y8=3ahBFiV7>Ju+HTt zggkF$($cCY`#E?CJVTeAR0IecSAndi%iqYJ42n@VhG`9ywJc4V6t6gYVBVPmYZcn*RwB6zb>fEFqQJJidZ9|CZgmXn(wj-v6#cgK`s4{`N(xt;{1* z+B+L*iwI4;-bV3bZ0v}ko^0@0%O z-87^;sQ#pRMgm`IetSTA(`Gc4(pUtiG>GyXA*ObnvA)D8^BuCBbq_a}H>J+q&vI1u z#PBqdh|-}dq$D5@B3UdXX@~#_)B7UPNV|3aoITiiwztJ9PdnA9c{rIb6~c{ private static final Logger LOG = Logger.getLogger(ProvMgr.class.getName()); @@ -71,6 +72,50 @@ public class ProvMgr { private Model model; // + /** + * The getter for provURI. + * + * @return return the provURI. + * + */ + public String getProvURI() { + return provOutputFileURI; + } + + /** + * The getter for LocalURI. + * + * @return return the LocalURI. + * + */ + public String getLocalURI() { + return localNameSpaceURI; + } + + /** + * The getter for RemoteURI. + * + * @return return the RemoteURI. + * + */ + public String getRemoteURI() { + return remoteNameSpaceURI; + } + /** + * The constructor used by resume Lastsimulation. + * + * @param provURI the provURI + * @param localURI the localURI + * @param remoteURI the remoteURI + * @param model the model + */ + public ProvMgr(String provURI, String localURI, String remoteURI, Model model) { + this.provOutputFileURI = provURI; + this.localNameSpaceURI = localURI; + this.remoteNameSpaceURI = remoteURI; + this.model = model; + } + // /** * Constructs the Provenance Constructor object from a previously recorded provenance file. diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java index 2710e34..a13836d 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java @@ -4,7 +4,10 @@ import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.ObjectOutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -56,6 +59,14 @@ public final class WorkbenchManager { private Project project; private Simulation simulation; private ProvMgr prov; + + public void simulationSetter(Simulation inputSimulation) { + this.simulation = inputSimulation; + } + + public void provMgrSetter(ProvMgr inputProv) { + this.prov = inputProv; + } // // @@ -527,8 +538,17 @@ public boolean runScript() { neuronLists, simulation.getSimConfigFilename()); simulation.setScriptRan(success); simulation.setScriptStartedAt(); + if (success) { + File simulationFile = new File(workingDir() + "\\LastSimulation\\simulation"); + FileOutputStream simOut = new FileOutputStream(simulationFile); + ObjectOutputStream simObjOut = new ObjectOutputStream(simOut); + simObjOut.writeObject(simulation); + } + + //save the simulation here messageAccumulator += sm.getOutstandingMessages(); } catch (JSchException | SftpException | IOException | NullPointerException e) { + e.printStackTrace(); messageAccumulator += "\n" + "Script did not run do to " + e.getClass() + "...\n"; messageAccumulator += "Exception message: " + e.getMessage(); @@ -537,6 +557,15 @@ public boolean runScript() { return success; } + private static String workingDir() { + String dir = System.getProperty("user.dir"); + String target = "\\target"; + if (dir.endsWith(target)) { + dir = dir.substring(0, dir.length() - target.length()); + } + return dir; + } + /** * Analyzes the redirected provenance output from an executed script. * diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java index 696129d..c6f5e7d 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java @@ -9,6 +9,9 @@ import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpProgressMonitor; +import edu.uwb.braingrid.workbench.WorkbenchManager; +import edu.uwb.braingrid.workbench.ui.SimulationRuntimeDialog; +import javafx.scene.control.TextArea; import riotcmd.infer; import java.io.BufferedReader; @@ -20,6 +23,9 @@ import java.io.InputStreamReader; import java.util.Date; +import javax.swing.JFrame; +import javax.swing.JOptionPane; + /** * Provides abbreviated SSF/FTP functionality. This includes uploading/downloading files and * execution of commands on a remote machine. @@ -287,9 +293,11 @@ private boolean readInputStream(InputStream in, ChannelExec cExec) { * @param username The user's login username. * @param password The user's login password. * @param simName The last simulation to connect to. + * @param manager The temp place holder. */ - public void checkLastSim(String hostname, String username, String password, String simName) { + public void checkLastSim(String hostname, String username, + String password, String simName, WorkbenchManager manager) { JSch jsch = new JSch(); try { session = jsch.getSession(username, hostname, PORT); @@ -326,7 +334,8 @@ public void checkLastSim(String hostname, String username, String password, Stri lastline = lastline.substring( lastline.length() - completion.length(), lastline.length()); if (lastline.equals("Complete")) { - System.out.println("hhoooray!"); + displayDownloadFrame(channel2, manager); + break; } } catch (SftpException e) { e.printStackTrace(); @@ -340,6 +349,18 @@ public void checkLastSim(String hostname, String username, String password, Stri } catch (JSchException e) { e.printStackTrace(); } + } + private void displayDownloadFrame(Channel channel, WorkbenchManager manager) { + JFrame frame = new JFrame(); + String[] options = {"Download", "Cancel"}; + int option = JOptionPane.showOptionDialog(frame, + "Last simlation completed, do you want to download?", "Last Simulation Completed", + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, + null, options, options[0]); + if (option == JOptionPane.YES_NO_OPTION) { + SimulationRuntimeDialog srd = new SimulationRuntimeDialog( + new TextArea(manager.getMessages())); + } } } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/ScriptHistory.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/ScriptHistory.java index d1f6069..66e5beb 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/ScriptHistory.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/ScriptHistory.java @@ -1,5 +1,7 @@ package edu.uwb.braingrid.workbench.model; +import java.io.Serializable; + import edu.uwb.braingrid.workbench.utils.DateTime; /** @@ -7,7 +9,7 @@ * * @author Aaron Conrad */ -public class ScriptHistory { +public class ScriptHistory implements Serializable { // private long startedAt; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/Simulation.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/Simulation.java index 1ab69e7..23e633b 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/Simulation.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/Simulation.java @@ -1,5 +1,6 @@ package edu.uwb.braingrid.workbench.model; +import java.io.Serializable; import java.nio.file.Path; import java.util.logging.Logger; @@ -13,7 +14,7 @@ * * @author Steven Leighton */ -public class Simulation { +public class Simulation implements Serializable { // private static final Logger LOG = Logger.getLogger(Simulation.class.getName()); diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java index e9f58f5..4b4a66c 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java @@ -1,6 +1,8 @@ package edu.uwb.braingrid.workbench.model; import com.fasterxml.jackson.annotation.JsonIgnore; + +import java.io.Serializable; import java.util.Objects; /** @@ -10,7 +12,7 @@ * * @author Del Davis */ -public class SimulationSpecification { +public class SimulationSpecification implements Serializable { /** * Description of the execution model for a simulation (in particular, these values indicate the diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 5d3fd93..e404bbb 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -1,13 +1,17 @@ package edu.uwb.braingrid.workbench.script; +import com.fasterxml.jackson.databind.ObjectMapper; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; +import java.io.FileWriter; import java.io.IOException; import java.io.ObjectOutputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -409,6 +413,27 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat DateTime.recordAccumulatedProvTiming("ScriptManager", "runRemoteScript", accumulatedTime); } + if (success) { + String simLocation = workingDir() + "\\LastSimulation"; + File messageFile = new File(simLocation + "\\message"); + File uriFile = new File(simLocation + "\\uri"); + FileOutputStream messageOut = new FileOutputStream(messageFile); + try { + ObjectOutputStream messageOutObj = new ObjectOutputStream(messageOut); + messageOutObj.writeObject(outstandingMessages); + provMgr.getModel().write( + new FileOutputStream(new File( + workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); + FileWriter uriWriter = new FileWriter(uriFile); + uriWriter.write(provMgr.getProvURI() + "\n"); + uriWriter.write(provMgr.getLocalURI() + "\n"); + uriWriter.write(provMgr.getRemoteURI() + "\n"); + uriWriter.close(); + messageOutObj.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } return success; } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 2baf487..16b3ed7 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -1,9 +1,11 @@ package edu.uwb.braingrid.workbenchdashboard; import java.awt.FlowLayout; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.ObjectInputStream; import java.nio.file.Files; @@ -14,8 +16,12 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; +import org.apache.jena.rdf.model.Model; +import org.apache.jena.rdf.model.ModelFactory; import org.eclipse.jgit.transport.CredentialItem.Username; +import com.fasterxml.jackson.databind.ObjectMapper; + import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.image.Image; @@ -24,9 +30,11 @@ import javafx.stage.Stage; import edu.uwb.braingrid.general.LoggerHelper; +import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.workbench.FileManager; import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; +import edu.uwb.braingrid.workbench.model.Simulation; import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import edu.uwb.braingrid.workbenchdashboard.utils.SystemProperties; @@ -169,7 +177,7 @@ private void checkLastSim() { JFrame frame = new JFrame(); String[] options = {"Resume", "No"}; int option = JOptionPane.showOptionDialog(frame, - "Do you want to resume last simulation?", "Confirmation", + "Do you want to resume last simulation?", "Last Simulation Detected", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (option == JOptionPane.YES_NO_OPTION) { @@ -194,7 +202,26 @@ private void checkLastSim() { String username = loginToResume.getUsername(); String password = new String(loginToResume.getPassword()); SecureFileTransfer fileTransfer = new SecureFileTransfer(); - fileTransfer.checkLastSim(realHostInfo, username, password, simName); + + File simulationInput = new File(workingDir() + "\\LastSimulation\\simulation"); + FileInputStream simIn = new FileInputStream(simulationInput); + ObjectInputStream simInObj = new ObjectInputStream(simIn); + + BufferedReader readURI = new BufferedReader( + new FileReader(workingDir() + "\\LastSimulation\\uri")); + String provURI = readURI.readLine(); + String localURI = readURI.readLine(); + String remoteURI = readURI.readLine(); + Model model = ModelFactory.createDefaultModel(); +// String modelPath = workingDir() + "\\LastSimulation\\model.ttl"; +// modelPath = modelPath.replaceAll(" ", "%20"); + model.read(workingDir() + "\\LastSimulation\\model.ttl", "TURTLE"); + ProvMgr lastMgr = new ProvMgr(provURI, localURI, remoteURI, model); + WorkbenchManager.getInstance().simulationSetter((Simulation) simInObj.readObject()); + WorkbenchManager.getInstance().provMgrSetter(lastMgr); + fileTransfer.checkLastSim(realHostInfo, username, + password, simName, WorkbenchManager.getInstance()); + JOptionPane.getRootFrame().dispose(); } catch (ClassNotFoundException e) { e.printStackTrace(); } @@ -205,6 +232,8 @@ private void checkLastSim() { e.printStackTrace(); } } + } else { + JOptionPane.getRootFrame().dispose(); } } } From 7143787e1abcee3895a6321a6531db1f99f42e0f Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 16:51:12 -0800 Subject: [PATCH 07/15] now the previous msg(String) will be saved and displayed too --- WorkbenchProject/Cache/hostname.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Cache/username.encrypted | Bin 43 -> 43 bytes WorkbenchProject/Key | Bin 23 -> 23 bytes WorkbenchProject/LastSimulation/message | Bin 742 -> 810 bytes WorkbenchProject/LastSimulation/model.ttl | 106 +++++++++--------- WorkbenchProject/LastSimulation/simName | Bin 9 -> 15 bytes WorkbenchProject/LastSimulation/simdir | Bin 32 -> 38 bytes WorkbenchProject/LastSimulation/simulation | Bin 1021 -> 1073 bytes WorkbenchProject/LastSimulation/uri | 4 +- .../braingrid/workbench/WorkbenchManager.java | 9 ++ .../workbench/script/ScriptManager.java | 4 +- .../WorkbenchDashboard.java | 4 + 12 files changed, 71 insertions(+), 56 deletions(-) diff --git a/WorkbenchProject/Cache/hostname.encrypted b/WorkbenchProject/Cache/hostname.encrypted index c0764006646f19aa1624e5d216c97aa39865f3cd..adee18bf862bc36d8122b385c94495e3d9c1c5eb 100644 GIT binary patch delta 21 dcmdPao**r-$>hG>?MeCXH(Lf6QNbRxGio0{~eZ2;Kky diff --git a/WorkbenchProject/Key b/WorkbenchProject/Key index dd8712719c4eb8d8a97f7ff5090bdddc42497b45..2a9788f292d5b46b56427754d0c18940d064700d 100644 GIT binary patch literal 23 ecmZ4UmVvc|L7*(i%P_Dq&C)Bm%F!*v*AoC+$p>cu literal 23 ecmZ4UmVvc|K_E0IGc`CMsi4Hm)F?2w+!X*{FbBo} diff --git a/WorkbenchProject/LastSimulation/message b/WorkbenchProject/LastSimulation/message index 133cfe4ff799600f88915f3fbb2d230308099f97..78ad9423b930ff792a8da8b8be045ce44f9719bd 100644 GIT binary patch literal 810 zcmchV!Ab)$5QYWulBXCDJZ|e+itMda1wpjfmR zd+^ZP4EdS)n0%jKM<;xIDu$Vy2J}G=ii#`+_KKaCGv{A&w7ML5_l%l@yu!JPh9!Ga zrq}Jspgq;w{^_?*LMdWxoGP#YcHmg)l9KqACs;%wrt7!=FV@b^X)z~*LEhgr$a0{W zUU5|?%gTs7dv_xTXS}r~<<#8vy_Iuc?BJ}mcR3cVoV$@W#ob26IR+ T;k=)9ds*6t(Rc!BH@y(wyi+F- delta 236 zcmZ3*_KekG&07Z65~llH&Q>v@#i>QbF_DRR=?cF2NvWAJ;rT_`NvV0s839H4S*gh- z#W5j8nTa_uM#eG4$wiq3B|z51KucAkv`pMpLY%_Maf~%Ys^nryVgfqhx8mffOj@i) g#`;FalP@rN2pJey8CqHy87Kq diff --git a/WorkbenchProject/LastSimulation/model.ttl b/WorkbenchProject/LastSimulation/model.ttl index b463013..ca92a10 100644 --- a/WorkbenchProject/LastSimulation/model.ttl +++ b/WorkbenchProject/LastSimulation/model.ttl @@ -3,52 +3,49 @@ @prefix rdfs: . @prefix remote: . @prefix prov: . -@prefix local: . +@prefix local: . - - a prov:Entity ; - rdfs:label "script" . - - + a prov:Entity ; rdfs:label "simulationConfigurationFile" ; - prov:wasGeneratedBy . + prov:wasDerivedFrom ; + prov:wasGeneratedBy . + + + a prov:Entity ; + rdfs:label "nlist" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . a prov:Activity ; rdfs:label "upload" ; - prov:endedAtTime "2023-02-28T08:19:20.003Z"^^ ; - prov:generated ; - prov:startedAtTime "2023-02-28T08:19:19.454Z"^^ ; - prov:used ; + prov:endedAtTime "2023-03-01T00:04:26.626Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-03-01T00:04:26.298Z"^^ ; + prov:used ; prov:wasAssociatedWith . - + a prov:Entity ; rdfs:label "nlist" . - - a prov:Entity ; - rdfs:label "script" ; - prov:wasDerivedFrom ; - prov:wasGeneratedBy . - - + a prov:Entity ; rdfs:label "nlist" ; - prov:wasDerivedFrom ; - prov:wasGeneratedBy . + prov:wasDerivedFrom ; + prov:wasGeneratedBy . - + a prov:Entity ; rdfs:label "nlist" . a prov:Activity ; rdfs:label "upload" ; - prov:endedAtTime "2023-02-28T08:19:17.839Z"^^ ; - prov:generated ; - prov:startedAtTime "2023-02-28T08:19:17.285Z"^^ ; - prov:used ; + prov:endedAtTime "2023-03-01T00:04:25.333Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-03-01T00:04:25.026Z"^^ ; + prov:used ; prov:wasAssociatedWith . a prov:SoftwareAgent . @@ -56,53 +53,56 @@ a prov:Activity ; rdfs:label "upload" ; - prov:endedAtTime "2023-02-28T08:19:18.918Z"^^ ; - prov:generated ; - prov:startedAtTime "2023-02-28T08:19:18.385Z"^^ ; - prov:used ; + prov:endedAtTime "2023-03-01T00:04:25.99Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-03-01T00:04:25.682Z"^^ ; + prov:used ; prov:wasAssociatedWith . a prov:Activity ; rdfs:label "upload" ; - prov:endedAtTime "2023-02-28T08:19:19.454Z"^^ ; - prov:generated ; - prov:startedAtTime "2023-02-28T08:19:18.919Z"^^ ; - prov:used ; + prov:endedAtTime "2023-03-01T00:04:26.298Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-03-01T00:04:25.991Z"^^ ; + prov:used ; prov:wasAssociatedWith . - - a prov:Entity ; - rdfs:label "simulationConfigurationFile" ; - prov:wasDerivedFrom ; - prov:wasGeneratedBy . + + a prov:Entity ; + rdfs:label "nlist" . a prov:Activity ; rdfs:label "upload" ; - prov:endedAtTime "2023-02-28T08:19:18.385Z"^^ ; - prov:generated ; - prov:startedAtTime "2023-02-28T08:19:17.84Z"^^ ; - prov:used ; + prov:endedAtTime "2023-03-01T00:04:25.682Z"^^ ; + prov:generated ; + prov:startedAtTime "2023-03-01T00:04:25.333Z"^^ ; + prov:used ; prov:wasAssociatedWith . a prov:Activity ; - prov:generated ; + prov:generated ; prov:wasAssociatedWith . - + + a prov:Entity ; + rdfs:label "simulationConfigurationFile" ; + prov:wasGeneratedBy . + + a prov:Entity ; rdfs:label "nlist" ; - prov:wasDerivedFrom ; - prov:wasGeneratedBy . + prov:wasDerivedFrom ; + prov:wasGeneratedBy . - + a prov:Entity ; - rdfs:label "nlist" . + rdfs:label "script" . - + a prov:Entity ; - rdfs:label "nlist" ; - prov:wasDerivedFrom ; - prov:wasGeneratedBy . + rdfs:label "script" ; + prov:wasDerivedFrom ; + prov:wasGeneratedBy . diff --git a/WorkbenchProject/LastSimulation/simName b/WorkbenchProject/LastSimulation/simName index 6dbd8afaeae28fc0d8a4ac6650879e13857544c6..ccff4fa73c8c8e692e822326692c634f933a1128 100644 GIT binary patch literal 15 WcmZ4UmVvc|fup1-Gcm`+zyts)k_68H literal 9 QcmZ4UmVvc|fyu}i01$ivdH?_b diff --git a/WorkbenchProject/LastSimulation/simdir b/WorkbenchProject/LastSimulation/simdir index 8e673646b4ae99fcb0375c5589588f32c0b3bd85..a3876cd778730b129bd22409f3cab9c9e1b2042d 100644 GIT binary patch literal 38 tcmZ4UmVvc|LB38uJijPADK#%SBRDg+G$*knGe56bzoaNLF~`Kf1OO9o4gCNB literal 32 ncmZ4UmVvc|L9$LiJijPADK#%SBRDg+G$*knGe56b-^dsM!L19Z diff --git a/WorkbenchProject/LastSimulation/simulation b/WorkbenchProject/LastSimulation/simulation index 7f8bb283717cfeb55754c1800b536fbc865d740e..cb7015ff127e8b29e8078679101c6c61c607b55f 100644 GIT binary patch delta 273 zcmey%zL8^tDx(ZXNl|8Ej){Ru34=sYYH?{!NwGdmXtF8e^!iyfd`n6gf}O2mLW@(2 ziens8ax?QXi%W_UOY)0i!t;x=lT!1NGXje8vr>~wiep?-(-MKE#J~)RDNZiREI{z% zA$+~!j1q<*!ls(wGB!CsFD)}YEi)&z7;cwdMQ%=U5rgGqM@Hq%4NOLiYMOQWDjxp6 YuKI9?2507$<|LM6=I0@K^b)f+0IK?9vH$=8 delta 197 zcmdnU@t1vrDx(0Ck#PxwP*G}eX--M8zLD`{N5<*()1^)VMV*|jVnT~ki;80+6Z6s) zeDjl1Gh@Q@i?Wka^O7?Hit@8klS_(YLW(jIb7G8)V~UfDG7Cz8tau1ZuQ;QG!I4Bm xlJoP@gfi39GILUkfkx?7(9TQF-!1W?7)CC$q6=0|4!dL`MJs diff --git a/WorkbenchProject/LastSimulation/uri b/WorkbenchProject/LastSimulation/uri index cf129ce..28fee28 100644 --- a/WorkbenchProject/LastSimulation/uri +++ b/WorkbenchProject/LastSimulation/uri @@ -1,3 +1,3 @@ -C:\Users\Yang Mobei\WorkbenchProjects\Trial\23\provenance\23.ttl -DESKTOP-3N8B16A@73.225.90.139# +C:\Users\Administrator\WorkbenchProjects\Default\trial404\provenance\trial404.ttl +DESKTOP-3N8B16A@205.175.118.10# null diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java index a13836d..2ecae82 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java @@ -764,6 +764,15 @@ public String getMessages() { return messageAccumulator; } + /** + * Set the message for message Accumulator, used for remember last simulation. + * + * @param msg msg to set + */ + public void setMessages(String msg) { + messageAccumulator = msg; + } + /** * Clears the accumulated messages for this manager. */ diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index e404bbb..3d7c9f4 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -27,6 +27,8 @@ import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.provenance.WorkbenchOperationRecorder; import edu.uwb.braingrid.workbench.FileManager; +import edu.uwb.braingrid.workbench.Workbench; +import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; import edu.uwb.braingrid.workbench.data.InputAnalyzer; import edu.uwb.braingrid.workbench.model.Simulation; @@ -420,7 +422,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat FileOutputStream messageOut = new FileOutputStream(messageFile); try { ObjectOutputStream messageOutObj = new ObjectOutputStream(messageOut); - messageOutObj.writeObject(outstandingMessages); + messageOutObj.writeObject(WorkbenchManager.getInstance().getMessages()); provMgr.getModel().write( new FileOutputStream(new File( workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 16b3ed7..4eca052 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -219,6 +219,10 @@ private void checkLastSim() { ProvMgr lastMgr = new ProvMgr(provURI, localURI, remoteURI, model); WorkbenchManager.getInstance().simulationSetter((Simulation) simInObj.readObject()); WorkbenchManager.getInstance().provMgrSetter(lastMgr); + ObjectInputStream msgReader = new ObjectInputStream( + new FileInputStream(new File(workingDir() + "\\LastSimulation\\message"))); + String message = (String) msgReader.readObject(); + WorkbenchManager.getInstance().setMessages(message); fileTransfer.checkLastSim(realHostInfo, username, password, simName, WorkbenchManager.getInstance()); JOptionPane.getRootFrame().dispose(); From f106c8686c9596f28a3ea265fa81d6cf9264bfbd Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 16:57:09 -0800 Subject: [PATCH 08/15] trial to solve checkstyle1 --- .../braingrid/workbench/WorkbenchManager.java | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java index 2ecae82..4dc6304 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java @@ -60,13 +60,13 @@ public final class WorkbenchManager { private Simulation simulation; private ProvMgr prov; - public void simulationSetter(Simulation inputSimulation) { - this.simulation = inputSimulation; - } + public void simulationSetter(Simulation inputSimulation) { + this.simulation = inputSimulation; + } - public void provMgrSetter(ProvMgr inputProv) { - this.prov = inputProv; - } + public void provMgrSetter(ProvMgr inputProv) { + this.prov = inputProv; + } // // @@ -527,35 +527,35 @@ public boolean generateScript() { * @return True if all files were uploaded/copied successfully and the script was started, * otherwise false */ - public boolean runScript() { - boolean success = false; - ScriptManager sm = new ScriptManager(); - try { - String simulationName = simulation.getName(); - String scriptPath = simulation.getScriptFilePath(); - String[] neuronLists = FileManager.getNeuronListFilenames(simulationName); - success = sm.runScript(prov, simulation.getSimSpec(), simulationName, scriptPath, - neuronLists, simulation.getSimConfigFilename()); - simulation.setScriptRan(success); - simulation.setScriptStartedAt(); - if (success) { - File simulationFile = new File(workingDir() + "\\LastSimulation\\simulation"); - FileOutputStream simOut = new FileOutputStream(simulationFile); - ObjectOutputStream simObjOut = new ObjectOutputStream(simOut); - simObjOut.writeObject(simulation); - } - - //save the simulation here - messageAccumulator += sm.getOutstandingMessages(); - } catch (JSchException | SftpException | IOException | NullPointerException e) { - e.printStackTrace(); - messageAccumulator += "\n" + "Script did not run do to " - + e.getClass() + "...\n"; - messageAccumulator += "Exception message: " + e.getMessage(); - } - - return success; - } + public boolean runScript() { + boolean success = false; + ScriptManager sm = new ScriptManager(); + try { + String simulationName = simulation.getName(); + String scriptPath = simulation.getScriptFilePath(); + String[] neuronLists = FileManager.getNeuronListFilenames(simulationName); + success = sm.runScript(prov, simulation.getSimSpec(), simulationName, scriptPath, + neuronLists, simulation.getSimConfigFilename()); + simulation.setScriptRan(success); + simulation.setScriptStartedAt(); + if (success) { + File simulationFile = new File(workingDir() + "\\LastSimulation\\simulation"); + FileOutputStream simOut = new FileOutputStream(simulationFile); + ObjectOutputStream simObjOut = new ObjectOutputStream(simOut); + simObjOut.writeObject(simulation); + } + + //save the simulation here + messageAccumulator += sm.getOutstandingMessages(); + } catch (JSchException | SftpException | IOException | NullPointerException e) { + e.printStackTrace(); + messageAccumulator += "\n" + "Script did not run do to " + + e.getClass() + "...\n"; + messageAccumulator += "Exception message: " + e.getMessage(); + } + + return success; + } private static String workingDir() { String dir = System.getProperty("user.dir"); From 8513d26eaf209c5739f8b2d338d367f3c1424e59 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:09:42 -0800 Subject: [PATCH 09/15] trial to solve checkstyle3 --- .../workbench/script/ScriptManager.java | 272 +++++++++--------- 1 file changed, 136 insertions(+), 136 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 3d7c9f4..b1924b4 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -295,149 +295,149 @@ private void saveSimName(String simName) { } } - private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulationName, - String scriptPath, String[] nListFilenames, String simConfigFilename) - throws JSchException, FileNotFoundException, SftpException { - Long functionStartTime = System.currentTimeMillis(); - Long accumulatedTime = 0L; - char[] password = null; - boolean success = true; - // get username and password - LoginCredentialsDialog lcd = new LoginCredentialsDialog(hostname, true); - if (lcd.okClicked()) { - SecureFileTransfer sft = new SecureFileTransfer(); - password = lcd.getPassword(); - lcd.clearPassword(); - /* Create Simulation Directory and Subdirectories */ - String simDir = FileManager.getSimulationsDirectory() + "/" + simulationName; - String configDir = simDir + "/configfiles"; - String nListDir = simDir + "/configfiles/NList"; - String remoteScriptPath = simDir + "/" + FileManager.getSimpleFilename(scriptPath); - String cmd = "mkdir -p " + nListDir; - sft.executeCommand(cmd, hostname, lcd.getUsername(), password, true); - saveSimDir(simDir); - saveSimName(simulationName); - /* Upload Script */ - Date uploadStartTime = new Date(); - if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { - // record provenance of upload - if (provMgr != null) { - Long startTime = System.currentTimeMillis(); - WorkbenchOperationRecorder.recordFile(provMgr, scriptPath, remoteScriptPath, - "script", hostname, "uploadScript", uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); - } - outstandingMessages += "\n" + scriptPath + "\nuploaded to " + hostname + "\n"; - /* Upload Neuron List Files */ - boolean loopSuccess; - if (nListFilenames != null) { - for (String nListFilename : nListFilenames) { - String filename = FileManager.getSimpleFilename(nListFilename); - outstandingMessages += "\n" + "Uploaded " + nListFilename + "\nto " - + hostname + "\n"; - uploadStartTime = new Date(); - loopSuccess = sft.uploadFile(nListFilename, nListDir, hostname, - lcd.getUsername(), password, null); - if (!loopSuccess) { - success = false; - outstandingMessages += "\n" + "Problem uploading " + nListFilename - + "\nto " + hostname + "\n"; - break; - } else { - outstandingMessages += "\n" + filename + "\nuploaded to " + hostname - + "\n"; - // record upload provenance - if (provMgr != null) { - Long startTime = System.currentTimeMillis(); - String nlType = ""; - try { - nlType = InputAnalyzer.getInputType( - new File(nListFilename)).toString(); - } catch (ParserConfigurationException | SAXException - | IOException ex) { - } - WorkbenchOperationRecorder.recordFile(provMgr, nListFilename, - nListDir + FileManager.getSimpleFilename(nListFilename), - "nlist", hostname, "upload_" + nlType + "_NList", - uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, - accumulatedTime); - } - } - } - } - /* Upload Simulation Configuration File */ - if (success) { - uploadStartTime = new Date(); - success = sft.uploadFile(simConfigFilename, configDir, hostname, - lcd.getUsername(), password, null); - if (success) { - if (provMgr != null) { - Long startTime = System.currentTimeMillis(); - WorkbenchOperationRecorder.recordFile(provMgr, simConfigFilename, - configDir + FileManager.getSimpleFilename(simConfigFilename), - "simulationConfigurationFile", hostname, "upload_SimConfig", - uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); - } - outstandingMessages += "\n" - + FileManager.getSimpleFilename(simConfigFilename) - + "\nuploaded to " + hostname + "\n"; - } else { - outstandingMessages += "\n" + "Problem uploading " - + FileManager.getSimpleFilename(simConfigFilename) - + "\nto " + hostname + "\n"; - } - } - /* Execute Script */ - if (success) { - cmd = "nohup sh " + remoteScriptPath + " &"; - outstandingMessages += "\n" + "Executing " + cmd - + "\nat " - + hostname + "\n"; - sft.executeCommand(cmd, hostname, lcd.getUsername(), password, false); - success = true; - } - } else { - outstandingMessages += "\n" + "Failed to upload script to " + hostname + "\n"; - } - } else { - outstandingMessages += "\n" + "\nRemote Credentials Specification Cancelled\n"; - } - outstandingMessages += "\n" + "Remote Operations Completed: " + new Date() + "\n"; - - if (password != null) { - Arrays.fill(password, '0'); + private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulationName, + String scriptPath, String[] nListFilenames, String simConfigFilename) + throws JSchException, FileNotFoundException, SftpException { + Long functionStartTime = System.currentTimeMillis(); + Long accumulatedTime = 0L; + char[] password = null; + boolean success = true; + // get username and password + LoginCredentialsDialog lcd = new LoginCredentialsDialog(hostname, true); + if (lcd.okClicked()) { + SecureFileTransfer sft = new SecureFileTransfer(); + password = lcd.getPassword(); + lcd.clearPassword(); + /* Create Simulation Directory and Subdirectories */ + String simDir = FileManager.getSimulationsDirectory() + "/" + simulationName; + String configDir = simDir + "/configfiles"; + String nListDir = simDir + "/configfiles/NList"; + String remoteScriptPath = simDir + "/" + FileManager.getSimpleFilename(scriptPath); + String cmd = "mkdir -p " + nListDir; + sft.executeCommand(cmd, hostname, lcd.getUsername(), password, true); + saveSimDir(simDir); + saveSimName(simulationName); + /* Upload Script */ + Date uploadStartTime = new Date(); + if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { + // record provenance of upload + if (provMgr != null) { + Long startTime = System.currentTimeMillis(); + WorkbenchOperationRecorder.recordFile(provMgr, scriptPath, remoteScriptPath, + "script", hostname, "uploadScript", uploadStartTime, new Date()); + accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); } + outstandingMessages += "\n" + scriptPath + "\nuploaded to " + hostname + "\n"; + /* Upload Neuron List Files */ + boolean loopSuccess; + if (nListFilenames != null) { + for (String nListFilename : nListFilenames) { + String filename = FileManager.getSimpleFilename(nListFilename); + outstandingMessages += "\n" + "Uploaded " + nListFilename + "\nto " + + hostname + "\n"; + uploadStartTime = new Date(); + loopSuccess = sft.uploadFile(nListFilename, nListDir, hostname, + lcd.getUsername(), password, null); + if (!loopSuccess) { + success = false; + outstandingMessages += "\n" + "Problem uploading " + nListFilename + + "\nto " + hostname + "\n"; + break; + } else { + outstandingMessages += "\n" + filename + "\nuploaded to " + hostname + + "\n"; + // record upload provenance + if (provMgr != null) { + Long startTime = System.currentTimeMillis(); + String nlType = ""; + try { + nlType = InputAnalyzer.getInputType( + new File(nListFilename)).toString(); + } catch (ParserConfigurationException | SAXException + | IOException ex) { + } + WorkbenchOperationRecorder.recordFile(provMgr, nListFilename, + nListDir + FileManager.getSimpleFilename(nListFilename), + "nlist", hostname, "upload_" + nlType + "_NList", + uploadStartTime, new Date()); + accumulatedTime = DateTime.sumProvTiming(startTime, + accumulatedTime); + } + } + } + } + /* Upload Simulation Configuration File */ + if (success) { + uploadStartTime = new Date(); + success = sft.uploadFile(simConfigFilename, configDir, hostname, + lcd.getUsername(), password, null); + if (success) { + if (provMgr != null) { + Long startTime = System.currentTimeMillis(); + WorkbenchOperationRecorder.recordFile(provMgr, simConfigFilename, + configDir + FileManager.getSimpleFilename(simConfigFilename), + "simulationConfigurationFile", hostname, "upload_SimConfig", + uploadStartTime, new Date()); + accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); + } + outstandingMessages += "\n" + + FileManager.getSimpleFilename(simConfigFilename) + + "\nuploaded to " + hostname + "\n"; + } else { + outstandingMessages += "\n" + "Problem uploading " + + FileManager.getSimpleFilename(simConfigFilename) + + "\nto " + hostname + "\n"; + } + } + /* Execute Script */ + if (success) { + cmd = "nohup sh " + remoteScriptPath + " &"; + outstandingMessages += "\n" + "Executing " + cmd + + "\nat " + + hostname + "\n"; + sft.executeCommand(cmd, hostname, lcd.getUsername(), password, false); + success = true; + } + } else { + outstandingMessages += "\n" + "Failed to upload script to " + hostname + "\n"; + } + } else { + outstandingMessages += "\n" + "\nRemote Credentials Specification Cancelled\n"; + } + outstandingMessages += "\n" + "Remote Operations Completed: " + new Date() + "\n"; + + if (password != null) { + Arrays.fill(password, '0'); + } DateTime.recordFunctionExecutionTime("ScriptManager", "runRemoteScript", System.currentTimeMillis() - functionStartTime, provMgr != null); if (provMgr != null) { DateTime.recordAccumulatedProvTiming("ScriptManager", "runRemoteScript", accumulatedTime); } - if (success) { - String simLocation = workingDir() + "\\LastSimulation"; - File messageFile = new File(simLocation + "\\message"); - File uriFile = new File(simLocation + "\\uri"); - FileOutputStream messageOut = new FileOutputStream(messageFile); - try { - ObjectOutputStream messageOutObj = new ObjectOutputStream(messageOut); - messageOutObj.writeObject(WorkbenchManager.getInstance().getMessages()); - provMgr.getModel().write( - new FileOutputStream(new File( - workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); - FileWriter uriWriter = new FileWriter(uriFile); - uriWriter.write(provMgr.getProvURI() + "\n"); - uriWriter.write(provMgr.getLocalURI() + "\n"); - uriWriter.write(provMgr.getRemoteURI() + "\n"); - uriWriter.close(); - messageOutObj.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - return success; - } + if (success) { + String simLocation = workingDir() + "\\LastSimulation"; + File messageFile = new File(simLocation + "\\message"); + File uriFile = new File(simLocation + "\\uri"); + FileOutputStream messageOut = new FileOutputStream(messageFile); + try { + ObjectOutputStream messageOutObj = new ObjectOutputStream(messageOut); + messageOutObj.writeObject(WorkbenchManager.getInstance().getMessages()); + provMgr.getModel().write( + new FileOutputStream(new File( + workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); + FileWriter uriWriter = new FileWriter(uriFile); + uriWriter.write(provMgr.getProvURI() + "\n"); + uriWriter.write(provMgr.getLocalURI() + "\n"); + uriWriter.write(provMgr.getRemoteURI() + "\n"); + uriWriter.close(); + messageOutObj.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return success; + } private boolean runLocalScript(ProvMgr provMgr, String simulationName, String scriptLocation, String[] inputFilenames, String simConfigFilename) throws IOException { From cabbedf6df231ec97bdc02ef67133d3682c35473 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:34:13 -0800 Subject: [PATCH 10/15] trial to solve checkstyle4 --- .../edu/uwb/braingrid/provenance/ProvMgr.java | 70 ++++++++-------- .../uwb/braingrid/workbench/FileManager.java | 6 +- .../braingrid/workbench/WorkbenchManager.java | 26 +++--- .../workbench/comm/SecureFileTransfer.java | 83 +++++++++---------- .../model/SimulationSpecification.java | 1 - .../workbench/script/ScriptManager.java | 11 ++- .../workbench/ui/LoginCredentialsDialog.java | 2 +- 7 files changed, 97 insertions(+), 102 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java index 7375bff..fcff333 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java @@ -64,32 +64,32 @@ public class ProvMgr implements Serializable { public static final String LOCAL_NS_PREFIX = "local"; /* URIs used to describe the provenance */ - private String provOutputFileURI; - private String localNameSpaceURI; - private String remoteNameSpaceURI; + private String provOutputFileUri; + private String localNameSpaceUri; + private String remoteNameSpaceUri; /* RDF in-memory representation of the provenance */ private Model model; // - /** - * The getter for provURI. - * - * @return return the provURI. - * - */ - public String getProvURI() { - return provOutputFileURI; + /** + * The getter for provURI. + * + * @return return the provURI. + * + */ + public String getProvUri() { + return provOutputFileUri; } - /** - * The getter for LocalURI. - * - * @return return the LocalURI. - * - */ - public String getLocalURI() { - return localNameSpaceURI; + /** + * The getter for LocalURI. + * + * @return return the LocalURI. + * + */ + public String getLocalUri() { + return localNameSpaceUri; } /** @@ -98,8 +98,8 @@ public String getLocalURI() { * @return return the RemoteURI. * */ - public String getRemoteURI() { - return remoteNameSpaceURI; + public String getRemoteUri() { + return remoteNameSpaceUri; } /** * The constructor used by resume Lastsimulation. @@ -110,9 +110,9 @@ public String getRemoteURI() { * @param model the model */ public ProvMgr(String provURI, String localURI, String remoteURI, Model model) { - this.provOutputFileURI = provURI; - this.localNameSpaceURI = localURI; - this.remoteNameSpaceURI = remoteURI; + this.provOutputFileUri = provURI; + this.localNameSpaceUri = localURI; + this.remoteNameSpaceUri = remoteURI; this.model = model; } @@ -142,7 +142,7 @@ public ProvMgr(Simulation simulation, boolean load) throws IOException, RiotNotF private void init(Simulation simulation) { // create RDF model model = ModelFactory.createDefaultModel(); - provOutputFileURI = simulation.getProvLocation() + provOutputFileUri = simulation.getProvLocation() .resolve(simulation.getName() + ".ttl").toString(); // set prefixes for... // RDF syntax @@ -153,9 +153,9 @@ private void init(Simulation simulation) { model.setNsPrefix("prov", ProvOntology.getPROVNameSpaceURI()); // XML schema model.setNsPrefix("xsd", ProvOntology.getXSDNameSpaceURI()); - localNameSpaceURI = getLocalNameSpaceURI(); + localNameSpaceUri = getLocalNameSpaceURI(); // Graphitti Prov - model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceURI); + model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); } /** @@ -165,10 +165,10 @@ private void init(Simulation simulation) { */ private void load(Simulation simulation) throws RiotNotFoundException { String name = simulation.getName(); - provOutputFileURI = simulation.getProvLocation().resolve(name + ".ttl").toString(); - model = RDFDataMgr.loadModel(provOutputFileURI); - localNameSpaceURI = getLocalNameSpaceURI(); - model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceURI); + provOutputFileUri = simulation.getProvLocation().resolve(name + ".ttl").toString(); + model = RDFDataMgr.loadModel(provOutputFileUri); + localNameSpaceUri = getLocalNameSpaceURI(); + model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); trimRemoteNS(); } @@ -182,8 +182,8 @@ private void trimRemoteNS() { String nameSpace = entry.getKey(); String uri = entry.getValue(); if (nameSpace.startsWith(REMOTE_NS_PREFIX)) { - remoteNameSpaceURI = uri.substring(uri.lastIndexOf('/') + 1); - model.setNsPrefix(nameSpace, remoteNameSpaceURI); + remoteNameSpaceUri = uri.substring(uri.lastIndexOf('/') + 1); + model.setNsPrefix(nameSpace, remoteNameSpaceUri); } } } @@ -211,8 +211,8 @@ public void setNsPrefix(String prefix, String uri) { * * @return The URI of the provenance output file */ - public String getProvFileURI() { - return provOutputFileURI; + public String getProvFileUri() { + return provOutputFileUri; } /** diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/FileManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/FileManager.java index fb1c036..b945dc1 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/FileManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/FileManager.java @@ -189,9 +189,9 @@ private static String workingDir() { * * @return The working directory of the current user */ - public static Path getUserDir() { - return Paths.get(workingDir()); - } + public static Path getUserDir() { + return Paths.get(workingDir()); + } /** * Provides the home directory of the current user. diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java index 4dc6304..518a66f 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java @@ -546,15 +546,15 @@ public boolean runScript() { } //save the simulation here - messageAccumulator += sm.getOutstandingMessages(); - } catch (JSchException | SftpException | IOException | NullPointerException e) { - e.printStackTrace(); - messageAccumulator += "\n" + "Script did not run do to " - + e.getClass() + "...\n"; - messageAccumulator += "Exception message: " + e.getMessage(); - } - - return success; + messageAccumulator += sm.getOutstandingMessages(); + } catch (JSchException | SftpException | IOException | NullPointerException e) { + e.printStackTrace(); + messageAccumulator += "\n" + "Script did not run do to " + + e.getClass() + "...\n"; + messageAccumulator += "Exception message: " + e.getMessage(); + } + + return success; } private static String workingDir() { @@ -640,7 +640,7 @@ private void persistProvenance() { prov.persist(simulation); messageAccumulator += "\n" + "Provenance persisted to: " - + prov.getProvFileURI() + "\n"; + + prov.getProvFileUri() + "\n"; } catch (IOException e) { messageAccumulator += "\n" + "Unable to persist provenance\n" @@ -769,9 +769,9 @@ public String getMessages() { * * @param msg msg to set */ - public void setMessages(String msg) { - messageAccumulator = msg; - } + public void setMessages(String msg) { + messageAccumulator = msg; + } /** * Clears the accumulated messages for this manager. diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java index c6f5e7d..0abbb23 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java @@ -8,24 +8,21 @@ import com.jcraft.jsch.Session; import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpProgressMonitor; - import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.ui.SimulationRuntimeDialog; import javafx.scene.control.TextArea; +import java.io.InputStreamReader; +import javax.swing.JFrame; +import javax.swing.JOptionPane; import riotcmd.infer; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.util.Date; -import javax.swing.JFrame; -import javax.swing.JOptionPane; - /** * Provides abbreviated SSF/FTP functionality. This includes uploading/downloading files and * execution of commands on a remote machine. @@ -286,15 +283,15 @@ private boolean readInputStream(InputStream in, ChannelExec cExec) { } // - /** - * Connects to the last simulation. - * - * @param hostname The name of the host machine to connect to. - * @param username The user's login username. - * @param password The user's login password. - * @param simName The last simulation to connect to. - * @param manager The temp place holder. - */ + /** + * Connects to the last simulation. + * + * @param hostname The name of the host machine to connect to. + * @param username The user's login username. + * @param password The user's login password. + * @param simName The last simulation to connect to. + * @param manager The temp place holder. + */ public void checkLastSim(String hostname, String username, String password, String simName, WorkbenchManager manager) { @@ -311,40 +308,40 @@ public void checkLastSim(String hostname, String username, channel.connect(); InputStream in; - try { + try { in = channel.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String files; while ((files = reader.readLine()) != null) { if (files.equals(simName)) { - Channel channel2 = session.openChannel("sftp"); - channel2.connect(); - //((ChannelSftp) channel2).setInputStream(null); - try { - ((ChannelSftp) channel2).cd( - "WorkbenchSimulations//" + simName + "//Output//Debug"); - InputStream workBenchLOG = ((ChannelSftp) channel2).get("workbench.txt"); - BufferedReader readLOG = new BufferedReader(new InputStreamReader(workBenchLOG)); - String line; - String lastline = ""; - while ((line = readLOG.readLine()) != null) { - lastline = line; - } - String completion = "Complete"; - lastline = lastline.substring( - lastline.length() - completion.length(), lastline.length()); - if (lastline.equals("Complete")) { - displayDownloadFrame(channel2, manager); - break; - } + Channel channel2 = session.openChannel("sftp"); + channel2.connect(); + //((ChannelSftp) channel2).setInputStream(null); + try { + ((ChannelSftp) channel2).cd( + "WorkbenchSimulations//" + simName + "//Output//Debug"); + InputStream workBenchLog = ((ChannelSftp) channel2).get("workbench.txt"); + BufferedReader readLog = new BufferedReader(new InputStreamReader(workBenchLog)); + String line; + String lastline = ""; + while ((line = readLog.readLine()) != null) { + lastline = line; + } + String completion = "Complete"; + lastline = lastline.substring( + lastline.length() - completion.length(), lastline.length()); + if (lastline.equals("Complete")) { + displayDownloadFrame(channel2, manager); + break; + } } catch (SftpException e) { e.printStackTrace(); } } } - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) { + e.printStackTrace(); + } } catch (JSchException e) { e.printStackTrace(); @@ -358,9 +355,9 @@ private void displayDownloadFrame(Channel channel, WorkbenchManager manager) { "Last simlation completed, do you want to download?", "Last Simulation Completed", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); - if (option == JOptionPane.YES_NO_OPTION) { - SimulationRuntimeDialog srd = new SimulationRuntimeDialog( - new TextArea(manager.getMessages())); - } + if (option == JOptionPane.YES_NO_OPTION) { + SimulationRuntimeDialog srd = new SimulationRuntimeDialog( + new TextArea(manager.getMessages())); + } } } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java index 4b4a66c..cb4e4a5 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/model/SimulationSpecification.java @@ -1,7 +1,6 @@ package edu.uwb.braingrid.workbench.model; import com.fasterxml.jackson.annotation.JsonIgnore; - import java.io.Serializable; import java.util.Objects; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index b1924b4..95f4082 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -22,13 +22,12 @@ import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; import org.apache.jena.rdf.model.Resource; +import edu.uwb.braingrid.workbench.Workbench; +import edu.uwb.braingrid.workbench.WorkbenchManager; import org.xml.sax.SAXException; - import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.provenance.WorkbenchOperationRecorder; import edu.uwb.braingrid.workbench.FileManager; -import edu.uwb.braingrid.workbench.Workbench; -import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; import edu.uwb.braingrid.workbench.data.InputAnalyzer; import edu.uwb.braingrid.workbench.model.Simulation; @@ -427,9 +426,9 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat new FileOutputStream(new File( workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); FileWriter uriWriter = new FileWriter(uriFile); - uriWriter.write(provMgr.getProvURI() + "\n"); - uriWriter.write(provMgr.getLocalURI() + "\n"); - uriWriter.write(provMgr.getRemoteURI() + "\n"); + uriWriter.write(provMgr.getProvUri() + "\n"); + uriWriter.write(provMgr.getLocalUri() + "\n"); + uriWriter.write(provMgr.getRemoteUri() + "\n"); uriWriter.close(); messageOutObj.close(); } catch (IOException e) { diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/LoginCredentialsDialog.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/LoginCredentialsDialog.java index 72dd0d5..4d7dea9 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/LoginCredentialsDialog.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/ui/LoginCredentialsDialog.java @@ -15,7 +15,7 @@ * @author Del Davis */ public class LoginCredentialsDialog extends javax.swing.JDialog { - + private String workingDir() { String dir = System.getProperty("user.dir"); String target = "\\target"; From 8a45062c26561db526c38e295ff7431760cda7a0 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 17:48:18 -0800 Subject: [PATCH 11/15] trial to solve checkstyle4 --- .../braingrid/workbench/WorkbenchManager.java | 13 +- .../workbench/script/ScriptManager.java | 126 +++++++++--------- 2 files changed, 69 insertions(+), 70 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java index 518a66f..c41ace3 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/WorkbenchManager.java @@ -17,7 +17,6 @@ import javafx.scene.control.TextInputDialog; import javafx.stage.FileChooser; import javafx.stage.FileChooser.ExtensionFilter; - import edu.uwb.braingrid.general.LoggerHelper; import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.workbench.model.Project; @@ -545,7 +544,7 @@ public boolean runScript() { simObjOut.writeObject(simulation); } - //save the simulation here + //save the simulation here messageAccumulator += sm.getOutstandingMessages(); } catch (JSchException | SftpException | IOException | NullPointerException e) { e.printStackTrace(); @@ -764,11 +763,11 @@ public String getMessages() { return messageAccumulator; } - /** - * Set the message for message Accumulator, used for remember last simulation. - * - * @param msg msg to set - */ + /** + * Set the message for message Accumulator, used for remember last simulation. + * + * @param msg msg to set + */ public void setMessages(String msg) { messageAccumulator = msg; } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 95f4082..e2f26a4 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -21,9 +21,9 @@ import java.util.UUID; import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; -import org.apache.jena.rdf.model.Resource; import edu.uwb.braingrid.workbench.Workbench; import edu.uwb.braingrid.workbench.WorkbenchManager; +import org.apache.jena.rdf.model.Resource; import org.xml.sax.SAXException; import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.provenance.WorkbenchOperationRecorder; @@ -321,85 +321,85 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat if (sft.uploadFile(scriptPath, simDir, hostname, lcd.getUsername(), password, null)) { // record provenance of upload if (provMgr != null) { - Long startTime = System.currentTimeMillis(); - WorkbenchOperationRecorder.recordFile(provMgr, scriptPath, remoteScriptPath, + Long startTime = System.currentTimeMillis(); + WorkbenchOperationRecorder.recordFile(provMgr, scriptPath, remoteScriptPath, "script", hostname, "uploadScript", uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); + accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); } outstandingMessages += "\n" + scriptPath + "\nuploaded to " + hostname + "\n"; /* Upload Neuron List Files */ boolean loopSuccess; if (nListFilenames != null) { for (String nListFilename : nListFilenames) { - String filename = FileManager.getSimpleFilename(nListFilename); - outstandingMessages += "\n" + "Uploaded " + nListFilename + "\nto " - + hostname + "\n"; + String filename = FileManager.getSimpleFilename(nListFilename); + outstandingMessages += "\n" + "Uploaded " + nListFilename + "\nto " + + hostname + "\n"; + uploadStartTime = new Date(); + loopSuccess = sft.uploadFile(nListFilename, nListDir, hostname, + lcd.getUsername(), password, null); + if (!loopSuccess) { + success = false; + outstandingMessages += "\n" + "Problem uploading " + nListFilename + + "\nto " + hostname + "\n"; + break; + } else { + outstandingMessages += "\n" + filename + "\nuploaded to " + hostname + + "\n"; + // record upload provenance + if (provMgr != null) { + Long startTime = System.currentTimeMillis(); + String nlType = ""; + try { + nlType = InputAnalyzer.getInputType( + new File(nListFilename)).toString(); + } catch (ParserConfigurationException | SAXException + | IOException ex) { + } + WorkbenchOperationRecorder.recordFile(provMgr, nListFilename, + nListDir + FileManager.getSimpleFilename(nListFilename), + "nlist", hostname, "upload_" + nlType + "_NList", + uploadStartTime, new Date()); + accumulatedTime = DateTime.sumProvTiming(startTime, + accumulatedTime); + } + } + } + } + /* Upload Simulation Configuration File */ + if (success) { uploadStartTime = new Date(); - loopSuccess = sft.uploadFile(nListFilename, nListDir, hostname, + success = sft.uploadFile(simConfigFilename, configDir, hostname, lcd.getUsername(), password, null); - if (!loopSuccess) { - success = false; - outstandingMessages += "\n" + "Problem uploading " + nListFilename - + "\nto " + hostname + "\n"; - break; - } else { - outstandingMessages += "\n" + filename + "\nuploaded to " + hostname - + "\n"; - // record upload provenance + if (success) { if (provMgr != null) { Long startTime = System.currentTimeMillis(); - String nlType = ""; - try { - nlType = InputAnalyzer.getInputType( - new File(nListFilename)).toString(); - } catch (ParserConfigurationException | SAXException - | IOException ex) { - } - WorkbenchOperationRecorder.recordFile(provMgr, nListFilename, - nListDir + FileManager.getSimpleFilename(nListFilename), - "nlist", hostname, "upload_" + nlType + "_NList", - uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, - accumulatedTime); - } + WorkbenchOperationRecorder.recordFile(provMgr, simConfigFilename, + configDir + FileManager.getSimpleFilename(simConfigFilename), + "simulationConfigurationFile", hostname, "upload_SimConfig", + uploadStartTime, new Date()); + accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); } - } - } - /* Upload Simulation Configuration File */ - if (success) { - uploadStartTime = new Date(); - success = sft.uploadFile(simConfigFilename, configDir, hostname, - lcd.getUsername(), password, null); - if (success) { - if (provMgr != null) { - Long startTime = System.currentTimeMillis(); - WorkbenchOperationRecorder.recordFile(provMgr, simConfigFilename, - configDir + FileManager.getSimpleFilename(simConfigFilename), - "simulationConfigurationFile", hostname, "upload_SimConfig", - uploadStartTime, new Date()); - accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); - } - outstandingMessages += "\n" + outstandingMessages += "\n" + FileManager.getSimpleFilename(simConfigFilename) + "\nuploaded to " + hostname + "\n"; - } else { - outstandingMessages += "\n" + "Problem uploading " + } else { + outstandingMessages += "\n" + "Problem uploading " + FileManager.getSimpleFilename(simConfigFilename) + "\nto " + hostname + "\n"; - } - } + } + } /* Execute Script */ - if (success) { - cmd = "nohup sh " + remoteScriptPath + " &"; - outstandingMessages += "\n" + "Executing " + cmd - + "\nat " - + hostname + "\n"; - sft.executeCommand(cmd, hostname, lcd.getUsername(), password, false); - success = true; - } - } else { - outstandingMessages += "\n" + "Failed to upload script to " + hostname + "\n"; - } + if (success) { + cmd = "nohup sh " + remoteScriptPath + " &"; + outstandingMessages += "\n" + "Executing " + cmd + + "\nat " + + hostname + "\n"; + sft.executeCommand(cmd, hostname, lcd.getUsername(), password, false); + success = true; + } + } else { + outstandingMessages += "\n" + "Failed to upload script to " + hostname + "\n"; + } } else { outstandingMessages += "\n" + "\nRemote Credentials Specification Cancelled\n"; } From cb6ae7a283107bf47968e97db51bec41cca0b0c0 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:04:59 -0800 Subject: [PATCH 12/15] trial to solve checkstyle5 --- .../edu/uwb/braingrid/provenance/ProvMgr.java | 24 ++++++----- .../workbench/comm/SecureFileTransfer.java | 4 +- .../workbench/script/ScriptManager.java | 42 ++++++++++--------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java index fcff333..33bdc8c 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java @@ -64,9 +64,9 @@ public class ProvMgr implements Serializable { public static final String LOCAL_NS_PREFIX = "local"; /* URIs used to describe the provenance */ - private String provOutputFileUri; - private String localNameSpaceUri; - private String remoteNameSpaceUri; + private String provOutputFileUri; + private String localNameSpaceUri; + private String remoteNameSpaceUri; /* RDF in-memory representation of the provenance */ private Model model; @@ -79,7 +79,7 @@ public class ProvMgr implements Serializable { * */ public String getProvUri() { - return provOutputFileUri; + return provOutputFileUri; } /** @@ -92,15 +92,16 @@ public String getLocalUri() { return localNameSpaceUri; } - /** - * The getter for RemoteURI. - * - * @return return the RemoteURI. - * - */ + /** + * The getter for RemoteURI. + * + * @return return the RemoteURI. + * + */ public String getRemoteUri() { return remoteNameSpaceUri; - } + } + /** * The constructor used by resume Lastsimulation. * @@ -109,6 +110,7 @@ public String getRemoteUri() { * @param remoteURI the remoteURI * @param model the model */ + public ProvMgr(String provURI, String localURI, String remoteURI, Model model) { this.provOutputFileUri = provURI; this.localNameSpaceUri = localURI; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java index 0abbb23..7fb9424 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/comm/SecureFileTransfer.java @@ -10,8 +10,8 @@ import com.jcraft.jsch.SftpProgressMonitor; import edu.uwb.braingrid.workbench.WorkbenchManager; import edu.uwb.braingrid.workbench.ui.SimulationRuntimeDialog; -import javafx.scene.control.TextArea; import java.io.InputStreamReader; +import javafx.scene.control.TextArea; import javax.swing.JFrame; import javax.swing.JOptionPane; import riotcmd.infer; @@ -357,7 +357,7 @@ private void displayDownloadFrame(Channel channel, WorkbenchManager manager) { null, options, options[0]); if (option == JOptionPane.YES_NO_OPTION) { SimulationRuntimeDialog srd = new SimulationRuntimeDialog( - new TextArea(manager.getMessages())); + new TextArea(manager.getMessages())); } } } diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index e2f26a4..b2dff27 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -20,10 +20,11 @@ import java.util.Scanner; import java.util.UUID; import java.util.logging.Logger; -import javax.xml.parsers.ParserConfigurationException; import edu.uwb.braingrid.workbench.Workbench; import edu.uwb.braingrid.workbench.WorkbenchManager; +import javax.xml.parsers.ParserConfigurationException; import org.apache.jena.rdf.model.Resource; +import org.apache.jena.sparql.function.library.e; import org.xml.sax.SAXException; import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.provenance.WorkbenchOperationRecorder; @@ -323,7 +324,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat if (provMgr != null) { Long startTime = System.currentTimeMillis(); WorkbenchOperationRecorder.recordFile(provMgr, scriptPath, remoteScriptPath, - "script", hostname, "uploadScript", uploadStartTime, new Date()); + "script", hostname, "uploadScript", uploadStartTime, new Date()); accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); } outstandingMessages += "\n" + scriptPath + "\nuploaded to " + hostname + "\n"; @@ -354,6 +355,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat new File(nListFilename)).toString(); } catch (ParserConfigurationException | SAXException | IOException ex) { + ex.printStackTrace(); } WorkbenchOperationRecorder.recordFile(provMgr, nListFilename, nListDir + FileManager.getSimpleFilename(nListFilename), @@ -365,7 +367,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat } } } - /* Upload Simulation Configuration File */ + /* Upload Simulation Configuration File */ if (success) { uploadStartTime = new Date(); success = sft.uploadFile(simConfigFilename, configDir, hostname, @@ -374,12 +376,12 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat if (provMgr != null) { Long startTime = System.currentTimeMillis(); WorkbenchOperationRecorder.recordFile(provMgr, simConfigFilename, - configDir + FileManager.getSimpleFilename(simConfigFilename), - "simulationConfigurationFile", hostname, "upload_SimConfig", - uploadStartTime, new Date()); + configDir + FileManager.getSimpleFilename(simConfigFilename), + "simulationConfigurationFile", hostname, "upload_SimConfig", + uploadStartTime, new Date()); accumulatedTime = DateTime.sumProvTiming(startTime, accumulatedTime); } - outstandingMessages += "\n" + outstandingMessages += "\n" + FileManager.getSimpleFilename(simConfigFilename) + "\nuploaded to " + hostname + "\n"; } else { @@ -388,7 +390,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat + "\nto " + hostname + "\n"; } } - /* Execute Script */ + /* Execute Script */ if (success) { cmd = "nohup sh " + remoteScriptPath + " &"; outstandingMessages += "\n" + "Executing " + cmd @@ -400,14 +402,14 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat } else { outstandingMessages += "\n" + "Failed to upload script to " + hostname + "\n"; } - } else { - outstandingMessages += "\n" + "\nRemote Credentials Specification Cancelled\n"; - } - outstandingMessages += "\n" + "Remote Operations Completed: " + new Date() + "\n"; - - if (password != null) { - Arrays.fill(password, '0'); - } + } else { + outstandingMessages += "\n" + "\nRemote Credentials Specification Cancelled\n"; + } + outstandingMessages += "\n" + "Remote Operations Completed: " + new Date() + "\n"; + + if (password != null) { + Arrays.fill(password, '0'); + } DateTime.recordFunctionExecutionTime("ScriptManager", "runRemoteScript", System.currentTimeMillis() - functionStartTime, provMgr != null); if (provMgr != null) { @@ -423,7 +425,7 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat ObjectOutputStream messageOutObj = new ObjectOutputStream(messageOut); messageOutObj.writeObject(WorkbenchManager.getInstance().getMessages()); provMgr.getModel().write( - new FileOutputStream(new File( + new FileOutputStream(new File( workingDir() + "\\LastSimulation\\model.ttl")), "TURTLE"); FileWriter uriWriter = new FileWriter(uriFile); uriWriter.write(provMgr.getProvUri() + "\n"); @@ -432,9 +434,9 @@ private boolean runRemoteScript(ProvMgr provMgr, String hostname, String simulat uriWriter.close(); messageOutObj.close(); } catch (IOException e) { - e.printStackTrace(); - } - } + e.printStackTrace(); + } + } return success; } From 1a605acd1a4bb5dc268a31a592395bdaf5dce31d Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:17:32 -0800 Subject: [PATCH 13/15] trial to solve checkstyle6 --- .../edu/uwb/braingrid/provenance/ProvMgr.java | 48 +++++++++---------- .../workbench/script/ScriptManager.java | 2 +- .../WorkbenchDashboard.java | 21 ++++---- 3 files changed, 33 insertions(+), 38 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java index 33bdc8c..18bc960 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java @@ -92,12 +92,12 @@ public String getLocalUri() { return localNameSpaceUri; } - /** - * The getter for RemoteURI. - * - * @return return the RemoteURI. - * - */ + /** + * The getter for RemoteURI. + * + * @return return the RemoteURI. + * + */ public String getRemoteUri() { return remoteNameSpaceUri; } @@ -111,12 +111,12 @@ public String getRemoteUri() { * @param model the model */ - public ProvMgr(String provURI, String localURI, String remoteURI, Model model) { - this.provOutputFileUri = provURI; - this.localNameSpaceUri = localURI; - this.remoteNameSpaceUri = remoteURI; + public ProvMgr(String provUri, String localUri, String remoteUri, Model model) { + this.provOutputFileUri = provUri; + this.localNameSpaceUri = localUri; + this.remoteNameSpaceUri = remoteUri; this.model = model; - } + } // /** @@ -144,7 +144,7 @@ public ProvMgr(Simulation simulation, boolean load) throws IOException, RiotNotF private void init(Simulation simulation) { // create RDF model model = ModelFactory.createDefaultModel(); - provOutputFileUri = simulation.getProvLocation() + provOutputFileUri = simulation.getProvLocation() .resolve(simulation.getName() + ".ttl").toString(); // set prefixes for... // RDF syntax @@ -155,9 +155,9 @@ private void init(Simulation simulation) { model.setNsPrefix("prov", ProvOntology.getPROVNameSpaceURI()); // XML schema model.setNsPrefix("xsd", ProvOntology.getXSDNameSpaceURI()); - localNameSpaceUri = getLocalNameSpaceURI(); + localNameSpaceUri = getLocalNameSpaceURI(); // Graphitti Prov - model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); + model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); } /** @@ -167,11 +167,11 @@ private void init(Simulation simulation) { */ private void load(Simulation simulation) throws RiotNotFoundException { String name = simulation.getName(); - provOutputFileUri = simulation.getProvLocation().resolve(name + ".ttl").toString(); - model = RDFDataMgr.loadModel(provOutputFileUri); - localNameSpaceUri = getLocalNameSpaceURI(); - model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); - trimRemoteNS(); + provOutputFileUri = simulation.getProvLocation().resolve(name + ".ttl").toString(); + model = RDFDataMgr.loadModel(provOutputFileUri); + localNameSpaceUri = getLocalNameSpaceURI(); + model.setNsPrefix(LOCAL_NS_PREFIX, localNameSpaceUri); + trimRemoteNS(); } /** @@ -184,8 +184,8 @@ private void trimRemoteNS() { String nameSpace = entry.getKey(); String uri = entry.getValue(); if (nameSpace.startsWith(REMOTE_NS_PREFIX)) { - remoteNameSpaceUri = uri.substring(uri.lastIndexOf('/') + 1); - model.setNsPrefix(nameSpace, remoteNameSpaceUri); + remoteNameSpaceUri = uri.substring(uri.lastIndexOf('/') + 1); + model.setNsPrefix(nameSpace, remoteNameSpaceUri); } } } @@ -213,9 +213,9 @@ public void setNsPrefix(String prefix, String uri) { * * @return The URI of the provenance output file */ - public String getProvFileUri() { - return provOutputFileUri; - } + public String getProvFileUri() { + return provOutputFileUri; + } /** * Gets the RDF model maintained by the manager. diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index b2dff27..ff93909 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -19,9 +19,9 @@ import java.util.Date; import java.util.Scanner; import java.util.UUID; -import java.util.logging.Logger; import edu.uwb.braingrid.workbench.Workbench; import edu.uwb.braingrid.workbench.WorkbenchManager; +import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; import org.apache.jena.rdf.model.Resource; import org.apache.jena.sparql.function.library.e; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 4eca052..da586b3 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -12,31 +12,26 @@ import java.nio.file.Path; import java.util.logging.FileHandler; import java.util.logging.Logger; - import javax.swing.JFrame; import javax.swing.JOptionPane; - import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; -import org.eclipse.jgit.transport.CredentialItem.Username; - import com.fasterxml.jackson.databind.ObjectMapper; - +import edu.uwb.braingrid.provenance.ProvMgr; +import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; +import edu.uwb.braingrid.workbench.model.Simulation; +import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; +import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; +import org.eclipse.jgit.transport.CredentialItem.Username; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.input.KeyCode; import javafx.application.Application; import javafx.stage.Stage; - import edu.uwb.braingrid.general.LoggerHelper; -import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.workbench.FileManager; import edu.uwb.braingrid.workbench.WorkbenchManager; -import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; -import edu.uwb.braingrid.workbench.model.Simulation; -import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; -import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import edu.uwb.braingrid.workbenchdashboard.utils.SystemProperties; /** @@ -152,8 +147,8 @@ public void start(Stage primaryStage) throws Exception { // Initialize Workbench Manager WorkbenchManager.getInstance(); - checkLastSim(); - } + checkLastSim(); + } private String workingDir() { String dir = System.getProperty("user.dir"); From ffd7a052c71caad544310c1d6cdab68228dcc518 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:25:52 -0800 Subject: [PATCH 14/15] trial to solve checkstyle maybe final --- .../edu/uwb/braingrid/provenance/ProvMgr.java | 6 +++--- .../workbench/script/ScriptManager.java | 4 ++-- .../workbenchdashboard/WorkbenchDashboard.java | 18 ++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java index 18bc960..acd0529 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/provenance/ProvMgr.java @@ -105,9 +105,9 @@ public String getRemoteUri() { /** * The constructor used by resume Lastsimulation. * - * @param provURI the provURI - * @param localURI the localURI - * @param remoteURI the remoteURI + * @param provUri the provURI + * @param localUri the localURI + * @param remoteUri the remoteURI * @param model the model */ diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index ff93909..1bdb7b6 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -15,12 +15,12 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import edu.uwb.braingrid.workbench.Workbench; +import edu.uwb.braingrid.workbench.WorkbenchManager; import java.util.Arrays; import java.util.Date; import java.util.Scanner; import java.util.UUID; -import edu.uwb.braingrid.workbench.Workbench; -import edu.uwb.braingrid.workbench.WorkbenchManager; import java.util.logging.Logger; import javax.xml.parsers.ParserConfigurationException; import org.apache.jena.rdf.model.Resource; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index da586b3..4e374b2 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -15,13 +15,13 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; import com.fasterxml.jackson.databind.ObjectMapper; import edu.uwb.braingrid.provenance.ProvMgr; import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; import edu.uwb.braingrid.workbench.model.Simulation; import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; +import org.apache.jena.rdf.model.ModelFactory; import org.eclipse.jgit.transport.CredentialItem.Username; import javafx.application.Platform; import javafx.scene.Scene; @@ -194,22 +194,20 @@ private void checkLastSim() { String simName = (String) readSimNameObj.readObject(); LoginCredentialsDialog loginToResume = new LoginCredentialsDialog(realHostInfo, true); - String username = loginToResume.getUsername(); - String password = new String(loginToResume.getPassword()); - SecureFileTransfer fileTransfer = new SecureFileTransfer(); + final String username = loginToResume.getUsername(); + final String password = new String(loginToResume.getPassword()); + final SecureFileTransfer fileTransfer = new SecureFileTransfer(); File simulationInput = new File(workingDir() + "\\LastSimulation\\simulation"); FileInputStream simIn = new FileInputStream(simulationInput); ObjectInputStream simInObj = new ObjectInputStream(simIn); - BufferedReader readURI = new BufferedReader( + BufferedReader readUri = new BufferedReader( new FileReader(workingDir() + "\\LastSimulation\\uri")); - String provURI = readURI.readLine(); - String localURI = readURI.readLine(); - String remoteURI = readURI.readLine(); + String provURI = readUri.readLine(); + String localURI = readUri.readLine(); + String remoteURI = readUri.readLine(); Model model = ModelFactory.createDefaultModel(); -// String modelPath = workingDir() + "\\LastSimulation\\model.ttl"; -// modelPath = modelPath.replaceAll(" ", "%20"); model.read(workingDir() + "\\LastSimulation\\model.ttl", "TURTLE"); ProvMgr lastMgr = new ProvMgr(provURI, localURI, remoteURI, model); WorkbenchManager.getInstance().simulationSetter((Simulation) simInObj.readObject()); From 26c45e970c1388745cd4d22841187304cf7b7d79 Mon Sep 17 00:00:00 2001 From: BenYang2002 <96927991+BenYang2002@users.noreply.github.com> Date: Tue, 28 Feb 2023 18:32:49 -0800 Subject: [PATCH 15/15] this should solve all the checkstyle conflicts --- .../workbench/script/ScriptManager.java | 4 ++-- .../WorkbenchDashboard.java | 20 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java index 1bdb7b6..955a945 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbench/script/ScriptManager.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.SftpException; +import edu.uwb.braingrid.workbench.Workbench; +import edu.uwb.braingrid.workbench.WorkbenchManager; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -15,8 +17,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import edu.uwb.braingrid.workbench.Workbench; -import edu.uwb.braingrid.workbench.WorkbenchManager; import java.util.Arrays; import java.util.Date; import java.util.Scanner; diff --git a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java index 4e374b2..535eb27 100644 --- a/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java +++ b/WorkbenchProject/src/main/java/edu/uwb/braingrid/workbenchdashboard/WorkbenchDashboard.java @@ -1,5 +1,11 @@ package edu.uwb.braingrid.workbenchdashboard; +import com.fasterxml.jackson.databind.ObjectMapper; +import edu.uwb.braingrid.provenance.ProvMgr; +import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; +import edu.uwb.braingrid.workbench.model.Simulation; +import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; +import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import java.awt.FlowLayout; import java.io.BufferedReader; import java.io.File; @@ -15,12 +21,6 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import org.apache.jena.rdf.model.Model; -import com.fasterxml.jackson.databind.ObjectMapper; -import edu.uwb.braingrid.provenance.ProvMgr; -import edu.uwb.braingrid.workbench.comm.SecureFileTransfer; -import edu.uwb.braingrid.workbench.model.Simulation; -import edu.uwb.braingrid.workbench.ui.LoginCredentialsDialog; -import edu.uwb.braingrid.workbench.ui.SimulationSpecificationDialog; import org.apache.jena.rdf.model.ModelFactory; import org.eclipse.jgit.transport.CredentialItem.Username; import javafx.application.Platform; @@ -204,12 +204,12 @@ private void checkLastSim() { BufferedReader readUri = new BufferedReader( new FileReader(workingDir() + "\\LastSimulation\\uri")); - String provURI = readUri.readLine(); - String localURI = readUri.readLine(); - String remoteURI = readUri.readLine(); + String provUri = readUri.readLine(); + String localUri = readUri.readLine(); + String remoteUri = readUri.readLine(); Model model = ModelFactory.createDefaultModel(); model.read(workingDir() + "\\LastSimulation\\model.ttl", "TURTLE"); - ProvMgr lastMgr = new ProvMgr(provURI, localURI, remoteURI, model); + ProvMgr lastMgr = new ProvMgr(provUri, localUri, remoteUri, model); WorkbenchManager.getInstance().simulationSetter((Simulation) simInObj.readObject()); WorkbenchManager.getInstance().provMgrSetter(lastMgr); ObjectInputStream msgReader = new ObjectInputStream(