Search in sources :

Example 1 with Agent

use of com.thoughtworks.go.server.websocket.Agent in project gocd by gocd.

the class BuildAssignmentService method matchingJobForRegisteredAgents.

private void matchingJobForRegisteredAgents() {
    Map<String, Agent> agents = agentRemoteHandler.connectedAgents();
    if (agents.isEmpty()) {
        return;
    }
    Long start = System.currentTimeMillis();
    for (Map.Entry<String, Agent> entry : agents.entrySet()) {
        String agentUUId = entry.getKey();
        Agent agent = entry.getValue();
        AgentInstance agentInstance = agentService.findAgentAndRefreshStatus(agentUUId);
        if (!agentInstance.isRegistered()) {
            agent.send(new Message(Action.reregister));
            continue;
        }
        if (agentInstance.isDisabled() || !agentInstance.isIdle()) {
            LOGGER.debug("Ignore agent [{}] that is {} and {}", agentInstance.getAgentIdentifier(), agentInstance.getRuntimeStatus(), agentInstance.getAgentConfigStatus());
            continue;
        }
        Work work = assignWorkToAgent(agentInstance);
        if (work != NO_WORK) {
            if (agentInstance.getSupportsBuildCommandProtocol()) {
                BuildSettings buildSettings = createBuildSettings(((BuildWork) work).getAssignment());
                agent.send(new Message(Action.build, MessageEncoding.encodeData(buildSettings)));
            } else {
                agent.send(new Message(Action.assignWork, MessageEncoding.encodeWork(work)));
            }
        }
    }
    LOGGER.debug("Matching {} agents with {} jobs took: {}ms", agents.size(), jobPlans.size(), System.currentTimeMillis() - start);
}
Also used : Agent(com.thoughtworks.go.server.websocket.Agent) Message(com.thoughtworks.go.websocket.Message)

Aggregations

Agent (com.thoughtworks.go.server.websocket.Agent)1 Message (com.thoughtworks.go.websocket.Message)1