use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsEntityConfigUpdateCommandTest method shouldThrowExceptionIfElasticAgentResourceIsUpdated.
@Test
public void shouldThrowExceptionIfElasticAgentResourceIsUpdated() throws Exception {
resourcesToAdd.add("firefox");
uuids.add("uuid-1");
AgentInstance agentInstance = mock(AgentInstance.class);
when(agentInstance.isNullAgent()).thenReturn(false);
when(agentInstance.isElastic()).thenReturn(true);
when(agentInstances.findAgent("uuid-1")).thenReturn(agentInstance);
AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
exception.expect(ElasticAgentsResourceUpdateException.class);
exception.expectMessage("Can not update resources on Elastic Agents [uuid-1]");
command.update(cruiseConfig);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsEntityConfigUpdateCommandTest method shouldThrowExceptionIfPendingAgentIsUpdatedWithoutChangingItsState.
@Test
public void shouldThrowExceptionIfPendingAgentIsUpdatedWithoutChangingItsState() throws Exception {
resourcesToAdd.add("firefox");
triState = TriState.UNSET;
AgentInstance agentInstance = AgentInstanceMother.pendingInstance();
AgentConfig agentConfig = agentInstance.agentConfig();
uuids.add(agentConfig.getUuid());
when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
exception.expect(InvalidPendingAgentOperationException.class);
exception.expectMessage(String.format("Invalid operation performed on pending agents: [%s]", agentConfig.getUuid()));
command.update(cruiseConfig);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsEntityConfigUpdateCommandTest method shouldUpdateEnvironmentOfAgents.
@Test
public void shouldUpdateEnvironmentOfAgents() throws Exception {
environmentsToAdd.add("prod");
environmentsToRemove.add("dev");
AgentInstance agentInstance = AgentInstanceMother.disabled();
AgentConfig agentConfig = agentInstance.agentConfig();
cruiseConfig.addEnvironment("dev");
cruiseConfig.addEnvironment("prod");
cruiseConfig.agents().add(agentConfig);
cruiseConfig.getEnvironments().addAgentsToEnvironment("dev", agentConfig.getUuid());
uuids.add(agentConfig.getUuid());
List<String> emptyList = new ArrayList<>();
assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("dev")).getAgents().getUuids(), is(uuids));
assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("prod")).getAgents().getUuids(), is(emptyList));
when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
command.update(cruiseConfig);
assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("dev")).getAgents().getUuids(), is(emptyList));
assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("prod")).getAgents().getUuids(), is(uuids));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsEntityConfigUpdateCommandTest method shouldUpdateResourcesOfAgents.
@Test
public void shouldUpdateResourcesOfAgents() throws Exception {
resourcesToAdd.add("firefox");
resourcesToRemove.add("linux");
AgentInstance agentInstance = AgentInstanceMother.disabled();
AgentConfig agentConfig = agentInstance.agentConfig();
agentConfig.addResourceConfig(new ResourceConfig("linux"));
cruiseConfig.agents().add(agentConfig);
assertThat(agentConfig.getResourceConfigs().resourceNames(), is(Arrays.asList("linux")));
when(agentInstances.findAgent(agentConfig.getUuid())).thenReturn(agentInstance);
uuids.add(agentConfig.getUuid());
AgentsEntityConfigUpdateCommand command = new AgentsEntityConfigUpdateCommand(agentInstances, currentUser, result, uuids, environmentsToAdd, environmentsToRemove, triState, resourcesToAdd, resourcesToRemove, goConfigService);
command.update(cruiseConfig);
assertThat(agentConfig.getResourceConfigs().resourceNames(), is(Arrays.asList("firefox")));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentInstances method allElasticAgentsGroupedByPluginId.
public LinkedMultiValueMap<String, ElasticAgentMetadata> allElasticAgentsGroupedByPluginId() {
LinkedMultiValueMap<String, ElasticAgentMetadata> map = new LinkedMultiValueMap<>();
for (Map.Entry<String, AgentInstance> entry : agentInstances.entrySet()) {
AgentInstance agentInstance = entry.getValue();
if (agentInstance.isElastic()) {
ElasticAgentMetadata metadata = agentInstance.elasticAgentMetadata();
map.add(metadata.elasticPluginId(), metadata);
}
}
return map;
}
Aggregations