use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.
the class AgentMetadataConverterV3Test method fromDTO_shouldConvertToAgentMetadataFromAgentMetadataDTO.
@Test
public void fromDTO_shouldConvertToAgentMetadataFromAgentMetadataDTO() {
final AgentMetadataDTO agentMetadataDTO = new AgentMetadataDTO("agent-id", "Idle", "Building", "Enabled");
final AgentMetadata agentMetadata = new AgentMetadataConverterV3().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 ElasticAgentExtensionConverterV1 method listAgentsResponseBody.
@Override
public String listAgentsResponseBody(Collection<AgentMetadata> metadata) {
Gson gson = new Gson();
JsonArray array = new JsonArray();
for (AgentMetadata agentMetadata : metadata) {
array.add(agentMetadata.toJSON());
}
return gson.toJson(array);
}
use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.
the class ElasticAgentRequestProcessorTest method shouldProcessDeleteAgentRequest.
@Test
public void shouldProcessDeleteAgentRequest() throws Exception {
AgentMetadata agent = new AgentMetadata("foo", null, null, null);
DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DELETE_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).deleteAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
use of com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata in project gocd by gocd.
the class ElasticAgentExtensionTest 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 = extension.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 ElasticAgentExtensionV1Test 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 = extensionV1.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("1.0", REQUEST_SHOULD_ASSIGN_WORK, expectedRequestBody);
}
Aggregations