use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class JobInstanceStatusMonitorTest method shouldSendCancelMessageIfJobIsCancelled.
@Test
public void shouldSendCancelMessageIfJobIsCancelled() throws Exception {
AgentConfig agentConfig = AgentMother.remoteAgent();
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(1));
Work work = MessageEncoding.decodeWork(agent.messages.get(0).getData());
assertThat(work, instanceOf(BuildWork.class));
BuildAssignment assignment = ((BuildWork) work).getAssignment();
final JobInstance instance = jobInstanceService.buildByIdWithTransitions(assignment.getJobIdentifier().getBuildId());
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jobInstanceService.cancelJob(instance);
}
});
assertThat(agent.messages.size(), is(2));
assertThat(agent.messages.get(1).getAction(), is(Action.cancelBuild));
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class AgentWebSocketClientController method process.
void process(Message message) throws InterruptedException {
switch(message.getAction()) {
case cancelBuild:
cancelJobIfThereIsOneRunning();
cancelBuild();
break;
case setCookie:
String cookie = MessageEncoding.decodeData(message.getData(), String.class);
getAgentRuntimeInfo().setCookie(cookie);
LOG.info("Got cookie: {}", cookie);
break;
case assignWork:
cancelJobIfThereIsOneRunning();
Work work = MessageEncoding.decodeWork(message.getData());
LOG.debug("Got work from server: [{}]", work.description());
runner = new JobRunner();
try {
runner.run(work, new AgentWorkContext(agentIdentifier(), new BuildRepositoryRemoteAdapter(runner, webSocketSessionHandler), manipulator, getAgentRuntimeInfo(), packageRepositoryExtension, scmExtension, taskExtension, artifactExtension, pluginRequestProcessorRegistry));
} finally {
getAgentRuntimeInfo().idle();
updateServerAgentRuntimeInfo();
}
break;
case build:
cancelBuild();
BuildSettings buildSettings = MessageEncoding.decodeData(message.getData(), BuildSettings.class);
runBuild(buildSettings);
break;
case reregister:
LOG.warn("Reregister: invalidate current agent certificate fingerprint {} and stop websocket webSocketClient.", getAgentRegistry().uuid());
webSocketSessionHandler.stop();
sslInfrastructureService.invalidateAgentCertificate();
break;
case acknowledge:
webSocketSessionHandler.acknowledge(message);
break;
default:
throw new RuntimeException("Unknown action: " + message.getAction());
}
}
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));
}
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));
}
use of com.thoughtworks.go.remote.work.Work in project gocd by gocd.
the class BuildAssignmentServiceIntegrationTest method shouldNotScheduleIfAgentDoesNotHaveResources.
@Test
public void shouldNotScheduleIfAgentDoesNotHaveResources() throws Exception {
JobConfig plan = evolveConfig.findBy(new CaseInsensitiveString(STAGE_NAME)).jobConfigByInstanceName("unit", true);
plan.addResourceConfig("some-resource");
scheduleHelper.schedule(evolveConfig, modifySomeFiles(evolveConfig), DEFAULT_APPROVED_BY);
Work work = buildAssignmentService.assignWorkToAgent(agent(AgentMother.localAgent()));
Pipeline pipeline = pipelineDao.mostRecentPipeline(CaseInsensitiveString.str(evolveConfig.name()));
JobInstance job = pipeline.findStage(STAGE_NAME).findJob("unit");
assertThat(work, is(BuildAssignmentService.NO_WORK));
assertThat(job.getState(), is(JobState.Scheduled));
assertThat(job.getAgentUuid(), is(nullValue()));
}
Aggregations