Search in sources :

Example 21 with Agent

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

the class AgentRegistrationControllerIntegrationTest method shouldRegisterElasticAgent.

@Test
public void shouldRegisterElasticAgent() {
    String autoRegisterKey = ephemeralAutoRegisterKeyService.autoRegisterKey();
    String uuid = UUID.randomUUID().toString();
    String elasticAgentId = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    final ResponseEntity responseEntity = controller.agentRequest("elastic-agent-hostname", uuid, "sandbox", "100", "Alpine Linux v3.5", autoRegisterKey, "", "", "hostname", elasticAgentId, "elastic-plugin-id", token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    Agent agent = agentService.getAgentByUUID(uuid);
    assertTrue(agent.isElastic());
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
    assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
    assertThat(responseEntity.getBody().toString(), is(""));
}
Also used : Agent(com.thoughtworks.go.config.Agent) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 22 with Agent

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

the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys.

@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithAutoRegisterKeys() {
    String uuid = UUID.randomUUID().toString();
    agentService.saveOrUpdate(new Agent(uuid, "hostname", "127.0.01", uuidGenerator.randomUuid()));
    assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
    MockHttpServletRequest request = new MockHttpServletRequest();
    final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, goConfigService.serverConfig().getAgentAutoRegisterKey(), "", "", null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    AgentInstance agentInstance = agentService.findAgent(uuid);
    assertTrue(agentInstance.isIdle());
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
    assertThat(responseEntity.getBody().toString(), is(""));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 23 with Agent

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

the class AgentInstanceTest method buildingWithTimeProvider.

public static AgentInstance buildingWithTimeProvider(TimeProvider timeProvider) {
    Agent idleAgentConfig = new Agent("uuid2", "localhost", "10.18.5.1");
    AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(idleAgentConfig.getAgentIdentifier(), Building, currentWorkingDirectory(), "cookie");
    agentRuntimeInfo.setLocation("/var/lib/foo");
    agentRuntimeInfo.idle();
    agentRuntimeInfo.setUsableSpace(10 * 1024l);
    AgentInstance agentInstance = new AgentInstance(idleAgentConfig, LOCAL, new SystemEnvironment(), mock(AgentStatusChangeListener.class), timeProvider);
    agentInstance.enable();
    return 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) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Example 24 with Agent

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

the class AgentInstanceTest method shouldOrderByHostname.

@Test
void shouldOrderByHostname() {
    AgentInstance agentA = new AgentInstance(new Agent("UUID", "A", "127.0.0.1"), LOCAL, systemEnvironment, null);
    AgentInstance agentB = new AgentInstance(new Agent("UUID", "B", "127.0.0.2"), LOCAL, systemEnvironment, null);
    assertThat(agentA.compareTo(agentA)).isEqualTo(0);
    assertThat(agentA.compareTo(agentB)).isLessThan(0);
    assertThat(agentB.compareTo(agentA)).isGreaterThan(0);
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 25 with Agent

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

the class AgentInstanceTest method shouldDenyAgentWhenAgentIsDeniedInConfigFile.

@Test
void shouldDenyAgentWhenAgentIsDeniedInConfigFile() {
    AgentInstance original = AgentInstance.createFromAgent(agent, systemEnvironment, mock(AgentStatusChangeListener.class));
    original.update(buildingRuntimeInfo());
    Agent newAgent = new Agent(agent.getUuid(), agent.getHostname(), agent.getIpaddress());
    newAgent.disable();
    original.syncAgentFrom(newAgent);
    assertThat(original.getStatus()).isEqualTo(AgentStatus.Disabled);
}
Also used : AgentInstance.createFromLiveAgent(com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent) Agent(com.thoughtworks.go.config.Agent) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) 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