use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentMutex method fetchAgentFromDBByUUID.
public Agent fetchAgentFromDBByUUID(final String uuid) {
List<String> uuids = singletonList(uuid);
AgentMutex mutex = agentMutexes.acquire(uuids);
synchronized (mutex) {
Agent agent = (Agent) transactionTemplate.execute((TransactionCallback) transactionStatus -> {
Query query = sessionFactory.getCurrentSession().createQuery("FROM Agent where uuid = :uuid and deleted = false");
query.setCacheable(true);
query.setParameter("uuid", uuid);
return query.uniqueResult();
});
agentMutexes.release(uuids, mutex);
return agent;
}
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldNotRelyOnAutoRegisterKeyForRegisteringElasticAgents.
@Test
public void shouldNotRelyOnAutoRegisterKeyForRegisteringElasticAgents() {
String uuid = "elastic-uuid";
String autoRegisterKey = "auto_register_key";
final ServerConfig serverConfig = mockedServerConfig("token-generation-key", autoRegisterKey);
final String token = token(uuid, serverConfig.getTokenGenerationKey());
when(agentService.isRegistered(uuid)).thenReturn(false);
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
when(ephemeralAutoRegisterKeyService.validateAndRevoke(any())).thenReturn(false);
controller.agentRequest("host", uuid, "location", "233232", "osx", autoRegisterKey, "", "e1", "", "elastic-agent-id", "elastic-plugin-id", token, request);
verify(agentService, never()).register(any(Agent.class));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentInstance method createFromLiveAgent.
public static AgentInstance createFromLiveAgent(AgentRuntimeInfo agentRuntimeInfo, SystemEnvironment sysEnv, AgentStatusChangeListener agentStatusChangeListener) {
Agent agent = agentRuntimeInfo.agent();
AgentType type = agent.isFromLocalHost() ? AgentType.LOCAL : AgentType.REMOTE;
AgentInstance instance;
if (sysEnv.isAutoRegisterLocalAgentEnabled() && agent.isFromLocalHost()) {
instance = new AgentInstance(agent, type, sysEnv, agentStatusChangeListener, agentRuntimeInfo);
instance.agentConfigStatus = Enabled;
instance.agentRuntimeInfo.idle();
instance.update(agentRuntimeInfo);
return instance;
} else {
instance = new AgentInstance(agent, type, sysEnv, agentStatusChangeListener);
instance.update(agentRuntimeInfo);
}
return instance;
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentMother method localAgentWithResources.
public static Agent localAgentWithResources(String... resources) {
Agent agent = localAgent();
agent.setResourcesFromList(asList(resources));
return agent;
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class ScheduleServiceRescheduleHungJobsTest method activities.
private AgentInstances activities() {
AgentStatusChangeListener agentStatusChangeListener = mock(AgentStatusChangeListener.class);
final AgentInstances activities = new AgentInstances(agentStatusChangeListener);
SystemEnvironment systemEnvironment = new SystemEnvironment();
activities.add(AgentInstance.createFromAgent(new Agent("uuid1"), systemEnvironment, agentStatusChangeListener));
activities.add(AgentInstance.createFromAgent(new Agent("uuid2"), systemEnvironment, agentStatusChangeListener));
return activities;
}
Aggregations