Search in sources :

Example 66 with AgentInstance

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

the class ElasticAgentRequestProcessorTest method shouldProcessDeleteAgentRequest.

@Test
public void shouldProcessDeleteAgentRequest() throws Exception {
    AgentMetadata agent = new AgentMetadata("foo", null, null, null);
    DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DELETE_AGENTS, "1.0", pluginIdentifier);
    goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
    AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
    when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
    processor.process(pluginDescriptor, goPluginApiRequest);
    verify(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentConfig(com.thoughtworks.go.config.AgentConfig) ElasticAgentMetadata(com.thoughtworks.go.server.domain.ElasticAgentMetadata) AgentMetadata(com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata) DefaultGoApiRequest(com.thoughtworks.go.plugin.api.request.DefaultGoApiRequest) Test(org.junit.Test)

Example 67 with AgentInstance

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

the class AgentRemoteHandler method remove.

public void remove(Agent agent) {
    agentCookie.remove(agent);
    String uuid = sessionIds.remove(agent);
    if (uuid == null) {
        return;
    }
    agentSessions.remove(uuid);
    AgentInstance instance = agentService.findAgent(uuid);
    if (instance != null) {
        instance.lostContact();
        LOGGER.info("{} lost contact because websocket connection is closed", instance.getAgentIdentifier());
    }
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance)

Example 68 with AgentInstance

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

the class AgentConfigServiceTest method shouldEnableAgentWhenAlreadyInTheConfig.

@Test
public void shouldEnableAgentWhenAlreadyInTheConfig() {
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
    agentConfig.disable();
    AgentInstance instance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), null);
    when(goConfigService.currentCruiseConfig()).thenReturn(mock(CruiseConfig.class));
    when(goConfigService.hasAgent(agentConfig.getUuid())).thenReturn(true);
    agentConfigService.enableAgents(Username.ANONYMOUS, instance);
    shouldPerformCommand(new GoConfigDao.CompositeConfigCommand((UpdateConfigCommand) new AgentConfigService.UpdateAgentApprovalStatus(agentId, false)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Example 69 with AgentInstance

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

the class AgentConfigServiceTest method shouldEnableAgentWhenPending.

@Test
public void shouldEnableAgentWhenPending() {
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, "remote-host", "50.40.30.20");
    AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromAgent(new AgentIdentifier("remote-host", "50.40.30.20", agentId), AgentRuntimeStatus.Unknown, "cookie", false);
    AgentInstance instance = AgentInstance.createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment(), null);
    agentConfigService.enableAgents(Username.ANONYMOUS, instance);
    shouldPerformCommand(new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(agentConfig)));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentConfig(com.thoughtworks.go.config.AgentConfig) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) Test(org.junit.Test)

Example 70 with AgentInstance

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

the class AgentStatusChangeNotifierTest method shouldNotifyInterestedPluginsWithAgentInformation.

@Test
public void shouldNotifyInterestedPluginsWithAgentInformation() {
    AgentInstance agentInstance = AgentInstanceMother.building();
    when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
    agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
    verify(pluginNotificationQueue).post(captor.capture());
    assertThat(captor.getValue().getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) captor.getValue().getData();
    assertThat(data.getUuid(), is(agentInstance.getUuid()));
    assertThat(data.getHostName(), is(agentInstance.getHostname()));
    assertFalse(data.isElastic());
    assertThat(data.getIpAddress(), is(agentInstance.getIpAddress()));
    assertThat(data.getFreeSpace(), is(agentInstance.freeDiskSpace().toString()));
    assertThat(data.getAgentConfigState(), is(agentInstance.getAgentConfigStatus().name()));
    assertThat(data.getAgentState(), is(agentInstance.getRuntimeStatus().agentState().name()));
    assertThat(data.getBuildState(), is(agentInstance.getRuntimeStatus().buildState().name()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) Test(org.junit.Test)

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