Search in sources :

Example 26 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstanceTest method shouldSetAgentToIdleWhenItIsApproved.

@Test
void shouldSetAgentToIdleWhenItIsApproved() {
    AgentInstance pendingAgentInstance = AgentInstanceMother.pending();
    Agent agent = new Agent(pendingAgentInstance.getUuid(), pendingAgentInstance.getHostname(), pendingAgentInstance.getIpAddress());
    pendingAgentInstance.syncAgentFrom(agent);
    AgentStatus status = pendingAgentInstance.getStatus();
    assertThat(status).isEqualTo(AgentStatus.Idle);
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 27 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstanceTest method shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBuildAssignmentService.

@Test
void shouldNotMatchJobPlanIfJobRequiresElasticAgent_MatchingIsManagedByBuildAssignmentService() {
    Agent agent = new Agent("uuid");
    agent.setElasticAgentId("elastic-agent-id-1");
    String elasticPluginId = "elastic-plugin-id-1";
    agent.setElasticPluginId(elasticPluginId);
    AgentInstance agentInstance = new AgentInstance(agent, REMOTE, mock(SystemEnvironment.class), null);
    DefaultJobPlan jobPlan1 = new DefaultJobPlan();
    jobPlan1.setElasticProfile(new ElasticProfile("foo", "prod-cluster"));
    List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan());
    assertThat(agentInstance.firstMatching(jobPlans)).isNull();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.jupiter.api.Test)

Example 28 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstanceTest method shouldNotReturnAJobWithMismatchedUuid.

@Test
void shouldNotReturnAJobWithMismatchedUuid() {
    Agent agent = agent("linux, mercurial");
    AgentInstance agentInstance = new AgentInstance(agent, LOCAL, systemEnvironment, null);
    final JobPlan job = jobPlan("pipeline-name", "job-name", "linux", agent.getUuid() + "-ensure-doesn't-match");
    JobPlan matchingJob = agentInstance.firstMatching(new ArrayList<JobPlan>() {

        {
            add(job);
        }
    });
    assertThat(matchingJob).isNull();
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 29 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstanceTest method shouldBeAbleToDenyAgentThatIsRunningCancelledJob.

@Test
void shouldBeAbleToDenyAgentThatIsRunningCancelledJob() {
    Agent agent = new Agent("UUID", "A", "127.0.0.1");
    AgentInstance agentInstance = new AgentInstance(agent, LOCAL, systemEnvironment, mock(AgentStatusChangeListener.class));
    agentInstance.cancel();
    AgentBuildingInfo cancelled = agentInstance.getBuildingInfo();
    assertThat(agentInstance.canDisable()).isTrue();
    agentInstance.deny();
    assertThat(agent.isDisabled()).isTrue();
    assertThat(agentInstance.getStatus()).isEqualTo(AgentStatus.Disabled);
    assertThat(agentInstance.getBuildingInfo()).isEqualTo(cancelled);
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 30 with Agent

use of com.thoughtworks.go.config.Agent in project gocd by gocd.

the class AgentInstanceTest method shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThatConfiguredForTheJob.

@Test
void shouldNotMatchJobPlanIfTheAgentWasLaunchedByADifferentPluginFromThatConfiguredForTheJob() {
    Agent agent = new Agent("uuid");
    agent.setElasticAgentId("elastic-agent-id-1");
    String elasticPluginId = "elastic-plugin-id-1";
    agent.setElasticPluginId(elasticPluginId);
    AgentInstance agentInstance = new AgentInstance(agent, REMOTE, mock(SystemEnvironment.class), null);
    DefaultJobPlan jobPlan1 = new DefaultJobPlan();
    jobPlan1.setElasticProfile(new ElasticProfile("foo", "prod-cluster"));
    List<JobPlan> jobPlans = asList(jobPlan1, new DefaultJobPlan());
    assertThat(agentInstance.firstMatching(jobPlans)).isNull();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.go.config.Agent)100 Test (org.junit.jupiter.api.Test)52 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)36 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)19 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)16 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)13 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)11 JobInstance (com.thoughtworks.go.domain.JobInstance)8 ResponseEntity (org.springframework.http.ResponseEntity)8 ServerConfig (com.thoughtworks.go.config.ServerConfig)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)6 Username (com.thoughtworks.go.server.domain.Username)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)4 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)4 Query (org.hibernate.Query)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 Gson (com.google.gson.Gson)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3