use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentService method updateAgentAttributes.
public AgentInstance updateAgentAttributes(String uuid, String hostname, String resources, String environments, TriState state) {
AgentInstance agentInstance = agentInstances.findAgent(uuid);
validateThatAgentExists(agentInstance);
Agent agent = getPendingAgentOrFromDB(agentInstance);
if (validateAnyOperationPerformedOnAgent(hostname, environments, resources, state)) {
new AgentUpdateValidator(agentInstance, state).validate();
setAgentAttributes(hostname, resources, environments, state, agent);
saveOrUpdate(agent);
return createFromAgent(agent, systemEnvironment, agentStatusChangeNotifier);
}
return null;
}
use of com.thoughtworks.go.domain.AgentInstance 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.domain.AgentInstance in project gocd by gocd.
the class PluginNotificationServiceTest method shouldConstructDataForAgentNotification.
@Test
public void shouldConstructDataForAgentNotification() {
when(notificationPluginRegistry.getPluginsInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION)).thenReturn(new LinkedHashSet<>(asList(PLUGIN_ID_1)));
when(systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL)).thenReturn(1000L);
AgentInstance agentInstance = AgentInstanceMother.building();
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();
assertThat(data.getUuid(), is(agentInstance.getUuid()));
assertThat(data.getHostName(), is(agentInstance.getHostname()));
assertFalse(data.isElastic());
assertThat(data.getIpAddress(), is(agentInstance.getIpAddress()));
assertThat(data.getFreeSpace(), is(agentInstance.freeDiskSpace().toString()));
assertThat(data.getAgentConfigState(), is(agentInstance.getAgentConfigStatus().name()));
assertThat(data.getAgentState(), is(agentInstance.getRuntimeStatus().agentState().name()));
assertThat(data.getBuildState(), is(agentInstance.getRuntimeStatus().buildState().name()));
}
use of com.thoughtworks.go.domain.AgentInstance 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.domain.AgentInstance in project gocd by gocd.
the class AgentServiceIntegrationTest method getRegisteredAgentsViewModelShouldNotReturnNotRegisteredAgentsViewModel.
@Test
void getRegisteredAgentsViewModelShouldNotReturnNotRegisteredAgentsViewModel() {
AgentInstance idle = AgentInstanceMother.updateUuid(idle(new Date(), "CCeDev01"), UUID);
AgentInstance pending = pending();
AgentInstance building = building();
AgentInstance denied = disabled();
AgentInstances instances = new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), idle, pending, building, denied);
AgentService agentService = newAgentService(instances);
AgentsViewModel agentViewModels = agentService.getRegisteredAgentsViewModel();
assertThat(agentViewModels.size(), is(3));
agentViewModels.forEach(agentViewModel -> assertThat(agentViewModel.getStatus().getConfigStatus(), not(is(Pending))));
}
Aggregations