mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-11 06:40:53 +00:00
a) Bulk of changes related to UI - making the replication tab a better
world :-) b) Added unique identifier for each replica. This now allows to have multiple replicas per physical host. It also make deregistration deterministic.
This commit is contained in:
1 parent
059887e180
commit
f9ac08032c
19 files changed
+203
-54
No files matched your search
+3
-2
@@ -3,6 +3,7 @@ package com.sap.sailing.server.replication;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.rabbitmq.client.QueueingConsumer;
|
||||
|
||||
@@ -14,9 +15,9 @@ import com.rabbitmq.client.QueueingConsumer;
|
||||
*/
|
||||
public interface ReplicationMasterDescriptor {
|
||||
|
||||
URL getReplicationRegistrationRequestURL() throws MalformedURLException;
|
||||
URL getReplicationRegistrationRequestURL(UUID uuid, String additionalInformation) throws MalformedURLException;
|
||||
|
||||
URL getReplicationDeRegistrationRequestURL() throws MalformedURLException;
|
||||
URL getReplicationDeRegistrationRequestURL(UUID uuid) throws MalformedURLException;
|
||||
|
||||
URL getInitialLoadURL() throws MalformedURLException;
|
||||
|
||||
|
||||
+13
@@ -2,6 +2,7 @@ package com.sap.sailing.server.replication;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
import com.sap.sailing.server.replication.impl.ReplicaDescriptor;
|
||||
@@ -49,4 +50,16 @@ public interface ReplicationService {
|
||||
* @throws IOException
|
||||
*/
|
||||
void stopToReplicateFromMaster() throws IOException;
|
||||
|
||||
/**
|
||||
* Stops all replica currently registered with this server.
|
||||
* @throws IOException
|
||||
*/
|
||||
void stopAllReplica() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns an unique server identifier
|
||||
* @return
|
||||
*/
|
||||
UUID getServerIdentifier();
|
||||
}
|
||||
+8
-4
@@ -18,18 +18,18 @@ public class ReplicaDescriptor implements Serializable {
|
||||
private static final long serialVersionUID = -5451556877949921454L;
|
||||
|
||||
private final UUID uuid;
|
||||
|
||||
private final InetAddress ipAddress;
|
||||
|
||||
private final TimePoint registrationTime;
|
||||
private final String additionalInformation;
|
||||
|
||||
/**
|
||||
* Sets the registration time to now.
|
||||
*/
|
||||
public ReplicaDescriptor(InetAddress ipAddress) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
public ReplicaDescriptor(InetAddress ipAddress, UUID serverUuid, String additionalInformation) {
|
||||
this.uuid = serverUuid;
|
||||
this.registrationTime = MillisecondsTimePoint.now();
|
||||
this.ipAddress = ipAddress;
|
||||
this.additionalInformation = additionalInformation;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@@ -43,6 +43,10 @@ public class ReplicaDescriptor implements Serializable {
|
||||
public TimePoint getRegistrationTime() {
|
||||
return registrationTime;
|
||||
}
|
||||
|
||||
public String getAdditionalInformation() {
|
||||
return additionalInformation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
+5
@@ -85,4 +85,9 @@ public class ReplicationInstancesManager {
|
||||
public Map<Class<? extends RacingEventServiceOperation<?>>, Integer> getStatistics(ReplicaDescriptor replica) {
|
||||
return replicationCounts.get(replica);
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
replicationCounts.clear();
|
||||
replicaDescriptors.clear();
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -3,12 +3,14 @@ package com.sap.sailing.server.replication.impl;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import com.rabbitmq.client.QueueingConsumer;
|
||||
import com.sap.sailing.server.replication.ReplicationMasterDescriptor;
|
||||
import com.sap.sailing.util.BuildVersion;
|
||||
|
||||
public class ReplicationMasterDescriptorImpl implements ReplicationMasterDescriptor {
|
||||
private static final String REPLICATION_SERVLET = "/replication/replication";
|
||||
@@ -28,15 +30,18 @@ public class ReplicationMasterDescriptorImpl implements ReplicationMasterDescrip
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getReplicationRegistrationRequestURL() throws MalformedURLException {
|
||||
public URL getReplicationRegistrationRequestURL(UUID uuid, String additional) throws MalformedURLException {
|
||||
return new URL("http", hostname, servletPort, REPLICATION_SERVLET + "?" + ReplicationServlet.ACTION + "="
|
||||
+ ReplicationServlet.Action.REGISTER.name());
|
||||
+ ReplicationServlet.Action.REGISTER.name()
|
||||
+ "&" + ReplicationServlet.SERVER_UUID + "=" + uuid.toString()
|
||||
+ "&" + ReplicationServlet.ADDITIONAL_INFORMATION + "=" + BuildVersion.getBuildVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getReplicationDeRegistrationRequestURL() throws MalformedURLException {
|
||||
public URL getReplicationDeRegistrationRequestURL(UUID uuid) throws MalformedURLException {
|
||||
return new URL("http", hostname, servletPort, REPLICATION_SERVLET + "?" + ReplicationServlet.ACTION + "="
|
||||
+ ReplicationServlet.Action.DEREGISTER.name());
|
||||
+ ReplicationServlet.Action.DEREGISTER.name()
|
||||
+ "&" + ReplicationServlet.SERVER_UUID + "=" + uuid.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,5 +90,5 @@ public class ReplicationMasterDescriptorImpl implements ReplicationMasterDescrip
|
||||
public String getExchangeName() {
|
||||
return exchangeName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+31
-2
@@ -10,6 +10,7 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.osgi.util.tracker.ServiceTracker;
|
||||
@@ -23,6 +24,7 @@ import com.sap.sailing.server.RacingEventService;
|
||||
import com.sap.sailing.server.RacingEventServiceOperation;
|
||||
import com.sap.sailing.server.replication.ReplicationMasterDescriptor;
|
||||
import com.sap.sailing.server.replication.ReplicationService;
|
||||
import com.sap.sailing.util.BuildVersion;
|
||||
|
||||
/**
|
||||
* Can observe a {@link RacingEventService} for the operations it performs that require replication. Only observes as
|
||||
@@ -69,6 +71,11 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
*/
|
||||
private final String exchangeName;
|
||||
|
||||
/**
|
||||
* UUID that identifies this server
|
||||
*/
|
||||
private final UUID serverUUID;
|
||||
|
||||
private Replicator replicator;
|
||||
private Thread replicatorThread;
|
||||
|
||||
@@ -81,6 +88,7 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
localService = null;
|
||||
this.exchangeName = exchangeName;
|
||||
replicator = null;
|
||||
serverUUID = UUID.randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,6 +103,7 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
this.localService = localService;
|
||||
this.exchangeName = exchangeName;
|
||||
replicator = null;
|
||||
serverUUID = UUID.randomUUID();
|
||||
}
|
||||
|
||||
private Channel createMasterChannel(String exchangeName) throws IOException {
|
||||
@@ -220,7 +229,7 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
* @return the UUID that the master generated for this client which is also entered into {@link #replicaUUIDs}
|
||||
*/
|
||||
private String registerReplicaWithMaster(ReplicationMasterDescriptor master) throws IOException, ClassNotFoundException {
|
||||
URL replicationRegistrationRequestURL = master.getReplicationRegistrationRequestURL();
|
||||
URL replicationRegistrationRequestURL = master.getReplicationRegistrationRequestURL(getServerIdentifier(), BuildVersion.getBuildVersion());
|
||||
final URLConnection registrationRequestConnection = replicationRegistrationRequestURL.openConnection();
|
||||
registrationRequestConnection.connect();
|
||||
InputStream content = (InputStream) registrationRequestConnection.getContent();
|
||||
@@ -238,7 +247,7 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
|
||||
protected void deregisterReplicaWithMaster(ReplicationMasterDescriptor master) {
|
||||
try {
|
||||
URL replicationDeRegistrationRequestURL = master.getReplicationDeRegistrationRequestURL();
|
||||
URL replicationDeRegistrationRequestURL = master.getReplicationDeRegistrationRequestURL(getServerIdentifier());
|
||||
final URLConnection deregistrationRequestConnection = replicationDeRegistrationRequestURL.openConnection();
|
||||
deregistrationRequestConnection.connect();
|
||||
StringBuilder uuid = new StringBuilder();
|
||||
@@ -293,4 +302,24 @@ public class ReplicationServiceImpl implements ReplicationService, OperationExec
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAllReplica() throws IOException {
|
||||
if (replicationInstancesManager.hasReplicas()) {
|
||||
replicationInstancesManager.removeAll();
|
||||
removeAsListenerFromRacingEventService();
|
||||
synchronized (this) {
|
||||
if (masterChannel != null) {
|
||||
masterChannel.close();
|
||||
masterChannel = null;
|
||||
}
|
||||
}
|
||||
logger.info("Unregistered all replicas from this server!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getServerIdentifier() {
|
||||
return serverUUID;
|
||||
}
|
||||
|
||||
}
|
||||
+7
-2
@@ -5,6 +5,7 @@ import java.io.ObjectOutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -34,6 +35,8 @@ public class ReplicationServlet extends SailingServerHttpServlet {
|
||||
public enum Action { REGISTER, INITIAL_LOAD, DEREGISTER }
|
||||
|
||||
public static final String ACTION = "action";
|
||||
public static final String SERVER_UUID = "uuid";
|
||||
public static final String ADDITIONAL_INFORMATION = "additional";
|
||||
|
||||
private ServiceTracker<ReplicationService, ReplicationService> replicationServiceTracker;
|
||||
|
||||
@@ -98,8 +101,10 @@ public class ReplicationServlet extends SailingServerHttpServlet {
|
||||
}
|
||||
|
||||
private ReplicaDescriptor getReplicaDescriptor(HttpServletRequest req) throws UnknownHostException {
|
||||
// XXX: this can lead to problems if there are multiple replicas on one server
|
||||
InetAddress ipAddress = InetAddress.getByName(req.getRemoteAddr());
|
||||
return new ReplicaDescriptor(ipAddress);
|
||||
UUID uuid = UUID.fromString(req.getParameter(SERVER_UUID));
|
||||
String additional = req.getParameter(ADDITIONAL_INFORMATION);
|
||||
logger.info("Registered new replica " + ipAddress + " " + uuid.toString() + " " + additional);
|
||||
return new ReplicaDescriptor(ipAddress, uuid, additional);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user