use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldMarkAgentAsLostContactIfAgentDidNotPingForMoreThanTimeout.
@Test
public void shouldMarkAgentAsLostContactIfAgentDidNotPingForMoreThanTimeout() throws Exception {
new SystemEnvironment().setProperty("agent.connection.timeout", "-1");
CONFIG_HELPER.addMailHost(new MailHost("ghost.name", 25, "loser", "boozer", true, false, "go@foo.mail.com", "admin@foo.mail.com"));
Date date = new Date(70, 1, 1, 1, 1, 1);
AgentInstance instance = AgentInstanceMother.idle(date, "CCeDev01");
((AgentRuntimeInfo) ReflectionUtil.getField(instance, "agentRuntimeInfo")).setOperatingSystem("Minix");
EmailSender mailSender = mock(EmailSender.class);
AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), environmentConfigService, securityService, agentDao, new UuidGenerator(), serverHealthService, mailSender, agentStatusChangeNotifier());
AgentInstances agentInstances = (AgentInstances) ReflectionUtil.getField(agentService, "agentInstances");
agentInstances.add(instance);
AgentInstances agents = agentService.findRegisteredAgents();
assertThat(agents.size(), is(1));
AgentInstance agentInstance = agents.findAgentAndRefreshStatus(instance.agentConfig().getUuid());
assertThat(agentInstance.getStatus(), is(AgentStatus.LostContact));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus.
@Test
public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
AgentInstance instance = AgentInstanceMother.building();
AgentService agentService = getAgentService(new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), instance));
AgentInstances agents = agentService.findRegisteredAgents();
String uuid = instance.agentConfig().getUuid();
assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
AgentIdentifier identifier = instance.agentConfig().getAgentIdentifier();
agentDao.associateCookie(identifier, "new_cookie");
AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(identifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "old_cookie", false);
try {
agentService.updateRuntimeInfo(runtimeInfo);
fail("agent with bad cookie should not be able to update runtime info");
} catch (AgentWithDuplicateUUIDException e) {
assertThat(e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
}
agents = agentService.findRegisteredAgents();
assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
AgentIdentifier agentIdentifier = instance.agentConfig().getAgentIdentifier();
String cookie = agentService.assignCookie(agentIdentifier);
agentService.updateRuntimeInfo(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), cookie, false));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistration.
@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistration() throws Exception {
String uuid = UUID.randomUUID().toString();
agentConfigService.addAgent(new AgentConfig(uuid, "hostname", "127.0.01"), Username.ANONYMOUS);
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, false, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isIdle());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertTrue(RegistrationJSONizer.fromJson(responseEntity.getBody().toString()).isValid());
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsControllerV7 method show.
public String show(Request request, Response response) throws IOException {
String uuid = request.params("uuid");
final AgentInstance agentInstance = fetchEntityFromConfig(uuid);
return writerForTopLevelObject(request, response, outputWriter -> toJSON(outputWriter, agentInstance, environmentConfigService.getAgentEnvironments(uuid), securityService, currentUsername()));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsControllerV7 method update.
public String update(Request request, Response response) {
String uuid = request.params("uuid");
AgentUpdateRequest req = fromJSON(request.body());
String hostname = req.getHostname();
String resources = req.getResources();
String environments = filterOutEnvsWhichAreAssociatedViaConfigRepo(uuid, req.getEnvironments());
TriState configState = req.getAgentConfigState();
HttpOperationResult result = new HttpOperationResult();
AgentInstance updatedAgentInstance = null;
try {
updatedAgentInstance = agentService.updateAgentAttributes(uuid, hostname, resources, environments, configState);
handleUpdateAgentResponse(updatedAgentInstance, result);
} catch (HttpException e) {
throw e;
} catch (Exception e) {
throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(e.getMessage()));
}
return handleCreateOrUpdateResponse(request, response, updatedAgentInstance, result);
}
Aggregations