use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.
the class AgentStatusReportingIntegrationTest method shouldReportBuildingWhenAgentRunningBuildWork.
@Test
public void shouldReportBuildingWhenAgentRunningBuildWork() throws Exception {
Work work = BuildWorkTest.getWork(WILL_PASS, BuildWorkTest.PIPELINE_NAME);
work.doWork(agentIdentifier, buildRepository, artifactManipulator, environmentVariableContext, agentRuntimeInfo, null, null, null);
AgentRuntimeInfo agentRuntimeInfo1 = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
agentRuntimeInfo1.busy(new AgentBuildingInfo("pipeline1/100/mingle/100/run-ant", "pipeline1/100/mingle/100/run-ant"));
assertThat(agentRuntimeInfo, is(agentRuntimeInfo1));
}
use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.
the class AgentWebSocketClientController method runBuild.
private void runBuild(BuildSettings buildSettings) {
URLService urlService = new URLService();
TaggedStreamConsumer buildConsole;
if (getSystemEnvironment().isConsoleLogsThroughWebsocketEnabled()) {
buildConsole = new ConsoleOutputWebsocketTransmitter(webSocketSessionHandler, buildSettings.getBuildId());
} else {
buildConsole = new ConsoleOutputTransmitter(new RemoteConsoleAppender(urlService.prefixPartialUrl(buildSettings.getConsoleUrl()), httpService, buildSettings.getConsoleLogCharset()));
}
ArtifactsRepository artifactsRepository = new UrlBasedArtifactsRepository(httpService, urlService.prefixPartialUrl(buildSettings.getArtifactUploadBaseUrl()), urlService.prefixPartialUrl(buildSettings.getPropertyBaseUrl()), new ZipUtil());
DefaultBuildStateReporter buildStateReporter = new DefaultBuildStateReporter(webSocketSessionHandler, getAgentRuntimeInfo());
TimeProvider clock = new TimeProvider();
BuildVariables buildVariables = new BuildVariables(getAgentRuntimeInfo(), clock);
BuildSession build = new BuildSession(buildSettings.getBuildId(), getAgentRuntimeInfo().getIdentifier(), buildStateReporter, buildConsole, buildVariables, artifactsRepository, httpService, clock, new File("."), buildSettings.getConsoleLogCharset());
this.buildSession.set(build);
build.setEnv("GO_SERVER_URL", getSystemEnvironment().getServiceUrl());
getAgentRuntimeInfo().idle();
try {
getAgentRuntimeInfo().busy(new AgentBuildingInfo(buildSettings.getBuildLocatorForDisplay(), buildSettings.getBuildLocator()));
build.build(buildSettings.getBuildCommand());
} finally {
try {
buildConsole.stop();
} finally {
getAgentRuntimeInfo().idle();
}
}
this.buildSession.set(null);
}
use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processBuildCommandWithConsoleLogsThroughWebSockets.
@Test
public void processBuildCommandWithConsoleLogsThroughWebSockets() throws Exception {
ArgumentCaptor<Message> currentStatusMessageCaptor = ArgumentCaptor.forClass(Message.class);
when(systemEnvironment.isConsoleLogsThroughWebsocketEnabled()).thenReturn(true);
when(agentRegistry.uuid()).thenReturn(agentUuid);
agentController = createAgentController();
agentController.init();
BuildSettings build = new BuildSettings();
build.setBuildId("b001");
build.setConsoleUrl("http://foo.bar/console");
build.setArtifactUploadBaseUrl("http://foo.bar/artifacts");
build.setPropertyBaseUrl("http://foo.bar/properties");
build.setBuildLocator("build1");
build.setBuildLocatorForDisplay("build1ForDisplay");
build.setBuildCommand(BuildCommand.compose(BuildCommand.echo("building"), BuildCommand.reportCurrentStatus(JobState.Building)));
agentController.process(new Message(Action.build, MessageEncoding.encodeData(build)));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
AgentRuntimeInfo agentRuntimeInfo = cloneAgentRuntimeInfo(agentController.getAgentRuntimeInfo());
agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
verify(webSocketSessionHandler, times(3)).sendAndWaitForAcknowledgement(currentStatusMessageCaptor.capture());
Message consoleOutMsg = currentStatusMessageCaptor.getAllValues().get(0);
assertThat(consoleOutMsg.getAcknowledgementId(), notNullValue());
assertThat(consoleOutMsg.getAction(), is(Action.consoleOut));
ConsoleTransmission ct = MessageEncoding.decodeData(consoleOutMsg.getData(), ConsoleTransmission.class);
assertThat(ct.getLine(), RegexMatcher.matches("building"));
assertEquals(ct.getBuildId(), "b001");
Message message = currentStatusMessageCaptor.getAllValues().get(1);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.reportCurrentStatus));
assertThat(message.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", JobState.Building, null))));
Message jobCompletedMessage = currentStatusMessageCaptor.getAllValues().get(2);
assertThat(jobCompletedMessage.getAcknowledgementId(), notNullValue());
assertThat(jobCompletedMessage.getAction(), is(Action.reportCompleted));
assertThat(jobCompletedMessage.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", null, JobResult.Passed))));
}
use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.
the class AgentWebSocketClientControllerTest method processBuildCommand.
@Test
public void processBuildCommand() throws Exception {
ArgumentCaptor<Message> currentStatusMessageCaptor = ArgumentCaptor.forClass(Message.class);
when(agentRegistry.uuid()).thenReturn(agentUuid);
CloseableHttpResponse httpResponse = mock(CloseableHttpResponse.class);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
when(httpService.execute(any())).thenReturn(httpResponse);
agentController = createAgentController();
agentController.init();
BuildSettings build = new BuildSettings();
build.setBuildId("b001");
build.setConsoleUrl("http://foo.bar/console");
build.setArtifactUploadBaseUrl("http://foo.bar/artifacts");
build.setPropertyBaseUrl("http://foo.bar/properties");
build.setBuildLocator("build1");
build.setBuildLocatorForDisplay("build1ForDisplay");
build.setBuildCommand(BuildCommand.compose(BuildCommand.echo("building"), BuildCommand.reportCurrentStatus(JobState.Building)));
agentController.process(new Message(Action.build, MessageEncoding.encodeData(build)));
assertThat(agentController.getAgentRuntimeInfo().getRuntimeStatus(), is(AgentRuntimeStatus.Idle));
AgentRuntimeInfo agentRuntimeInfo = cloneAgentRuntimeInfo(agentController.getAgentRuntimeInfo());
agentRuntimeInfo.busy(new AgentBuildingInfo("build1ForDisplay", "build1"));
verify(webSocketSessionHandler, times(2)).sendAndWaitForAcknowledgement(currentStatusMessageCaptor.capture());
Message message = currentStatusMessageCaptor.getAllValues().get(0);
assertThat(message.getAcknowledgementId(), notNullValue());
assertThat(message.getAction(), is(Action.reportCurrentStatus));
assertThat(message.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", JobState.Building, null))));
Message jobCompletedMessage = currentStatusMessageCaptor.getAllValues().get(1);
assertThat(jobCompletedMessage.getAcknowledgementId(), notNullValue());
assertThat(jobCompletedMessage.getAction(), is(Action.reportCompleted));
assertThat(jobCompletedMessage.getData(), is(MessageEncoding.encodeData(new Report(agentRuntimeInfo, "b001", null, JobResult.Passed))));
}
use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.
the class BuildWork method initialize.
private void initialize(AgentWorkContext agentWorkContext) {
JobIdentifier jobIdentifier = assignment.getJobIdentifier();
this.timeProvider = new TimeProvider();
agentWorkContext.getAgentRuntimeInfo().busy(new AgentBuildingInfo(jobIdentifier.buildLocatorForDisplay(), jobIdentifier.buildLocator()));
this.workingDirectory = assignment.getWorkingDirectory();
this.materialRevisions = assignment.materialRevisions();
this.goPublisher = new DefaultGoPublisher(agentWorkContext.getArtifactsManipulator(), jobIdentifier, agentWorkContext.getRepositoryRemote(), agentWorkContext.getAgentRuntimeInfo(), consoleLogCharset);
this.artifactsPublisher = new ArtifactsPublisher(goPublisher, agentWorkContext.getArtifactExtension(), assignment.getArtifactStores(), agentWorkContext.getPluginRequestProcessorRegistry(), workingDirectory);
this.builders = new Builders(assignment.getBuilders(), goPublisher, agentWorkContext.getTaskExtension(), agentWorkContext.getArtifactExtension(), agentWorkContext.getPluginRequestProcessorRegistry());
}
Aggregations