Search in sources :

Example 61 with AgentInstance

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

the class AgentService method updateAgentAttributes.

public AgentInstance updateAgentAttributes(String uuid, String hostname, String resources, String environments, TriState state) {
    AgentInstance agentInstance = agentInstances.findAgent(uuid);
    validateThatAgentExists(agentInstance);
    Agent agent = getPendingAgentOrFromDB(agentInstance);
    if (validateAnyOperationPerformedOnAgent(hostname, environments, resources, state)) {
        new AgentUpdateValidator(agentInstance, state).validate();
        setAgentAttributes(hostname, resources, environments, state, agent);
        saveOrUpdate(agent);
        return createFromAgent(agent, systemEnvironment, agentStatusChangeNotifier);
    }
    return null;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) AgentInstance.createFromAgent(com.thoughtworks.go.domain.AgentInstance.createFromAgent) AgentUpdateValidator(com.thoughtworks.go.config.update.AgentUpdateValidator)

Example 62 with AgentInstance

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

the class PluginNotificationServiceTest method shouldConstructDataForElasticAgentNotification.

@Test
public void shouldConstructDataForElasticAgentNotification() {
    when(notificationPluginRegistry.getPluginsInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION)).thenReturn(new LinkedHashSet<>(asList(PLUGIN_ID_1)));
    when(systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL)).thenReturn(1000L);
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    Agent agent = new Agent("some-uuid");
    agent.setElasticAgentId("42");
    agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agent.setIpaddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    pluginNotificationService.notifyAgentStatus(agentInstance);
    ArgumentCaptor<PluginNotificationMessage> captor = ArgumentCaptor.forClass(PluginNotificationMessage.class);
    verify(pluginNotificationsQueueHandler).post(captor.capture(), eq(1000L));
    PluginNotificationMessage message = captor.getValue();
    assertThat(message.pluginId(), is(PLUGIN_ID_1));
    assertThat(message.getRequestName(), is(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION));
    assertThat(message.getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) message.getData();
    assertTrue(data.isElastic());
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Agent(com.thoughtworks.go.config.Agent) AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 63 with AgentInstance

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

the class PluginNotificationServiceTest method shouldConstructDataForAgentNotification.

@Test
public void shouldConstructDataForAgentNotification() {
    when(notificationPluginRegistry.getPluginsInterestedIn(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION)).thenReturn(new LinkedHashSet<>(asList(PLUGIN_ID_1)));
    when(systemEnvironment.get(NOTIFICATION_PLUGIN_MESSAGES_TTL)).thenReturn(1000L);
    AgentInstance agentInstance = AgentInstanceMother.building();
    pluginNotificationService.notifyAgentStatus(agentInstance);
    ArgumentCaptor<PluginNotificationMessage> captor = ArgumentCaptor.forClass(PluginNotificationMessage.class);
    verify(pluginNotificationsQueueHandler).post(captor.capture(), eq(1000L));
    PluginNotificationMessage message = captor.getValue();
    assertThat(message.pluginId(), is(PLUGIN_ID_1));
    assertThat(message.getRequestName(), is(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION));
    assertThat(message.getData() instanceof AgentNotificationData, is(true));
    AgentNotificationData data = (AgentNotificationData) message.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.jupiter.api.Test)

Example 64 with AgentInstance

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

the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.

@Test
public void shouldNotifyIfAgentIsElastic() {
    ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
    Agent agent = new Agent("some-uuid");
    agent.setElasticAgentId("42");
    agent.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
    agent.setIpaddress("127.0.0.1");
    AgentInstance agentInstance = AgentInstance.createFromAgent(agent, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
    agentInstance.update(agentRuntimeInfo);
    when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
    agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
    verify(pluginNotificationService).notifyAgentStatus(agentInstance);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Agent(com.thoughtworks.go.config.Agent) ElasticAgentRuntimeInfo(com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) AgentStatusChangeListener(com.thoughtworks.go.listener.AgentStatusChangeListener) Test(org.junit.jupiter.api.Test)

Example 65 with AgentInstance

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

the class AgentServiceIntegrationTest method getRegisteredAgentsViewModelShouldNotReturnNotRegisteredAgentsViewModel.

@Test
void getRegisteredAgentsViewModelShouldNotReturnNotRegisteredAgentsViewModel() {
    AgentInstance idle = AgentInstanceMother.updateUuid(idle(new Date(), "CCeDev01"), UUID);
    AgentInstance pending = pending();
    AgentInstance building = building();
    AgentInstance denied = disabled();
    AgentInstances instances = new AgentInstances(new SystemEnvironment(), agentStatusChangeListener(), idle, pending, building, denied);
    AgentService agentService = newAgentService(instances);
    AgentsViewModel agentViewModels = agentService.getRegisteredAgentsViewModel();
    assertThat(agentViewModels.size(), is(3));
    agentViewModels.forEach(agentViewModel -> assertThat(agentViewModel.getStatus().getConfigStatus(), not(is(Pending))));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) AgentInstances(com.thoughtworks.go.server.domain.AgentInstances) AgentsViewModel(com.thoughtworks.go.server.ui.AgentsViewModel) Test(org.junit.jupiter.api.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