Search in sources :

Example 1 with AgentMetadata

use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.

the class ElasticAgentRequestProcessorTest method shouldProcessDisableAgentRequest.

@Test
public void shouldProcessDisableAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DISABLE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 2 with AgentMetadata

use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.

the class ElasticAgentExtensionV2Test method shouldMakeShouldAssignWorkCall.

@Test
public void shouldMakeShouldAssignWorkCall() throws JSONException {
    final Map<String, String> profile = Collections.singletonMap("ServerURL", "https://example.com/go");
    final AgentMetadata agentMetadata = new AgentMetadata("foo-agent-id", "Idle", "Idle", "Enabled");
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success("true"));
    final boolean shouldAssignWork = extensionV2.shouldAssignWork(PLUGIN_ID, agentMetadata, "test-env", profile, new JobIdentifier());
    assertTrue(shouldAssignWork);
    String expectedRequestBody = "{\n" + "  \"properties\": {\n" + "    \"ServerURL\": \"https://example.com/go\"\n" + "  },\n" + "  \"environment\": \"test-env\",\n" + "  \"agent\": {\n" + "    \"agent_id\": \"foo-agent-id\",\n" + "    \"agent_state\": \"Idle\",\n" + "    \"build_state\": \"Idle\",\n" + "    \"config_state\": \"Enabled\"\n" + "  }\n" + "}";
    assertExtensionRequest("2.0", REQUEST_SHOULD_ASSIGN_WORK, expectedRequestBody);
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 3 with AgentMetadata

use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.

the class ElasticAgentExtensionV3Test method shouldMakeShouldAssignWorkCall.

@Test
public void shouldMakeShouldAssignWorkCall() throws JSONException {
    final Map<String, String> profile = Collections.singletonMap("ServerURL", "https://example.com/go");
    final AgentMetadata agentMetadata = new AgentMetadata("foo-agent-id", "Idle", "Idle", "Enabled");
    when(pluginManager.submitTo(eq(PLUGIN_ID), eq(ELASTIC_AGENT_EXTENSION), requestArgumentCaptor.capture())).thenReturn(DefaultGoPluginApiResponse.success("true"));
    final boolean shouldAssignWork = extensionV3.shouldAssignWork(PLUGIN_ID, agentMetadata, "test-env", profile, new JobIdentifier());
    assertTrue(shouldAssignWork);
    String expectedRequestBody = "{\n" + "  \"properties\": {\n" + "    \"ServerURL\": \"https://example.com/go\"\n" + "  },\n" + "  \"environment\": \"test-env\",\n" + "  \"agent\": {\n" + "    \"agent_id\": \"foo-agent-id\",\n" + "    \"agent_state\": \"Idle\",\n" + "    \"build_state\": \"Idle\",\n" + "    \"config_state\": \"Enabled\"\n" + "  },\n" + "  \"job_identifier\": {}\n" + "}";
    assertExtensionRequest("3.0", REQUEST_SHOULD_ASSIGN_WORK, expectedRequestBody);
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 4 with AgentMetadata

use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.

the class AgentMetadataConverterV1Test method fromDTO_shouldConvertToAgentMetadataFromAgentMetadataDTO.

@Test
public void fromDTO_shouldConvertToAgentMetadataFromAgentMetadataDTO() {
    final AgentMetadataDTO agentMetadataDTO = new AgentMetadataDTO("agent-id", "Idle", "Building", "Enabled");
    final AgentMetadata agentMetadata = new AgentMetadataConverterV1().fromDTO(agentMetadataDTO);
    assertThat(agentMetadata.elasticAgentId(), is("agent-id"));
    assertThat(agentMetadata.agentState(), is("Idle"));
    assertThat(agentMetadata.buildState(), is("Building"));
    assertThat(agentMetadata.configState(), is("Enabled"));
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) Test(org.junit.Test)

Example 5 with AgentMetadata

use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.

the class AgentMetadataConverterV2Test method fromDTO_shouldConvertToAgentMetadataDTOFromAgentMetadata.

@Test
public void fromDTO_shouldConvertToAgentMetadataDTOFromAgentMetadata() {
    final AgentMetadata agentMetadata = new AgentMetadata("agent-id", "Idle", "Building", "Enabled");
    final AgentMetadataDTO agentMetadataDTO = new AgentMetadataConverterV2().toDTO(agentMetadata);
    assertThat(agentMetadataDTO.elasticAgentId(), is("agent-id"));
    assertThat(agentMetadataDTO.agentState(), is("Idle"));
    assertThat(agentMetadataDTO.buildState(), is("Building"));
    assertThat(agentMetadataDTO.configState(), is("Enabled"));
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) Test(org.junit.Test)

Aggregations

AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)23 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)10 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)7 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 DefaultGoApiRequest (com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest)2 ElasticAgentMetadata (com.thoughtworks.go.server.domain.ElasticAgentMetadata)2