Search in sources :

Example 21 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentsEntityConfigUpdateCommandTest method shouldThrowExceptionIfAgentWithUUIDNotFound.

@Test
public void shouldThrowExceptionIfAgentWithUUIDNotFound() throws Exception {
    uuids.add("uuid-1");
    AgentInstance agentInstance = mock(AgentInstance.class);
    when(agentInstance.isNullAgent()).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(NoSuchAgentException.class);
    exception.expectMessage("Agents [uuid-1] could not be found");
    command.update(cruiseConfig);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Test(org.junit.Test)

Example 22 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentsEntityConfigUpdateCommandTest method shouldUpdateConfigStateOfAgents.

@Test
public void shouldUpdateConfigStateOfAgents() throws Exception {
    AgentInstance agentInstance = AgentInstanceMother.disabled();
    AgentConfig agentConfig = agentInstance.agentConfig();
    agentConfig.disable();
    cruiseConfig.agents().add(agentConfig);
    assertThat(agentConfig.isEnabled(), is(false));
    triState = TriState.TRUE;
    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);
    command.update(cruiseConfig);
    assertThat(agentConfig.isEnabled(), is(true));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) Test(org.junit.Test)

Example 23 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldEnableMultipleAgents.

@Test
public void shouldEnableMultipleAgents() {
    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 fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    AgentInstance fromConfigFile2 = AgentInstance.createFromConfig(agentConfig2, new SystemEnvironment(), getAgentStatusChangeListener());
    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(agentConfig1.getUuid()).isDisabled(), is(true));
    agentConfigService.enableAgents(Username.ANONYMOUS, fromConfigFile1, fromConfigFile2);
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Test(org.junit.Test)

Example 24 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAddResourcestoTheSpecifiedAgents.

@Test
public void shouldAddResourcestoTheSpecifiedAgents() 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()).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");
    resources.add("resource2");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resources, new ArrayList<>(), 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(2));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs(), containsInAnyOrder(new ResourceConfig("resource1"), new ResourceConfig("resource2")));
}
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 25 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.

the class AgentConfigServiceIntegrationTest method shouldAddProvidedAgentsToTheSpecifiedEnvironments.

@Test
public void shouldAddProvidedAgentsToTheSpecifiedEnvironments() 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);
    BasicEnvironmentConfig environment = new BasicEnvironmentConfig(new CaseInsensitiveString("Dev"));
    goConfigDao.addEnvironment(environment);
    assertFalse(environment.hasAgent(agentConfig1.getUuid()));
    assertFalse(environment.hasAgent(agentConfig2.getUuid()));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> environmentsToAdd = new ArrayList<>();
    environmentsToAdd.add("Dev");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), environmentsToAdd, new ArrayList<>(), TriState.TRUE);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertThat(goConfigDao.load().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)95 Test (org.junit.Test)68 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)27 ArrayList (java.util.ArrayList)21 AgentConfig (com.thoughtworks.go.config.AgentConfig)20 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)17 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)9 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)9 AgentInstances (com.thoughtworks.go.server.domain.AgentInstances)7 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)7 Username (com.thoughtworks.go.server.domain.Username)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)5 ResponseEntity (org.springframework.http.ResponseEntity)4 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3 BuildWork (com.thoughtworks.go.remote.work.BuildWork)3 NoWork (com.thoughtworks.go.remote.work.NoWork)3 Work (com.thoughtworks.go.remote.work.Work)3 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)3 AgentViewModel (com.thoughtworks.go.server.ui.AgentViewModel)3