Search in sources :

Example 1 with ServerPingMessage

use of com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldSendServerHeartBeatMessageWithTimeToLive.

@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);
    service.heartbeat();
    verify(serverPingQueue, times(3)).post(captor.capture(), ttl.capture());
    assertThat(ttl.getValue()).isEqualTo(50000L);
}
Also used : ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ServerPingMessage(com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage) Test(org.junit.jupiter.api.Test)

Example 2 with ServerPingMessage

use of com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage in project gocd by gocd.

the class ElasticAgentPluginService method heartbeat.

public void heartbeat() {
    LinkedMultiValueMap<String, ElasticAgentMetadata> elasticAgentsOfMissingPlugins = agentService.allElasticAgents();
    // pingMessage TTL is set lesser than elasticPluginHeartBeatInterval to ensure there aren't multiple ping request for the same plugin
    long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L;
    for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) {
        elasticAgentsOfMissingPlugins.remove(descriptor.id());
        List<ClusterProfile> clusterProfiles = clusterProfilesService.getPluginProfiles().findByPluginId(descriptor.id());
        boolean secretsResolved = resolveSecrets(descriptor.id(), clusterProfiles);
        if (!secretsResolved)
            continue;
        serverPingQueue.post(new ServerPingMessage(descriptor.id(), clusterProfiles), pingMessageTimeToLive);
        serverHealthService.removeByScope(scope(descriptor.id()));
    }
    if (!elasticAgentsOfMissingPlugins.isEmpty()) {
        for (String pluginId : elasticAgentsOfMissingPlugins.keySet()) {
            Collection<String> uuids = elasticAgentsOfMissingPlugins.get(pluginId).stream().map(ElasticAgentMetadata::uuid).collect(toList());
            String description = format("Elastic agent plugin with identifier %s has gone missing, but left behind %s agent(s) with UUIDs %s.", pluginId, elasticAgentsOfMissingPlugins.get(pluginId).size(), uuids);
            serverHealthService.update(ServerHealthState.warning("Elastic agents with no matching plugins", description, general(scope(pluginId))));
            LOGGER.warn(description);
        }
    }
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluginDescriptor(com.thoughtworks.go.plugin.api.info.PluginDescriptor) ServerPingMessage(com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile)

Example 3 with ServerPingMessage

use of com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldSendServerHeartbeatToAllElasticPlugins.

@Test
void shouldSendServerHeartbeatToAllElasticPlugins() {
    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();
    ArgumentCaptor<ServerPingMessage> captor = ArgumentCaptor.forClass(ServerPingMessage.class);
    ArgumentCaptor<Long> ttl = ArgumentCaptor.forClass(Long.class);
    verify(serverPingQueue, times(3)).post(captor.capture(), ttl.capture());
    List<ServerPingMessage> messages = captor.getAllValues();
    assertThat(messages).hasSize(3).contains(new ServerPingMessage("p1", p1ClusterProfiles), new ServerPingMessage("p2", p2ClusterProfiles), new ServerPingMessage("docker", dockerClusterProfiles));
}
Also used : ClusterProfiles(com.thoughtworks.go.config.elastic.ClusterProfiles) ServerPingMessage(com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ServerPingMessage (com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage)3 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)2 ClusterProfiles (com.thoughtworks.go.config.elastic.ClusterProfiles)2 Test (org.junit.jupiter.api.Test)2 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)1