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();
}
}
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);
}
}
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());
}
Aggregations