use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldNotRemoveAgentFromNonExistingEnvironment.
@Test
public void shouldNotRemoveAgentFromNonExistingEnvironment() 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);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
ArrayList<String> environmentsToRemove = new ArrayList<>();
environmentsToRemove.add("NonExistingEnvironment");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), environmentsToRemove, TriState.TRUE);
assertFalse(result.isSuccessful());
assertThat(result.toString(), result.httpCode(), is(400));
assertThat(result.toString(), containsString("RESOURCE_NOT_FOUND"));
assertThat(result.toString(), containsString("NonExistingEnvironment"));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldNotAddAgentToNonExistingEnvironment.
@Test
public void shouldNotAddAgentToNonExistingEnvironment() 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);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
ArrayList<String> environmentsToAdd = new ArrayList<>();
environmentsToAdd.add("Non-Existing-Environment");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), environmentsToAdd, new ArrayList<>(), TriState.TRUE);
assertFalse(result.isSuccessful());
assertThat(result.toString(), result.httpCode(), is(400));
assertThat(result.toString(), containsString("RESOURCE_NOT_FOUND"));
assertThat(result.toString(), containsString("Non-Existing-Environment"));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldNotUpdateResourcesOnElasticAgents.
@Test
public void shouldNotUpdateResourcesOnElasticAgents() throws Exception {
AgentConfig elasticAgent = AgentMother.elasticAgent();
AgentInstance agentInstance = AgentInstance.createFromConfig(elasticAgent, new SystemEnvironment(), getAgentStatusChangeListener());
agentInstances.add(agentInstance);
agentConfigService.addAgent(elasticAgent, Username.ANONYMOUS);
CruiseConfig cruiseConfig = goConfigDao.load();
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
List<String> uuids = Arrays.asList(elasticAgent.getUuid());
List<String> resourcesToAdd = Arrays.asList("resource");
assertTrue(cruiseConfig.agents().getAgentByUuid(elasticAgent.getUuid()).getResourceConfigs().isEmpty());
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resourcesToAdd, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
cruiseConfig = goConfigDao.load();
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.badRequest(LocalizedMessage.string("CAN_NOT_UPDATE_RESOURCES_ON_ELASTIC_AGENT", uuids));
assertThat(result, is(expectedResult));
assertTrue(cruiseConfig.agents().getAgentByUuid(elasticAgent.getUuid()).getResourceConfigs().isEmpty());
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldEnableTheProvidedAgents.
@Test
public void shouldEnableTheProvidedAgents() 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");
agentConfig1.disable();
agentConfig2.disable();
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(true));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(true));
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.TRUE);
cruiseConfig = goConfigDao.load();
assertTrue(result.isSuccessful());
assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceIntegrationTest method shouldUpdateResourcesEnvironmentsAndAgentStateOfTheProvidedStatesAllTogether.
@Test
public void shouldUpdateResourcesEnvironmentsAndAgentStateOfTheProvidedStatesAllTogether() 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();
BasicEnvironmentConfig environment = new BasicEnvironmentConfig(new CaseInsensitiveString("Dev"));
goConfigDao.addEnvironment(environment);
assertThat(environment.getAgents().getUuids(), not(containsInAnyOrder(agentConfig1.getUuid(), agentConfig2.getUuid())));
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertFalse(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(0));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(0));
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ArrayList<String> uuids = new ArrayList<>();
uuids.add(agentConfig1.getUuid());
uuids.add(agentConfig2.getUuid());
ArrayList<String> resources = new ArrayList<>();
resources.add("resource1");
ArrayList<String> environmentsToAdd = new ArrayList<>();
environmentsToAdd.add("Dev");
agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resources, new ArrayList<>(), environmentsToAdd, new ArrayList<>(), TriState.FALSE);
cruiseConfig = goConfigDao.load();
assertTrue(result.isSuccessful());
assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled());
assertTrue(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled());
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs(), contains(new ResourceConfig("resource1")));
assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs(), contains(new ResourceConfig("resource1")));
assertThat(cruiseConfig.getEnvironments().find(new CaseInsensitiveString("Dev")).getAgents().getUuids(), containsInAnyOrder(agentConfig1.getUuid(), agentConfig2.getUuid()));
}
Aggregations