Commit a03691fa authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Clone the protocols to make logging operations thread safe

parent d4811507
......@@ -184,29 +184,29 @@ public class Transfer implements Serializable, Runnable {
if (s.equals("root")) {
if (!onlyAccess) {
if (Factory.xrd3cp.isSupported())
ret.add(Factory.xrd3cp);
ret.add(Factory.xrd3cp.clone());
if (Factory.xrd3cp4.isSupported())
ret.add(Factory.xrd3cp4);
ret.add(Factory.xrd3cp4.clone());
}
if (Factory.xrootd.isSupported())
ret.add(Factory.xrootd);
ret.add(Factory.xrootd.clone());
}
else
if (s.equals("http")) {
if (Factory.http.isSupported())
ret.add(Factory.http);
ret.add(Factory.http.clone());
}
else
if (s.equals("torrent")) {
if (Factory.torrent.isSupported())
ret.add(Factory.torrent);
ret.add(Factory.torrent.clone());
}
else
if (s.equals("file"))
if (Factory.cp.isSupported())
ret.add(Factory.cp);
ret.add(Factory.cp.clone());
return ret;
}
......
......@@ -116,7 +116,8 @@ public class CpForTest extends Protocol {
throw new IOException("Local file " + localFile.getCanonicalPath() + " exists already. Cp would fail.");
target = localFile;
} else {
}
else {
target = File.createTempFile("cp-get", null, IOUtils.getTemporaryDirectory());
if (!target.delete())
......@@ -288,4 +289,11 @@ public class CpForTest extends Protocol {
public byte protocolID() {
return 0;
}
@Override
public Protocol clone() {
final CpForTest ret = new CpForTest();
return ret;
}
}
/**
*
*
*/
package alien.io.protocols;
......@@ -18,7 +18,7 @@ import alien.io.IOUtils;
*/
public class Http extends Protocol {
/**
*
*
*/
private static final long serialVersionUID = -9087355732313314671L;
/**
......@@ -35,7 +35,7 @@ public class Http extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#get(alien.catalogue.PFN, alien.catalogue.access.CatalogueReadAccess, java.lang.String)
*/
@Override
......@@ -84,7 +84,7 @@ public class Http extends Protocol {
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
......@@ -94,7 +94,7 @@ public class Http extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#delete(alien.catalogue.PFN)
*/
@Override
......@@ -104,7 +104,7 @@ public class Http extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#put(alien.catalogue.PFN, java.io.File)
*/
@Override
......@@ -114,7 +114,7 @@ public class Http extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#transfer(alien.catalogue.PFN, alien.catalogue.PFN)
*/
@Override
......@@ -136,4 +136,11 @@ public class Http extends Protocol {
public byte protocolID() {
return 1;
}
@Override
public Protocol clone() {
final Http ret = new Http();
return ret;
}
}
......@@ -100,34 +100,32 @@ public abstract class Protocol implements Serializable, Comparable<Protocol> {
if (f.length() != guid.size)
return false;
if (isValidMD5(guid.md5)) {
if (isValidMD5(guid.md5))
try {
String fileMD5 = IOUtils.getMD5(f);
final String fileMD5 = IOUtils.getMD5(f);
if (!fileMD5.equalsIgnoreCase(guid.md5))
return false;
} catch (IOException e) {
} catch (final IOException e) {
logger.log(Level.SEVERE, "Error during MD5 check of " + f.getAbsolutePath());
logger.log(Level.SEVERE, e.getMessage());
return false;
}
}
else {
final LFN lfn = LFNUtils.getLFN(guid);
if (lfn != null && isValidMD5(lfn.md5)) {
if (lfn != null && isValidMD5(lfn.md5))
try {
String fileMD5 = IOUtils.getMD5(f);
final String fileMD5 = IOUtils.getMD5(f);
if (!fileMD5.equalsIgnoreCase(lfn.md5))
return false;
} catch (IOException e) {
} catch (final IOException e) {
logger.log(Level.SEVERE, "Error during MD5 check of " + f.getAbsolutePath());
logger.log(Level.SEVERE, e.getMessage());
return false;
}
}
}
// otherwise don't check md5 at all
......@@ -143,7 +141,7 @@ public abstract class Protocol implements Serializable, Comparable<Protocol> {
* string to check
* @return <code>true</code> if a string is a valid md5 hash, <code>false</code> otherwise
*/
private static boolean isValidMD5(String s) {
private static boolean isValidMD5(final String s) {
if (s != null && s.length() > 0)
return md5pattern.matcher(s).matches();
......@@ -170,6 +168,12 @@ 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;
/**
......
/**
*
*
*/
package alien.io.protocols;
......@@ -18,7 +18,7 @@ import alien.io.IOUtils;
*/
public class Torrent extends Protocol {
/**
*
*
*/
private static final long serialVersionUID = 4568694269197082489L;
/**
......@@ -35,7 +35,7 @@ public class Torrent extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#get(alien.catalogue.PFN, alien.catalogue.access.CatalogueReadAccess, java.lang.String)
*/
@Override
......@@ -80,7 +80,7 @@ public class Torrent extends Protocol {
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
......@@ -90,7 +90,7 @@ public class Torrent extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#delete(alien.catalogue.PFN)
*/
@Override
......@@ -100,7 +100,7 @@ public class Torrent extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#put(alien.catalogue.PFN, java.io.File)
*/
@Override
......@@ -110,7 +110,7 @@ public class Torrent extends Protocol {
/*
* (non-Javadoc)
*
*
* @see alien.io.protocols.Protocol#transfer(alien.catalogue.PFN, alien.catalogue.PFN)
*/
@Override
......@@ -132,4 +132,11 @@ public class Torrent extends Protocol {
public byte protocolID() {
return 2;
}
@Override
public Protocol clone() {
final Torrent ret = new Torrent();
return ret;
}
}
......@@ -152,7 +152,7 @@ public class Xrd3cp extends Xrootd {
checkLibraryPath(pBuilder, xrd3cpBasePath.substring(0, xrd3cpBasePath.lastIndexOf('/')), true);
long seconds = source.getGuid().size / 200000; // average target
// speed: 200KB/s
// speed: 200KB/s
seconds += 5 * 60; // 5 minutes extra time, handshakes and such
......@@ -256,4 +256,13 @@ public class Xrd3cp extends Xrootd {
public byte protocolID() {
return 4;
}
@Override
public Protocol clone() {
final Xrd3cp ret = new Xrd3cp();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
/**
*
*
*/
package alien.io.protocols;
......@@ -9,14 +9,14 @@ import alien.catalogue.PFN;
/**
* 3rd party Xrootd transfers using the default client in Xrootd 4+
*
*
* @author costing
* @since Jun 16 2015
*/
public class Xrd3cp4 extends Xrootd {
/**
*
*
*/
private static final long serialVersionUID = 9084272684664087714L;
......@@ -28,13 +28,13 @@ public class Xrd3cp4 extends Xrootd {
}
@Override
public String transfer(PFN source, PFN target) throws IOException {
public String transfer(final PFN source, final PFN target) throws IOException {
return transferv4(source, target, TPC_ONLY);
}
/*
* (non-Javadoc)
*
*
* @see java.lang.Object#toString()
*/
@Override
......@@ -56,4 +56,13 @@ public class Xrd3cp4 extends Xrootd {
public byte protocolID() {
return 5;
}
@Override
public Protocol clone() {
final Xrd3cp4 ret = new Xrd3cp4();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
......@@ -161,7 +161,7 @@ public class Xrd3cpGW extends Xrootd {
checkLibraryPath(pBuilder);
long seconds = source.getGuid().size / 200000; // average target
// speed: 200KB/s
// speed: 200KB/s
seconds += 5 * 60; // 5 minutes extra time, handshakes and such
......@@ -255,4 +255,13 @@ public class Xrd3cpGW extends Xrootd {
public byte protocolID() {
return 6;
}
@Override
public Protocol clone() {
final Xrd3cpGW ret = new Xrd3cpGW();
ret.setDebugLevel(xrdcpdebuglevel);
return ret;
}
}
......@@ -46,7 +46,7 @@ public class Xrootd extends Protocol {
static transient final Logger logger = ConfigUtils.getLogger(Xrootd.class.getCanonicalName());
private static String xrdcpdebug = "-d";
private int xrdcpdebuglevel = 0;
protected int xrdcpdebuglevel = 0;
/**
* Path to the Xrootd command line binaries
......@@ -188,12 +188,12 @@ public class Xrootd extends Protocol {
* whether to append to the existing value (<code>true</code>) or replace it (<code>false</code>)
*/
public static void checkLibraryPath(final ProcessBuilder p, final String path, final boolean append) {
if (path != null) {
if (path != null)
if (!append) {
p.environment().put("LD_LIBRARY_PATH", path + "/lib");
p.environment().put("DYLD_LIBRARY_PATH", path + "/lib");
}
else {
else
for (final String key : new String[] { "LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH" }) {
final String old = p.environment().get(key);
......@@ -202,8 +202,6 @@ public class Xrootd extends Protocol {
else
p.environment().put(key, old + ":" + path + "/lib");
}
}
}
}
/**
......@@ -978,7 +976,7 @@ public class Xrootd extends Protocol {
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());
+ ", " + "for command : " + command.toString());
Thread.sleep(sleep * 1000);
continue;
......@@ -1131,7 +1129,7 @@ public class Xrootd extends Protocol {
checkLibraryPath(pBuilder);
long seconds = source.getGuid().size / 200000; // average target
// speed: 200KB/s
// speed: 200KB/s
seconds += 5 * 60; // 5 minutes extra time, handshakes and such
......@@ -1441,4 +1439,13 @@ 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