From 15c3513b877d4999e218cb32ac6fd68d86c3311b Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Mon, 17 Jul 2023 12:45:42 +0200 Subject: [PATCH 1/2] [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())); } From ed2a98eda8dd78db58d77731ead5b8f869f0f5e6 Mon Sep 17 00:00:00 2001 From: Alberto Fanjul Date: Thu, 22 Feb 2024 11:05:45 +0100 Subject: [PATCH 2/2] Detect repeated deployments from kie servers under load balancer All request will come from same url, and will not detect ongoing builds --- .../jbpm/workbench/ks/integration/KieServerIntegration.java | 5 +++++ 1 file changed, 5 insertions(+) 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 94a72897ba..19916cb598 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 @@ -248,6 +248,11 @@ public void onServerInstanceConnected(@Observes ServerInstanceConnected serverIn ServerInstanceKey serverInstanceKey = serverInstancesById.computeIfAbsent(serverInstance.getServerInstanceId(),s -> { logger.debug("Server {} connected!", serverInstance); + if (Boolean.parseBoolean(System.getProperty("org.kie.server.startup.detectOpenshiftLoadBalancer", "false"))) { + serverInstancesById.put(serverInstance.getServerInstanceId(), + serverInstance); + } + serverTemplatesClients.computeIfPresent(serverInstance.getServerTemplateId(), (serverTemplateId, clients) -> { clients.forEach((key, client) -> {