Search in sources :

Example 6 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentInstancesTest method shouldFindAgentsByItHostName.

@Test
public void shouldFindAgentsByItHostName() throws Exception {
    AgentInstance idle = AgentInstanceMother.idle(new Date(), "ghost-name");
    AgentInstances agentInstances = new AgentInstances(null, systemEnvironment, idle, AgentInstanceMother.building());
    AgentInstance byHostname = agentInstances.findFirstByHostname("ghost-name");
    assertThat(byHostname, is(idle));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) Date(java.util.Date) Test(org.junit.Test)

Example 7 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentInstancesTest method shouldReturnNullAgentsWhenHostNameIsNotFound.

@Test
public void shouldReturnNullAgentsWhenHostNameIsNotFound() throws Exception {
    AgentInstances agentInstances = new AgentInstances(null, systemEnvironment, AgentInstanceMother.building());
    agentInstances.add(idle);
    agentInstances.add(building);
    AgentInstance byHostname = agentInstances.findFirstByHostname("not-exist");
    assertThat(byHostname, is(instanceOf(NullAgentInstance.class)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) Test(org.junit.Test)

Example 8 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotShootoutMailsForEveryStatusChange.

@Test
public void shouldNotShootoutMailsForEveryStatusChange() throws Exception {
    //should, only for lost-contact
    CONFIG_HELPER.addMailHost(new MailHost("ghost.name", 25, "loser", "boozer", true, false, "go@foo.mail.com", "admin@foo.mail.com"));
    AgentInstance instance = AgentInstanceMother.idle(new Date(), "CCeDev01");
    EmailSender mailSender = mock(EmailSender.class);
    agentDao.associateCookie(instance.getAgentIdentifier(), "rotten-cookie");
    AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), environmentConfigService, goConfigService, securityService, agentDao, new UuidGenerator(), serverHealthService, mailSender);
    AgentInstances agentInstances = (AgentInstances) ReflectionUtil.getField(agentService, "agentInstances");
    agentInstances.add(instance);
    ReflectionUtil.setField(instance, "lastHeardTime", null);
    AgentRuntimeInfo runtimeInfo = (AgentRuntimeInfo) ReflectionUtil.getField(instance, "agentRuntimeInfo");
    runtimeInfo.setCookie("rotten-cookie");
    runtimeInfo.setStatus(AgentStatus.Building);
    agentService.updateRuntimeInfo(runtimeInfo);
    verify(mailSender, never()).sendEmail(any(SendEmailMessage.class));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) Test(org.junit.Test)

Example 9 with AgentInstance

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, goConfigService, securityService, agentDao, new UuidGenerator(), serverHealthService, mailSender);
    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"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) Test(org.junit.Test)

Example 10 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentServiceIntegrationTest method enabledAgents_shouldNotIncludePendingAgents.

@Test
public void enabledAgents_shouldNotIncludePendingAgents() throws Exception {
    AgentInstance idle = AgentInstanceMother.updateUuid(AgentInstanceMother.idle(new Date(), "CCeDev01"), UUID);
    AgentInstance pending = AgentInstanceMother.pending();
    AgentInstance building = AgentInstanceMother.building();
    AgentInstance denied = AgentInstanceMother.disabled();
    createEnvironment("uat");
    EnvironmentConfig environment = environmentConfigService.named("uat");
    environment.addAgent(UUID);
    AgentInstances instances = new AgentInstances(null, new SystemEnvironment(), idle, pending, building, denied);
    AgentService agentService = getAgentService(instances);
    AgentsViewModel agents = agentService.registeredAgents();
    assertThat(agents.size(), is(3));
    for (AgentViewModel agent : agents) {
        assertThat(agent.getStatus().getConfigStatus(), not(is(AgentConfigStatus.Pending)));
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentsViewModel(com.thoughtworks.go.server.ui.AgentsViewModel) AgentViewModel(com.thoughtworks.go.server.ui.AgentViewModel) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)85 Test (org.junit.Test)58 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)26 ArrayList (java.util.ArrayList)21 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 AgentConfig (com.thoughtworks.go.config.AgentConfig)15 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)9 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)7 Username (com.thoughtworks.go.server.domain.Username)6 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)4 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 Resource (com.thoughtworks.go.config.Resource)3 BuildWork (com.thoughtworks.go.remote.work.BuildWork)3 NoWork (com.thoughtworks.go.remote.work.NoWork)3 Work (com.thoughtworks.go.remote.work.Work)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)3 AgentsViewModel (com.thoughtworks.go.server.ui.AgentsViewModel)3 UuidGenerator (com.thoughtworks.go.server.util.UuidGenerator)3