Search in sources :

Example 6 with Work

use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.

the class JobAssignmentTest method shouldAssignJobToLocalAgentEvenReachedLimit.

@Test
public void shouldAssignJobToLocalAgentEvenReachedLimit() throws UnknownHostException {
    AgentInstance local = setupLocalAgent();
    AgentInstance remote = setupRemoteAgent();
    fixture.createPipelineWithFirstStageScheduled();
    assignmentService.onTimer();
    assignmentService.assignWorkToAgent(remote);
    Work work = assignmentService.assignWorkToAgent(local);
    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 7 with Work

use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.

the class JobAssignmentTest method shouldNotAssignJobToRemoteAgentIfReachedLimit.

@Test
public void shouldNotAssignJobToRemoteAgentIfReachedLimit() throws UnknownHostException {
    AgentInstance local = setupLocalAgent();
    AgentInstance remote = setupRemoteAgent();
    AgentInstance remote2 = setupRemoteAgent();
    fixture.createPipelineWithFirstStageScheduled();
    assignmentService.onConfigChange(null);
    assignmentService.assignWorkToAgent(local);
    assignmentService.assignWorkToAgent(remote);
    Work work = assignmentService.assignWorkToAgent(remote2);
    assertThat(work, instanceOf(NoWork.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) NoWork(com.thoughtworks.go.remote.work.NoWork) Test(org.junit.Test)

Example 8 with Work

use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.

the class WorkAssignments method getWork.

public Work getWork(AgentRuntimeInfo runtimeInfo) {
    AgentIdentifier agent = runtimeInfo.getIdentifier();
    synchronized (agentMutex(agent)) {
        Work work = assignments.get(agent);
        if (work == null) {
            assignments.put(agent, NO_WORK);
            idleAgentsTopic.post(new IdleAgentMessage(runtimeInfo));
            return NO_WORK;
        }
        if (work instanceof NoWork) {
            return work;
        }
        return assignments.remove(agent);
    }
}
Also used : Work(com.thoughtworks.go.remote.work.Work) NoWork(com.thoughtworks.go.remote.work.NoWork) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) NoWork(com.thoughtworks.go.remote.work.NoWork)

Example 9 with Work

use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.

the class WorkAssignments method onMessage.

public void onMessage(WorkAssignedMessage message) {
    AgentIdentifier agentIdentifier = message.getAgent();
    Work work = message.getWork();
    if (work instanceof NoWork) {
        synchronized (agentMutex(agentIdentifier)) {
            assignments.remove(agentIdentifier);
        }
    } else {
        synchronized (agentMutex(agentIdentifier)) {
            assignments.replace(agentIdentifier, NO_WORK, work);
        }
    }
}
Also used : Work(com.thoughtworks.go.remote.work.Work) NoWork(com.thoughtworks.go.remote.work.NoWork) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) NoWork(com.thoughtworks.go.remote.work.NoWork)

Example 10 with Work

use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.

the class BuildRepositoryMessageProducer method getWork.

public Work getWork(AgentRuntimeInfo runtimeInfo) {
    long startTime = System.currentTimeMillis();
    Work work = workAssignments.getWork(runtimeInfo);
    workAssignmentPerformanceLogger.retrievedWorkForAgent(runtimeInfo, work, startTime, System.currentTimeMillis());
    return work;
}
Also used : Work(com.thoughtworks.go.remote.work.Work)

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