Search in sources :

Example 6 with AgentBuildingInfo

use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.

the class SleepWork method doWork.

@Override
public void doWork(EnvironmentVariableContext environmentVariableContext, AgentWorkContext agentWorkContext) {
    cancelLatch = new CountDownLatch(1);
    agentWorkContext.getAgentRuntimeInfo().busy(new AgentBuildingInfo("sleepwork", "sleepwork1"));
    boolean canceled = false;
    DefaultGoPublisher goPublisher = new DefaultGoPublisher(agentWorkContext.getArtifactsManipulator(), new JobIdentifier(), agentWorkContext.getRepositoryRemote(), agentWorkContext.getAgentRuntimeInfo(), "utf-8");
    try {
        if (this.sleepInMilliSeconds > 0) {
            canceled = cancelLatch.await(this.sleepInMilliSeconds, TimeUnit.MILLISECONDS);
        }
        String result = canceled ? "done_canceled" : "done";
        agentWorkContext.getArtifactsManipulator().setProperty(null, new Property(name + "_result", result));
        SystemEnvironment systemEnvironment = new SystemEnvironment();
        if (systemEnvironment.isConsoleLogsThroughWebsocketEnabled() && systemEnvironment.isWebsocketsForAgentsEnabled()) {
            goPublisher.consumeLine(format("Sleeping for %s milliseconds", this.sleepInMilliSeconds));
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) CountDownLatch(java.util.concurrent.CountDownLatch) Property(com.thoughtworks.go.domain.Property)

Example 7 with AgentBuildingInfo

use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.

the class AgentStatusReportingTest method expectedAgentRuntimeInfo.

private AgentRuntimeInfo expectedAgentRuntimeInfo() {
    AgentRuntimeInfo info = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
    info.setBuildingInfo(new AgentBuildingInfo("pipeline1/100/mingle/100/run-ant", "pipeline1/100/mingle/100/run-ant"));
    info.cancel();
    return info;
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo)

Example 8 with AgentBuildingInfo

use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.

the class AgentInstanceTest method shouldBeAbleToDenyAgentThatIsRunningCancelledJob.

@Test
public void shouldBeAbleToDenyAgentThatIsRunningCancelledJob() {
    AgentConfig config = new AgentConfig("UUID", "A", "127.0.0.1");
    AgentInstance agent = new AgentInstance(config, LOCAL, systemEnvironment, mock(AgentStatusChangeListener.class));
    agent.cancel();
    AgentBuildingInfo cancelled = agent.getBuildingInfo();
    assertThat(agent.canDisable(), is(true));
    agent.deny();
    assertThat(config.isDisabled(), is(true));
    assertThat(agent.getStatus(), is(AgentStatus.Disabled));
    assertThat(agent.getBuildingInfo(), is(cancelled));
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.Test)

Example 9 with AgentBuildingInfo

use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.

the class AgentInstanceTest method shouldUpdateBuildingInfoWhenAgentIsBuilding.

@Test
public void shouldUpdateBuildingInfoWhenAgentIsBuilding() throws Exception {
    AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, systemEnvironment, mock(AgentStatusChangeListener.class));
    AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
    AgentBuildingInfo buildingInfo = new AgentBuildingInfo("running pipeline/stage/build", "buildLocator");
    agentRuntimeInfo.busy(buildingInfo);
    agentInstance.update(agentRuntimeInfo);
    assertThat(agentInstance.getBuildingInfo(), is(buildingInfo));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.Test)

Example 10 with AgentBuildingInfo

use of com.thoughtworks.go.server.service.AgentBuildingInfo in project gocd by gocd.

the class AgentInstanceTest method shouldNotifyAgentChangeListenerOnAgentBuilding.

@Test
public void shouldNotifyAgentChangeListenerOnAgentBuilding() throws Exception {
    AgentInstance idleAgent = AgentInstance.createFromConfig(agentConfig("abc"), new SystemEnvironment(), agentStatusChangeListener);
    idleAgent.building(new AgentBuildingInfo("running pipeline/stage/build", "buildLocator"));
    verify(agentStatusChangeListener).onAgentStatusChange(idleAgent);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) Test(org.junit.Test)

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