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);
}
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;
}
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;
}
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));
}
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);
}
Aggregations