Commit 87e52de0 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Another set of SpotBugs-suggested fixes

parent 18e71a00
......@@ -388,7 +388,7 @@ public class DispatchSSLClient {
/**
* Total amount of time (in milliseconds) spent in writing objects to the socket.
*/
public static long lSerialization = 0;
private static long lSerialization = 0;
private static synchronized void initializeSocketInfo() {
addr = ConfigUtils.getConfig().gets(serviceName).trim();
......@@ -501,6 +501,13 @@ public class DispatchSSLClient {
return reply;
}
/**
* @return total time in milliseconds spent in serializing objects
*/
public static long getSerializationTime() {
return lSerialization;
}
private static void printSocketInfo(final SSLSocket s, final Level level) {
if (logger.isLoggable(level)) {
logger.log(level, "Remote address: " + s.getInetAddress().toString() + ":" + s.getPort());
......
......@@ -264,7 +264,14 @@ public class DispatchSSLMTClient extends Thread {
/**
* Total amount of time (in milliseconds) spent in writing objects to the socket.
*/
public static long lSerialization = 0;
private static long lSerialization = 0;
/**
* @return total time in milliseconds spent in serializing objects
*/
public static long getSerializationTime() {
return lSerialization;
}
private static synchronized void initializeSocketInfo() {
addr = ConfigUtils.getConfig().gets(serviceName).trim();
......
......@@ -563,7 +563,7 @@ public class DispatchSSLServer extends Thread {
/**
* Total amount of time (in milliseconds) spent in writing objects to the socket.
*/
public static double lSerialization = 0;
private static double lSerialization = 0;
/**
* Print client info on SSL partner
......
......@@ -663,7 +663,14 @@ public class DispatchSSLServerNIO implements Runnable {
/**
* Total amount of time (in milliseconds) spent in writing objects to the socket.
*/
public static double lSerialization = 0;
private static double lSerialization = 0;
/**
* @return total time in milliseconds spent in serializing objects
*/
public static double getSerializationTime() {
return lSerialization;
}
/**
* Print client info on SSL partner
......
......@@ -68,11 +68,11 @@ public class LFNCSDUtils {
/**
* Cassandra table suffix
*/
static public String append_table = "";
public static final String append_table = "";
/**
* Cassandra consistency
*/
static public ConsistencyLevel clevel = ConsistencyLevel.QUORUM;
public static final ConsistencyLevel clevel = ConsistencyLevel.QUORUM;
/**
* the "-s" flag of AliEn `find`
......@@ -406,8 +406,8 @@ public class LFNCSDUtils {
}
for (String lfnc_str : lfn_to_csd.keySet())
if (!operation.callback(lfn_to_csd.get(lfnc_str))) {
for (final LFN_CSD lfn : lfn_to_csd.values())
if (!operation.callback(lfn)) {
parent.critical_errors = true;
}
......
package alien.catalogue;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
......@@ -51,7 +50,7 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
/**
* Root UUID
*/
public static final UUID root_uuid = UUID.nameUUIDFromBytes("root".getBytes()); // 63a9f0ea-7bb9-3050-b96b-649e85481845
static final UUID root_uuid = UUID.nameUUIDFromBytes("root".getBytes()); // 63a9f0ea-7bb9-3050-b96b-649e85481845
/**
* Pool of PreparedStatements
......@@ -66,25 +65,17 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
/**
* dirCache stats
*/
public static int dirCache_get_hit = 0;
static int dirCache_get_hit = 0;
/**
* dirCache stats
*/
public static int dirCache_put = 0;
static int dirCache_put = 0;
/**
* Unique Ctime for auto insertion
*/
public static Date ctime_fixed = null;
static {
try {
ctime_fixed = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").parse("2017-01-01 00:00:00");
}
catch (ParseException e) {
System.err.println(e);
System.exit(-1);
}
}
public static final Date ctime_fixed = new Date(1483225200000L);
/**
* Modulo of seNumber to partition balance
*/
......@@ -447,7 +438,7 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
path_id = results.one().getUUID("child_id");
if (path_id == null) {
logger.severe("Error getting parent id for path_id: " + path_id + " path: " + (i == 0 ? "/" : path_chunks[i - 1]));
logger.severe("Error getting parent id for path_id for path: " + (i == 0 ? "/" : path_chunks[i - 1]));
return null;
}
......@@ -1360,8 +1351,8 @@ public class LFN_CSD implements Comparable<LFN_CSD>, CatalogEntity {
if (monitor != null)
monitor.incrementCounter("PFN_CSD_db_lookup");
for (Integer senumber : this.pfns.keySet()) {
final PFN pfn = new PFN(senumber, this.pfns.get(senumber), this.id, this.size);
for (final Map.Entry<Integer, String> entry : this.pfns.entrySet()) {
final PFN pfn = new PFN(entry.getKey(), entry.getValue(), this.id, this.size);
pfnCache.add(pfn);
}
......
......@@ -713,14 +713,14 @@ public class ConfigUtils {
else if (configuration.containsKey("site_logdir"))
folders_config.put("logdir", (String) configuration.get("site_logdir"));
for (final String folder : folders_config.keySet()) {
final String folderpath = folders_config.get(folder);
for (final Map.Entry<String, String> entry : folders_config.entrySet()) {
final String folderpath = entry.getValue();
try {
final File folderf = new File(folderpath);
if (!folderf.exists()) {
final boolean created = folderf.mkdirs();
if (!created)
logger.severe("Directory for " + folder + "can't be created: " + folderpath);
logger.severe("Directory for " + entry.getKey() + "can't be created: " + folderpath);
}
}
catch (final Exception e) {
......@@ -746,9 +746,9 @@ public class ConfigUtils {
return siteConfig;
}
/**
* @param checkContent
* @param site
/**
* @param checkContent
* @param site
* @param cename
* @return CE information based on the site and ce name for the host
*/
......@@ -761,6 +761,7 @@ public class ConfigUtils {
}
return ceConfig;
}
/**
*
* @param cename
......
......@@ -51,7 +51,7 @@ public class Xrd3cp extends Xrootd {
cachedPath = true;
for (final String path : new String[] { xrootd_default_path, ConfigUtils.getConfig().gets("xrd3cp.location", null), UserFactory.getUserHome() + "/alien/api", "/opt/alien/api" })
for (final String path : new String[] { getXrootdDefaultPath(), ConfigUtils.getConfig().gets("xrd3cp.location", null), UserFactory.getUserHome() + "/alien/api", "/opt/alien/api" })
if (path != null) {
final File test = new File(path + "/bin/xrd3cp");
......@@ -110,9 +110,9 @@ public class Xrd3cp extends Xrootd {
command.add("-S");
final boolean sourceEnvelope = source.ticket != null && source.ticket.envelope != null;
final boolean sourceEnvelope = source.ticket.envelope != null;
final boolean targetEnvelope = target.ticket != null && target.ticket.envelope != null;
final boolean targetEnvelope = target.ticket.envelope != null;
if (sourceEnvelope)
command.add(source.ticket.envelope.getTransactionURL());
......@@ -165,14 +165,10 @@ public class Xrd3cp extends Xrootd {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command: " + command);
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
catch (final InterruptedException ie) {
setLastExitStatus(null);
......
......@@ -105,16 +105,16 @@ public class Xrd3cpGW extends Xrootd {
throw new IOException("The ticket for target PFN " + target.toString() + " could not be found or is not a WRITE one.");
final List<String> command = new LinkedList<>();
command.add(xrootd_default_path + "/bin/xrdcp");
command.add(getXrootdDefaultPath() + "/bin/xrdcp");
command.add("--tpc");
command.add("only");
command.add("--force");
command.add("--path");
command.add("--posc");
final boolean sourceEnvelope = source.ticket != null && source.ticket.envelope != null;
final boolean sourceEnvelope = source.ticket.envelope != null;
final boolean targetEnvelope = target.ticket != null && target.ticket.envelope != null;
final boolean targetEnvelope = target.ticket.envelope != null;
final String serverInstance = getTransferServerInstance();
......@@ -172,14 +172,10 @@ public class Xrd3cpGW extends Xrootd {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command: " + command);
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
catch (final InterruptedException ie) {
setLastExitStatus(null);
......
......@@ -72,14 +72,14 @@ public class Xrootd extends Protocol {
/**
* Path to the Xrootd command line binaries
*/
protected static String xrootd_default_path = null;
private static final String xrootd_default_path;
private static String xrdcpPath = null;
/**
* Statically filled variable, <code>true</code> when
*/
protected static boolean xrootdNewerThan4 = false;
protected static final boolean xrootdNewerThan4;
private Map<String, String> extraEnvVariables = new HashMap<>();
......@@ -98,12 +98,14 @@ public class Xrootd extends Protocol {
}
}
String defaultPath = null;
if (ConfigUtils.getConfig() != null) {
xrootd_default_path = ConfigUtils.getConfig().gets("xrootd.location", null);
defaultPath = ConfigUtils.getConfig().gets("xrootd.location", null);
if (xrootd_default_path != null)
if (defaultPath != null)
for (final String command : new String[] { "xrdcpapmon", "xrdcp" }) {
xrdcpPath = ExternalCalls.programExistsInFolders(command, xrootd_default_path, xrootd_default_path + "/bin");
xrdcpPath = ExternalCalls.programExistsInFolders(command, defaultPath, defaultPath + "/bin");
if (xrdcpPath != null)
break;
......@@ -126,6 +128,8 @@ public class Xrootd extends Protocol {
break;
}
boolean newerThan4 = false;
if (xrdcpPath != null) {
int idx = xrdcpPath.lastIndexOf('/');
......@@ -133,7 +137,7 @@ public class Xrootd extends Protocol {
idx = xrdcpPath.lastIndexOf('/', idx - 1);
if (idx >= 0)
xrootd_default_path = xrdcpPath.substring(0, idx);
defaultPath = xrdcpPath.substring(0, idx);
}
final ProcessBuilder pBuilder = new ProcessBuilder(Arrays.asList(xrdcpPath, "--version"));
......@@ -147,20 +151,16 @@ public class Xrootd extends Protocol {
try {
p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout timeout = new ProcessWithTimeout(p, pBuilder);
final ProcessWithTimeout timeout = new ProcessWithTimeout(p, pBuilder);
if (timeout.waitFor(15, TimeUnit.SECONDS) && timeout.exitValue() == 0) {
final String version = timeout.getStdout().toString();
if (timeout.waitFor(15, TimeUnit.SECONDS) && timeout.exitValue() == 0) {
final String version = timeout.getStdout().toString();
logger.log(Level.FINE, "Local Xrootd version is " + version);
logger.log(Level.FINE, "Local Xrootd version is " + version);
if (version.indexOf('.') > 0)
xrootdNewerThan4 = version.substring(0, version.indexOf('.')).compareTo("v4") >= 0;
}
if (version.indexOf('.') > 0)
newerThan4 = version.substring(0, version.indexOf('.')).compareTo("v4") >= 0;
}
else
logger.log(Level.WARNING, "Cannot execute " + xrdcpPath);
}
catch (final IOException | InterruptedException ie) {
if (p != null)
......@@ -169,6 +169,9 @@ public class Xrootd extends Protocol {
logger.log(Level.WARNING, "Interrupted while waiting for `" + xrdcpPath + " --version` to finish", ie);
}
}
xrootd_default_path = defaultPath;
xrootdNewerThan4 = newerThan4;
}
private static String DIConnectionWindow = "3"; // Xrootd default is 2 minutes, which is too long to give up on non-working IPv6 sockets (* number of IPs in the alias)
......@@ -751,10 +754,10 @@ public class Xrootd extends Protocol {
command.add("-np");
/**
// explicitly ask to create intermediate paths
if (xrootdNewerThan4)
command.add("--path");
*/
* // explicitly ask to create intermediate paths
* if (xrootdNewerThan4)
* command.add("--path");
*/
command.add("--verbose"); // display summary output
command.add("--force"); // re-create a file if already present
......@@ -1056,14 +1059,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(15, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute this command:\n" + getFormattedLastCommand());
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(15, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
catch (final InterruptedException ie) {
setLastExitStatus(null);
......@@ -1150,16 +1149,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(processTimeout, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else {
setLastCommand(command);
throw new SourceException(CANNOT_START_PROCESS, "Cannot execute command:\n" + getFormattedLastCommand());
}
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(processTimeout, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
catch (final InterruptedException ie) {
setLastExitStatus(null);
......@@ -1298,15 +1291,15 @@ public class Xrootd extends Protocol {
}
command.add("--force");
//command.add("--path");
// command.add("--path");
command.add("--posc");
command.add("--nopbar");
command.addAll(getCommonArguments("transfer-3rd"));
final boolean sourceEnvelope = source.ticket != null && source.ticket.envelope != null;
final boolean sourceEnvelope = source.ticket.envelope != null;
final boolean targetEnvelope = target.ticket != null && target.ticket.envelope != null;
final boolean targetEnvelope = target.ticket.envelope != null;
String sourcePath;
......@@ -1359,14 +1352,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command:\n" + getFormattedLastCommand());
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(seconds, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
catch (final InterruptedException ie) {
setLastExitStatus(null);
......@@ -1495,6 +1484,13 @@ public class Xrootd extends Protocol {
return xrootd_default_path;
}
/**
* @return path to the xrdcp command line binary
*/
public static String getXrdcpPath() {
return xrdcpPath;
}
/**
* @param pfn
* Some path + read access token to get the space information for
......@@ -1602,14 +1598,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(2, TimeUnit.MINUTES);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command:\n" + getFormattedLastCommand());
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(2, TimeUnit.MINUTES);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
try (BufferedReader br = new BufferedReader(new StringReader(exitStatus.getStdOut()))) {
String line;
......@@ -1734,14 +1726,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(2, TimeUnit.MINUTES);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command:\n" + getFormattedLastCommand());
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(2, TimeUnit.MINUTES);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
try (BufferedReader br = new BufferedReader(new StringReader(exitStatus.getStdOut()))) {
String line;
......@@ -1820,14 +1808,10 @@ public class Xrootd extends Protocol {
try {
final Process p = pBuilder.start();
if (p != null) {
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(15, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
}
else
throw new IOException("Cannot execute command:\n" + getFormattedLastCommand());
final ProcessWithTimeout pTimeout = new ProcessWithTimeout(p, pBuilder);
pTimeout.waitFor(15, TimeUnit.SECONDS);
exitStatus = pTimeout.getExitStatus();
setLastExitStatus(exitStatus);
try (BufferedReader br = new BufferedReader(new StringReader(exitStatus.getStdOut()))) {
String line = br.readLine();
......
......@@ -25,7 +25,6 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
......@@ -39,9 +38,7 @@ import alien.catalogue.access.AccessType;
import alien.config.ConfigUtils;
import alien.io.IOUtils;
import alien.se.SE;
import alien.user.UserFactory;
import lia.util.process.ExternalProcess.ExitStatus;
import utils.ExternalCalls;
import utils.ProcessWithTimeout;
/**
......@@ -69,102 +66,14 @@ public class XrootdCsd extends Protocol {
/**
* Path to the Xrootd command line binaries
*/
protected static String xrootd_default_path = null;
protected static final String xrootd_default_path = Xrootd.getXrootdDefaultPath();
private static String xrdcpPath = null;
private static final String xrdcpPath = Xrootd.getXrdcpPath();
/**
* Statically filled variable, <code>true</code> when
*/
protected static boolean xrootdNewerThan4 = false;
static {
try {
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory.getInstance().addUserFactory(new ROOTURLStreamHandlerFactory());
}
catch (final Throwable t) {
logger.log(Level.WARNING, "Tomcat URL handler is not available", t);
try {
URL.setURLStreamHandlerFactory(new ROOTURLStreamHandlerFactory());
}
catch (final Throwable t2) {
logger.log(Level.WARNING, "Cannot set ROOT URL stream handler factory", t2);
}
}
if (ConfigUtils.getConfig() != null) {
xrootd_default_path = ConfigUtils.getConfig().gets("xrootd.location", null);
if (xrootd_default_path != null)
for (final String command : new String[] { "xrdcpapmon", "xrdcp" }) {
xrdcpPath = ExternalCalls.programExistsInFolders(command, xrootd_default_path, xrootd_default_path + "/bin");
if (xrdcpPath != null)
break;
}
}
if (xrdcpPath == null)
for (final String command : new String[] { "xrdcpapmon", "xrdcp" }) {
xrdcpPath = ExternalCalls.programExistsInPath(command);
if (xrdcpPath != null)
break;
}