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 2015/06/19 14:47:41 UTC
svn commit: r1686400 - in
/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws:
server/DuccFile.java server/DuccHandler.java utils/alien/
utils/alien/AlienDirectory.java utils/alien/FileInfo.java
utils/alien/OsProxy.java
Author: degenaro
Date: Fri Jun 19 12:47:41 2015
New Revision: 1686400
URL: http://svn.apache.org/r1686400
Log:
UIMA-4468 DUCC Web Server (WS) Files tab shows no files (on Job and Service details)
Added:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java (with props)
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java (with props)
Modified:
uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccFile.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/DuccFile.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccFile.java?rev=1686400&r1=1686399&r2=1686400&view=diff
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccFile.java (original)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/server/DuccFile.java Fri Jun 19 12:47:41 2015
@@ -26,7 +26,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.Properties;
-import java.util.TreeMap;
import java.util.zip.GZIPInputStream;
import org.apache.uima.ducc.cli.DuccUiConstants;
@@ -41,22 +40,6 @@ public class DuccFile {
Utils.resolvePlaceholderIfExists(
System.getProperty("ducc.agent.launcher.ducc_spawn_path"),System.getProperties());
- public static TreeMap<String, File> getFilesInLogDirectory(IDuccWorkJob job, String user) throws Throwable {
- String directory = job.getUserLogsDir()+job.getDuccId().getFriendly()+File.separator;
- TreeMap<String, File> map = new TreeMap<String, File>();
- try {
- File filedir = new File(directory);
- File[] filelist = filedir.listFiles();
- for(File file : filelist) {
- map.put(file.getName(), file);
- }
- }
- catch(Exception e) {
- // no worries
- }
- return map;
- }
-
public static Properties getUserSpecifiedProperties(IDuccWorkJob job, String user) throws Throwable {
String directory = job.getUserLogsDir()+job.getDuccId().getFriendly()+File.separator;
String name = DuccUiConstants.user_specified_properties;
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=1686400&r1=1686399&r2=1686400&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 Fri Jun 19 12:47:41 2015
@@ -66,6 +66,7 @@ import org.apache.uima.ducc.common.utils
import org.apache.uima.ducc.common.utils.IDuccLoggerComponents;
import org.apache.uima.ducc.common.utils.SynchronizedSimpleDateFormat;
import org.apache.uima.ducc.common.utils.TimeStamp;
+import org.apache.uima.ducc.common.utils.Utils;
import org.apache.uima.ducc.common.utils.Version;
import org.apache.uima.ducc.common.utils.id.DuccId;
import org.apache.uima.ducc.orchestrator.authentication.DuccWebAdministrators;
@@ -111,6 +112,8 @@ import org.apache.uima.ducc.ws.utils.For
import org.apache.uima.ducc.ws.utils.HandlersHelper;
import org.apache.uima.ducc.ws.utils.LinuxSignals;
import org.apache.uima.ducc.ws.utils.LinuxSignals.Signal;
+import org.apache.uima.ducc.ws.utils.alien.FileInfo;
+import org.apache.uima.ducc.ws.utils.alien.OsProxy;
import org.eclipse.jetty.server.Request;
public class DuccHandler extends DuccAbstractHandler {
@@ -120,7 +123,11 @@ public class DuccHandler extends DuccAbs
private static DuccLogger duccLogger = DuccLoggerComponents.getWsLogger(DuccHandler.class.getName());
private static Messages messages = Messages.getInstance();
private static DuccId jobid = null;
-
+
+ private static String ducc_ling =
+ Utils.resolvePlaceholderIfExists(
+ System.getProperty("ducc.agent.launcher.ducc_spawn_path"),System.getProperties());
+
private enum DetailsType { Job, Reservation, Service };
private enum ShareType { JD, MR, SPC, SPU, UIMA };
private enum LogType { POP, UIMA };
@@ -206,6 +213,14 @@ public class DuccHandler extends DuccAbs
super.init(duccWebServer);
}
+ public String getDuccling(HttpServletRequest request) {
+ String retVal = null;
+ if(duccWebSessionManager.isAuthentic(request)) {
+ retVal = ducc_ling;
+ }
+ return retVal;
+ }
+
/*
* non-authenticated
*/
@@ -392,6 +407,7 @@ public class DuccHandler extends DuccAbs
return retVal;
}
+ @Deprecated
private String getFileSize(String fileName) {
String location = "getFileSize";
String retVal = "0";
@@ -2042,11 +2058,12 @@ public class DuccHandler extends DuccAbs
if(job != null) {
try {
String userId = duccWebSessionManager.getUserId(request);
- TreeMap<String, File> map = DuccFile.getFilesInLogDirectory(job, userId);
+ String directory = job.getUserLogsDir()+job.getDuccId().getFriendly()+File.separator;
+ Map<String, FileInfo> map = OsProxy.getFilesInDirectory(getDuccling(request), userId, directory);
Set<String> keys = map.keySet();
int counter = 0;
for(String key : keys) {
- File file = map.get(key);
+ FileInfo fileInfo = map.get(key);
StringBuffer row = new StringBuffer();
//
String tr = trGet(counter);
@@ -2062,13 +2079,13 @@ public class DuccHandler extends DuccAbs
*/
// name
row.append("<td>");
- 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>";
+ String url = getFilePagerUrl(userId, fileInfo.getName());
+ String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars'); newWin.focus(); return false;\">"+fileInfo.getShortName()+"</a>";
row.append(href);
row.append("</td>");
// size
row.append("<td>");
- row.append(getFileSize(file.getAbsolutePath()));
+ row.append(fileInfo.getLength());
row.append("</td>");
//
row.append("</tr>");
@@ -2097,11 +2114,12 @@ public class DuccHandler extends DuccAbs
if(reservation != null) {
try {
String userId = duccWebSessionManager.getUserId(request);
- TreeMap<String, File> map = DuccFile.getFilesInLogDirectory(reservation, userId);
+ String directory = reservation.getUserLogsDir()+reservation.getDuccId().getFriendly()+File.separator;
+ Map<String, FileInfo> map = OsProxy.getFilesInDirectory(getDuccling(request), userId, directory);
Set<String> keys = map.keySet();
int counter = 0;
for(String key : keys) {
- File file = map.get(key);
+ FileInfo fileInfo = map.get(key);
StringBuffer row = new StringBuffer();
//
String tr = trGet(counter);
@@ -2117,13 +2135,13 @@ public class DuccHandler extends DuccAbs
*/
// name
row.append("<td>");
- 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>";
+ String url = getFilePagerUrl(userId, fileInfo.getName());
+ String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars'); newWin.focus(); return false;\">"+fileInfo.getShortName()+"</a>";
row.append(href);
row.append("</td>");
// size
row.append("<td>");
- row.append(getFileSize(file.getAbsolutePath()));
+ row.append(fileInfo.getLength());
row.append("</td>");
//
row.append("</tr>");
@@ -2145,10 +2163,11 @@ public class DuccHandler extends DuccAbs
if(job != null) {
try {
String userId = duccWebSessionManager.getUserId(request);
- TreeMap<String, File> map = DuccFile.getFilesInLogDirectory(job, userId);
+ String directory = job.getUserLogsDir()+job.getDuccId().getFriendly()+File.separator;
+ Map<String, FileInfo> map = OsProxy.getFilesInDirectory(getDuccling(request), userId, directory);
Set<String> keys = map.keySet();
for(String key : keys) {
- File file = map.get(key);
+ FileInfo fileInfo = map.get(key);
StringBuffer row = new StringBuffer();
//
String tr = trGet(counter);
@@ -2168,13 +2187,13 @@ public class DuccHandler extends DuccAbs
row.append("</td>");
// name
row.append("<td>");
- 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>";
+ String url = getFilePagerUrl(userId, fileInfo.getName());
+ String href = "<a href=\""+url+"\" onclick=\"var newWin = window.open(this.href,'child','height=800,width=1200,scrollbars'); newWin.focus(); return false;\">"+fileInfo.getShortName()+"</a>";
row.append(href);
row.append("</td>");
// size
row.append("<td>");
- row.append(getFileSize(file.getAbsolutePath()));
+ row.append(fileInfo.getLength());
row.append("</td>");
//
row.append("</tr>");
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java?rev=1686400&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java Fri Jun 19 12:47:41 2015
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.ws.utils.alien;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.InputStream;
+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.DuccLoggerComponents;
+
+public class AlienDirectory extends AlienAbstract {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(AlienDirectory.class.getName());
+
+ private String dashdash = "--";
+
+ private String command_ls = "/bin/ls";
+ private String command_ls_flags = "-atl";
+ private String directory_name;
+
+ protected void set_command_ls(String value) {
+ command_ls = value;
+ }
+
+ protected String get_command_ls() {
+ return command_ls;
+ }
+
+ protected void set_command_ls_flags(String value) {
+ command_ls_flags = value;
+ }
+
+ protected String get_command_ls_flags() {
+ return command_ls_flags;
+ }
+
+ protected void set_directory_name(String value) {
+ directory_name = value;
+ }
+
+ protected String get_directory_name() {
+ return directory_name;
+ }
+
+ public AlienDirectory(String user, String directory_name, String ducc_ling) {
+ set_user(user);
+ set_directory_name(directory_name);
+ set_ducc_ling(ducc_ling);
+ }
+
+ private String[] getCommand() {
+ String[] command_ducc_ling_yes = { ducc_ling, q_parameter, u_parameter, user, dashdash, command_ls, command_ls_flags, directory_name};
+ String[] command_ducc_ling_no = { command_ls, command_ls_flags, directory_name};
+ String[] command = command_ducc_ling_yes;
+ if(ducc_ling == null) {
+ command = command_ducc_ling_no;
+ }
+ return command;
+ }
+
+ private String reader() throws Throwable {
+ String data = null;
+ BufferedReader br = null;
+ InputStreamReader isr = null;
+ try {
+ String[] command = getCommand();
+ echo(command);
+ ProcessBuilder pb = new ProcessBuilder( command );
+ Process p = pb.start();
+ //p.waitFor();
+ InputStream pOut = p.getInputStream();
+ isr = new InputStreamReader(pOut);
+ br = new BufferedReader(isr);
+ StringBuilder sb = new StringBuilder();
+ String line;
+ boolean first = true;
+ while ((line = br.readLine()) != null) {
+ if(first) {
+ first = false;
+ }
+ else {
+ sb.append(line);
+ sb.append("\n");
+ }
+ }
+ data = sb.toString();
+ return data;
+ }
+ catch(Throwable t) {
+ t.printStackTrace();
+ throw t;
+ }
+ finally {
+ closer(br);
+ closer(isr);
+ }
+ }
+
+ public String getString() throws Throwable {
+ String methodName = "getString";
+ String data = reader();
+ logger.debug(methodName, duccId, data);
+ return data;
+ }
+
+ public InputStreamReader getInputStreamReader() throws Throwable {
+ InputStreamReader isr = null;
+ try {
+ String[] command = getCommand();
+ echo(command);
+ ProcessBuilder pb = new ProcessBuilder( command );
+ Process p = pb.start();
+ //p.waitFor();
+ InputStream pOut = p.getInputStream();
+ isr = new InputStreamReader(pOut);
+ }
+ catch(Throwable t) {
+ throw t;
+ }
+ return isr;
+ }
+
+ public DataInputStream getDataInputStream() throws Throwable {
+ DataInputStream dis = null;
+ try {
+ String[] command = getCommand();
+ echo(command);
+ ProcessBuilder pb = new ProcessBuilder( command );
+ Process p = pb.start();
+ //p.waitFor();
+ InputStream pOut = p.getInputStream();
+ dis= new DataInputStream(pOut);
+ }
+ catch(Throwable t) {
+ throw t;
+ }
+ return dis;
+ }
+
+ public static void main(String[] args) throws Throwable {
+ AlienDirectory alienDirectory;
+ String arg_user = args[0];
+ String arg_directory = args[1];
+ if(args.length < 3) {
+ alienDirectory = new AlienDirectory(arg_user, arg_directory, null);
+ }
+ else {
+ String arg_ducc_ling = args[2];
+ alienDirectory = new AlienDirectory(arg_user, arg_directory, arg_ducc_ling);
+ }
+ String data = alienDirectory.getString();
+ System.out.println(data);
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/AlienDirectory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java?rev=1686400&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java Fri Jun 19 12:47:41 2015
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.ws.utils.alien;
+
+import java.io.File;
+
+public class FileInfo {
+
+ public String name;
+ public long length;
+
+ public FileInfo(String name, long length) {
+ setName(name);
+ setLength(length);
+ }
+
+ public void setName(String value) {
+ name = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getShortName() {
+ String retVal = name;
+ if(name != null) {
+ retVal = name.substring(name.lastIndexOf(File.separator)+1);
+ }
+ return retVal;
+ }
+
+ public void setLength(long value) {
+ length = value;
+ }
+
+ public long getLength() {
+ return length;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/FileInfo.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java?rev=1686400&view=auto
==============================================================================
--- uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java (added)
+++ uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java Fri Jun 19 12:47:41 2015
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+package org.apache.uima.ducc.ws.utils.alien;
+
+import java.io.File;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.uima.ducc.common.utils.DuccLogger;
+import org.apache.uima.ducc.common.utils.DuccLoggerComponents;
+import org.apache.uima.ducc.common.utils.id.DuccId;
+
+public class OsProxy {
+
+ private static DuccLogger logger = DuccLoggerComponents.getWsLogger(OsProxy.class.getName());
+ private static DuccId jobid = null;
+
+ private static String newline = "\n";
+ private static String whitespace = "\\s+";
+
+ public static Map<String, FileInfo> getFilesInDirectory(String ducc_ling, String user, String directory) throws Throwable {
+ String location = "getFilesInDirectory";
+ TreeMap<String, FileInfo> map = new TreeMap<String, FileInfo>();
+ if(ducc_ling == null) {
+ try {
+ File filedir = new File(directory);
+ File[] filelist = filedir.listFiles();
+ for(File file : filelist) {
+ String name = file.getName();
+ String fullname = file.getAbsolutePath();
+ long length = file.length();
+ FileInfo fileInfo = new FileInfo(fullname,length);
+ map.put(name, fileInfo);
+ }
+ }
+ catch(Exception e) {
+ // no worries
+ }
+ }
+ else {
+ try {
+ AlienDirectory alienDirectory = new AlienDirectory(user, directory, ducc_ling);
+ String result = alienDirectory.getString();
+ logger.debug(location, jobid, result);
+ if(result != null) {
+ String[] lines = result.split(newline);
+ for(String line : lines) {
+ logger.debug(location, jobid, line);
+ String[] element = line.split(whitespace);
+ String name = element[8];
+ String fullname = directory+name;
+ if(!name.startsWith(".")) {
+ if(!directory.endsWith(File.separator)) {
+ fullname = directory+File.separator+name;
+ }
+ long length = Long.parseLong(element[4]);
+ FileInfo fileInfo = new FileInfo(fullname,length);
+ map.put(name, fileInfo);
+ }
+ }
+ }
+ }
+ catch(Exception e) {
+ // no worries
+ }
+ }
+ return map;
+ }
+}
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: uima/sandbox/uima-ducc/trunk/uima-ducc-web/src/main/java/org/apache/uima/ducc/ws/utils/alien/OsProxy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain