Search in sources :

Example 1 with UnregisteredAgentException

use of com.thoughtworks.go.domain.exception.UnregisteredAgentException 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)

Example 2 with UnregisteredAgentException

use of com.thoughtworks.go.domain.exception.UnregisteredAgentException in project gocd by gocd.

the class AgentMutex method associateCookie.

public void associateCookie(final AgentIdentifier agentIdentifier, final String cookie) {
    final String uuid = agentIdentifier.getUuid();
    final String key = agentCacheKey(uuid);
    List<String> uuids = singletonList(agentIdentifier.getUuid());
    AgentMutex mutex = agentMutexes.acquire(uuids);
    synchronized (mutex) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                Agent agent = fetchAgentFromDBByUUID(uuid);
                if (agent == null) {
                    throw new UnregisteredAgentException(format("Agent [%s] is not registered.", uuid), uuid);
                }
                agent.setCookie(cookie);
                getHibernateTemplate().saveOrUpdate(agent);
                final Agent updatedAgent = agent;
                registerAfterCommitCallback(() -> clearCacheAndNotifyAgentEntityChangeListeners(key, updatedAgent));
            }
        });
        agentMutexes.release(uuids, mutex);
    }
}
Also used : Agent(com.thoughtworks.go.config.Agent) UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult)

Example 3 with UnregisteredAgentException

use of com.thoughtworks.go.domain.exception.UnregisteredAgentException in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotBeAbleToAssignCookieToAnUnregisteredAgent.

@Test
void shouldNotBeAbleToAssignCookieToAnUnregisteredAgent() {
    Agent pendingAgent = pending().getAgent();
    AgentIdentifier pendingAgentIdentifier = new AgentIdentifier(pendingAgent.getHostname(), pendingAgent.getIpaddress(), pendingAgent.getUuid());
    UnregisteredAgentException exception = assertThrows(UnregisteredAgentException.class, () -> agentService.assignCookie(pendingAgentIdentifier));
    assertEquals(format("Agent [%s] is not registered.", pendingAgent.getUuid()), exception.getMessage());
}
Also used : UnregisteredAgentException(com.thoughtworks.go.domain.exception.UnregisteredAgentException) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.jupiter.api.Test)

Aggregations

UnregisteredAgentException (com.thoughtworks.go.domain.exception.UnregisteredAgentException)3 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 Agent (com.thoughtworks.go.config.Agent)1 BuildRepositoryRemote (com.thoughtworks.go.remote.BuildRepositoryRemote)1 AgentWorkContext (com.thoughtworks.go.remote.work.AgentWorkContext)1 NoWork (com.thoughtworks.go.remote.work.NoWork)1 Work (com.thoughtworks.go.remote.work.Work)1 Test (org.junit.jupiter.api.Test)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1