Search in sources :

Example 1 with ElasticAgentMetadata

use of com.thoughtworks.go.server.domain.ElasticAgentMetadata in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessListAgentRequest.

@Test
public void shouldProcessListAgentRequest() throws Exception {
    LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
    ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "docker", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
    allAgents.put("docker", Arrays.asList(agent));
    when(agentService.allElasticAgents()).thenReturn(allAgents);
    GoApiResponse response = processor.process(pluginDescriptor, new DefaultGoApiRequest(REQUEST_SERVER_LIST_AGENTS, "1.0", pluginIdentifier));
    JSONAssert.assertEquals("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]", response.responseBody(), true);
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 2 with ElasticAgentMetadata

use of com.thoughtworks.go.server.domain.ElasticAgentMetadata in project gocd by gocd.

the class ElasticAgentRequestProcessorV1Test method shouldProcessListAgentRequest.

@Test
public void shouldProcessListAgentRequest() throws Exception {
    LinkedMultiValueMap<String, ElasticAgentMetadata> allAgents = new LinkedMultiValueMap<>();
    ElasticAgentMetadata agent = new ElasticAgentMetadata("foo", "bar", "cd.go.example.plugin", AgentRuntimeStatus.Building, AgentConfigStatus.Disabled);
    allAgents.put("cd.go.example.plugin", asList(agent));
    when(agentService.allElasticAgents()).thenReturn(allAgents);
    when(request.api()).thenReturn(REQUEST_SERVER_LIST_AGENTS);
    GoApiResponse response = processor.process(pluginDescriptor, request);
    assertThatJson("[{\"agent_id\":\"bar\",\"agent_state\":\"Building\",\"build_state\":\"Building\",\"config_state\":\"Disabled\"}]").isEqualTo(response.responseBody());
}
Also used : GoApiResponse(com.thoughtworks.go.plugin.api.response.GoApiResponse) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) Test(org.junit.jupiter.api.Test)

Example 3 with ElasticAgentMetadata

use of com.thoughtworks.go.server.domain.ElasticAgentMetadata 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 4 with ElasticAgentMetadata

use of com.thoughtworks.go.server.domain.ElasticAgentMetadata in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldAssignJobToAnAgentIfThePluginMatchesForTheAgentAndJob_AndThePluginAgreesToTheAssignment.

@Test
void shouldAssignJobToAnAgentIfThePluginMatchesForTheAgentAndJob_AndThePluginAgreesToTheAssignment() {
    String uuid = randomUUID().toString();
    String elasticPluginId = "plugin-1";
    ElasticAgentMetadata agentMetadata = new ElasticAgentMetadata(uuid, uuid, elasticPluginId, AgentRuntimeStatus.Idle, AgentConfigStatus.Enabled);
    ElasticProfile elasticProfile = new ElasticProfile("1", "clusterProfileId");
    when(registry.shouldAssignWork(any(), any(), any(), any(), any(), any())).thenReturn(true);
    assertThat(service.shouldAssignWork(agentMetadata, null, elasticProfile, new ClusterProfile("clusterProfileId", elasticPluginId), null)).isTrue();
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 5 with ElasticAgentMetadata

use of com.thoughtworks.go.server.domain.ElasticAgentMetadata in project gocd by gocd.

the class ElasticAgentPluginServiceTest method shouldNotAssignJobToAnAgentBroughtUpByADifferentElasticPlugin.

@Test
void shouldNotAssignJobToAnAgentBroughtUpByADifferentElasticPlugin() {
    String uuid = randomUUID().toString();
    ElasticAgentMetadata agentMetadata = new ElasticAgentMetadata(uuid, uuid, "plugin-1", AgentRuntimeStatus.Idle, AgentConfigStatus.Enabled);
    ElasticProfile elasticProfile = new ElasticProfile("1", "clusterProfileId");
    assertThat(service.shouldAssignWork(agentMetadata, null, elasticProfile, new ClusterProfile("clusterProfileId", "plugin-2"), null)).isFalse();
    verifyNoMoreInteractions(registry);
}
Also used : ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Aggregations

ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)6 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)4 Test (org.junit.jupiter.api.Test)4 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)3 GoApiResponse (com.thoughtworks.go.plugin.api.response.GoApiResponse)2 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)2 PluginDescriptor (com.thoughtworks.go.plugin.api.info.PluginDescriptor)1 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)1 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)1 ServerPingMessage (com.thoughtworks.go.server.messaging.elasticagents.ServerPingMessage)1 Test (org.junit.Test)1