use of com.thoughtworks.go.remote.work.BuildWork in project gocd by gocd.
the class DefaultWorkCreator method getWork.
public Work getWork(AgentIdentifier agentIdentifier) {
try {
CruiseConfig config = GoConfigMother.pipelineHavingJob(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, ARTIFACT_FILE.getAbsolutePath(), ARTIFACT_FOLDER.getAbsolutePath());
BuildCause buildCause = BuildCause.createWithEmptyModifications();
BuildAssignment buildAssignment = BuildAssignment.create(toPlan(config), buildCause, new ArrayList<>(), new File("testdata/" + CruiseConfig.WORKING_BASE_DIR + STAGE_NAME));
return new BuildWork(buildAssignment);
} catch (Exception e) {
throw bomb(e);
}
}
use of com.thoughtworks.go.remote.work.BuildWork in project gocd by gocd.
the class LongWorkCreator method getWork.
public Work getWork() {
try {
CruiseConfig config = GoConfigMother.pipelineHavingJob(PIPELINE_NAME, STAGE_NAME, JOB_PLAN_NAME, ARTIFACT_FILE.getAbsolutePath(), ARTIFACT_FOLDER.getAbsolutePath());
BuildCause buildCause = BuildCause.createWithEmptyModifications();
builder = new ArrayList<>();
builder.add(new SleepBuilder());
JobPlan instance = toBuildInstance(config);
BuildAssignment buildAssignment = BuildAssignment.create(instance, buildCause, builder, new File(CruiseConfig.WORKING_BASE_DIR + PIPELINE_NAME));
return new BuildWork(buildAssignment);
} catch (Exception e) {
throw bomb(e);
}
}
use of com.thoughtworks.go.remote.work.BuildWork in project gocd by gocd.
the class MessageTest method encodeAndDecodeAssignWorkWithDifferentBuilders.
@Test
public void encodeAndDecodeAssignWorkWithDifferentBuilders() throws Exception {
File workingDir = new File(CruiseConfig.WORKING_BASE_DIR + "pipelineName");
Materials materials = MaterialsMother.defaultMaterials();
MaterialRevisions revisions = ModificationsMother.modifyOneFile(materials, ModificationsMother.nextRevision());
BuildCause buildCause = BuildCause.createWithModifications(revisions, "");
List<Builder> builder = new ArrayList<>();
builder.add(new CommandBuilder("command", "args", workingDir, new RunIfConfigs(), new NullBuilder(), "desc"));
builder.add(new BuilderForKillAllChildTask());
builder.add(new CommandBuilderWithArgList("command", new String[] { "arg1", "arg2" }, workingDir, new RunIfConfigs(), new NullBuilder(), "desc"));
builder.add(new FetchArtifactBuilder(new RunIfConfigs(), new NullBuilder(), "desc", jobPlan().getIdentifier(), "srcdir", "dest", new FileHandler(workingDir, "src"), new ChecksumFileHandler(workingDir)));
BuildAssignment assignment = BuildAssignment.create(jobPlan(), buildCause, builder, workingDir);
BuildWork work = new BuildWork(assignment);
byte[] msg = MessageEncoding.encodeMessage(new Message(Action.assignWork, MessageEncoding.encodeWork(work)));
Message decodedMsg = MessageEncoding.decodeMessage(new ByteArrayInputStream(msg));
BuildWork decodedWork = (BuildWork) MessageEncoding.decodeWork(decodedMsg.getData());
assertThat(decodedWork.getAssignment().getPlan().getPipelineName(), is("pipelineName"));
}
use of com.thoughtworks.go.remote.work.BuildWork 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));
JobPlan jobPlan = ((BuildWork) work).getAssignment().getPlan();
final JobInstance instance = jobInstanceService.buildByIdWithTransitions(jobPlan.getJobId());
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.BuildWork in project gocd by gocd.
the class WorkAssignmentPerformanceLogger method assignedWorkToAgent.
public void assignedWorkToAgent(Work work, AgentIdentifier agentIdentifier, long assignWorkStartTime, long assignWorkEndTime) {
if (work == null || !(work instanceof BuildWork)) {
return;
}
BuildWork buildWork = (BuildWork) work;
performanceLogger.log("WORK-ASSIGNED {} {} {} {}", agentIdentifier.getUuid(), buildWork.identifierForLogging(), assignWorkStartTime, assignWorkEndTime);
}
Aggregations