use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class DefaultBuildStateReporter method reportCompleted.
@Override
public void reportCompleted(String buildId, JobResult buildResult) {
Report report = new Report(agentRuntimeInfo, buildId, null, buildResult);
webSocketSessionHandler.sendAndWaitForAcknowledgement(new Message(Action.reportCompleted, MessageEncoding.encodeData(report)));
}
use of com.thoughtworks.go.websocket.Message 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()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Ignore agent [{}] that is {}", agentInstance.getAgentIdentifier().toString(), agentInstance.getStatus());
}
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)));
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Matching {} agents with {} jobs took: {}ms", agents.size(), jobPlans.size(), System.currentTimeMillis() - start);
}
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldNotAssignDeniedAgentWorkToAgentsRegisteredInAgentRemoteHandler.
@Test
public void shouldNotAssignDeniedAgentWorkToAgentsRegisteredInAgentRemoteHandler() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
agentConfig.disable();
configHelper.addAgent(agentConfig);
fixture.createPipelineWithFirstStageScheduled();
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
buildAssignmentService.onTimer();
assertThat(agent.messages.size(), is(0));
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler.
@Test
public void shouldOnlyAssignWorkToIdleAgentsRegisteredInAgentRemoteHandler() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
fixture.createPipelineWithFirstStageScheduled();
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
AgentStatus[] statuses = new AgentStatus[] { AgentStatus.Building, AgentStatus.Pending, AgentStatus.Disabled, AgentStatus.Disabled, AgentStatus.LostContact, AgentStatus.Missing };
for (AgentStatus status : statuses) {
info.setStatus(status);
agent = new AgentStub();
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
buildAssignmentService.onTimer();
assertThat("Should not assign work when agent status is " + status, agent.messages.size(), is(0));
}
}
use of com.thoughtworks.go.websocket.Message in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldNotAssignNoWorkToAgentsRegisteredInAgentRemoteHandler.
@Test
public void shouldNotAssignNoWorkToAgentsRegisteredInAgentRemoteHandler() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
configHelper.addAgent(agentConfig);
fixture.createdPipelineWithAllStagesPassed();
AgentRuntimeInfo info = AgentRuntimeInfo.fromServer(agentConfig, true, "location", 1000000l, "OS", false);
info.setCookie("cookie");
agentRemoteHandler.process(agent, new Message(Action.ping, MessageEncoding.encodeData(info)));
buildAssignmentService.onTimer();
assertThat(agent.messages.size(), is(0));
}
Aggregations