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);
}
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);
}
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);
}
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"));
}
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"));
}
Aggregations