Search in sources :

Example 81 with AgentInstance

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

the class JobAssignmentTest method shouldAssignJobToRemoteAgent.

@Test
public void shouldAssignJobToRemoteAgent() throws UnknownHostException {
    AgentInstance local = setupLocalAgent();
    AgentInstance remote = setupRemoteAgent();
    fixture.createPipelineWithFirstStageScheduled();
    assignmentService.onTimer();
    assignmentService.assignWorkToAgent(local);
    assignmentService.onTimer();
    Work work = assignmentService.assignWorkToAgent(remote);
    assertThat(work, instanceOf(BuildWork.class));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Work(com.thoughtworks.go.remote.work.Work) BuildWork(com.thoughtworks.go.remote.work.BuildWork) NoWork(com.thoughtworks.go.remote.work.NoWork) BuildWork(com.thoughtworks.go.remote.work.BuildWork) Test(org.junit.Test)

Example 82 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldRemoveAgentFromEnvironmentBeforeDeletingAgent.

@Test
public void shouldRemoveAgentFromEnvironmentBeforeDeletingAgent() throws Exception {
    AgentConfig agentConfig1 = new AgentConfig(UUID.randomUUID().toString(), "hostname", "127.0.0.1");
    AgentInstance fromConfigFile1 = AgentInstance.createFromConfig(agentConfig1, new SystemEnvironment(), getAgentStatusChangeListener());
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    AgentConfig agentConfig2 = new AgentConfig(UUID.randomUUID().toString(), "hostname", "127.0.0.1");
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    BasicEnvironmentConfig env = new BasicEnvironmentConfig(new CaseInsensitiveString(UUID.randomUUID().toString()));
    env.addAgent(agentConfig1.getUuid());
    env.addAgent(agentConfig2.getUuid());
    goConfigDao.addEnvironment(env);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().size(), is(2));
    agentConfigService.deleteAgents(Username.ANONYMOUS, fromConfigFile1);
    cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().size(), is(1));
    assertThat(cruiseConfig.getEnvironments().named(env.name()).getAgents().get(0).getUuid(), is(agentConfig2.getUuid()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Test(org.junit.Test)

Example 83 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldNotAllowAnyUpdateOperationOnPendingAgentsIfConfigStateIsNotProvided.

@Test
public void shouldNotAllowAnyUpdateOperationOnPendingAgentsIfConfigStateIsNotProvided() 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());
    ArrayList<String> resourcesToAdd = new ArrayList<>();
    resourcesToAdd.add("Linux");
    ArrayList<String> resourcesToRemove = new ArrayList<>();
    resourcesToRemove.add("Gauge");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, resourcesToAdd, resourcesToRemove, new ArrayList<>(), new ArrayList<>(), TriState.UNSET);
    HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
    expectedResult.badRequest(LocalizedMessage.string("PENDING_AGENT_INVALID_OPERATION", uuids));
    assertThat(result, is(expectedResult));
}
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 84 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldDeleteMultipleAgents.

@Test
public void shouldDeleteMultipleAgents() {
    AgentConfig agentConfig1 = new AgentConfig("UUID1", "remote-host1", "50.40.30.21");
    AgentConfig agentConfig2 = new AgentConfig("UUID2", "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());
    GoConfigDao.CompositeConfigCommand command = agentConfigService.commandForDeletingAgents(fromConfigFile1, fromConfigFile2);
    List<UpdateConfigCommand> commands = command.getCommands();
    assertThat(commands.size(), is(2));
    String uuid1 = (String) ReflectionUtil.getField(commands.get(0), "uuid");
    String uuid2 = (String) ReflectionUtil.getField(commands.get(1), "uuid");
    assertThat(uuid1, is("UUID1"));
    assertThat(uuid2, is("UUID2"));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Test(org.junit.Test)

Example 85 with AgentInstance

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

the class AgentConfigServiceIntegrationTest method shouldRemoveResourcesFromTheSpecifiedAgents.

@Test
public void shouldRemoveResourcesFromTheSpecifiedAgents() 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);
    agentConfig1.addResourceConfig(new ResourceConfig("resource-1"));
    agentConfig1.addResourceConfig(new ResourceConfig("resource-2"));
    agentConfig2.addResourceConfig(new ResourceConfig("resource-2"));
    agentConfigService.addAgent(agentConfig1, Username.ANONYMOUS);
    agentConfigService.addAgent(agentConfig2, Username.ANONYMOUS);
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs().size(), is(2));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(1));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ArrayList<String> uuids = new ArrayList<>();
    uuids.add(agentConfig1.getUuid());
    uuids.add(agentConfig2.getUuid());
    ArrayList<String> resources = new ArrayList<>();
    resources.add("resource-2");
    agentConfigService.bulkUpdateAgentAttributes(agentInstances, Username.ANONYMOUS, result, uuids, new ArrayList<>(), resources, 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(1));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig1.getUuid()).getResourceConfigs(), contains(new ResourceConfig("resource-1")));
    assertThat(cruiseConfig.agents().getAgentByUuid(agentConfig2.getUuid()).getResourceConfigs().size(), is(0));
}
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