Skip to content

Commit

Permalink
Pass along all cluster-profiles belonging to that plugin as part of s…
Browse files Browse the repository at this point in the history
…erver ping request (gocd#5538)

* Do not send all available cluster profiles from different plugins.
  • Loading branch information
GaneshSPatil committed Apr 16, 2019
1 parent b8a499b commit 5cb7795
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,9 +26,9 @@

public class ServerPingMessage implements PluginAwareMessage {
private final String pluginId;
private ClusterProfiles clusterProfiles;
private List<ClusterProfile> clusterProfiles;

public ServerPingMessage(String pluginId, ClusterProfiles clusterProfiles) {
public ServerPingMessage(String pluginId, List<ClusterProfile> clusterProfiles) {
this.pluginId = pluginId;
this.clusterProfiles = clusterProfiles;
}
Expand All @@ -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 +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void heartbeat() {
long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L;

for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) {
ClusterProfiles clusterProfiles = (ClusterProfiles) clusterProfilesService.getPluginProfiles();
List<ClusterProfile> clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(descriptor.id());
serverPingQueue.post(new ServerPingMessage(descriptor.id(), clusterProfiles), pingMessageTimeToLive);
elasticAgentsOfMissingPlugins.remove(descriptor.id());
serverHealthService.removeByScope(scope(descriptor.id()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -125,14 +134,15 @@ void shouldSendServerHeartbeatToAllElasticPlugins() {
List<ServerPingMessage> 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<ServerPingMessage> captor = ArgumentCaptor.forClass(ServerPingMessage.class);
ArgumentCaptor<Long> ttl = ArgumentCaptor.forClass(Long.class);
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 5cb7795

Please sign in to comment.