Search in sources :

Example 1 with NoWork

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

the class AgentHTTPClientController method retrieveWork.

void retrieveWork() {
    AgentIdentifier agentIdentifier = agentIdentifier();
    LOG.debug("[Agent Loop] {} is checking for work from Go", agentIdentifier);
    Work work;
    try {
        getAgentRuntimeInfo().idle();
        work = server.getWork(getAgentRuntimeInfo());
        if (!(work instanceof NoWork)) {
            LOG.debug("[Agent Loop] Got work from server: [{}]", work.description());
        }
        runner = new JobRunner();
        runner.run(work, agentIdentifier, server, manipulator, getAgentRuntimeInfo(), packageRepositoryExtension, scmExtension, taskExtension);
    } catch (UnregisteredAgentException e) {
        LOG.warn("[Agent Loop] Invalid agent certificate with fingerprint {}. Registering with server on next iteration.", e.getUuid());
        sslInfrastructureService.invalidateAgentCertificate();
    } finally {
        getAgentRuntimeInfo().idle();
    }
}
Also used : UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) 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 2 with NoWork

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

the class WorkFinderTest method shouldReturnNoWorkInCaseOfAnErrorIsThrown.

@Test
public void shouldReturnNoWorkInCaseOfAnErrorIsThrown() {
    BuildAssignmentService assigner = mock(BuildAssignmentService.class);
    IdleAgentTopic idleTopic = mock(IdleAgentTopic.class);
    WorkAssignedTopic assignedTopic = mock(WorkAssignedTopic.class);
    WorkFinder finder = new WorkFinder(assigner, idleTopic, assignedTopic, workAssignmentPerformanceLogger);
    AgentRuntimeInfo runtimeInfo = AgentRuntimeInfo.initialState(AgentMother.approvedAgent());
    when(assigner.assignWorkToAgent(runtimeInfo.getIdentifier())).thenThrow(new OutOfMemoryError("test error for martians"));
    try {
        finder.onMessage(new IdleAgentMessage(runtimeInfo));
        fail("should have propagated error");
    } catch (OutOfMemoryError e) {
        String message = e.getMessage();
        if (message != null && message.equals("test error for martians")) {
        //expected
        } else {
            throw e;
        }
    }
    verify(assignedTopic).post(new WorkAssignedMessage(runtimeInfo.getIdentifier(), new NoWork()));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildAssignmentService(com.thoughtworks.go.server.service.BuildAssignmentService) Test(org.junit.Test)

Example 3 with NoWork

use of com.thoughtworks.go.remote.work.NoWork 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 4 with NoWork

use of com.thoughtworks.go.remote.work.NoWork 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)

Aggregations

NoWork (com.thoughtworks.go.remote.work.NoWork)4 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)3 Work (com.thoughtworks.go.remote.work.Work)3 UnregisteredAgentException (com.thoughtworks.go.domain.exception.UnregisteredAgentException)1 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)1 BuildAssignmentService (com.thoughtworks.go.server.service.BuildAssignmentService)1 Test (org.junit.Test)1