Skip to content

Commit 3f995e4

Browse files
jayblancsergehuber
andauthored
UNOMI-877: Replace Karaf Cellar and Hazelcast with PersistenceService for cluster synchronization (#723)
* UNOMI-877: Replace Karaf Cellar and Hazelcast with PersistenceService for cluster synchronization (code isolated from branch unomi-3-dev made by Serge Hubert) * UNOMI-877: Not sending event to cluster anymore. --------- Co-authored-by: Serge Huber <[email protected]>
1 parent f5223b8 commit 3f995e4

File tree

8 files changed

+575
-236
lines changed

8 files changed

+575
-236
lines changed

api/src/main/java/org/apache/unomi/api/ClusterNode.java

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,31 @@
2222
/**
2323
* Information about a cluster node.
2424
*/
25-
public class ClusterNode implements Serializable {
25+
public class ClusterNode extends Item {
2626

2727
private static final long serialVersionUID = 1281422346318230514L;
2828

29+
public static final String ITEM_TYPE = "clusterNode";
30+
2931
private double cpuLoad;
3032
private double[] loadAverage;
3133
private String publicHostAddress;
3234
private String internalHostAddress;
3335
private long uptime;
3436
private boolean master;
3537
private boolean data;
38+
private long startTime;
39+
private long lastHeartbeat;
40+
41+
// Server information
42+
private ServerInfo serverInfo;
3643

3744
/**
3845
* Instantiates a new Cluster node.
3946
*/
4047
public ClusterNode() {
48+
super();
49+
setItemType(ITEM_TYPE);
4150
}
4251

4352
/**
@@ -165,4 +174,58 @@ public boolean isData() {
165174
public void setData(boolean data) {
166175
this.data = data;
167176
}
177+
178+
/**
179+
* Retrieves the node start time in milliseconds.
180+
*
181+
* @return the start time
182+
*/
183+
public long getStartTime() {
184+
return startTime;
185+
}
186+
187+
/**
188+
* Sets the node start time in milliseconds.
189+
*
190+
* @param startTime the start time
191+
*/
192+
public void setStartTime(long startTime) {
193+
this.startTime = startTime;
194+
}
195+
196+
/**
197+
* Retrieves the last heartbeat time in milliseconds.
198+
*
199+
* @return the last heartbeat time
200+
*/
201+
public long getLastHeartbeat() {
202+
return lastHeartbeat;
203+
}
204+
205+
/**
206+
* Sets the last heartbeat time in milliseconds.
207+
*
208+
* @param lastHeartbeat the last heartbeat time
209+
*/
210+
public void setLastHeartbeat(long lastHeartbeat) {
211+
this.lastHeartbeat = lastHeartbeat;
212+
}
213+
214+
/**
215+
* Gets the server information.
216+
*
217+
* @return the server information
218+
*/
219+
public ServerInfo getServerInfo() {
220+
return serverInfo;
221+
}
222+
223+
/**
224+
* Sets the server information.
225+
*
226+
* @param serverInfo the server information
227+
*/
228+
public void setServerInfo(ServerInfo serverInfo) {
229+
this.serverInfo = serverInfo;
230+
}
168231
}

api/src/main/java/org/apache/unomi/api/services/ClusterService.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,4 @@ public interface ClusterService {
5151
*/
5252
void purge(final String scope);
5353

54-
/**
55-
* This function will send an event to the nodes of the cluster
56-
* The function takes a Serializable to avoid dependency on any clustering framework
57-
*
58-
* @param event this object will be cast to a org.apache.karaf.cellar.core.event.Event object
59-
*/
60-
void sendEvent(Serializable event);
6154
}

extensions/router/router-core/src/main/java/org/apache/unomi/router/core/context/RouterCamelContext.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.apache.unomi.router.api.RouterConstants;
3232
import org.apache.unomi.router.api.services.ImportExportConfigurationService;
3333
import org.apache.unomi.router.api.services.ProfileExportService;
34-
import org.apache.unomi.router.core.event.UpdateCamelRouteEvent;
3534
import org.apache.unomi.router.core.processor.ExportRouteCompletionProcessor;
3635
import org.apache.unomi.router.core.processor.ImportConfigByFileNameProcessor;
3736
import org.apache.unomi.router.core.processor.ImportRouteCompletionProcessor;
@@ -240,12 +239,6 @@ public void killExistingRoute(String routeId, boolean fireEvent) throws Exceptio
240239
camelContext.removeRouteDefinition(routeDefinition);
241240
}
242241
}
243-
244-
if (fireEvent) {
245-
UpdateCamelRouteEvent event = new UpdateCamelRouteEvent(EVENT_ID_REMOVE);
246-
event.setRouteId(routeId);
247-
clusterService.sendEvent(event);
248-
}
249242
}
250243

251244
public void updateProfileImportReaderRoute(String configId, boolean fireEvent) throws Exception {
@@ -266,11 +259,6 @@ public void updateProfileImportReaderRoute(String configId, boolean fireEvent) t
266259
builder.setJacksonDataFormat(jacksonDataFormat);
267260
builder.setContext(camelContext);
268261
camelContext.addRoutes(builder);
269-
270-
if (fireEvent) {
271-
UpdateCamelRouteEvent event = new UpdateCamelRouteEvent(EVENT_ID_IMPORT);
272-
clusterService.sendEvent(event);
273-
}
274262
}
275263
}
276264

@@ -291,11 +279,6 @@ public void updateProfileExportReaderRoute(String configId, boolean fireEvent) t
291279
profileExportCollectRouteBuilder.setJacksonDataFormat(jacksonDataFormat);
292280
profileExportCollectRouteBuilder.setContext(camelContext);
293281
camelContext.addRoutes(profileExportCollectRouteBuilder);
294-
295-
if (fireEvent) {
296-
UpdateCamelRouteEvent event = new UpdateCamelRouteEvent(EVENT_ID_EXPORT);
297-
clusterService.sendEvent(event);
298-
}
299282
}
300283
}
301284

package/src/main/resources/etc/custom.system.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,14 @@ org.apache.unomi.admin.servlet.context=${env:UNOMI_ADMIN_CONTEXT:-/cxs}
8181
#######################################################################################################################
8282
## Cluster Settings ##
8383
#######################################################################################################################
84-
org.apache.unomi.cluster.group=${env:UNOMI_CLUSTER_GROUP:-default}
8584
# To simplify testing we set the public address to use HTTP, but for production environments it is highly recommended
8685
# to switch to using HTTPS with a proper SSL certificate installed.
8786
org.apache.unomi.cluster.public.address=${env:UNOMI_CLUSTER_PUBLIC_ADDRESS:-http://localhost:8181}
8887
org.apache.unomi.cluster.internal.address=${env:UNOMI_CLUSTER_INTERNAL_ADDRESS:-https://localhost:9443}
88+
# The nodeId is a required setting that uniquely identifies this node in the cluster.
89+
# It must be set to a unique value for each node in the cluster.
90+
# Example: nodeId=node1
91+
org.apache.unomi.cluster.nodeId=${env:UNOMI_CLUSTER_NODEID:-unomi-node-1}
8992
# The nodeStatisticsUpdateFrequency controls the frequency of the update of system statistics such as CPU load,
9093
# system load average and uptime. This value is set in milliseconds and is set to 10 seconds by default. Each node
9194
# will retrieve the local values and broadcast them through a cluster event to all the other nodes to update

services/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
<version>${project.version}</version>
5757
<scope>provided</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>org.apache.unomi</groupId>
61+
<artifactId>unomi-lifecycle-watcher</artifactId>
62+
<version>${project.version}</version>
63+
<scope>provided</scope>
64+
</dependency>
5965

6066
<dependency>
6167
<groupId>javax.servlet</groupId>
@@ -175,6 +181,7 @@
175181
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
176182
<Import-Package>
177183
sun.misc;resolution:=optional,
184+
com.sun.management;resolution:=optional,
178185
*
179186
</Import-Package>
180187
</instructions>

0 commit comments

Comments
 (0)