Search in sources :

Example 1 with Agent

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

the class JobStatusJsonPresentationModelTest method shouldShowBuildStatus.

@Test
public void shouldShowBuildStatus() throws Exception {
    JobInstance instance = JobInstanceMother.assigned("test");
    instance.setId(12);
    instance.setAgentUuid("1234");
    final Agent agent = new Agent("1234", "cookie", "localhost", "1234");
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, agent, mock(DurationBean.class));
    Map json = presenter.toJsonHash();
    JSONAssert.assertEquals("{\n" + "  \"name\": \"test\",\n" + "  \"id\": \"12\",\n" + "  \"agent\": \"localhost\",\n" + "  \"current_status\": \"assigned\"\n" + "}", new Gson().toJson(json), false);
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent) DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) Gson(com.google.gson.Gson) Map(java.util.Map) Test(org.junit.Test)

Example 2 with Agent

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

the class AgentService method findAgentObjectByUuid.

public Agent findAgentObjectByUuid(String uuid) {
    Agent agent;
    AgentConfig agentFromConfig = agentConfigService.agents().getAgentByUuid(uuid);
    if (agentFromConfig != null && !agentFromConfig.isNull()) {
        agent = Agent.fromConfig(agentFromConfig);
    } else {
        agent = agentDao.agentByUuid(uuid);
    }
    return agent;
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent) AgentConfig(com.thoughtworks.go.config.AgentConfig)

Example 3 with Agent

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

the class AgentDao method agentByUuid.

public Agent agentByUuid(String uuid) {
    String key = agentCacheKey(uuid);
    Agent agent = (Agent) cache.get(key);
    if (agent == null) {
        synchronized (key) {
            agent = (Agent) cache.get(key);
            if (agent != null) {
                return agent;
            }
            agent = fetchAgentByUuid(uuid);
            cache.put(key, agent);
        }
    }
    return agent;
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent)

Example 4 with Agent

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

the class JobInstanceModelTest method shouldReturnFalseForLiveAgentIfAgentInfoIsConstructedFromDb.

@Test
public void shouldReturnFalseForLiveAgentIfAgentInfoIsConstructedFromDb() throws Exception {
    JobInstanceModel instance = new JobInstanceModel(JobInstanceMother.building("cruise"), JobDurationStrategy.ALWAYS_ZERO, new Agent("uuid", "cookie", "hostname", "ip"));
    assertThat(instance.hasLiveAgent(), is(false));
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent) Test(org.junit.Test)

Example 5 with Agent

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

the class JobPresentationServiceTest method shouldReturnJobModelForAnAgentThatIsNoMoreAvailableInTheConfig.

@Test
public void shouldReturnJobModelForAnAgentThatIsNoMoreAvailableInTheConfig() throws Exception {
    String deletedAgentUuid = "deleted_agent";
    JobInstance jobWithDeletedAgent = assignedWithAgentId("dev", deletedAgentUuid);
    when(agentService.findAgentAndRefreshStatus(deletedAgentUuid)).thenReturn(null);
    Agent agentFromDb = new Agent(deletedAgentUuid, "cookie", "hostname", "1.2.3.4");
    when(agentService.findAgentObjectByUuid(deletedAgentUuid)).thenReturn(agentFromDb);
    List<JobInstanceModel> models = new JobPresentationService(jobDurationStrategy, agentService).jobInstanceModelFor(new JobInstances(jobWithDeletedAgent));
    assertThat(models.size(), is(1));
    assertThat(models.get(0), is(new JobInstanceModel(jobWithDeletedAgent, jobDurationStrategy, agentFromDb)));
    verify(agentService, times(1)).findAgentAndRefreshStatus(deletedAgentUuid);
    verify(agentService, times(1)).findAgentObjectByUuid(deletedAgentUuid);
    verifyNoMoreInteractions(agentService);
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent) JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Aggregations

Agent (com.thoughtworks.go.server.domain.Agent)14 Test (org.junit.Test)9 JobInstance (com.thoughtworks.go.domain.JobInstance)5 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)4 Gson (com.google.gson.Gson)3 DurationBean (com.thoughtworks.go.dto.DurationBean)3 Session (org.hibernate.Session)3 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)3 JobInstanceModel (com.thoughtworks.go.server.ui.JobInstanceModel)2 SQLException (java.sql.SQLException)2 HibernateException (org.hibernate.HibernateException)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 JobInstances (com.thoughtworks.go.domain.JobInstances)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Query (org.hibernate.Query)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1