Search in sources :

Example 1 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances 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 2 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldLoadAgentsByApprovalStatus.

@Test
public void shouldLoadAgentsByApprovalStatus() throws Exception {
    AgentConfig deniedAgent1 = new AgentConfig("uuid1", "deniedAgent1", "127.0.0.1");
    deniedAgent1.disable();
    CONFIG_HELPER.addAgent(deniedAgent1);
    AgentConfig deniedAgent2 = new AgentConfig("uuid2", "deniedAgent2", "127.0.0.2");
    deniedAgent2.disable();
    CONFIG_HELPER.addAgent(deniedAgent2);
    CONFIG_HELPER.addAgent(new AgentConfig("uuid3", "approvedAgent1", "127.0.0.3"));
    goConfigDao.load();
    agentService.initialize();
    AgentInstances approvedAgents = agentService.findEnabledAgents();
    assertThat(approvedAgents.size(), is(1));
    assertThat(approvedAgents.findAgentAndRefreshStatus("uuid3").agentConfig().getHostname(), is("approvedAgent1"));
    AgentInstances deniedAgents = agentService.findDisabledAgents();
    assertThat(deniedAgents.size(), is(2));
    assertThat(deniedAgents.findAgentAndRefreshStatus("uuid1").agentConfig().getHostname(), is("deniedAgent1"));
    assertThat(deniedAgents.findAgentAndRefreshStatus("uuid2").agentConfig().getHostname(), is("deniedAgent2"));
}
Also used : AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) Test(org.junit.Test)

Example 3 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances 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 4 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances 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)

Example 5 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldUpdateAgentStatus.

@Test
public void shouldUpdateAgentStatus() throws Exception {
    AgentInstance instance = AgentInstanceMother.building();
    AgentService agentService = getAgentService(new AgentInstances(null, new SystemEnvironment(), instance));
    AgentInstances agents = agentService.findRegisteredAgents();
    String uuid = instance.agentConfig().getUuid();
    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));
    agents = agentService.findRegisteredAgents();
    assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Idle));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Aggregations

AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)14 Test (org.junit.Test)9 AgentInstance (com.thoughtworks.go.domain.AgentInstance)7 UuidGenerator (com.thoughtworks.go.server.util.UuidGenerator)4 Before (org.junit.Before)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 SendEmailMessage (com.thoughtworks.go.server.messaging.SendEmailMessage)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 AgentRuntimeStatus (com.thoughtworks.go.domain.AgentRuntimeStatus)1 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)1 InvalidAgentException (com.thoughtworks.go.remote.work.InvalidAgentException)1 GoUnauthorizedException (com.thoughtworks.go.server.GoUnauthorizedException)1 Username (com.thoughtworks.go.server.domain.Username)1 AgentDao (com.thoughtworks.go.server.persistence.AgentDao)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)1 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)1 AgentsViewModel (com.thoughtworks.go.server.ui.AgentsViewModel)1