Search in sources :

Example 1 with AgentBuildingInfo

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));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) Test(org.junit.Test)

Example 2 with AgentBuildingInfo

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);
}
Also used : AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) BuildSession(com.thoughtworks.go.buildsession.BuildSession) TaggedStreamConsumer(com.thoughtworks.go.util.command.TaggedStreamConsumer) ConsoleOutputTransmitter(com.thoughtworks.go.remote.work.ConsoleOutputTransmitter) RemoteConsoleAppender(com.thoughtworks.go.remote.work.RemoteConsoleAppender) ArtifactsRepository(com.thoughtworks.go.buildsession.ArtifactsRepository) BuildVariables(com.thoughtworks.go.buildsession.BuildVariables) File(java.io.File)

Example 3 with AgentBuildingInfo

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))));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) Test(org.junit.Test)

Example 4 with AgentBuildingInfo

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))));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) BasicStatusLine(org.apache.http.message.BasicStatusLine) Test(org.junit.Test)

Example 5 with AgentBuildingInfo

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());
}
Also used : AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) TimeProvider(com.thoughtworks.go.util.TimeProvider) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) ArtifactsPublisher(com.thoughtworks.go.remote.work.artifact.ArtifactsPublisher)

Aggregations

AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)18 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)10 Test (org.junit.Test)8 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)2 Property (com.thoughtworks.go.domain.Property)2 TimeProvider (com.thoughtworks.go.util.TimeProvider)2 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ArtifactsRepository (com.thoughtworks.go.buildsession.ArtifactsRepository)1 BuildSession (com.thoughtworks.go.buildsession.BuildSession)1 BuildVariables (com.thoughtworks.go.buildsession.BuildVariables)1 ConsoleOutputTransmitter (com.thoughtworks.go.remote.work.ConsoleOutputTransmitter)1 RemoteConsoleAppender (com.thoughtworks.go.remote.work.RemoteConsoleAppender)1 ArtifactsPublisher (com.thoughtworks.go.remote.work.artifact.ArtifactsPublisher)1 TaggedStreamConsumer (com.thoughtworks.go.util.command.TaggedStreamConsumer)1 File (java.io.File)1