Skip to content

Commit

Permalink
fix the progress bar of jupyterhub, add notes to history version of j…
Browse files Browse the repository at this point in the history
…upyter notebooks
  • Loading branch information
ZihengSun committed Mar 13, 2021
1 parent ba05ac9 commit 127eb77
Show file tree
Hide file tree
Showing 15 changed files with 761 additions and 45 deletions.
17 changes: 14 additions & 3 deletions src/main/java/com/gw/jpa/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

Expand Down Expand Up @@ -36,6 +33,10 @@ public class History {
@Temporal(TemporalType.TIMESTAMP)
private Date history_end_time;

@Column(columnDefinition = "TEXT")
private String history_notes;


private String history_process;

private String host_id;
Expand All @@ -46,6 +47,16 @@ public class History {
/** end of history section **/
/**********************************************/


public String getHistory_notes() {
return this.history_notes;
}

public void setHistory_notes(String history_notes) {
this.history_notes = history_notes;
}


public String getIndicator() {
return indicator;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/gw/server/Java2JupyterClientEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public void beforeRequest(Map<String, List<String>> nativeheaders) {
List<String> values = mapElement.getValue();

// if("Sec-WebSocket-Key".equals(newkey)) {
if("Host".equals(newkey) || "Origin".equals(newkey) || "Sec-WebSocket-Key".equals(newkey)) {
// if("Host".equals(newkey) || "Origin".equals(newkey) ) {
if("Host".equals(newkey) || "Origin".equals(newkey) || "Sec-WebSocket-Key".equals(newkey)) {

continue;

Expand Down
98 changes: 97 additions & 1 deletion src/main/java/com/gw/tools/HistoryTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import java.sql.SQLException;
import java.util.List;
import java.util.Optional;

import java.util.Collection;
import javax.annotation.PostConstruct;
import java.util.Iterator;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -398,7 +399,102 @@ public String process_all_history(String pid) {
// return resp.toString();

}

public String deleteAllHistoryByHost(String hostid){

String resp = null;

try{

Collection<History> historylist = historyrepository.findRecentHistory(hostid, 1000);

Iterator<History> hisint = historylist.iterator();

StringBuffer idlist = new StringBuffer();

while(hisint.hasNext()) {

History h = hisint.next();

idlist.append(h.getHistory_id()).append(",");

historyrepository.delete(h);

}

resp = "{ \"removed_history_ids\": \"" + idlist.toString() + "\"";

}catch(Exception e){

e.printStackTrace();

}

return resp;

}

public String deleteNoNotesHistoryByHost(String hostid){

String resp = null;

try{

Collection<History> historylist = historyrepository.findRecentHistory(hostid, 1000);

Iterator<History> hisint = historylist.iterator();

StringBuffer idlist = new StringBuffer();

while(hisint.hasNext()) {

History h = hisint.next();

if(bt.isNull(h.getHistory_notes())){

idlist.append(h.getHistory_id()).append(",");

historyrepository.delete(h);

}

}

resp = "{ \"removed_history_ids\": \"" + idlist.toString() + "\"";

}catch(Exception e){

e.printStackTrace();

}

return resp;

}

/**
* Update the notes of a history
*/
public void updateNotes(String hisid, String notes){

try{

logger.info("Updating history: " + hisid + " - " + notes);

History h = this.getHistoryById(hisid);

h.setHistory_notes(notes);

this.saveHistory(h);

}catch(Exception e){

e.printStackTrace();

}

}

/**
* Save Jupyter Notebook Checkpoints into the GW database
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/gw/tools/HostTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public String recent(String hostid, int limit) {
resp.append("\"name\": \"").append(h.getHistory_process()).append("\", ");

resp.append("\"end_time\": \"").append(h.getHistory_end_time()).append("\", ");

resp.append("\"notes\": \"").append(h.getHistory_notes()).append("\", ");

resp.append("\"status\": \"").append(h.getIndicator()).append("\", ");

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/gw/tools/ProcessTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,9 @@ public String recent(int limit) {

resp.append("{ \"id\": \"").append(process_obj[0]).append("\", ");

resp.append("\"name\": \"").append(process_obj[11]).append("\", ");
resp.append("\"name\": \"").append(process_obj[12]).append("\", ");

resp.append("\"notes\": \"").append(process_obj[8]).append("\", ");

resp.append("\"end_time\": \"").append(process_obj[2]).append("\", ");

Expand Down Expand Up @@ -950,7 +952,9 @@ public String one_history(String hid) {

resp.append("\"id\": \"").append(first_obj[5]).append("\", ");

resp.append("\"name\": \"").append(first_obj[11]).append("\", ");
resp.append("\"name\": \"").append(first_obj[12]).append("\", ");

resp.append("\"notes\": \"").append(first_obj[8]).append("\", ");

resp.append("\"begin_time\":\"").append(first_obj[1]).append("\", ");

Expand Down Expand Up @@ -1024,6 +1028,8 @@ public String all_active_process() {

resp.append("\", \"status\": \"").append(escape(String.valueOf(row[4])));

resp.append("\", \"notes\": \"").append(escape(String.valueOf(row[8])));

resp.append("\", \"host\": \"").append(escape(String.valueOf(row[5])));

resp.append("\"}");
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/gw/utils/BaseTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.ParseException;
Expand Down Expand Up @@ -116,7 +118,16 @@ public String removeLob(String lob) {

}


public String encodeValue(String value) {

try {
value = URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return value;
}

/**
* Get the temp folder for file transfer
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/gw/utils/LoggingRequestInterceptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.gw.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

public class LoggingRequestInterceptor implements ClientHttpRequestInterceptor {

final static Logger log = LoggerFactory.getLogger(LoggingRequestInterceptor.class);

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
traceRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
traceResponse(response);
return response;
}

private void traceRequest(HttpRequest request, byte[] body) throws IOException {
log.info("===========================request begin================================================");
log.info("URI : {}", request.getURI());
log.info("Method : {}", request.getMethod());
log.info("Headers : {}", request.getHeaders() );
log.info("Request body: {}", new String(body, "UTF-8"));
log.info("==========================request end================================================");
}

private void traceResponse(ClientHttpResponse response) throws IOException {
StringBuilder inputStringBuilder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), "UTF-8"));
String line = bufferedReader.readLine();
while (line != null) {
inputStringBuilder.append(line);
inputStringBuilder.append('\n');
line = bufferedReader.readLine();
}
log.info("============================response begin==========================================");
log.info("Status code : {}", response.getStatusCode());
log.info("Status text : {}", response.getStatusText());
log.info("Headers : {}", response.getHeaders());
log.info("Response body: {}", inputStringBuilder.toString());
log.info("=======================response end=================================================");
}

}
78 changes: 65 additions & 13 deletions src/main/java/com/gw/web/GeoweaverController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,29 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.gw.search.GWSearchTool;
import com.gw.ssh.RSAEncryptTool;
import com.gw.ssh.SSHSession;
import com.gw.tools.FileTool;
import com.gw.tools.HistoryTool;
import com.gw.tools.HostTool;
import com.gw.tools.ProcessTool;
import com.gw.tools.SessionManager;
import com.gw.tools.WorkflowTool;
import com.gw.utils.BaseTool;
import com.gw.utils.RandomString;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -31,18 +43,6 @@
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.context.request.WebRequest;

import com.gw.search.GWSearchTool;
import com.gw.ssh.RSAEncryptTool;
import com.gw.ssh.SSHSession;
import com.gw.tools.FileTool;
import com.gw.tools.HistoryTool;
import com.gw.tools.HostTool;
import com.gw.tools.ProcessTool;
import com.gw.tools.SessionManager;
import com.gw.tools.WorkflowTool;
import com.gw.utils.BaseTool;
import com.gw.utils.RandomString;

/**
*
* Controller for SSH related activities, including all the handlers for Geoweaver.
Expand Down Expand Up @@ -104,6 +104,48 @@ public void destroy() {
sessionManager.closeAll();

}

@RequestMapping(value="/delAllHistory", method= RequestMethod.POST)
public @ResponseBody String delAllHistory(ModelMap model, WebRequest request){

String resp = null;

try{

String hostid = request.getParameter("id");

resp = hist.deleteAllHistoryByHost(hostid);

}catch(Exception e){

throw new RuntimeException("failed " + e.getLocalizedMessage());

}

return resp;

}

@RequestMapping(value="/delNoNotesHistory", method = RequestMethod.POST)
public @ResponseBody String delNoNotesHistory(ModelMap model, WebRequest request){

String resp = null;

try{

String hostid = request.getParameter("id");

resp = hist.deleteNoNotesHistoryByHost(hostid);

}catch(Exception e){

throw new RuntimeException("failed " + e.getLocalizedMessage());

}

return resp;

}

@RequestMapping(value = "/del", method = RequestMethod.POST)
public @ResponseBody String del(ModelMap model, WebRequest request){
Expand Down Expand Up @@ -898,6 +940,16 @@ public ResponseEntity<Resource> fileGetter(ModelMap model, @PathVariable(value="

resp = "{\"id\" : \"" + wid + "\"}";

}else if(type.equals("history")){

String hisid = request.getParameter("id");

String notes = request.getParameter("notes");

hist.updateNotes(hisid, notes);

resp = "{\"id\" : \"" + hisid + "\"}";

}

}catch(Exception e) {
Expand Down
Loading

0 comments on commit 127eb77

Please sign in to comment.