Search in sources :

Example 56 with Agent

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

the class AgentInstanceTest method shouldReturnAJobPlanWithMatchingUuidSet.

@Test
void shouldReturnAJobPlanWithMatchingUuidSet() {
    Agent agent = agent("linux, mercurial");
    AgentInstance agentInstance = new AgentInstance(agent, LOCAL, systemEnvironment, null);
    final JobPlan job = jobPlan("pipeline-name", "job-name", "resource", agent.getUuid());
    JobPlan matchingJob = agentInstance.firstMatching(new ArrayList<JobPlan>() {

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

Example 57 with Agent

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

the class AgentInstanceTest method buildingMethodShouldUpdateAgentRuntimeStatusToBuildingAndSetSpecifiedBuildInfoInItsRuntimeInfo.

@Test
void buildingMethodShouldUpdateAgentRuntimeStatusToBuildingAndSetSpecifiedBuildInfoInItsRuntimeInfo() {
    Agent mockAgent = mock(Agent.class);
    AgentRuntimeInfo mockAgentRuntimeInfo = mock(AgentRuntimeInfo.class);
    AgentBuildingInfo mockAgentBuildingInfo = mock(AgentBuildingInfo.class);
    SystemEnvironment mockSysEnv = mock(SystemEnvironment.class);
    AgentStatusChangeListener mockAgentStatusChangeListener = mock(AgentStatusChangeListener.class);
    when(mockAgent.isFromLocalHost()).thenReturn(true);
    when(mockAgentRuntimeInfo.agent()).thenReturn(mockAgent);
    when(mockSysEnv.isAutoRegisterLocalAgentEnabled()).thenReturn(true);
    when(mockAgentRuntimeInfo.isCancelled()).thenReturn(false);
    doNothing().when(mockAgentRuntimeInfo).busy(mockAgentBuildingInfo);
    AgentInstance agentInstance = createFromLiveAgent(mockAgentRuntimeInfo, mockSysEnv, mockAgentStatusChangeListener);
    agentInstance.building(mockAgentBuildingInfo);
    verify(mockAgentRuntimeInfo, atLeastOnce()).getRuntimeStatus();
    verify(mockAgentRuntimeInfo).setRuntimeStatus(Building);
    verify(mockAgentRuntimeInfo).busy(mockAgentBuildingInfo);
    verify(mockAgentStatusChangeListener).onAgentStatusChange(agentInstance);
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 58 with Agent

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

the class AgentInstanceTest method shouldSyncIPWithConfig.

@Test
void shouldSyncIPWithConfig() {
    AgentInstance originalAgentInstance = AgentInstance.createFromAgent(agent, systemEnvironment, mock(AgentStatusChangeListener.class));
    originalAgentInstance.update(new AgentRuntimeInfo(new AgentIdentifier("CCeDev01", "10.18.5.2", "uuid2"), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie"));
    assertThat(originalAgentInstance.getAgent()).isEqualTo(new Agent("uuid2", "CCeDev01", "10.18.5.2"));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 59 with Agent

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

the class AgentInstanceTest method shouldNotMatchJobPlanIfTheAgentIsElasticAndJobHasResourcesDefined.

@Test
void shouldNotMatchJobPlanIfTheAgentIsElasticAndJobHasResourcesDefined() {
    Agent agent = new Agent("uuid", "hostname", "11.1.1.1", singletonList("r1"));
    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.setResources(asList(new Resource("r1")));
    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) Test(org.junit.jupiter.api.Test)

Example 60 with Agent

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

the class AgentInstanceMother method idleWith.

public static AgentInstance idleWith(String uuid, String hostname, String ipAddress, String location, long space, String os, List<String> resourceList, String agentBootstrapperVersion, String agentVersion) {
    Agent agent = new Agent(uuid, hostname, ipAddress);
    agent.setResourcesFromList(resourceList);
    AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agent.getAgentIdentifier(), AgentRuntimeStatus.Idle, location, "cookie");
    agentRuntimeInfo.idle();
    agentRuntimeInfo.setUsableSpace(space);
    agentRuntimeInfo.setOperatingSystem(os);
    agentRuntimeInfo.updateAgentVersion(agentVersion);
    agentRuntimeInfo.updateBootstrapperVersion(agentBootstrapperVersion);
    AgentInstance agentInstance = createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.idle();
    agentInstance.update(agentRuntimeInfo);
    agentInstance.syncAgentFrom(agent);
    return agentInstance;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

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