diff --git a/server/src/main/java/com/thoughtworks/go/server/messaging/elasticagents/ServerPingMessage.java b/server/src/main/java/com/thoughtworks/go/server/messaging/elasticagents/ServerPingMessage.java index 52454668843..bd285e73dc5 100644 --- a/server/src/main/java/com/thoughtworks/go/server/messaging/elasticagents/ServerPingMessage.java +++ b/server/src/main/java/com/thoughtworks/go/server/messaging/elasticagents/ServerPingMessage.java @@ -16,7 +16,7 @@ package com.thoughtworks.go.server.messaging.elasticagents; -import com.thoughtworks.go.config.elastic.ClusterProfiles; +import com.thoughtworks.go.config.elastic.ClusterProfile; import com.thoughtworks.go.server.messaging.PluginAwareMessage; import java.util.List; @@ -26,9 +26,9 @@ public class ServerPingMessage implements PluginAwareMessage { private final String pluginId; - private ClusterProfiles clusterProfiles; + private List clusterProfiles; - public ServerPingMessage(String pluginId, ClusterProfiles clusterProfiles) { + public ServerPingMessage(String pluginId, List clusterProfiles) { this.pluginId = pluginId; this.clusterProfiles = clusterProfiles; } @@ -54,4 +54,12 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(pluginId, clusterProfiles); } + + @Override + public String toString() { + return "ServerPingMessage{" + + "pluginId='" + pluginId + '\'' + + ", clusterProfiles=" + clusterProfiles + + '}'; + } } diff --git a/server/src/main/java/com/thoughtworks/go/server/service/ElasticAgentPluginService.java b/server/src/main/java/com/thoughtworks/go/server/service/ElasticAgentPluginService.java index 26027fcc109..67acfd6999f 100644 --- a/server/src/main/java/com/thoughtworks/go/server/service/ElasticAgentPluginService.java +++ b/server/src/main/java/com/thoughtworks/go/server/service/ElasticAgentPluginService.java @@ -120,7 +120,7 @@ public void heartbeat() { long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L; for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) { - ClusterProfiles clusterProfiles = (ClusterProfiles) clusterProfilesService.getPluginProfiles(); + List clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(descriptor.id()); serverPingQueue.post(new ServerPingMessage(descriptor.id(), clusterProfiles), pingMessageTimeToLive); elasticAgentsOfMissingPlugins.remove(descriptor.id()); serverHealthService.removeByScope(scope(descriptor.id())); diff --git a/server/src/test-fast/java/com/thoughtworks/go/server/service/ElasticAgentPluginServiceTest.java b/server/src/test-fast/java/com/thoughtworks/go/server/service/ElasticAgentPluginServiceTest.java index f4198d486e0..0ed89a337e3 100644 --- a/server/src/test-fast/java/com/thoughtworks/go/server/service/ElasticAgentPluginServiceTest.java +++ b/server/src/test-fast/java/com/thoughtworks/go/server/service/ElasticAgentPluginServiceTest.java @@ -113,9 +113,18 @@ void tearDown() { @Test void shouldSendServerHeartbeatToAllElasticPlugins() { - ClusterProfiles clusterProfiles = new ClusterProfiles(); - clusterProfiles.add(new ClusterProfile("id", "pluginId")); - when(clusterProfilesService.getPluginProfiles()).thenReturn(clusterProfiles); + ClusterProfiles allClusterProfiles = new ClusterProfiles(); + allClusterProfiles.add(new ClusterProfile("id1", "p1")); + allClusterProfiles.add(new ClusterProfile("id2", "p2")); + allClusterProfiles.add(new ClusterProfile("id3", "docker")); + when(clusterProfilesService.getPluginProfiles()).thenReturn(allClusterProfiles); + + ClusterProfiles p1ClusterProfiles = new ClusterProfiles(); + p1ClusterProfiles.add(new ClusterProfile("id1", "p1")); + ClusterProfiles p2ClusterProfiles = new ClusterProfiles(); + p2ClusterProfiles.add(new ClusterProfile("id2", "p2")); + ClusterProfiles dockerClusterProfiles = new ClusterProfiles(); + dockerClusterProfiles.add(new ClusterProfile("id3", "docker")); service.heartbeat(); @@ -125,14 +134,15 @@ void shouldSendServerHeartbeatToAllElasticPlugins() { List messages = captor.getAllValues(); assertThat(messages).hasSize(3) .contains( - new ServerPingMessage("p1", clusterProfiles), - new ServerPingMessage("p2", clusterProfiles), - new ServerPingMessage("docker", clusterProfiles) + new ServerPingMessage("p1", p1ClusterProfiles), + new ServerPingMessage("p2", p2ClusterProfiles), + new ServerPingMessage("docker", dockerClusterProfiles) ); } @Test void shouldSendServerHeartBeatMessageWithTimeToLive() { + when(clusterProfilesService.getPluginProfiles()).thenReturn(new ClusterProfiles()); service.setElasticPluginHeartBeatInterval(60000L); ArgumentCaptor captor = ArgumentCaptor.forClass(ServerPingMessage.class); ArgumentCaptor ttl = ArgumentCaptor.forClass(Long.class); @@ -341,7 +351,7 @@ void shouldErrorOutWhenPluginDoesNotAgentSupportStatusReport() { } @Test - void shouldRaiseExceptionIfJobPlanIsNull(){ + void shouldRaiseExceptionIfJobPlanIsNull() { final Capabilities capabilities = new Capabilities(false, true); final GoPluginDescriptor descriptor = new GoPluginDescriptor("cd.go.example.plugin", null, null, null, null, false); elasticAgentMetadataStore.setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, capabilities));