Search in sources :

Example 1 with AgentWorkContext

use of com.thoughtworks.go.remote.work.AgentWorkContext 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 2 with AgentWorkContext

use of com.thoughtworks.go.remote.work.AgentWorkContext in project gocd by gocd.

the class AgentHTTPClientController method retrieveWork.

void retrieveWork() {
    final BuildRepositoryRemote client = remote();
    AgentIdentifier agentIdentifier = agentIdentifier();
    LOG.debug("[Agent Loop] {} is checking for work from Go", agentIdentifier);
    Work work;
    try {
        getAgentRuntimeInfo().idle();
        work = client.getWork(getAgentRuntimeInfo());
        if (!(work instanceof NoWork)) {
            LOG.debug("[Agent Loop] Got work from server: [{}]", work.description());
        }
        runner = new JobRunner();
        final AgentWorkContext agentWorkContext = new AgentWorkContext(agentIdentifier, client, manipulator, getAgentRuntimeInfo(), packageRepositoryExtension, scmExtension, taskExtension, artifactExtension, pluginRequestProcessorRegistry);
        runner.run(work, agentWorkContext);
    } catch (UnregisteredAgentException e) {
        LOG.warn("[Agent Loop] Invalid agent certificate with fingerprint {}. Registering with server on next iteration.", e.getUuid());
        sslInfrastructureService.invalidateAgentCertificate();
    } finally {
        getAgentRuntimeInfo().idle();
    }
}
Also used : UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) BuildRepositoryRemote(com.thoughtworks.go.remote.BuildRepositoryRemote) Work(com.thoughtworks.go.remote.work.Work) NoWork(com.thoughtworks.go.remote.work.NoWork) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentWorkContext(com.thoughtworks.go.remote.work.AgentWorkContext) NoWork(com.thoughtworks.go.remote.work.NoWork)

Aggregations

AgentWorkContext (com.thoughtworks.go.remote.work.AgentWorkContext)2 Work (com.thoughtworks.go.remote.work.Work)2 BuildSettings (com.thoughtworks.go.domain.BuildSettings)1 UnregisteredAgentException (com.thoughtworks.go.domain.exception.UnregisteredAgentException)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 BuildRepositoryRemote (com.thoughtworks.go.remote.BuildRepositoryRemote)1 NoWork (com.thoughtworks.go.remote.work.NoWork)1