use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRegisterElasticAgent.
@Test
public void shouldRegisterElasticAgent() {
String autoRegisterKey = ephemeralAutoRegisterKeyService.autoRegisterKey();
String uuid = UUID.randomUUID().toString();
String elasticAgentId = UUID.randomUUID().toString();
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", autoRegisterKey, "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
Agent agent = agentService.getAgentByUUID(uuid);
assertTrue(agent.isElastic());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
assertThat(responseEntity.getBody().toString(), is(""));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys.
@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys() {
String uuid = UUID.randomUUID().toString();
agentService.saveOrUpdate(new Agent(uuid, "hostname", "127.0.01", uuidGenerator.randomUuid()));
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, goConfigService.serverConfig().getAgentAutoRegisterKey(), "", "", null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isIdle());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getBody().toString(), is(""));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentInstanceTest method buildingWithTimeProvider.
public static AgentInstance buildingWithTimeProvider(TimeProvider timeProvider) {
Agent idleAgentConfig = new Agent("uuid2", "localhost", "10.18.5.1");
AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(idleAgentConfig.getAgentIdentifier(), Building, currentWorkingDirectory(), "cookie");
agentRuntimeInfo.setLocation("/var/lib/foo");
agentRuntimeInfo.idle();
agentRuntimeInfo.setUsableSpace(10 * 1024l);
AgentInstance agentInstance = new AgentInstance(idleAgentConfig, LOCAL, new SystemEnvironment(), mock(AgentStatusChangeListener.class), timeProvider);
agentInstance.enable();
return agentInstance;
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentInstanceTest method shouldOrderByHostname.
@Test
void shouldOrderByHostname() {
AgentInstance agentA = new AgentInstance(new Agent("UUID", "A", "127.0.0.1"), LOCAL, systemEnvironment, null);
AgentInstance agentB = new AgentInstance(new Agent("UUID", "B", "127.0.0.2"), LOCAL, systemEnvironment, null);
assertThat(agentA.compareTo(agentA)).isEqualTo(0);
assertThat(agentA.compareTo(agentB)).isLessThan(0);
assertThat(agentB.compareTo(agentA)).isGreaterThan(0);
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentInstanceTest method shouldDenyAgentWhenAgentIsDeniedInConfigFile.
@Test
void shouldDenyAgentWhenAgentIsDeniedInConfigFile() {
AgentInstance original = AgentInstance.createFromAgent(agent, systemEnvironment, mock(AgentStatusChangeListener.class));
original.update(buildingRuntimeInfo());
Agent newAgent = new Agent(agent.getUuid(), agent.getHostname(), agent.getIpaddress());
newAgent.disable();
original.syncAgentFrom(newAgent);
assertThat(original.getStatus()).isEqualTo(AgentStatus.Disabled);
}
Aggregations