Commit 0d4f0b94 authored by Costin Grigoras's avatar Costin Grigoras
Browse files

Minor optimizations, again from SpotBugs

parent 482a9feb
......@@ -4,6 +4,7 @@ import java.io.IOException;
import java.io.Serializable;
import java.net.InetAddress;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;
......@@ -133,7 +134,10 @@ public abstract class Request implements Serializable, Runnable {
* @return certificate of the partner, set on receiving a request over the wire
*/
public final X509Certificate[] getPartnerCertificate() {
return partner_certificate;
if (partner_certificate == null)
return null;
return Arrays.copyOf(partner_certificate, partner_certificate.length);
}
/**
......@@ -181,15 +185,14 @@ public abstract class Request implements Serializable, Runnable {
// first the user
if (requester_uid != null)
if (requester_ruid != null) {
if (requester_ruid.getName() != null)
if (requester_uid.canBecome(requester_ruid.getName())) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "Successfully switched user from '" + requester_euid + "' to '" + requester_ruid + "'.");
if ((requester_ruid.getName() != null) && requester_uid.canBecome(requester_ruid.getName())) {
if (logger.isLoggable(Level.FINE))
logger.log(Level.FINE, "Successfully switched user from '" + requester_euid + "' to '" + requester_ruid + "'.");
requester_euid = requester_ruid;
requester_euid = requester_ruid;
return true;
}
return true;
}
}
else {
if (logger.isLoggable(Level.FINE))
......
......@@ -33,7 +33,8 @@ public class HTCONDOR extends BatchQueue {
private boolean use_job_router = false;
private boolean use_external_cloud = false;
private static final Pattern p = Pattern.compile("(\\d+)\\s*\\*\\s*(\\S+)");
private static final Pattern pJobNumbers = Pattern.compile("^\\s*([12]).*\\s(\\S+)");
private static final Pattern pLoadBalancer = Pattern.compile("(\\d+)\\s*\\*\\s*(\\S+)");
//
// 2020-06-24 - Maarten Litmaath, Maxim Storetvedt
......@@ -131,7 +132,7 @@ public class HTCONDOR extends BatchQueue {
for (final String str : val.split(",")) {
double w = 1;
String ce = str;
final Matcher m = p.matcher(str);
final Matcher m = pLoadBalancer.matcher(str);
if (m.find()) {
w = Double.parseDouble(m.group(1));
......@@ -361,7 +362,7 @@ public class HTCONDOR extends BatchQueue {
if (!use_job_router && ce_list.size() > 0) {
logger.info("Determining the next CE to use:");
for (final String element : ce_list) {
for (int i = 0; i < ce_list.size(); i++) {
final String ce = ce_list.get(next_ce);
final AtomicInteger idle = waiting.computeIfAbsent(ce, (r) -> new AtomicInteger(0));
final Double w = ce_weight.get(ce);
......@@ -511,7 +512,6 @@ public class HTCONDOR extends BatchQueue {
final ArrayList<String> job_list = executeCommand(cmd);
tot_running = tot_waiting = 0;
final Pattern p = Pattern.compile("^\\s*([12]).*\\s(\\S+)");
// in case the CE list has changed
running.clear();
......@@ -523,7 +523,7 @@ public class HTCONDOR extends BatchQueue {
}
for (final String line : job_list) {
final Matcher m = p.matcher(line);
final Matcher m = pJobNumbers.matcher(line);
if (m.matches()) {
final int job_status = Integer.parseInt(m.group(1));
......
......@@ -54,6 +54,7 @@ public class PFNData {
/**
* Set a map holding crawling data for a PFN analysed
*
* @param data
*/
private void setData(final Map<String, Object> data) {
......@@ -250,6 +251,7 @@ public class PFNData {
/**
* Convert from PFNData to JSONObject
*
* @return JSONObject
*/
@SuppressWarnings("unchecked")
......@@ -261,6 +263,7 @@ public class PFNData {
/**
* Convert from JSONObject to PFNData
*
* @param jsonObject
* @return PFNData
*/
......@@ -268,8 +271,8 @@ public class PFNData {
final PFNData pfnData = new PFNData();
final Map<String, Object> data = new LinkedHashMap<>();
for (final Object key : jsonObject.keySet()) {
data.put(key.toString(), jsonObject.get(key));
for (final Map.Entry<?, ?> entry : (Set<Map.Entry<?, ?>>) jsonObject.entrySet()) {
data.put(entry.getKey().toString(), entry.getValue());
}
pfnData.setData(data);
......
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