use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInConfig.
@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInConfig() {
System.setProperty(AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
final String uuid = UUID.randomUUID().toString();
agentService.saveOrUpdate(new Agent(uuid, "hostname", "127.0.01", uuidGenerator.randomUuid()));
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
final ResponseEntity responseEntity = controller.getToken(uuid);
assertThat(responseEntity.getStatusCode(), is(CONFLICT));
assertThat(responseEntity.getBody(), is("A token has already been issued for this agent."));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobControllerIntegrationTest method jobDetailModel_shouldHaveTheElasticPluginIdAndElasticAgentIdWhenAgentIsAssigned.
@Test
public void jobDetailModel_shouldHaveTheElasticPluginIdAndElasticAgentIdWhenAgentIsAssigned() throws Exception {
Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
Stage stage = pipeline.getFirstStage();
JobInstance job = stage.getFirstJob();
GoPluginDescriptor.About about = GoPluginDescriptor.About.builder().name("name").version("0.1").targetGoVersion("17.3.0").description("desc").build();
GoPluginDescriptor descriptor = GoPluginDescriptor.builder().id("plugin_id").about(about).build();
ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, null, new Capabilities(false, true)));
ElasticProfile profile = new ElasticProfile("profile_id", "cluster_profile_id", Collections.EMPTY_LIST);
ClusterProfile clusterProfile = new ClusterProfile("cluster_profile_id", "plugin_id", Collections.EMPTY_LIST);
fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), profile, clusterProfile));
final Agent agent = new Agent(job.getAgentUuid(), "localhost", "127.0.0.1", uuidGenerator.randomUuid());
agent.setElasticAgentId("elastic_agent_id");
agent.setElasticPluginId("plugin_id");
agentService.saveOrUpdate(agent);
ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
assertThat(modelAndView.getModel().get("elasticAgentPluginId"), is("plugin_id"));
assertThat(modelAndView.getModel().get("elasticAgentId"), is("elastic_agent_id"));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobControllerIntegrationTest method jobDetailModel_shouldNotHaveTheElasticProfilePluginIdAndElasticAgentIdWhenAgentIsNotElasticAgent.
@Test
public void jobDetailModel_shouldNotHaveTheElasticProfilePluginIdAndElasticAgentIdWhenAgentIsNotElasticAgent() throws Exception {
Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
Stage stage = pipeline.getFirstStage();
JobInstance job = stage.getFirstJob();
final Agent agent = new Agent(job.getAgentUuid(), "localhost", "127.0.0.1", uuidGenerator.randomUuid());
agentService.saveOrUpdate(agent);
ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
assertNull(modelAndView.getModel().get("elasticAgentPluginId"));
assertNull(modelAndView.getModel().get("elasticAgentId"));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInPendingState.
@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInPendingState() {
System.setProperty(AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
final String uuid = UUID.randomUUID().toString();
final AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(new Agent(uuid, "hostname", "127.0.01"), false, "sandbox", 0l, "linux");
agentService.requestRegistration(agentRuntimeInfo);
final AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isPending());
final ResponseEntity responseEntity = controller.getToken(uuid);
assertThat(responseEntity.getStatusCode(), is(CONFLICT));
assertThat(responseEntity.getBody(), is("A token has already been issued for this agent."));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRegisterLocalAgent.
@Test
public void shouldRegisterLocalAgent() {
System.setProperty(AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "true");
String uuid = UUID.randomUUID().toString();
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
Agent agent = agentService.getAgentByUUID(uuid);
assertThat(agent.getHostname(), is("hostname"));
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
assertThat(responseEntity.getBody().toString(), is(""));
}
Aggregations