use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class WorkFinder method onMessage.
public void onMessage(IdleAgentMessage idleAgentMessage) {
AgentIdentifier agent = idleAgentMessage.getAgentIdentifier();
Work work = null;
long startTime = System.currentTimeMillis();
try {
work = buildAssignmentService.assignWorkToAgent(agent);
} finally {
if (work == null) {
work = NO_WORK;
}
workAssignmentPerformanceLogger.assignedWorkToAgent(work, agent, startTime, System.currentTimeMillis());
try {
assignedWorkTopic.post(new WorkAssignedMessage(agent, work));
} catch (Throwable e) {
LOGGER.fatal(null, e);
}
}
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class JobAssignmentTest method shouldAssignJobToRemoteAgent.
@Test
public void shouldAssignJobToRemoteAgent() throws UnknownHostException {
AgentInstance local = setupLocalAgent();
AgentInstance remote = setupRemoteAgent();
fixture.createPipelineWithFirstStageScheduled();
assignmentService.onTimer();
assignmentService.assignWorkToAgent(local);
assignmentService.onTimer();
Work work = assignmentService.assignWorkToAgent(remote);
assertThat(work, instanceOf(BuildWork.class));
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldNotScheduleIfAgentDoesNotHaveMatchingResources.
@Test
public void shouldNotScheduleIfAgentDoesNotHaveMatchingResources() throws Exception {
JobConfig plan = evolveConfig.findBy(new CaseInsensitiveString(STAGE_NAME)).jobConfigByInstanceName("unit", true);
plan.addResource("some-resource");
scheduleHelper.schedule(evolveConfig, modifySomeFiles(evolveConfig), DEFAULT_APPROVED_BY);
AgentConfig agentConfig = AgentMother.localAgent();
agentConfig.addResource(new Resource("some-other-resource"));
Work work = buildAssignmentService.assignWorkToAgent(agent(agentConfig));
assertThat(work, is(BuildAssignmentService.NO_WORK));
Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name()));
JobInstance job = pipeline.findStage(STAGE_NAME).findJob("unit");
assertThat(job.getState(), is(JobState.Scheduled));
assertThat(job.getAgentUuid(), is(nullValue()));
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldReScheduleToCorrectAgent.
@Test
public void shouldReScheduleToCorrectAgent() throws Exception {
JobConfig plan = evolveConfig.findBy(new CaseInsensitiveString(STAGE_NAME)).jobConfigByInstanceName("unit", true);
plan.addResource("some-resource");
scheduleHelper.schedule(evolveConfig, modifySomeFiles(evolveConfig), DEFAULT_APPROVED_BY);
buildAssignmentService.onTimer();
AgentConfig agentConfig = AgentMother.localAgent();
agentConfig.addResource(new Resource("some-resource"));
Work work = buildAssignmentService.assignWorkToAgent(agent(agentConfig));
assertThat(work, is(not(BuildAssignmentService.NO_WORK)));
Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name()));
JobInstance job = pipeline.findStage(STAGE_NAME).findJob("unit");
JobInstance runningJob = jobInstanceDao.buildByIdWithTransitions(job.getId());
scheduleService.rescheduleJob(runningJob);
pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name()));
JobInstance rescheduledJob = pipeline.findStage(STAGE_NAME).findJob("unit");
assertThat(rescheduledJob.getId(), not(runningJob.getId()));
buildAssignmentService.onTimer();
Work noResourcesWork = buildAssignmentService.assignWorkToAgent(agent(AgentMother.localAgentWithResources("WITHOUT_RESOURCES")));
assertThat(noResourcesWork, is(BuildAssignmentService.NO_WORK));
buildAssignmentService.onTimer();
Work correctAgentWork = buildAssignmentService.assignWorkToAgent(agent(agentConfig));
assertThat(correctAgentWork, is(not(BuildAssignmentService.NO_WORK)));
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldNotAssignWorkToDeniedAgent.
@Test
public void shouldNotAssignWorkToDeniedAgent() throws Exception {
AgentConfig deniedAgentConfig = AgentMother.localAgent();
deniedAgentConfig.disable();
Work assignedWork = buildAssignmentService.assignWorkToAgent(agent(deniedAgentConfig));
assertThat(assignedWork, instanceOf(DeniedAgentWork.class));
}
Aggregations