Commit 5988e690 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Better logging messages + use standard clone() mechanism

parent b6e722de
......@@ -184,29 +184,29 @@ public class Transfer implements Serializable, Runnable {
if (s.equals("root")) {
if (!onlyAccess) {
if (Factory.xrd3cp.isSupported())
ret.add(Factory.xrd3cp.clone());
ret.add((Protocol) Factory.xrd3cp.clone());
if (Factory.xrd3cp4.isSupported())
ret.add(Factory.xrd3cp4.clone());
ret.add((Protocol) Factory.xrd3cp4.clone());
}
if (Factory.xrootd.isSupported())
ret.add(Factory.xrootd.clone());
ret.add((Protocol) Factory.xrootd.clone());
}
else
if (s.equals("http")) {
if (Factory.http.isSupported())
ret.add(Factory.http.clone());
ret.add((Protocol) Factory.http.clone());
}
else
if (s.equals("torrent")) {
if (Factory.torrent.isSupported())
ret.add(Factory.torrent.clone());
ret.add((Protocol) Factory.torrent.clone());
}
else
if (s.equals("file"))
if (Factory.cp.isSupported())
ret.add(Factory.cp.clone());
ret.add((Protocol) Factory.cp.clone());
return ret;
}
......
......@@ -289,11 +289,4 @@ public class CpForTest extends Protocol {
public byte protocolID() {
return 0;
}
@Override
public Protocol clone() {
final CpForTest ret = new CpForTest();
return ret;
}
}
......@@ -136,11 +136,4 @@ public class Http extends Protocol {
public byte protocolID() {
return 1;
}
@Override
public Protocol clone() {
final Http ret = new Http();
return ret;
}
}
......@@ -23,7 +23,7 @@ import lia.util.process.ExternalProcess.ExitStatus;
* @author costing
* @since Dec 8, 2010
*/
public abstract class Protocol implements Serializable, Comparable<Protocol> {
public abstract class Protocol implements Serializable, Comparable<Protocol>, Cloneable {
/**
*
......@@ -168,12 +168,6 @@ public abstract class Protocol implements Serializable, Comparable<Protocol> {
*/
public abstract byte protocolID();
/**
* Clone a protocol, returning an object of a compatible type that can be freely modified by the application
*/
@Override
public abstract Protocol clone();
private ExitStatus lastExitStatus = null;
/**
......@@ -223,4 +217,15 @@ public abstract class Protocol implements Serializable, Comparable<Protocol> {
return URL + "?" + parameter;
}
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
logger.log(Level.SEVERE, "Some Protocol doesn't support cloning", e);
}
return null;
}
}
......@@ -132,11 +132,4 @@ public class Torrent extends Protocol {
public byte protocolID() {
return 2;
}
@Override
public Protocol clone() {
final Torrent ret = new Torrent();
return ret;
}
}
......@@ -256,13 +256,4 @@ public class Xrd3cp extends Xrootd {
public byte protocolID() {
return 4;
}
@Override
public Protocol clone() {
final Xrd3cp ret = new Xrd3cp();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
......@@ -56,13 +56,4 @@ public class Xrd3cp4 extends Xrootd {
public byte protocolID() {
return 5;
}
@Override
public Protocol clone() {
final Xrd3cp4 ret = new Xrd3cp4();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
......@@ -369,7 +369,7 @@ public class Xrootd extends Protocol {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "Exit code " + exitStatus.getExtProcExitStatus() + " and output is:\n" + exitStatus.getStdOut() + "\n, full command was:\n" + command);
throw new IOException("Exit code " + exitStatus.getExtProcExitStatus());
throw new IOException(exitStatus.getExtProcExitStatus() < 0 ? "Timeout after 1 minute" : "Exit code " + exitStatus.getExtProcExitStatus());
}
if (logger.isLoggable(Level.FINEST))
......@@ -535,10 +535,17 @@ public class Xrootd extends Protocol {
logger.log(Level.WARNING, "GET of " + pfn.pfn + " failed with " + exitStatus.getStdOut());
if (sMessage != null)
sMessage = xrdcpPath + " exited with " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
if (sMessage != null) {
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = xrdcpPath + " timed out and was killed after " + maxTime + "s: " + sMessage;
else
sMessage = xrdcpPath + " exited with " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
}
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = "The following command has timeout and was killed after " + maxTime + "s: " + command.toString();
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
throw new SourceException(sMessage);
}
......@@ -677,12 +684,20 @@ public class Xrootd extends Protocol {
if (exitStatus.getExtProcExitStatus() != 0) {
String sMessage = parseXrootdError(exitStatus.getStdOut());
logger.log(Level.WARNING, "PUT of " + pfn.pfn + " failed with " + exitStatus.getStdOut());
if (logger.isLoggable(Level.WARNING))
logger.log(Level.WARNING, "PUT of " + pfn.pfn + " failed with " + exitStatus.getStdOut());
if (sMessage != null)
sMessage = xrdcpPath + " exited with " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
if (sMessage != null) {
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = xrdcpPath + " timed out and was killed after " + maxTime + "s: " + sMessage;
else
sMessage = xrdcpPath + " exited with " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
}
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = "The following command had timed out and was killed after " + maxTime + "s: " + command.toString();
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
throw new TargetException(sMessage);
}
......@@ -887,8 +902,11 @@ public class Xrootd extends Protocol {
throw new IOException("Interrupted while waiting for the following command to finish : " + command.toString(), ie);
}
if (exitStatus.getExtProcExitStatus() != 0)
throw new IOException("Command exited with exit code: " + exitStatus.getExtProcExitStatus() + ", full command and output is below:\n" + command + "\n" + exitStatus.getStdOut());
if (exitStatus.getExtProcExitStatus() < 0)
throw new IOException("Prepare command has timed out and was killed after 15s:\n" + command + "\n" + exitStatus.getStdOut());
if (exitStatus.getExtProcExitStatus() > 0)
throw new IOException("Prepare command exited with exit code: " + exitStatus.getExtProcExitStatus() + ", full command and output is below:\n" + command + "\n" + exitStatus.getStdOut());
}
/**
......@@ -974,9 +992,11 @@ public class Xrootd extends Protocol {
final int sleep = statRetryTimes[statRetryCounter];
if (exitStatus.getExtProcExitStatus() != 0) {
if (sleep == 0 || !retryWithDelay)
throw new IOException("Exit code was " + exitStatus.getExtProcExitStatus() + ", retry #" + (statRetryCounter + 1) + ", output was " + cleanupXrdOutput(exitStatus.getStdOut())
+ ", " + "for command : " + command.toString());
if (sleep == 0 || !retryWithDelay) {
final String message = exitStatus.getExtProcExitStatus() > 0 ? "Exit code was " + exitStatus.getExtProcExitStatus() : "Command has timed out and was killed after 15s";
throw new IOException(
message + ", retry #" + (statRetryCounter + 1) + ", output was " + cleanupXrdOutput(exitStatus.getStdOut()) + ", " + "for command : " + command.toString());
}
Thread.sleep(sleep * 1000);
continue;
......@@ -1158,10 +1178,17 @@ public class Xrootd extends Protocol {
logger.log(Level.WARNING, "TRANSFER failed with " + exitStatus.getStdOut());
if (sMessage != null)
sMessage = "xrdcp (TPC==" + iTPC + ") exited with " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
if (sMessage != null) {
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = "xrdcp (TPC==" + iTPC + ") timed out and was killed after " + seconds + "s, error message was: " + sMessage;
else
sMessage = "xrdcp (TPC==" + iTPC + ") exited with exit code " + exitStatus.getExtProcExitStatus() + ": " + sMessage;
}
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
if (exitStatus.getExtProcExitStatus() < 0)
sMessage = "The following command has timed out and was killed after " + seconds + "s: " + command.toString();
else
sMessage = "Exit code was " + exitStatus.getExtProcExitStatus() + " for command : " + command.toString();
if (exitStatus.getExtProcExitStatus() == 5 && exitStatus.getStdOut().indexOf("source or destination has 0 size") >= 0) {
logger.log(Level.WARNING, "Retrying xrdstat, maybe the file shows up with the correct size in a few seconds");
......@@ -1439,13 +1466,4 @@ public class Xrootd extends Protocol {
return ret;
}
@Override
public Protocol clone() {
final Xrootd ret = new Xrootd();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment