You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2014/09/17 22:08:05 UTC

svn commit: r1625796 - in /uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server: AlienTextFile.java DuccHandler.java

Author: degenaro
Date: Wed Sep 17 20:08:05 2014
New Revision: 1625796

URL: http://svn.apache.org/r1625796
Log:
UIMA-4000 DUCC Web Server (WS) log pager not 100% reliable

Modified:
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/AlienTextFile.java
    uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/AlienTextFile.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/AlienTextFile.java?rev=1625796&r1=1625795&r2=1625796&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/AlienTextFile.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/AlienTextFile.java Wed Sep 17 20:08:05 2014
@@ -24,6 +24,7 @@ import java.io.InputStreamReader;
 
 import org.apache.uima.ducc.common.utils.AlienAbstract;
 import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.Utils;
 
 public class AlienTextFile extends AlienAbstract {	
 	
@@ -32,30 +33,34 @@ public class AlienTextFile extends Alien
 	private static String command_du = "/usr/bin/du";
 	private static String flag_dash_b = "-b";
 	
+	private static String double_dash = "--";
+	
 	private static String command_dd = "/bin/dd";
 	private static String arg_if = "if=";
 	private static String arg_skip = "skip=";
 	private static String arg_count = "count=";
 	
-	private static int sizeDu = 4096;
-	private static int sizeDefault = 0;
-	
 	private static int sizeBlockDd = 512;
+	private static int sizeDefault = 0;
 	
 	private String file_name;
 	private int page_bytes = 4096;
 	
-	public AlienTextFile(String user, String file_name, String ducc_ling) {
-		set_user(user);
-		set_file_name(file_name);
-		set_ducc_ling(ducc_ling);
+	public AlienTextFile(String user, String file_name) {
+		init(user, file_name, page_bytes);
+	}
+	
+	public AlienTextFile(String user, String file_name, int page_bytes) {
+		init(user, file_name, page_bytes);
 	}
 	
-	public AlienTextFile(String user, String file_name, String ducc_ling, int pageBytes) {
+	private void init(String user, String file_name, int page_bytes) {
+		String location = "init";
 		set_user(user);
 		set_file_name(file_name);
-		set_ducc_ling(ducc_ling);
-		set_page_bytes(pageBytes);
+		set_page_bytes(page_bytes);
+		set_ducc_ling(Utils.resolvePlaceholderIfExists(System.getProperty("ducc.agent.launcher.ducc_spawn_path"),System.getProperties()));
+		duccLogger.debug(location, duccId, "bytes:"+get_page_bytes());
 	}
 	
 	protected void set_file_name(String value) {
@@ -74,13 +79,59 @@ public class AlienTextFile extends Alien
 		return page_bytes;
 	}
 	
+	private void trace(String text) {
+		String location = "trace";
+		duccLogger.debug(location, duccId, text);
+	}
+	
+	private void trace(String[] textArray) {
+		String location = "trace";
+		StringBuffer sb = new StringBuffer();
+		if(textArray != null) {
+			for(String s : textArray) {
+				if(s != null) {
+					sb.append(s+" ");
+				}
+			}
+		}
+		duccLogger.debug(location, duccId, sb);
+	}
+	
+	private String getResult(String[] command) {
+		String location = "getResult";
+		StringBuffer sb = new StringBuffer();
+		try {
+			trace(command);
+			ProcessBuilder pb = new ProcessBuilder( command );
+			Process process = pb.start();
+			InputStream is = process.getInputStream();
+	        InputStreamReader isr = new InputStreamReader(is);
+	        BufferedReader br = new BufferedReader(isr);
+	        String line;
+	        while ((line = br.readLine()) != null) {
+	           sb.append(line);
+	           sb.append("\n");
+	        }
+	        int exitValue = process.waitFor();
+	        duccLogger.debug(location,duccId, exitValue);
+		}
+		catch(Exception e) {
+			duccLogger.error(location, duccId, e);
+		}
+		String retVal = sb.toString();
+		return retVal;
+	}
+	
 	private String[] buildCommandDu() {
-		String[] command_ducc_ling_yes = { ducc_ling, q_parameter, u_parameter, user, command_du, flag_dash_b, file_name };
+		String[] command_ducc_ling_yes = { ducc_ling, q_parameter, u_parameter, user, double_dash, command_du, flag_dash_b, file_name };
 		String[] command_ducc_ling_no  = { command_du, flag_dash_b, file_name };
 		String[] command = command_ducc_ling_yes;
 		if(ducc_ling == null) {
 			command = command_ducc_ling_no;
 		}
+		else if(user == null) {
+			command = command_ducc_ling_no;
+		}
 		return command;
 	}
 	
@@ -89,18 +140,8 @@ public class AlienTextFile extends Alien
 		String data = "";
 		try {
 			String[] command = buildCommandDu();
-			echo(command);
-			ProcessBuilder pb = new ProcessBuilder( command );
-			Process p = pb.start();
-			p.waitFor();
-			InputStream pOut = p.getInputStream();
-			InputStreamReader isr = new InputStreamReader(pOut);
-			BufferedReader br = new BufferedReader(isr);
-			char[] cbuf = new char[sizeDu];
-	        int rc = br.read(cbuf);
-	        duccLogger.debug(methodName, duccId, rc);
-	        data = new String(cbuf);
-	        duccLogger.debug(methodName, duccId, data);
+			data = getResult(command);
+	        trace("data size:"+data.length());
 		}
 		catch(Throwable t) {
 			duccLogger.warn(methodName, duccId, t);
@@ -146,12 +187,15 @@ public class AlienTextFile extends Alien
 	/******/
 	
 	private String[] buildCommandDd(int skip, int count) {
-		String[] command_ducc_ling_yes = { ducc_ling, q_parameter, u_parameter, user, command_dd, arg_if+file_name, arg_skip+skip, arg_count+count };
+		String[] command_ducc_ling_yes = { ducc_ling, q_parameter, u_parameter, user, double_dash, command_dd, arg_if+file_name, arg_skip+skip, arg_count+count };
 		String[] command_ducc_ling_no  = { command_dd, arg_if+file_name, arg_skip+skip, arg_count+count };
 		String[] command = command_ducc_ling_yes;
 		if(ducc_ling == null) {
 			command = command_ducc_ling_no;
 		}
+		else if(user == null) {
+			command = command_ducc_ling_no;
+		}
 		return command;
 	}
 	
@@ -160,22 +204,8 @@ public class AlienTextFile extends Alien
 		String data = "";
 		try {
 			String[] command = buildCommandDd(skip, count);
-			echo(command);
-			ProcessBuilder pb = new ProcessBuilder( command );
-			Process p = pb.start();
-			p.waitFor();
-			InputStream is = p.getInputStream();
-			int ev = p.exitValue();
-			if(ev > 0) {
-				is = p.getErrorStream();
-			}
-			InputStreamReader isr = new InputStreamReader(is);
-			BufferedReader br = new BufferedReader(isr);
-			int bufSize = count*sizeBlockDd;
-			char[] cbuf = new char[bufSize];
-			int rc = br.read(cbuf);
-			duccLogger.debug(methodName, duccId, rc);
-	        data = new String(cbuf);
+			data = getResult(command);
+	        trace("data size:"+data.length());
 		}
 		catch(Throwable t) {
 			duccLogger.warn(methodName, duccId, t);
@@ -242,12 +272,9 @@ public class AlienTextFile extends Alien
 		AlienTextFile alienTextFile;
 		String arg_user = args[0];
 		String arg_file = args[1];
-		if(args.length < 3) {
-			alienTextFile = new AlienTextFile(arg_user, arg_file, null);
-		}
-		else {
-			String arg_ducc_ling = args[2];
-			alienTextFile = new AlienTextFile(arg_user, arg_file, arg_ducc_ling);
+		alienTextFile = new AlienTextFile(arg_user, arg_file);
+		if(args.length > 2) {
+			alienTextFile.set_ducc_ling(args[2]);
 		}
 		int bytes = alienTextFile.getByteSize();
 		System.out.println("--- file bytes ---");

Modified: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java?rev=1625796&r1=1625795&r2=1625796&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccHandler.java Wed Sep 17 20:08:05 2014
@@ -205,10 +205,6 @@ public class DuccHandler extends DuccAbs
 		super.init(duccWebServer);
 	}
 	
-	public String getFileName() {
-		return dir_home+File.separator+dir_resources+File.separator+getDuccWebServer().getClassDefinitionFile();
-	}
-	
 	/*
 	 * non-authenticated
 	 */
@@ -408,6 +404,14 @@ public class DuccHandler extends DuccAbs
 		return retVal;
 	}
 	
+	private String getFilePagerUrl(String user, String file_name) {
+		AlienTextFile atf = new AlienTextFile(user, file_name);
+		int pages = atf.getPageCount();
+		String parms = "?"+"fname="+file_name+"&"+"pages="+pages;
+		String url=duccFilePager+parms;
+		return url;
+	}
+	
 	String pname_idJob = "idJob";
 	String pname_idPro = "idPro";
 	
@@ -428,13 +432,8 @@ public class DuccHandler extends DuccAbs
 		
 		String user = job.getStandardInfo().getUser();
 		String file_name = logsjobdir+logfile;
-		String ducc_ling = null;
 		
-		AlienTextFile atf = new AlienTextFile(user, file_name, ducc_ling);
-		int pages = atf.getPageCount();
-		String parms = "?"+"fname="+file_name+"&"+"pages="+pages;
-		String url=duccFilePager+parms;
-		String errfile = "jd.err.log";
+		String url = getFilePagerUrl(user, file_name);
 		String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+logfile+"</a>";
 		String tr = trGet(counter);
 		rb.append(tr);
@@ -968,6 +967,7 @@ public class DuccHandler extends DuccAbs
 		// additional job driver related log files
 		switch(sType) {
 		case JD:
+			String errfile = "jd.err.log";
 			// jd.err.log
 			if(fileExists(logsjobdir+errfile)) {
 				rb = new StringBuffer();
@@ -981,7 +981,8 @@ public class DuccHandler extends DuccAbs
 				index = 0;
 				// Log
 				index = 1;
-				String href2 = "<a href=\""+duccFilePager+"?"+"fname="+logsjobdir+errfile+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+errfile+"</a>";
+				String jd_url = getFilePagerUrl(user, logsjobdir+errfile);
+				String href2 = "<a href=\""+jd_url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+errfile+"</a>";
 				cbList[index] = new StringBuffer();
 				cbList[index].append("<td>");
 				cbList[index].append(href2);
@@ -1760,7 +1761,8 @@ public class DuccHandler extends DuccAbs
 					*/
 					// name
 					row.append("<td>");
-					String href = "<a href=\""+duccFilePager+"?"+"fname="+file.getAbsolutePath()+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
+					String url = getFilePagerUrl(userId, file.getAbsolutePath());
+					String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
 					row.append(href);
 					row.append("</td>");
 					// size
@@ -1814,7 +1816,8 @@ public class DuccHandler extends DuccAbs
 					*/
 					// name
 					row.append("<td>");
-					String href = "<a href=\""+duccFilePager+"?"+"fname="+file.getAbsolutePath()+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
+					String url = getFilePagerUrl(userId, file.getAbsolutePath());
+					String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
 					row.append(href);
 					row.append("</td>");
 					// size
@@ -1864,7 +1867,8 @@ public class DuccHandler extends DuccAbs
 					row.append("</td>");
 					// name
 					row.append("<td>");
-					String href = "<a href=\""+duccFilePager+"?"+"fname="+file.getAbsolutePath()+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
+					String url = getFilePagerUrl(userId, file.getAbsolutePath());
+					String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+file.getName()+"</a>";
 					row.append(href);
 					row.append("</td>");
 					// size
@@ -1952,6 +1956,7 @@ public class DuccHandler extends DuccAbs
 		try {
 			String name = request.getParameter("name");
 			duccLogger.debug(methodName, null, name);
+			String userId = duccWebSessionManager.getUserId(request);
 			ServicesRegistry servicesRegistry = ServicesRegistry.getInstance();
 			ServicesRegistryMapPayload payload = servicesRegistry.findService(name);
 			Properties properties;
@@ -1982,7 +1987,9 @@ public class DuccHandler extends DuccAbs
 						row.append("</td>");
 						// name
 						row.append("<td>");
-						String href = "<a href=\""+duccFilePager+"?"+"fname="+historyFile.getAbsolutePath()+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+historyFile.getName()+"</a>";
+						
+						String url = getFilePagerUrl(userId, historyFile.getAbsolutePath());
+						String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+historyFile.getName()+"</a>";
 						row.append(href);
 						row.append("</td>");
 						// size
@@ -2023,6 +2030,7 @@ public class DuccHandler extends DuccAbs
 	{
 		String methodName = "handleDuccServletJobSpecificationData";
 		duccLogger.trace(methodName, null, messages.fetch("enter"));
+		String userId = duccWebSessionManager.getUserId(request);
 		StringBuffer sb = new StringBuffer();
 		String jobNo = request.getParameter("id");
 		DuccWorkJob job = getJob(jobNo);
@@ -2066,7 +2074,8 @@ public class DuccHandler extends DuccAbs
 								link = logfile+":"+reason;
 							}
 						}
-						String href = "<a href=\""+duccFilePager+"?"+"fname="+logsjobdir+logfile+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+link+"</a>";
+						String url = getFilePagerUrl(userId, logsjobdir+logfile);
+						String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+link+"</a>";
 						data.append(href);
 					}
 					data.append("</table>");
@@ -2086,6 +2095,7 @@ public class DuccHandler extends DuccAbs
 	{
 		String methodName = "handleDuccServletJobSpecificationData";
 		duccLogger.trace(methodName, null, messages.fetch("enter"));
+		String userId = duccWebSessionManager.getUserId(request);
 		StringBuffer sb = new StringBuffer();
 		String jobNo = request.getParameter("id");
 		DuccWorkJob job = getJob(jobNo);
@@ -2114,7 +2124,8 @@ public class DuccHandler extends DuccAbs
 								link = logfile+":"+reason;
 							}
 						}
-						String href = "<a href=\""+duccFilePager+"?"+"fname="+logsjobdir+logfile+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+link+"</a>";
+						String url = getFilePagerUrl(userId, logsjobdir+logfile);
+						String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars');  newWin.focus(); return false;\">"+link+"</a>";
 						data.append(href);
 					}
 					data.append("</table>");
@@ -3499,8 +3510,7 @@ public class DuccHandler extends DuccAbs
 		try {
 			String user = userId;
 			String file_name = fname;
-			String ducc_ling = null;
-			AlienTextFile atf = new AlienTextFile(user, file_name, ducc_ling);
+			AlienTextFile atf = new AlienTextFile(user, file_name);
 			int pageCount = atf.getPageCount();
 			int pageNo = 0;
 			try {
@@ -3545,11 +3555,13 @@ public class DuccHandler extends DuccAbs
 				}
 			}
 			String aggregate = prepend + chunk + postpend;
-			
+
+			/*
 			if(fname.endsWith(".xml")) {
 				aggregate = aggregate.replace("<", "&lt");
 				aggregate = aggregate.replace(">", "&gt");
 			}
+			*/
 			
 			//if(!aggregate.trim().contains("\n")) {
 			//	if(aggregate.trim().contains(":")) {
@@ -3560,8 +3572,9 @@ public class DuccHandler extends DuccAbs
 			//		}
 			//	}
 			//}
-			
+			sb.append("<pre>");
 			sb.append(aggregate);
+			sb.append("</pre>");
 		}
 		catch(Exception e) {
 			duccLogger.error(methodName, jobid, e);