Search in sources :

Example 11 with AgentMetadata

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"));
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) Test(org.junit.Test)

Example 12 with AgentMetadata

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);
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)

Example 13 with AgentMetadata

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);
}
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 14 with AgentMetadata

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);
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 15 with AgentMetadata

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);
}
Also used : AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Aggregations

AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)17 Test (org.junit.Test)16 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)5 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