Search in sources :

Example 1 with Work

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));
}
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 2 with Work

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

Example 3 with Work

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Test(org.junit.Test)

Example 4 with Work

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));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) NoWork(com.thoughtworks.go.remote.work.NoWork) NoWork(com.thoughtworks.go.remote.work.NoWork) Test(org.junit.Test)

Example 5 with Work

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()));
}
Also used : BuildWork(com.thoughtworks.go.remote.work.BuildWork) Work(com.thoughtworks.go.remote.work.Work) DeniedAgentWork(com.thoughtworks.go.remote.work.DeniedAgentWork) Test(org.junit.jupiter.api.Test)

Aggregations

Work (com.thoughtworks.go.remote.work.Work)23 BuildWork (com.thoughtworks.go.remote.work.BuildWork)16 Test (org.junit.jupiter.api.Test)11 NoWork (com.thoughtworks.go.remote.work.NoWork)10 DeniedAgentWork (com.thoughtworks.go.remote.work.DeniedAgentWork)7 AgentInstance (com.thoughtworks.go.domain.AgentInstance)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 Test (org.junit.Test)3 AgentWorkContext (com.thoughtworks.go.remote.work.AgentWorkContext)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)1 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)1 BuildSettings (com.thoughtworks.go.domain.BuildSettings)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 UnregisteredAgentException (com.thoughtworks.go.domain.exception.UnregisteredAgentException)1 ElasticAgentPluginRegistry (com.thoughtworks.go.plugin.access.elastic.ElasticAgentPluginRegistry)1 BuildRepositoryRemote (com.thoughtworks.go.remote.BuildRepositoryRemote)1 BuildAssignment (com.thoughtworks.go.remote.work.BuildAssignment)1 ServerMaintenanceMode (com.thoughtworks.go.server.domain.ServerMaintenanceMode)1 JobStatusMessage (com.thoughtworks.go.server.messaging.JobStatusMessage)1