use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class JobAssignmentTest method shouldAssignJobToRemoteAgent.
@Test
public void shouldAssignJobToRemoteAgent() throws UnknownHostException {
AgentInstance local = setupLocalAgent();
AgentInstance remote = setupRemoteAgent();
fixture.createPipelineWithFirstStageScheduled();
assignmentService.onTimer();
assignmentService.assignWorkToAgent(local);
assignmentService.onTimer();
Work work = assignmentService.assignWorkToAgent(remote);
assertThat(work, instanceOf(BuildWork.class));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldRemoveAgentFromEnvironmentBeforeDeletingAgent.
@Test
public void shouldRemoveAgentFromEnvironmentBeforeDeletingAgent() throws Exception {
AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "hostname", "127.0.0.1");
AgentInstance fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "hostname", "127.0.0.1");
agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
BasicEnvironmentConfig env = new BasicEnvironmentConfig(new CaseInsensitiveString(UUID.randomUUID().toString()));
env.addAgent(agentConfig1.getUuid());
env.addAgent(agentConfig2.getUuid());
goConfigDao.addEnvironment(env);
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().size(), is(2));
agentConfigService.deleteAgents(Username.ANONYMOUS, fromConfigFile1);
cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().size(), is(1));
assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().get(0).getUuid(), is(agentConfig2.getUuid()));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldNotAllowAnyUpdateOperationOnPendingAgentsIfConfigStateIsNotProvided.
@Test
public void shouldNotAllowAnyUpdateOperationOnPendingAgentsIfConfigStateIsNotProvided() throws Exception {
AgentInstance pendingAgent = AgentInstanceMother.pending();
agentInstances.add(pendingAgent);
assertThat(pendingAgent.isRegistered(), is(false));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(pendingAgent.getUuid());
ArrayList<String> resourcesToAdd = new ArrayList<>();
resourcesToAdd.add("Linux");
ArrayList<String> resourcesToRemove = new ArrayList<>();
resourcesToRemove.add("Gauge");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resourcesToAdd, resourcesToRemove, new ArrayList<>(), new ArrayList<>(), TriState.UNSET);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.badRequest(LocalizedMessage.string("PENDING_AGENT_INVALID_OPERATION", uuids));
assertThat(result, is(expectedResult));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldDeleteMultipleAgents.
@Test
public void shouldDeleteMultipleAgents() {
AgentConfig agentConfig1 = new AgentConfig("UUID1", "remote-host1", "50.40.30.21");
AgentConfig agentConfig2 = new AgentConfig("UUID2", "remote-host2", "50.40.30.22");
agentConfig1.disable();
agentConfig2.disable();
AgentInstance fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
AgentInstance fromConfigFile2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
GoConfigDao.CompositeConfigCommand command = agentConfigService.commandForDeletingAgents(fromConfigFile1, fromConfigFile2);
List<UpdateConfigCommand> commands = command.getCommands();
assertThat(commands.size(), is(2));
String uuid1 = (String) ReflectionUtil.getField(commands.get(0), "uuid");
String uuid2 = (String) ReflectionUtil.getField(commands.get(1), "uuid");
assertThat(uuid1, is("UUID1"));
assertThat(uuid2, is("UUID2"));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldRemoveResourcesFromTheSpecifiedAgents.
@Test
public void shouldRemoveResourcesFromTheSpecifiedAgents() throws Exception {
AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "remote-host2", "50.40.30.22");
AgentInstance agentInstance1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
AgentInstance agentInstance2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
agentInstances.add(agentInstance1);
agentInstances.add(agentInstance2);
agentConfig1.addResourceConfig(new ResourceConfig("resource-1"));
agentConfig1.addResourceConfig(new ResourceConfig("resource-2"));
agentConfig2.addResourceConfig(new ResourceConfig("resource-2"));
agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(2));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(1));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
ArrayList<String> resources = new ArrayList<>();
resources.add("resource-2");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), resources, new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
cruiseConfig = goConfigDao.load();
assertTrue(result.isSuccessful());
assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(1));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs(), contains(new ResourceConfig("resource-1")));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(0));
}
Aggregations