diff options
Diffstat (limited to 'feature-server-pool/src')
3 files changed, 43 insertions, 45 deletions
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/MainLoop.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/MainLoop.java index 4ae8b59b..ca5e86ac 100644 --- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/MainLoop.java +++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/MainLoop.java @@ -84,7 +84,9 @@ class MainLoop extends Thread { * @param work this is the Runnable to invoke */ public static void queueWork(Runnable work) { - incomingWork.offer(work); + if (!incomingWork.offer(work)) { + logger.info("incomingWork returned false"); + } } /** @@ -143,11 +145,7 @@ class MainLoop extends Thread { // work that runs every cycle for (Runnable work : backgroundWork) { - try { - work.run(); - } catch (Exception e) { - logger.error("Exception in MainLoop background work", e); - } + backgroundWorkRunnable(work); } } catch (Exception e) { logger.error("Exception in MainLoop", e); @@ -156,6 +154,17 @@ class MainLoop extends Thread { } /** + * Runnable try loop. + */ + static void backgroundWorkRunnable(Runnable work) { + try { + work.run(); + } catch (Exception e) { + logger.error("Exception in MainLoop background work", e); + } + } + + /** * Poll for and process incoming messages for up to 1 second. */ static void handleIncomingWork() { diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java index 634c15ec..d310805a 100644 --- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java +++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java @@ -59,8 +59,6 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Collection; @@ -239,14 +237,14 @@ public class Server implements Comparable<Server> { * This method may be invoked from any thread, and is used as the main * entry point when testing. * - * @param args arguments contaning an '=' character are intepreted as + * @param args arguments containing an '=' character are interpreted as * a property, other arguments are presumed to be a property file. */ public static void main(String[] args) throws IOException { Properties prop = new Properties(); for (String arg : args) { - // arguments with an '=' in them are a property definition; + // arguments with an equals sign in them are a property definition; // otherwise, they are a properties file name if (arg.contains("=")) { @@ -646,9 +644,7 @@ public class Server implements Comparable<Server> { // initialize the 'target' field target = getTarget(client); - } catch (KeyManagementException | NoSuchAlgorithmException - | NoSuchFieldException | IllegalAccessException - | ClassNotFoundException | HttpClientConfigException e) { + } catch (NoSuchFieldException | IllegalAccessException | HttpClientConfigException e) { logger.error("Server.newServer: problems creating 'client'", e); } } @@ -684,9 +680,7 @@ public class Server implements Comparable<Server> { // initialize the 'target' field target = getTarget(client); - } catch (KeyManagementException | NoSuchAlgorithmException - | NoSuchFieldException | IllegalAccessException - | ClassNotFoundException | HttpClientConfigException e) { + } catch (NoSuchFieldException | IllegalAccessException | HttpClientConfigException e) { logger.error("Server.checkServer: problems recreating 'client'", e); } } @@ -756,7 +750,7 @@ public class Server implements Comparable<Server> { } /** - * Fetch, and possibily calculate, the "notify list" associated with this + * Fetch, and possibly calculate, the "notify list" associated with this * server. This is the list of servers to forward a server and bucket * information to, and is approximately log2(n) in length, where 'n' is * the total number of servers. @@ -790,7 +784,7 @@ public class Server implements Comparable<Server> { siteSocketAddresses.add(thisSiteSocketAddress); // the list we are building - notifyList = new LinkedList<Server>(); + notifyList = new LinkedList<>(); int index = 1; for ( ; ; ) { @@ -869,8 +863,7 @@ public class Server implements Comparable<Server> { * @param destName the string name to use for the destination */ static HttpClient buildClient(String name, InetSocketAddress dest, String destName) - throws KeyManagementException, NoSuchAlgorithmException, - ClassNotFoundException, HttpClientConfigException { + throws HttpClientConfigException { return HttpClientFactoryInstance.getClientFactory().build( BusTopicParams.builder() @@ -1211,9 +1204,6 @@ public class Server implements Comparable<Server> { getTarget(httpClient).path("admin").request().post(entity); httpClient.shutdown(); httpClient = null; - } catch (KeyManagementException | NoSuchAlgorithmException e) { - out.println(host + ": Unable to create client connection"); - logger.error(PINGHOSTS_ERROR, e); } catch (NoSuchFieldException | IllegalAccessException e) { out.println(host + ": Unable to get link to target"); logger.error(PINGHOSTS_ERROR, e); diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/TargetLock.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/TargetLock.java index ef88abf2..1637e9ef 100644 --- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/TargetLock.java +++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/TargetLock.java @@ -131,13 +131,13 @@ public class TargetLock implements Lock, Serializable { // this is used to notify the application when a lock is available, // or if it is not available - private volatile LockCallback owner; + private final LockCallback owner; // This is what is actually called by the infrastructure to do the owner // notification. The owner may be running in a Drools session, in which case // the actual notification should be done within that thread -- the 'context' // object ensures that it happens this way. - private volatile LockCallback context; + private final LockCallback context; // HTTP query parameters private static final String QP_KEY = "key"; @@ -150,6 +150,11 @@ public class TargetLock implements Lock, Serializable { // define a constant for empty of byte array private static final byte[] EMPTY_BYTE_ARRAY = {}; + // below are for duplicating string in printout or logger + private static final String PRINTOUT_DASHES = "---------"; + private static final String LOCK_AUDIT = "lock/audit"; + private static final String TARGETLOCK_AUDIT_SEND = "TargetLock.Audit.send: "; + /** * This method triggers registration of 'eventHandler', and also extracts * property values. @@ -1783,9 +1788,9 @@ public class TargetLock implements Lock, Serializable { out.printf(format, "Key", "Bucket", "Host UUID", "Owner Key", "Bucket", "Host UUID", "Lock UUID", "State", "Comments"); - out.printf(format, "---", "------", "---------", - "---------", "------", "---------", - "---------", "-----", "--------"); + out.printf(format, "---", "------", PRINTOUT_DASHES, + PRINTOUT_DASHES, "------", PRINTOUT_DASHES, + PRINTOUT_DASHES, "-----", "--------"); } else { // generate format based upon the maximum key length, maximum // owner key length, and whether comments are included anywhere @@ -1794,7 +1799,7 @@ public class TargetLock implements Lock, Serializable { // dump out the header out.printf(format, "Key", "Owner Key", "UUID", "State", "Comments"); - out.printf(format, "---", "---------", "----", "-----", "--------"); + out.printf(format, "---", PRINTOUT_DASHES, "----", "-----", "--------"); } dumpServerTable(out); @@ -2170,9 +2175,6 @@ public class TargetLock implements Lock, Serializable { static class AuditData implements Serializable { private static final long serialVersionUID = 1L; - // sending UUID - private UUID hostUuid; - // client records that currently exist, or records to be cleared // (depending upon message) -- client/server is from the senders side private List<Identity> clientData; @@ -2186,7 +2188,6 @@ public class TargetLock implements Lock, Serializable { * empty lists. */ AuditData() { - hostUuid = Server.getThisServer().getUuid(); clientData = new ArrayList<>(); serverData = new ArrayList<>(); } @@ -2530,9 +2531,9 @@ public class TargetLock implements Lock, Serializable { if (ttl > 0) { Server server = Server.getServer(serverUuid); if (server != null) { - WebTarget webTarget = server.getWebTarget("lock/audit"); + WebTarget webTarget = server.getWebTarget(LOCK_AUDIT); if (webTarget != null) { - logger.info("Forwarding 'lock/audit' to uuid {}", + logger.info("Forwarding {} to uuid {}", LOCK_AUDIT, serverUuid); Entity<String> entity = Entity.entity(new String(encodedData), @@ -2547,7 +2548,8 @@ public class TargetLock implements Lock, Serializable { // if we reach this point, we didn't forward for some reason - logger.error("Couldn't forward 'lock/audit to uuid {}", serverUuid); + logger.error("Couldn't forward {} to uuid {}", LOCK_AUDIT, + serverUuid); return EMPTY_BYTE_ARRAY; } @@ -2675,8 +2677,7 @@ public class TargetLock implements Lock, Serializable { if (respData.clientData.isEmpty() && respData.serverData.isEmpty()) { // no mismatches - logger.info("TargetLock.Audit.send: " - + "no errors from self ({})", server); + logger.info("{} no errors from self ({})", TARGETLOCK_AUDIT_SEND, server); return; } @@ -2687,7 +2688,7 @@ public class TargetLock implements Lock, Serializable { if (AuditPostResponse.responseSupport( respData, "self (" + server + ")", "TargetLock.Audit.send")) { - // a return falue of 'true' either indicates the + // a return value of 'true' either indicates the // mismatches were resolved after a retry, or we // received an interrupt, and need to abort return; @@ -2711,7 +2712,7 @@ public class TargetLock implements Lock, Serializable { Entity.entity(new String(encodedData), MediaType.APPLICATION_OCTET_STREAM_TYPE); - server.post("lock/audit", entity, new AuditPostResponse(server)); + server.post(LOCK_AUDIT, entity, new AuditPostResponse(server)); } } @@ -2736,9 +2737,8 @@ public class TargetLock implements Lock, Serializable { AuditData respData = AuditData.decode(response.readEntity(byte[].class)); if (respData == null) { - logger.error("TargetLock.Audit.send: " - + "couldn't process response from {}", - server); + logger.error("{} couldn't process response from {}", + TARGETLOCK_AUDIT_SEND, server); return; } @@ -2746,8 +2746,7 @@ public class TargetLock implements Lock, Serializable { if (respData.clientData.isEmpty() && respData.serverData.isEmpty()) { // no mismatches - logger.info("TargetLock.Audit.send: " - + "no errors from {}", server); + logger.info("{} no errors from {}", TARGETLOCK_AUDIT_SEND, server); return; } |