Search in sources :

Example 96 with AgentInstance

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

the class AgentServiceIntegrationTest method shouldMarkAgentAsLostContactIfAgentDidNotPingForMoreThanTimeout.

@Test
public void shouldMarkAgentAsLostContactIfAgentDidNotPingForMoreThanTimeout() throws Exception {
    new SystemEnvironment().setProperty("agent.connection.timeout", "-1");
    CONFIG_HELPER.addMailHost(new MailHost("ghost.name", 25, "loser", "boozer", true, false, "go@foo.mail.com", "admin@foo.mail.com"));
    Date date = new Date(70, 1, 1, 1, 1, 1);
    AgentInstance instance = AgentInstanceMother.idle(date, "CCeDev01");
    ((AgentRuntimeInfo) ReflectionUtil.getField(instance, "agentRuntimeInfo")).setOperatingSystem("Minix");
    EmailSender mailSender = mock(EmailSender.class);
    AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), environmentConfigService, securityService, agentDao, new UuidGenerator(), serverHealthService, mailSender, agentStatusChangeNotifier());
    AgentInstances agentInstances = (AgentInstances) ReflectionUtil.getField(agentService, "agentInstances");
    agentInstances.add(instance);
    AgentInstances agents = agentService.findRegisteredAgents();
    assertThat(agents.size(), is(1));
    AgentInstance agentInstance = agents.findAgentAndRefreshStatus(instance.agentConfig().getUuid());
    assertThat(agentInstance.getStatus(), is(AgentStatus.LostContact));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) UuidGenerator(com.thoughtworks.go.server.util.UuidGenerator) Test(org.junit.Test)

Example 97 with AgentInstance

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

the class AgentServiceIntegrationTest method shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus.

@Test
public void shouldThrowExceptionWhenADuplicateAgentTriesToUpdateStatus() throws Exception {
    AgentInstance instance = AgentInstanceMother.building();
    AgentService agentService = getAgentService(new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), instance));
    AgentInstances agents = agentService.findRegisteredAgents();
    String uuid = instance.agentConfig().getUuid();
    assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
    AgentIdentifier identifier = instance.agentConfig().getAgentIdentifier();
    agentDao.associateCookie(identifier, "new_cookie");
    AgentRuntimeInfo runtimeInfo = new AgentRuntimeInfo(identifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "old_cookie", false);
    try {
        agentService.updateRuntimeInfo(runtimeInfo);
        fail("agent with bad cookie should not be able to update runtime info");
    } catch (AgentWithDuplicateUUIDException e) {
        assertThat(e.getMessage(), is(format("Agent [%s] has invalid cookie", runtimeInfo.agentInfoDebugString())));
    }
    agents = agentService.findRegisteredAgents();
    assertThat(agents.findAgentAndRefreshStatus(uuid).getStatus(), is(AgentStatus.Building));
    AgentIdentifier agentIdentifier = instance.agentConfig().getAgentIdentifier();
    String cookie = agentService.assignCookie(agentIdentifier);
    agentService.updateRuntimeInfo(new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), cookie, false));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) Test(org.junit.Test)

Example 98 with AgentInstance

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

the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistration.

@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistration() throws Exception {
    String uuid = UUID.randomUUID().toString();
    agentConfigService.addAgent(new AgentConfig(uuid, "hostname", "127.0.01"), Username.ANONYMOUS);
    assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
    MockHttpServletRequest request = new MockHttpServletRequest();
    final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, false, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
    AgentInstance agentInstance = agentService.findAgent(uuid);
    assertTrue(agentInstance.isIdle());
    assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
    assertTrue(RegistrationJSONizer.fromJson(responseEntity.getBody().toString()).isValid());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 99 with AgentInstance

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

the class AgentsControllerV7 method show.

public String show(Request request, Response response) throws IOException {
    String uuid = request.params("uuid");
    final AgentInstance agentInstance = fetchEntityFromConfig(uuid);
    return writerForTopLevelObject(request, response, outputWriter -> toJSON(outputWriter, agentInstance, environmentConfigService.getAgentEnvironments(uuid), securityService, currentUsername()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance)

Example 100 with AgentInstance

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

the class AgentsControllerV7 method update.

public String update(Request request, Response response) {
    String uuid = request.params("uuid");
    AgentUpdateRequest req = fromJSON(request.body());
    String hostname = req.getHostname();
    String resources = req.getResources();
    String environments = filterOutEnvsWhichAreAssociatedViaConfigRepo(uuid, req.getEnvironments());
    TriState configState = req.getAgentConfigState();
    HttpOperationResult result = new HttpOperationResult();
    AgentInstance updatedAgentInstance = null;
    try {
        updatedAgentInstance = agentService.updateAgentAttributes(uuid, hostname, resources, environments, configState);
        handleUpdateAgentResponse(updatedAgentInstance, result);
    } catch (HttpException e) {
        throw e;
    } catch (Exception e) {
        throw halt(HttpStatus.SC_INTERNAL_SERVER_ERROR, MessageJson.create(e.getMessage()));
    }
    return handleCreateOrUpdateResponse(request, response, updatedAgentInstance, result);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) HttpException(com.thoughtworks.go.config.exceptions.HttpException) AgentUpdateRequest(com.thoughtworks.go.apiv7.agents.model.AgentUpdateRequest) TriState(com.thoughtworks.go.util.TriState) HttpException(com.thoughtworks.go.config.exceptions.HttpException) InvalidAgentInstructionException(com.thoughtworks.go.domain.exception.InvalidAgentInstructionException) IOException(java.io.IOException)

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