use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldAutoRegisterRemoteAgent.
@Test
public void shouldAutoRegisterRemoteAgent() {
System.setProperty(AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
String uuid = UUID.randomUUID().toString();
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, goConfigService.serverConfig().getAgentAutoRegisterKey(), "", "", null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isIdle());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
assertThat(responseEntity.getBody().toString(), is(""));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys.
@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys() {
String uuid = UUID.randomUUID().toString();
agentService.saveOrUpdate(new Agent(uuid, "hostname", "127.0.01", uuidGenerator.randomUuid()));
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, goConfigService.serverConfig().getAgentAutoRegisterKey(), "", "", null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isIdle());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getBody().toString(), is(""));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstancesTest method createElasticAgentInstance.
private AgentInstance createElasticAgentInstance(int counter, String elasticPluginId) {
String uuid = UUID.randomUUID().toString();
String ip = "127.0.0.1";
String host = "localhost";
String elasticAgentId = "elastic-agent-id-" + counter;
AgentIdentifier id = new AgentIdentifier(host, ip, uuid);
ElasticAgentRuntimeInfo elasticRuntime = new ElasticAgentRuntimeInfo(id, Idle, "/foo/one", null, elasticAgentId, elasticPluginId);
Agent elasticAgent = createElasticAgent(uuid, ip, elasticAgentId, elasticPluginId);
AgentInstance elasticAgentInstance = createFromAgent(elasticAgent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
elasticAgentInstance.update(elasticRuntime);
return elasticAgentInstance;
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentService method approve.
@Deprecated
public void approve(String uuid) {
AgentInstance agentInstance = findAgentAndRefreshStatus(uuid);
boolean doesAgentExistAndIsRegistered = isRegistered(agentInstance.getUuid());
agentInstance.enable();
if (doesAgentExistAndIsRegistered) {
LOGGER.warn("Registered agent with the same uuid [{}] already approved.", agentInstance);
} else {
Agent agent = agentInstance.getAgent();
if (!agent.cookieAssigned()) {
generateAndAddCookie(agent);
}
saveOrUpdate(agent);
}
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentService method killAllRunningTasksOnAgent.
public void killAllRunningTasksOnAgent(String uuid) throws InvalidAgentInstructionException {
AgentInstance agentInstance = agentInstances.findAgent(uuid);
if (agentInstance.isNullAgent()) {
throw new RecordNotFoundException(format("Agent with uuid: '%s' not found", uuid));
}
agentInstance.killRunningTasks();
}
Aggregations