use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.
@Test
public void shouldNotifyIfAgentIsElastic() throws Exception {
ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
AgentConfig agentConfig = new AgentConfig();
agentConfig.setElasticAgentId("42");
agentConfig.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
agentConfig.setIpAddress("127.0.0.1");
AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
agentInstance.update(agentRuntimeInfo);
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();
assertTrue(data.isElastic());
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstancesTest method shouldReturnFirstMatchedAgentsWhenHostNameHasMoreThanOneMatch.
@Test
public void shouldReturnFirstMatchedAgentsWhenHostNameHasMoreThanOneMatch() throws Exception {
AgentInstance agent = AgentInstance.createFromConfig(new AgentConfig("uuid20", "CCeDev01", "10.18.5.20"), systemEnvironment, null);
AgentInstance duplicatedAgent = AgentInstance.createFromConfig(new AgentConfig("uuid21", "CCeDev01", "10.18.5.20"), systemEnvironment, null);
AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, agent, duplicatedAgent);
AgentInstance byHostname = agentInstances.findFirstByHostname("CCeDev01");
assertThat(byHostname, is(agent));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigService method deleteAgents.
public void deleteAgents(Username currentUser, AgentInstance... agentInstances) {
GoConfigDao.CompositeConfigCommand commandForDeletingAgents = commandForDeletingAgents(agentInstances);
ArrayList<String> uuids = new ArrayList<>();
for (AgentInstance agentInstance : agentInstances) {
uuids.add(agentInstance.getUuid());
}
updateAgentWithoutValidations(commandForDeletingAgents, currentUser);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigService method updateAgentAttributes.
public AgentConfig updateAgentAttributes(final String uuid, Username username, String hostname, String resources, String environments, TriState enable, AgentInstances agentInstances, HttpOperationResult result) {
final GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
if (!goConfigService.hasAgent(uuid) && enable.isTrue()) {
AgentInstance agentInstance = agentInstances.findAgent(uuid);
AgentConfig agentConfig = agentInstance.agentConfig();
command.addCommand(new AddAgentCommand(agentConfig));
}
if (enable.isTrue()) {
command.addCommand(new UpdateAgentApprovalStatus(uuid, false));
}
if (enable.isFalse()) {
command.addCommand(new UpdateAgentApprovalStatus(uuid, true));
}
if (hostname != null) {
command.addCommand(new UpdateAgentHostname(uuid, hostname, username.getUsername().toString()));
}
if (resources != null) {
command.addCommand(new UpdateResourcesCommand(uuid, new ResourceConfigs(resources)));
}
if (environments != null) {
Set<String> existingEnvironments = goConfigService.getCurrentConfig().getEnvironments().environmentsForAgent(uuid);
Set<String> newEnvironments = new HashSet<>(asList(environments.split(",")));
Set<String> environmentsToRemove = Sets.difference(existingEnvironments, newEnvironments);
Set<String> environmentsToAdd = Sets.difference(newEnvironments, existingEnvironments);
for (String environmentToRemove : environmentsToRemove) {
command.addCommand(new ModifyEnvironmentCommand(uuid, environmentToRemove, TriStateSelection.Action.remove));
}
for (String environmentToAdd : environmentsToAdd) {
command.addCommand(new ModifyEnvironmentCommand(uuid, environmentToAdd, TriStateSelection.Action.add));
}
}
return updateAgent(command, uuid, result, username);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentService method populateAgentInstancesForUUIDs.
private boolean populateAgentInstancesForUUIDs(OperationResult operationResult, List<String> uuids, List<AgentInstance> agents) {
for (String uuid : uuids) {
AgentInstance agentInstance = findAgentAndRefreshStatus(uuid);
if (isUnknownAgent(agentInstance, operationResult)) {
return false;
}
agents.add(agentInstance);
}
return true;
}
Aggregations