Search in sources :

Example 86 with AgentInstance

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"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 87 with AgentInstance

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"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 88 with AgentInstance

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());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 89 with AgentInstance

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());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 90 with AgentInstance

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()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)129 Test (org.junit.Test)61 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)32 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)32 ArrayList (java.util.ArrayList)21 Agent (com.thoughtworks.go.config.Agent)20 Test (org.junit.jupiter.api.Test)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 AgentConfig (com.thoughtworks.go.config.AgentConfig)16 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)12 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)10 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)10 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)8 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)8 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)7 ResponseEntity (org.springframework.http.ResponseEntity)7 BuildWork (com.thoughtworks.go.remote.work.BuildWork)6 NoWork (com.thoughtworks.go.remote.work.NoWork)6 Work (com.thoughtworks.go.remote.work.Work)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6