Search in sources :

Example 31 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldNotEnableAgentsWhenInvalidAgentUUIDIsprovided.

@Test
public void shouldNotEnableAgentsWhenInvalidAgentUUIDIsprovided() 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(agentConfig2.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.TRUE);
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).isDisabled(), is(false));
    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"));
}
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 32 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldRemoveProvidedAgentsFromTheSpecifiedEnvironments.

@Test
public void shouldRemoveProvidedAgentsFromTheSpecifiedEnvironments() 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 devEnvironment = new BasicEnvironmentConfig(new CaseInsensitiveString("Dev"));
    BasicEnvironmentConfig testEnvironment = new BasicEnvironmentConfig(new CaseInsensitiveString("Test"));
    goConfigDao.addEnvironment(devEnvironment);
    goConfigDao.addEnvironment(testEnvironment);
    testEnvironment.addAgent(agentConfig1.getUuid());
    devEnvironment.addAgent(agentConfig1.getUuid());
    devEnvironment.addAgent(agentConfig2.getUuid());
    assertThat(devEnvironment.getAgents().getUuids(), containsInAnyOrder(agentConfig1.getUuid(), agentConfig2.getUuid()));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> environmentsToRemove = new ArrayList<>();
    environmentsToRemove.add("Dev");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), environmentsToRemove, TriState.TRUE);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("BULK_AGENT_UPDATE_SUCESSFUL"));
    assertFalse(goConfigDao.load().getEnvironments().find(new CaseInsensitiveString("Dev")).hasAgent(agentConfig1.getUuid()));
    assertFalse(goConfigDao.load().getEnvironments().find(new CaseInsensitiveString("Dev")).hasAgent(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)

Example 33 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldDisablePendingAgents.

@Test
public void shouldDisablePendingAgents() 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());
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), TriState.FALSE);
    assertTrue(result.isSuccessful());
    assertTrue(result.toString(), result.toString().contains("BULK_AGENT_UPDATE_SUCESSFUL"));
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(pendingAgent.getUuid()).isDisabled(), is(true));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with AgentInstance

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

the class AgentServiceIntegrationTest method enabledAgents_shouldNotIncludePendingAgents.

@Test
public void enabledAgents_shouldNotIncludePendingAgents() throws Exception {
    AgentInstance idle = AgentInstanceMother.updateUuid(AgentInstanceMother.idle(new Date(), "CCeDev01"), UUID);
    AgentInstance pending = AgentInstanceMother.pending();
    AgentInstance building = AgentInstanceMother.building();
    AgentInstance denied = AgentInstanceMother.disabled();
    createEnvironment("uat");
    EnvironmentConfig environment = environmentConfigService.named("uat");
    environment.addAgent(UUID);
    AgentInstances instances = new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), idle, pending, building, denied);
    AgentService agentService = getAgentService(instances);
    AgentsViewModel agents = agentService.registeredAgents();
    assertThat(agents.size(), is(3));
    for (AgentViewModel agent : agents) {
        assertThat(agent.getStatus().getConfigStatus(), not(is(AgentConfigStatus.Pending)));
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentsViewModel(com.thoughtworks.go.server.ui.AgentsViewModel) AgentViewModel(com.thoughtworks.go.server.ui.AgentViewModel) Test(org.junit.Test)

Example 35 with AgentInstance

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

the class AgentServiceIntegrationTest method shouldChangeAgentToIdleWhenAgentIsReApprovedInConfigFile.

@Test
public void shouldChangeAgentToIdleWhenAgentIsReApprovedInConfigFile() throws Exception {
    disableAgent();
    agentConfigService.updateAgentApprovalStatus("uuid1", false, Username.ANONYMOUS);
    AgentInstance instance = agentService.findAgentAndRefreshStatus("uuid1");
    assertThat(instance.getStatus(), is(AgentStatus.Idle));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) 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