Search in sources :

Example 11 with AgentInstances

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

the class AgentServiceIntegrationTest method shouldLoadAllAgents.

@Test
public void shouldLoadAllAgents() throws Exception {
    AgentInstance idle = AgentInstanceMother.idle(new Date(), "CCeDev01");
    AgentInstance pending = AgentInstanceMother.pending();
    AgentInstance building = AgentInstanceMother.building();
    AgentInstance denied = AgentInstanceMother.disabled();
    AgentService agentService = getAgentService(new AgentInstances(null, new SystemEnvironment(), idle, pending, building, denied));
    assertThat(agentService.agents().size(), is(4));
    assertThat(agentService.findAgentAndRefreshStatus(idle.agentConfig().getUuid()), is(idle));
    assertThat(agentService.findAgentAndRefreshStatus(pending.agentConfig().getUuid()), is(pending));
    assertThat(agentService.findAgentAndRefreshStatus(building.agentConfig().getUuid()), is(building));
    assertThat(agentService.findAgentAndRefreshStatus(denied.agentConfig().getUuid()), is(denied));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) Test(org.junit.Test)

Example 12 with AgentInstances

use of com.thoughtworks.go.server.domain.AgentInstances 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, 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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) Test(org.junit.Test)

Example 13 with AgentInstances

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

the class ScheduleService method rescheduleHungJobs.

//Note: This is called from a Spring timer
public void rescheduleHungJobs() {
    try {
        //TODO 2779
        AgentInstances knownAgents = agentService.findRegisteredAgents();
        List<String> liveAgentIdList = getLiveAgentUuids(knownAgents);
        if (!liveAgentIdList.isEmpty()) {
            JobInstances jobs = jobInstanceService.findHungJobs(liveAgentIdList);
            for (JobInstance buildId : jobs) {
                LOGGER.warn("Found hung job[id=" + buildId + "], rescheduling it");
                rescheduleJob(buildId);
            }
        }
    } catch (Exception e) {
        LOGGER.error("Error occured during reschedule hung builds: ", e);
    }
}
Also used : AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) GoUnauthorizedException(com.thoughtworks.go.server.GoUnauthorizedException) InvalidAgentException(com.thoughtworks.go.remote.work.InvalidAgentException)

Example 14 with AgentInstances

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

the class ScheduleServiceRescheduleHungJobsTest method shouldNotQueryForBuildWhenThereAreNoLiveAgents.

@Test
public void shouldNotQueryForBuildWhenThereAreNoLiveAgents() {
    when(agentService.findRegisteredAgents()).thenReturn(new AgentInstances(null));
    scheduleService.rescheduleHungJobs();
    verify(agentService).findRegisteredAgents();
    verify(jobInstanceService, times(0)).findHungJobs(any());
}
Also used : AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) 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