From 15c3513b877d4999e218cb32ac6fd68d86c3311b Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Mon, 17 Jul 2023 12:45:42 +0200 Subject: [PATCH] [JBPM-10184] Build templates optimization --- .../ks/integration/KieServerIntegration.java | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerIntegration.java b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerIntegration.java index d2df73c818..94a72897ba 100644 --- a/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerIntegration.java +++ b/jbpm-wb-kie-server/jbpm-wb-kie-server-backend/src/main/java/org/jbpm/workbench/ks/integration/KieServerIntegration.java @@ -245,26 +245,36 @@ public void onServerInstanceDisconnected(@Observes ServerInstanceDisconnected se public void onServerInstanceConnected(@Observes ServerInstanceConnected serverInstanceConnected) { ServerInstance serverInstance = serverInstanceConnected.getServerInstance(); - serverTemplatesClients.computeIfPresent(serverInstance.getServerTemplateId(), - (serverTemplateId, clients) -> { - clients.forEach((key, client) -> { - // update regular clients - updateOrBuildClient(client, - serverInstance); - - logger.debug("KieServerClient load balancer updated for server template {}", - serverTemplateId.equals(SERVER_TEMPLATE_KEY) ? serverInstance.getServerTemplateId() : serverTemplateId); - }); - return clients; - }); - - serverInstancesById.put(serverInstance.getServerInstanceId(), - serverInstance); + ServerInstanceKey serverInstanceKey = serverInstancesById.computeIfAbsent(serverInstance.getServerInstanceId(),s -> { + logger.debug("Server {} connected!", serverInstance); + + serverTemplatesClients.computeIfPresent(serverInstance.getServerTemplateId(), + (serverTemplateId, clients) -> { + clients.forEach((key, client) -> { + // update regular clients + updateOrBuildClient(client, + serverInstance); + + logger.debug("KieServerClient load balancer updated for server template {}", + serverTemplateId.equals(SERVER_TEMPLATE_KEY) ? serverInstance.getServerTemplateId() : serverTemplateId); + }); + return clients; + }); + + serverInstancesById.put(serverInstance.getServerInstanceId(), + serverInstance); + + KieServicesClient adminClient = adminClients.get(serverInstance.getServerTemplateId()); + // update admin clients + updateOrBuildClient(adminClient, + serverInstance); + return serverInstance; + }); + if (serverInstance != serverInstanceKey) { + // If Server is already connected do not proceed with Artifacts Build + logger.debug("Server {} already registered. Skipping build of containers", serverInstance); + } - KieServicesClient adminClient = adminClients.get(serverInstance.getServerTemplateId()); - // update admin clients - updateOrBuildClient(adminClient, - serverInstance); // once all steps are completed successfully notify other parts interested so the serverClient can actually be used serverInstanceRegisteredEvent.fire(new ServerInstanceRegistered(serverInstanceConnected.getServerInstance())); }