Search in sources :

Example 1 with BuildWork

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);
    }
}
Also used : BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) File(java.io.File) BuildWork(com.thoughtworks.go.remote.work.BuildWork) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) IOException(java.io.IOException) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 2 with BuildWork

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);
    }
}
Also used : JobPlan(com.thoughtworks.go.domain.JobPlan) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) File(java.io.File) BuildWork(com.thoughtworks.go.remote.work.BuildWork) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) IOException(java.io.IOException) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause)

Example 3 with BuildWork

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"));
}
Also used : Materials(com.thoughtworks.go.config.materials.Materials) ArrayList(java.util.ArrayList) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) BuildWork(com.thoughtworks.go.remote.work.BuildWork) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) ByteArrayInputStream(java.io.ByteArrayInputStream) File(java.io.File) Test(org.junit.Test)

Example 4 with BuildWork

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));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) JobPlan(com.thoughtworks.go.domain.JobPlan) JobInstance(com.thoughtworks.go.domain.JobInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionStatus(org.springframework.transaction.TransactionStatus) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 5 with BuildWork

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);
}
Also used : BuildWork(com.thoughtworks.go.remote.work.BuildWork)

Aggregations

BuildWork (com.thoughtworks.go.remote.work.BuildWork)11 BuildAssignment (com.thoughtworks.go.remote.work.BuildAssignment)4 File (java.io.File)4 JobPlan (com.thoughtworks.go.domain.JobPlan)3 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 Builder (com.thoughtworks.go.domain.builder.Builder)2 Message (com.thoughtworks.go.websocket.Message)2 IOException (java.io.IOException)2 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 Materials (com.thoughtworks.go.config.materials.Materials)1 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)1 FetchArtifactBuilder (com.thoughtworks.go.domain.builder.FetchArtifactBuilder)1 Work (com.thoughtworks.go.remote.work.Work)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1