Search in sources :

Example 91 with AgentRuntimeInfo

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

the class BuildWorkEnvironmentVariablesTest method shouldSetUpP4ClientEnvironmentVariableEnvironmentContextCorrectly.

@Test
public void shouldSetUpP4ClientEnvironmentVariableEnvironmentContextCorrectly() {
    new SystemEnvironment().setProperty("serviceUrl", "some_random_place");
    BuildWork work = getBuildWorkWithP4MaterialRevision(p4Material);
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    AgentIdentifier agentIdentifier = new AgentIdentifier("somename", "127.0.0.1", AGENT_UUID);
    work.doWork(environmentVariableContext, new AgentWorkContext(agentIdentifier, new FakeBuildRepositoryRemote(), new GoArtifactsManipulatorStub(), new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension, null, null));
    assertThat(environmentVariableContext.getProperty("GO_REVISION"), is("10"));
    assertThat(environmentVariableContext.getProperty("GO_SERVER_URL"), is("some_random_place"));
    assertThat(environmentVariableContext.getProperty("GO_TRIGGER_USER"), is(TRIGGERED_BY_USER));
    assertThat(environmentVariableContext.getProperty("GO_P4_CLIENT"), is(p4Material.clientName(dir)));
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) FakeBuildRepositoryRemote(com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) Test(org.junit.Test)

Example 92 with AgentRuntimeInfo

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

the class AgentRemoteHandler method processWithoutAcknowledgement.

public void processWithoutAcknowledgement(Agent agent, Message msg) throws Exception {
    switch(msg.getAction()) {
        case ping:
            AgentRuntimeInfo info = MessageEncoding.decodeData(msg.getData(), AgentRuntimeInfo.class);
            if (!sessionIds.containsKey(agent)) {
                LOGGER.info("{} is connected with websocket {}", info.getIdentifier(), agent);
                sessionIds.put(agent, info.getUUId());
                this.agentSessions.put(info.getUUId(), agent);
            }
            if (info.getCookie() == null) {
                String cookie = agentCookie.get(agent);
                if (cookie == null) {
                    cookie = buildRepositoryRemote.getCookie(info.getIdentifier(), info.getLocation());
                    agentCookie.put(agent, cookie);
                }
                info.setCookie(cookie);
                agent.send(new Message(Action.setCookie, MessageEncoding.encodeData(cookie)));
            }
            AgentInstruction instruction = this.buildRepositoryRemote.ping(info);
            if (instruction.isShouldCancelJob()) {
                agent.send(new Message(Action.cancelBuild));
            }
            break;
        case reportCurrentStatus:
            Report report = MessageEncoding.decodeData(msg.getData(), Report.class);
            buildRepositoryRemote.reportCurrentStatus(report.getAgentRuntimeInfo(), findJobIdentifier(report), report.getJobState());
            break;
        case reportCompleting:
            report = MessageEncoding.decodeData(msg.getData(), Report.class);
            buildRepositoryRemote.reportCompleting(report.getAgentRuntimeInfo(), findJobIdentifier(report), report.getResult());
            break;
        case reportCompleted:
            report = MessageEncoding.decodeData(msg.getData(), Report.class);
            buildRepositoryRemote.reportCompleted(report.getAgentRuntimeInfo(), findJobIdentifier(report), report.getResult());
            break;
        case consoleOut:
            ConsoleTransmission consoleTransmission = MessageEncoding.decodeData(msg.getData(), ConsoleTransmission.class);
            File consoleLogFile = consoleService.consoleLogFile(findJobIdentifier(consoleTransmission));
            consoleService.updateConsoleLog(consoleLogFile, consoleTransmission.getLineAsStream());
            break;
        default:
            throw new RuntimeException("Unknown action: " + msg.getAction());
    }
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstruction(com.thoughtworks.go.remote.AgentInstruction) File(java.io.File)

Example 93 with AgentRuntimeInfo

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

the class AgentInstanceMother method updateOS.

public static AgentInstance updateOS(AgentInstance agentInstance, String operatingSystem) {
    AgentConfig agentConfig = agentInstance.agentConfig();
    AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.fromServer(agentConfig, true, agentInstance.getLocation(), agentInstance.getUsableSpace(), operatingSystem, false);
    newRuntimeInfo.setStatus(agentInstance.getStatus());
    agentInstance.update(newRuntimeInfo);
    return agentInstance;
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo)

Example 94 with AgentRuntimeInfo

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

the class AgentInstanceMother method missing.

public static AgentInstance missing() {
    AgentConfig agentConfig = new AgentConfig("1234", "localhost", "192.168.0.1");
    AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.initialState(agentConfig);
    newRuntimeInfo.setStatus(AgentStatus.Missing);
    instance.update(newRuntimeInfo);
    return instance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Example 95 with AgentRuntimeInfo

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

the class AgentInstanceMother method lostContact.

public static AgentInstance lostContact(String buildLocator) {
    AgentConfig agentConfig = new AgentConfig("1234", "localhost", "192.168.0.1");
    AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    AgentRuntimeInfo newRuntimeInfo = AgentRuntimeInfo.initialState(agentConfig);
    newRuntimeInfo.setStatus(AgentStatus.LostContact);
    newRuntimeInfo.setUsableSpace(1000L);
    newRuntimeInfo.setBuildingInfo(new AgentBuildingInfo("buildInfo", buildLocator));
    instance.update(newRuntimeInfo);
    return instance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Aggregations

AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)123 Test (org.junit.Test)101 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)34 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)26 File (java.io.File)16 AgentInstruction (com.thoughtworks.go.remote.AgentInstruction)13 StringContains.containsString (org.hamcrest.core.StringContains.containsString)13 FakeBuildRepositoryRemote (com.thoughtworks.go.agent.testhelpers.FakeBuildRepositoryRemote)12 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)11 UploadEntry (com.thoughtworks.go.matchers.UploadEntry)10 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)10 ArrayList (java.util.ArrayList)10 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)9 AgentInstance (com.thoughtworks.go.domain.AgentInstance)7 Before (org.junit.Before)7 Expectations (org.jmock.Expectations)4 RunIf (com.googlecode.junit.ext.RunIf)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)3 Date (java.util.Date)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3