Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ public class KeRuntime {

static {

// although no guarantees can be made, let's try and shutdown gracefully and let
// others know.
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOG.warn("Graceful shutdown requested.");

// Perform cleanup tasks here
try {
getMessageDispatcher().stop();
} catch (Exception e) {
LOG.error("No error should occur when stopping the message dispatcher.", e);
}
}));

Config config = ConfigProvider.getConfig();
ConfigValue exposedUrl = config.getConfigValue(SmartConnectorConfig.CONF_KEY_KE_RUNTIME_EXPOSED_URL);
ConfigValue hostname = config.getConfigValue(SmartConnectorConfig.CONF_KEY_KE_RUNTIME_HOSTNAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public void stop() {
.header("Content-Type", "application/json").DELETE().build();

HttpResponse<String> response = this.httpClient.send(request, BodyHandlers.ofString());
if (response.statusCode() == 200) {
if (response.statusCode() == 204) {
LOG.trace("Successfully said goodbye to {}", this.remoteKerUri);
} else {
this.remoteKerDetails = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ private synchronized void queryKnowledgeDirectory() {
RemoteKerConnection messageSender = new RemoteKerConnection(messageDispatcher, knowledgeEngineRuntime);
remoteKerConnections.put(knowledgeEngineRuntime.getId(), messageSender);
messageSender.start();
messageSender.sendMyKerDetailsToPeer(messageDispatcher.getMyKnowledgeEngineRuntimeDetails());
}
}
// Check if there are KERs that need to be removed
Expand Down Expand Up @@ -151,6 +152,11 @@ private synchronized void queryKnowledgeDirectory() {

public void stop() {
this.scheduledScheduleFuture.cancel(false);

// let other KERs know we are stopping
for (RemoteKerConnection remoteKerConnection : this.remoteKerConnections.values()) {
remoteKerConnection.stop();
}
}

public RemoteKerConnection getRemoteKerConnection(URI toKnowledgeBase) {
Expand Down Expand Up @@ -203,6 +209,12 @@ public Response runtimedetailsKerIdDelete(String kerId, SecurityContext security
// That one didn't exist
return Response.status(404).build();
} else {
// make sure all SCs are notified correctly. We use fake/empty details for that.
KnowledgeEngineRuntimeDetails details = new KnowledgeEngineRuntimeDetails();
details.setRuntimeId(kerConnection.getRemoteKerUri().toString());
details.setSmartConnectorIds(new ArrayList<>());
kerConnection.updateKerDetails(details);

// Done!
return Response.status(204).build();
}
Expand Down