Search in sources :

Example 11 with Work

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);
        }
    }
}
Also used : Work(com.thoughtworks.go.remote.work.Work) NoWork(com.thoughtworks.go.remote.work.NoWork) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier)

Example 12 with Work

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Test(org.junit.Test)

Example 13 with Work

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()));
}
Also used : BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork)

Example 14 with Work

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)));
}
Also used : BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork)

Example 15 with 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));
}
Also used : DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork)

Aggregations

Work (com.thoughtworks.go.remote.work.Work)16 BuildWork (com.thoughtworks.go.remote.work.BuildWork)10 NoWork (com.thoughtworks.go.remote.work.NoWork)7 DeniedAgentWork (com.thoughtworks.go.remote.work.DeniedAgentWork)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)4 AgentInstance (com.thoughtworks.go.domain.AgentInstance)3 Test (org.junit.Test)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 BuildSettings (com.thoughtworks.go.domain.BuildSettings)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 JobPlan (com.thoughtworks.go.domain.JobPlan)1 UnregisteredAgentException (com.thoughtworks.go.domain.exception.UnregisteredAgentException)1 Message (com.thoughtworks.go.websocket.Message)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1