Search in sources :

Example 56 with AgentInstance

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

the class AgentRegistrationControllerIntegrationTest method shouldAutoRegisterRemoteAgent.

@Test
public void shouldAutoRegisterRemoteAgent() {
    System.setProperty(AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
    String uuid = UUID.randomUUID().toString();
    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.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
    assertThat(responseEntity.getBody().toString(), is(""));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 57 with AgentInstance

use of com.thoughtworks.go.domain.AgentInstance 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 58 with AgentInstance

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

the class AgentInstancesTest method createElasticAgentInstance.

private AgentInstance createElasticAgentInstance(int counter, String elasticPluginId) {
    String uuid = UUID.randomUUID().toString();
    String ip = "127.0.0.1";
    String host = "localhost";
    String elasticAgentId = "elastic-agent-id-" + counter;
    AgentIdentifier id = new AgentIdentifier(host, ip, uuid);
    ElasticAgentRuntimeInfo elasticRuntime = new ElasticAgentRuntimeInfo(id, Idle, "/foo/one", null, elasticAgentId, elasticPluginId);
    Agent elasticAgent = createElasticAgent(uuid, ip, elasticAgentId, elasticPluginId);
    AgentInstance elasticAgentInstance = createFromAgent(elasticAgent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    elasticAgentInstance.update(elasticRuntime);
    return elasticAgentInstance;
}
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) AgentInstance.createFromAgent(com.thoughtworks.go.domain.AgentInstance.createFromAgent) Agent(com.thoughtworks.go.config.Agent) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener)

Example 59 with AgentInstance

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

the class AgentService method approve.

@Deprecated
public void approve(String uuid) {
    AgentInstance agentInstance = findAgentAndRefreshStatus(uuid);
    boolean doesAgentExistAndIsRegistered = isRegistered(agentInstance.getUuid());
    agentInstance.enable();
    if (doesAgentExistAndIsRegistered) {
        LOGGER.warn("Registered agent with the same uuid [{}] already approved.", agentInstance);
    } else {
        Agent agent = agentInstance.getAgent();
        if (!agent.cookieAssigned()) {
            generateAndAddCookie(agent);
        }
        saveOrUpdate(agent);
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentInstance.createFromAgent(com.thoughtworks.go.domain.AgentInstance.createFromAgent)

Example 60 with AgentInstance

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

the class AgentService method killAllRunningTasksOnAgent.

public void killAllRunningTasksOnAgent(String uuid) throws InvalidAgentInstructionException {
    AgentInstance agentInstance = agentInstances.findAgent(uuid);
    if (agentInstance.isNullAgent()) {
        throw new RecordNotFoundException(format("Agent with uuid: '%s' not found", uuid));
    }
    agentInstance.killRunningTasks();
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance)

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