use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class DefaultSchedulingContext method permittedAgent.
@Override
public SchedulingContext permittedAgent(String permittedAgentUuid) {
Agents permitted = new Agents();
for (Agent agent : agents) {
if (agent.getUuid().equals(permittedAgentUuid)) {
permitted.add(agent);
}
}
DefaultSchedulingContext context = new DefaultSchedulingContext(approvedBy, permitted, profiles, clusterProfiles);
context.variables = variables.overrideWith(new EnvironmentVariablesConfig());
context.rerun = rerun;
return context;
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class PluginNotificationServiceTest method shouldConstructDataForElasticAgentNotification.
@Test
public void shouldConstructDataForElasticAgentNotification() {
when(notificationPluginRegistry.getPluginsInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION)).thenReturn(new LinkedHashSet<>(asList(PLUGIN_ID_1)));
when(systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL)).thenReturn(1000L);
ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
Agent agent = new Agent("some-uuid");
agent.setElasticAgentId("42");
agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
agent.setIpaddress("127.0.0.1");
AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
agentInstance.update(agentRuntimeInfo);
pluginNotificationService.notifyAgentStatus(agentInstance);
ArgumentCaptor<PluginNotificationMessage> captor = ArgumentCaptor.forClass(PluginNotificationMessage.class);
verify(pluginNotificationsQueueHandler).post(captor.capture(), eq(1000L));
PluginNotificationMessage message = captor.getValue();
assertThat(message.pluginId(), is(PLUGIN_ID_1));
assertThat(message.getRequestName(), is(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION));
assertThat(message.getData() instanceof AgentNotificationData, is(true));
AgentNotificationData data = (AgentNotificationData) message.getData();
assertTrue(data.isElastic());
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.
@Test
public void shouldNotifyIfAgentIsElastic() {
ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
Agent agent = new Agent("some-uuid");
agent.setElasticAgentId("42");
agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
agent.setIpaddress("127.0.0.1");
AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
agentInstance.update(agentRuntimeInfo);
when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
verify(pluginNotificationService).notifyAgentStatus(agentInstance);
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobControllerIntegrationTest method jobDetailModel_shouldNotHaveElasticPluginIdAndElasticAgentIdForACompletedJob.
@Test
public void jobDetailModel_shouldNotHaveElasticPluginIdAndElasticAgentIdForACompletedJob() throws Exception {
Pipeline pipeline = fixture.createdPipelineWithAllStagesPassed();
Stage stage = pipeline.getFirstStage();
JobInstance job = stage.getFirstJob();
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());
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 shouldNotRegisterElasticAgentWithDuplicateElasticAgentID.
@Test
public void shouldNotRegisterElasticAgentWithDuplicateElasticAgentID() {
String uuid = UUID.randomUUID().toString();
String elasticAgentId = UUID.randomUUID().toString();
MockHttpServletRequest request = new MockHttpServletRequest();
controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", ephemeralAutoRegisterKeyService.autoRegisterKey(), "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
Agent agent = agentService.getAgentByUUID(uuid);
assertTrue(agent.isElastic());
final ResponseEntity responseEntity = controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", ephemeralAutoRegisterKeyService.autoRegisterKey(), "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
assertThat(responseEntity.getStatusCode(), is(UNPROCESSABLE_ENTITY));
assertThat(responseEntity.getBody(), is("Duplicate Elastic agent Id used to register elastic agent."));
}
Aggregations