aboutsummaryrefslogtreecommitdiffstats
path: root/feature-server-pool
diff options
context:
space:
mode:
Diffstat (limited to 'feature-server-pool')
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java4
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Leader.java31
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Server.java17
-rw-r--r--feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/TargetLock.java44
4 files changed, 56 insertions, 40 deletions
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
index 87229fb8..c3b2ac82 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Bucket.java
@@ -602,7 +602,7 @@ public class Bucket {
* the selected bucket is associated with this particular server --
* no forwarding is needed.
*/
- out.format("Bucket is %d, which is owned by this server: %s\n",
+ out.format("Bucket is %d, which is owned by this server: %s%n",
bucketNumber, server.getUuid());
} else {
/*
@@ -656,7 +656,7 @@ public class Bucket {
if (response == null) {
out.println("Timed out waiting for a response");
} else {
- out.format("Received response code %s\nEntity = %s%n",
+ out.format("Received response code %s%nEntity = %s%n",
response.getStatus(), response.readEntity(String.class));
}
} catch (InterruptedException e) {
diff --git a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Leader.java b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Leader.java
index cf535b43..96b6598b 100644
--- a/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Leader.java
+++ b/feature-server-pool/src/main/java/org/onap/policy/drools/serverpool/Leader.java
@@ -40,6 +40,7 @@ import java.util.TreeSet;
import java.util.UUID;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
+import lombok.EqualsAndHashCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,7 +64,7 @@ class Leader {
}
// Server currently in the leader roll
- private static Server leader = null;
+ private static Server leaderLocal = null;
// Vote state machine -- it is null, unless a vote is in progress
private static VoteCycle voteCycle = null;
@@ -118,7 +119,7 @@ class Leader {
* @return the current leader ('null' if none has been selected)
*/
public static Server getLeader() {
- return leader;
+ return leaderLocal;
}
/**
@@ -168,10 +169,10 @@ class Leader {
*/
@Override
public void serverFailed(Server server) {
- if (server == leader) {
+ if (server == leaderLocal) {
// the lead server has failed --
// start/restart the VoteCycle state machine
- leader = null;
+ leaderLocal = null;
startVoting();
// send out a notification that the lead server has failed
@@ -223,7 +224,7 @@ class Leader {
* start the 'Discovery' thread.
*/
VoteCycle() {
- if (leader == null || leader == Server.getThisServer()) {
+ if (leaderLocal == null || leaderLocal == Server.getThisServer()) {
Discovery.startDiscovery();
}
}
@@ -294,20 +295,20 @@ class Leader {
// 5 second grace period has passed -- the leader is one with
// the most votes, which is the first entry in 'voteData'
- Server oldLeader = leader;
- leader = Server.getServer(voteData.first().uuid);
- if (leader != oldLeader) {
+ Server oldLeader = leaderLocal;
+ leaderLocal = Server.getServer(voteData.first().uuid);
+ if (leaderLocal != oldLeader) {
// the leader has changed -- send out notifications
for (Events listener : Events.getListeners()) {
- listener.newLeader(leader);
+ listener.newLeader(leaderLocal);
}
} else {
// the election is over, and the leader has been confirmed
for (Events listener : Events.getListeners()) {
- listener.leaderConfirmed(leader);
+ listener.leaderConfirmed(leaderLocal);
}
}
- if (leader == Server.getThisServer()) {
+ if (leaderLocal == Server.getThisServer()) {
// this is the lead server --
// make sure the 'Discovery' threads are running
Discovery.startDiscovery();
@@ -347,8 +348,7 @@ class Leader {
}
}
}
-
- logger.info(bos.toString());
+ logger.info("Output - {}", bos);
}
/**
@@ -495,9 +495,9 @@ class Leader {
if (uuidToVoterData.size() * 2 < Server.getServerCount()) {
// fewer than half of the nodes have voted
- if (leader != null) {
+ if (leaderLocal != null) {
// choose the current leader
- myVote = leader.getUuid();
+ myVote = leaderLocal.getUuid();
} else {
// choose the first entry in the servers list
myVote = Server.getFirstServer().getUuid();
@@ -525,6 +525,7 @@ class Leader {
* This class corresponds to a single vote recipient --
* the Server being voted for.
*/
+ @EqualsAndHashCode
private static class VoteData implements Comparable<VoteData> {
// uuid voted for
private UUID uuid;
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 511b79a7..c60683ef 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
@@ -215,6 +215,23 @@ public class Server implements Comparable<Server> {
return Util.uuidComparator.compare(uuid, other.uuid);
}
+ @Override
+ public int hashCode() {
+ return Objects.hash(uuid);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof Server)) {
+ return false;
+ }
+ Server other = (Server) obj;
+ return Objects.equals(uuid, other.uuid);
+ }
+
/**
* This method may be invoked from any thread, and is used as the main
* entry point when testing.
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 c7de4c43..66ac58da 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
@@ -981,9 +981,8 @@ public class TargetLock implements Lock, Serializable {
public void lockAvailable(final Lock lock) {
// Run 'owner.lockAvailable' within the Drools session
if (policySession != null) {
- DroolsRunnable callback = () -> {
+ DroolsRunnable callback = () ->
((TargetLock) lock).owner.lockAvailable(lock);
- };
policySession.getKieSession().insert(callback);
}
}
@@ -995,9 +994,8 @@ public class TargetLock implements Lock, Serializable {
public void lockUnavailable(Lock lock) {
// Run 'owner.unlockAvailable' within the Drools session
if (policySession != null) {
- DroolsRunnable callback = () -> {
+ DroolsRunnable callback = () ->
((TargetLock) lock).owner.lockUnavailable(lock);
- };
policySession.getKieSession().insert(callback);
}
}
@@ -1612,12 +1610,12 @@ public class TargetLock implements Lock, Serializable {
// process the client-end data
for (ClientData clientData : hostData.clientDataList) {
- populateLockData_clientData(clientData, server);
+ populateLockDataClientData(clientData, server);
}
// process the server-end data
for (ServerData serverData : hostData.serverDataList) {
- populateLockData_serverData(serverData, server);
+ populateLockDataServerData(serverData, server);
}
} else {
logger.error("TargetLock.DumpLocks.populateLockData: "
@@ -1626,7 +1624,7 @@ public class TargetLock implements Lock, Serializable {
}
}
- private void populateLockData_clientData(ClientData clientData, Server server) {
+ private void populateLockDataClientData(ClientData clientData, Server server) {
// 'true' if the bucket associated with this 'ClientData'
// doesn't belong to the remote server, as far as we can tell
boolean serverMismatch =
@@ -1665,7 +1663,7 @@ public class TargetLock implements Lock, Serializable {
}
}
- private void populateLockData_serverData(ServerData serverData, Server server) {
+ private void populateLockDataServerData(ServerData serverData, Server server) {
// 'true' if the bucket associated with this 'ServerData'
// doesn't belong to the remote server, as far as we can tell
boolean serverMismatch =
@@ -1713,13 +1711,13 @@ public class TargetLock implements Lock, Serializable {
// we need 'MergeData' entries for all waiting requests
for (Waiting waiting : le.waitingList) {
- populateLockData_serverData_waiting(
+ populateLockDataServerDataWaiting(
serverData, server, serverMismatch, le, waiting);
}
}
}
- private void populateLockData_serverData_waiting(
+ private void populateLockDataServerDataWaiting(
ServerData serverData, Server server, boolean serverMismatch,
LockEntry le, Waiting waiting) {
@@ -1808,11 +1806,11 @@ public class TargetLock implements Lock, Serializable {
out.printf(format, "---", "---------", "----", "-----", "--------");
}
- dump_serverTable(out);
- dump_clientOnlyEntries(out);
+ dumpServerTable(out);
+ dumpClientOnlyEntries(out);
}
- private void dump_serverTable(PrintStream out) {
+ private void dumpServerTable(PrintStream out) {
// iterate over the server table
for (LockEntry le : lockEntries.values()) {
// fetch merged data
@@ -1855,7 +1853,7 @@ public class TargetLock implements Lock, Serializable {
}
}
- private void dump_clientOnlyEntries(PrintStream out) {
+ private void dumpClientOnlyEntries(PrintStream out) {
// client records that don't have matching server entries
for (MergedData md : clientOnlyEntries.values()) {
ClientDataRecord cdr = md.clientDataRecord;
@@ -1981,7 +1979,7 @@ public class TargetLock implements Lock, Serializable {
Waiting serverWaiting = null;
// detected problems, such as server/client mismatches
- Queue<String> comments = new LinkedList<String>();
+ Queue<String> comments = new LinkedList<>();
/**
* Constructor - initialize the 'uuid'.
@@ -2050,8 +2048,8 @@ public class TargetLock implements Lock, Serializable {
hostUuid = Server.getThisServer().getUuid();
// initial storage for client and server data
- clientDataList = new ArrayList<ClientData>();
- serverDataList = new ArrayList<ServerData>();
+ clientDataList = new ArrayList<>();
+ serverDataList = new ArrayList<>();
// go through buckets
for (int i = 0; i < Bucket.BUCKETCOUNT; i += 1) {
@@ -2215,15 +2213,15 @@ public class TargetLock implements Lock, Serializable {
AuditData response = new AuditData();
// compare remote servers client data with our server data
- generateResponse_clientEnd(response, includeWarnings);
+ generateResponseClientEnd(response, includeWarnings);
// test server data
- generateResponse_serverEnd(response, includeWarnings);
+ generateResponseServerEnd(response, includeWarnings);
return response;
}
- private void generateResponse_clientEnd(AuditData response, boolean includeWarnings) {
+ private void generateResponseClientEnd(AuditData response, boolean includeWarnings) {
for (Identity identity : clientData) {
// remote end is the client, and we are the server
Bucket bucket = Bucket.getBucket(identity.key);
@@ -2275,7 +2273,7 @@ public class TargetLock implements Lock, Serializable {
}
}
- private void generateResponse_serverEnd(AuditData response, boolean includeWarnings) {
+ private void generateResponseServerEnd(AuditData response, boolean includeWarnings) {
for (Identity identity : serverData) {
// remote end is the server, and we are the client
Bucket bucket = Bucket.getBucket(identity.ownerKey);
@@ -2674,11 +2672,11 @@ public class TargetLock implements Lock, Serializable {
}
for (final Server server : auditMap.keySet()) {
- send_server(server);
+ sendServer(server);
}
}
- private void send_server(final Server server) {
+ private void sendServer(final Server server) {
// fetch audit data
AuditData auditData = auditMap.get(server);