use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class ElasticAgentRequestProcessorTest method shouldProcessDeleteAgentRequest.
@Test
public void shouldProcessDeleteAgentRequest() throws Exception {
AgentMetadata agent = new AgentMetadata("foo", null, null, null);
DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DELETE_AGENTS, "1.0", pluginIdentifier);
goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
processor.process(pluginDescriptor, goPluginApiRequest);
verify(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentRemoteHandler method remove.
public void remove(Agent agent) {
agentCookie.remove(agent);
String uuid = sessionIds.remove(agent);
if (uuid == null) {
return;
}
agentSessions.remove(uuid);
AgentInstance instance = agentService.findAgent(uuid);
if (instance != null) {
instance.lostContact();
LOGGER.info("{} lost contact because websocket connection is closed", instance.getAgentIdentifier());
}
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceTest method shouldEnableAgentWhenAlreadyInTheConfig.
@Test
public void shouldEnableAgentWhenAlreadyInTheConfig() {
String agentId = DatabaseAccessHelper.AGENT_UUID;
AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
agentConfig.disable();
AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), null);
when(goConfigService.currentCruiseConfig()).thenReturn(mock(CruiseConfig.class));
when(goConfigService.hasAgent(agentConfig.getUuid())).thenReturn(true);
agentConfigService.enableAgents(Username.ANONYMOUS, instance);
shouldPerformCommand(new GoConfigDao.CompositeConfigCommand((UpdateConfigCommand) new AgentConfigService.UpdateAgentApprovalStatus(agentId, false)));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceTest method shouldEnableAgentWhenPending.
@Test
public void shouldEnableAgentWhenPending() {
String agentId = DatabaseAccessHelper.AGENT_UUID;
AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromAgent(new AgentIdentifier("remote-host", "50.40.30.20", agentId), AgentRuntimeStatus.Unknown, "cookie", false);
AgentInstance instance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment(), null);
agentConfigService.enableAgents(Username.ANONYMOUS, instance);
shouldPerformCommand(new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(agentConfig)));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentStatusChangeNotifierTest method shouldNotifyInterestedPluginsWithAgentInformation.
@Test
public void shouldNotifyInterestedPluginsWithAgentInformation() {
AgentInstance agentInstance = AgentInstanceMother.building();
when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
verify(pluginNotificationQueue).post(captor.capture());
assertThat(captor.getValue().getData() instanceof AgentNotificationData, is(true));
AgentNotificationData data = (AgentNotificationData) captor.getValue().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()));
}
Aggregations