Search in sources :

Example 1 with BuildAssignment

use of com.thoughtworks.go.remote.work.BuildAssignment 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 2 with BuildAssignment

use of com.thoughtworks.go.remote.work.BuildAssignment 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));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) Message(com.thoughtworks.go.websocket.Message) 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) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) BuildWork(com.thoughtworks.go.remote.work.BuildWork) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 3 with BuildAssignment

use of com.thoughtworks.go.remote.work.BuildAssignment 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, new EnvironmentVariableContext(), new ArtifactStores());
    BuildWork work = new BuildWork(assignment, "utf-8");
    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().getJobIdentifier().getPipelineName(), is("pipelineName"));
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) 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) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) File(java.io.File) Test(org.junit.Test)

Example 4 with BuildAssignment

use of com.thoughtworks.go.remote.work.BuildAssignment in project gocd by gocd.

the class BuildComposerTest method build.

private void build(String jobXml, String pipelineName, boolean fetchMaterials, boolean cleanWorkingDir) throws Exception {
    BuildAssignment assignment = getAssigment(jobXml, pipelineName, fetchMaterials, cleanWorkingDir);
    final BuildCommand buildCommand = new BuildComposer(assignment).compose();
    buildSession = newBuildSession();
    buildSession.setEnv("GO_SERVER_URL", SERVER_URL);
    buildSession.build(buildCommand);
}
Also used : BuildComposer(com.thoughtworks.go.server.domain.BuildComposer) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment)

Example 5 with BuildAssignment

use of com.thoughtworks.go.remote.work.BuildAssignment 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), new EnvironmentVariableContext(), new ArtifactStores());
        return new BuildWork(buildAssignment, "utf-8");
    } catch (Exception e) {
        throw bomb(e);
    }
}
Also used : ArtifactStores(com.thoughtworks.go.config.ArtifactStores) BuildAssignment(com.thoughtworks.go.remote.work.BuildAssignment) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) 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)

Aggregations

BuildAssignment (com.thoughtworks.go.remote.work.BuildAssignment)7 BuildWork (com.thoughtworks.go.remote.work.BuildWork)6 File (java.io.File)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 ArtifactStores (com.thoughtworks.go.config.ArtifactStores)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)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 JobPlan (com.thoughtworks.go.domain.JobPlan)1 Builder (com.thoughtworks.go.domain.builder.Builder)1 Work (com.thoughtworks.go.remote.work.Work)1 BuildComposer (com.thoughtworks.go.server.domain.BuildComposer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1