Search in sources :

Example 76 with Agent

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

the class AgentRegistrationControllerTest method shouldRegisterWithProvidedAgentInformation.

@Test
public void shouldRegisterWithProvidedAgentInformation() {
    when(agentService.isRegistered("blahAgent-uuid")).thenReturn(false);
    ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("blahAgent-host", "blahAgent-uuid", "blah-location", "34567", "osx", "", "", "", "", "", "", token("blahAgent-uuid", serverConfig.getTokenGenerationKey()), request);
    verify(agentService).requestRegistration(AgentRuntimeInfo.fromServer(new Agent("blahAgent-uuid", "blahAgent-host", request.getRemoteAddr()), false, "blah-location", 34567L, "osx"));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 77 with Agent

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

the class AgentRegistrationControllerTest method shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties.

@Test
public void shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties() {
    String uuid = "uuid";
    when(agentService.isRegistered(uuid)).thenReturn(false);
    ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "autoregister-hostname")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "autoregister-hostname", "", "", token(uuid, serverConfig.getTokenGenerationKey()), request);
    verify(agentService).requestRegistration(AgentRuntimeInfo.fromServer(new Agent(uuid, "autoregister-hostname", request.getRemoteAddr()), false, "location", 233232L, "osx"));
    verify(agentService).register(any(Agent.class));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 78 with Agent

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

the class AgentRegistrationControllerTest method shouldAutoRegisterAgent.

@Test
public void shouldAutoRegisterAgent() {
    String uuid = "uuid";
    final ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
    final String token = token(uuid, serverConfig.getTokenGenerationKey());
    when(agentService.isRegistered(uuid)).thenReturn(false);
    when(goConfigService.serverConfig()).thenReturn(serverConfig);
    when(agentService.createAgentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
    controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "", "", "", token, request);
    verify(agentService).requestRegistration(AgentRuntimeInfo.fromServer(new Agent(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx"));
    verify(agentService).register(any(Agent.class));
}
Also used : ServerConfig(com.thoughtworks.go.config.ServerConfig) Agent(com.thoughtworks.go.config.Agent) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.jupiter.api.Test)

Example 79 with Agent

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

the class JobPresentationServiceTest method shouldReturnJobModelForAnAgentThatIsNoMoreAvailableInTheConfig.

@Test
public void shouldReturnJobModelForAnAgentThatIsNoMoreAvailableInTheConfig() {
    String deletedAgentUuid = "deleted_agent";
    JobInstance jobWithDeletedAgent = assignedWithAgentId("dev", deletedAgentUuid);
    when(agentService.findAgentAndRefreshStatus(deletedAgentUuid)).thenReturn(null);
    Agent agentFromDb = new Agent(deletedAgentUuid, "hostname", "1.2.3.4", "cookie");
    when(agentService.findAgentByUUID(deletedAgentUuid)).thenReturn(agentFromDb);
    List<JobInstanceModel> models = new JobPresentationService(jobDurationStrategy, agentService).jobInstanceModelFor(new JobInstances(jobWithDeletedAgent));
    assertThat(models.size(), is(1));
    assertThat(models.get(0), is(new JobInstanceModel(jobWithDeletedAgent, jobDurationStrategy, agentFromDb)));
    verify(agentService, times(1)).findAgentAndRefreshStatus(deletedAgentUuid);
    verify(agentService, times(1)).findAgentByUUID(deletedAgentUuid);
    verifyNoMoreInteractions(agentService);
}
Also used : Agent(com.thoughtworks.go.config.Agent) JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.jupiter.api.Test)

Example 80 with Agent

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

the class AgentMother method elasticAgent.

public static Agent elasticAgent() {
    Agent agent = new Agent(UUID.randomUUID().toString(), UUID.randomUUID().toString(), "127.0.0.1", UUID.randomUUID().toString());
    agent.setElasticAgentId(UUID.randomUUID().toString());
    agent.setElasticPluginId(UUID.randomUUID().toString());
    return agent;
}
Also used : Agent(com.thoughtworks.go.config.Agent)

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