use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldRegisterLocalAgentWithNonLoopbackIpAddress.
@Test
public void shouldRegisterLocalAgentWithNonLoopbackIpAddress() throws Exception {
String nonLoopbackIp = SystemUtil.getFirstLocalNonLoopbackIpAddress();
InetAddress inetAddress = InetAddress.getByName(nonLoopbackIp);
assertThat(SystemUtil.isLocalIpAddress(nonLoopbackIp), is(true));
AgentConfig agentConfig = new AgentConfig("uuid", inetAddress.getHostName(), nonLoopbackIp);
AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, false, "/var/lib", 0L, "linux", false);
agentService.requestRegistration(new Username("bob"), agentRuntimeInfo);
AgentInstance agentInstance = agentService.findRegisteredAgents().findAgentAndRefreshStatus("uuid");
assertThat(agentInstance.agentConfig().getIpAddress(), is(nonLoopbackIp));
assertThat(agentInstance.getStatus(), is(AgentStatus.Idle));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class JobAssignmentTest method setupRemoteAgent.
private AgentInstance setupRemoteAgent() {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
AgentInstance instance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, agentStatusChangeListener());
instance.enable();
return instance;
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class JobAssignmentTest method shouldAssignJobToLocalAgentEvenReachedLimit.
@Test
public void shouldAssignJobToLocalAgentEvenReachedLimit() throws UnknownHostException {
AgentInstance local = setupLocalAgent();
AgentInstance remote = setupRemoteAgent();
fixture.createPipelineWithFirstStageScheduled();
assignmentService.onTimer();
assignmentService.assignWorkToAgent(remote);
Work work = assignmentService.assignWorkToAgent(local);
assertThat(work, instanceOf(BuildWork.class));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class JobAssignmentTest method shouldNotAssignJobToRemoteAgentIfReachedLimit.
@Test
public void shouldNotAssignJobToRemoteAgentIfReachedLimit() throws UnknownHostException {
AgentInstance local = setupLocalAgent();
AgentInstance remote = setupRemoteAgent();
AgentInstance remote2 = setupRemoteAgent();
fixture.createPipelineWithFirstStageScheduled();
assignmentService.onConfigChange(null);
assignmentService.assignWorkToAgent(local);
assignmentService.assignWorkToAgent(remote);
Work work = assignmentService.assignWorkToAgent(remote2);
assertThat(work, instanceOf(NoWork.class));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldSendLostContactEmailWhenAgentStateIsLostContact_FEATURE_HIDDEN.
@Test
public void shouldSendLostContactEmailWhenAgentStateIsLostContact_FEATURE_HIDDEN() 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));
String body = String.format("The email has been sent out automatically by the Go server at (%s) to Go administrators.\n" + "\n" + "The Go server has lost contact with agent:\n" + "\n" + "Agent name: CCeDev01\n" + "Free Space: 10.0 KB\n" + "Sandbox: /var/lib/foo\n" + "IP Address: 10.18.5.1\n" + "OS: Minix\n" + "Resources: \n" + "Environments: \n" + "\n" + "Lost contact at: %s", SystemUtil.getFirstLocalNonLoopbackIpAddress(), date);
// verify(mailSender).sendEmail(new SendEmailMessage("[Lost Contact] Go agent host: " + instance.getHostname(), body, "admin@foo.mail.com"));
verify(mailSender, never()).sendEmail(new SendEmailMessage("[Lost Contact] Go agent host: " + instance.getHostname(), body, "admin@foo.mail.com"));
}
Aggregations