use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldDisableTheProvidedAgents.
@Test
public void shouldDisableTheProvidedAgents() 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);
agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
cruiseConfig = goConfigDao.load();
assertTrue(result.isSuccessful());
assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldDeleteAgentFromConfigFileGivenUUID.
@Test
public void shouldDeleteAgentFromConfigFileGivenUUID() throws Exception {
AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "test1", "192.168.0.1");
AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "test2", "192.168.0.2");
AgentInstance fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
agentConfigService.deleteAgents(Username.ANONYMOUS, fromConfigFile1);
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().hasAgent(agentConfig1.getUuid()), is(false));
assertThat(cruiseConfig.agents().hasAgent(agentConfig2.getUuid()), is(true));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldThrowBadRequestIfNoOperationsProvidedOnBulkUpdateAgents.
@Test
public void shouldThrowBadRequestIfNoOperationsProvidedOnBulkUpdateAgents() throws Exception {
AgentInstance pendingAgent = AgentInstanceMother.pending();
AgentInstance registeredAgent = AgentInstanceMother.disabled();
agentInstances.add(pendingAgent);
agentInstances.add(registeredAgent);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(pendingAgent.getUuid());
uuids.add(registeredAgent.getUuid());
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.UNSET);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.badRequest(LocalizedMessage.string("NO_OPERATION_PERFORMED_ON_AGENTS"));
assertThat(result, is(expectedResult));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldAllowEnablingThePendingAndDisabledAgentsTogether.
@Test
public void shouldAllowEnablingThePendingAndDisabledAgentsTogether() throws Exception {
AgentInstance pendingAgent = AgentInstanceMother.pending();
agentInstances.add(pendingAgent);
assertThat(pendingAgent.isRegistered(), is(false));
AgentConfig agentConfig = new AgentConfig(UUID.randomUUID().toString(), "remote-host1", "50.40.30.21");
agentConfig.disable();
AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), getAgentStatusChangeListener());
agentInstances.add(agentInstance);
agentConfigService.addAgent(agentConfig, Username.ANONYMOUS);
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig.getUuid()).isDisabled(), is(true));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(pendingAgent.getUuid());
uuids.add(agentConfig.getUuid());
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.TRUE);
assertTrue(result.isSuccessful());
assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().getAgentByUuid(pendingAgent.getUuid()).isEnabled(), is(true));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig.getUuid()).isEnabled(), is(true));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldNotDisableAgentsWhenInvalidAgentUUIDIsprovided.
@Test
public void shouldNotDisableAgentsWhenInvalidAgentUUIDIsprovided() 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);
agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
CruiseConfig cruiseConfig = goConfigDao.load();
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
uuids.add("invalid-uuid");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
cruiseConfig = goConfigDao.load();
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
assertFalse(result.isSuccessful());
assertThat(result.toString(), result.httpCode(), is(400));
assertTrue(result.toString(), result.toString().contains("RESOURCE_NOT_FOUND"));
assertTrue(result.toString(), result.toString().contains("invalid-uuid"));
}
Aggregations