Search in sources :

Example 1 with AgentNotificationData

use of com.thoughtworks.go.domain.notificationdata.AgentNotificationData in project gocd by gocd.

the class JsonMessageHandler1_0_Test method shouldNotHandleAgentNotificationRequest.

@Test
public void shouldNotHandleAgentNotificationRequest() throws Exception {
    thrown.expect(NotImplementedException.class);
    thrown.expectMessage(String.format("Converter for %s not supported", AgentNotificationData.class.getCanonicalName()));
    messageHandler.requestMessageForNotify(new AgentNotificationData(null, null, false, null, null, null, null, null, null, null));
}
Also used : AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) Test(org.junit.Test)

Example 2 with AgentNotificationData

use of com.thoughtworks.go.domain.notificationdata.AgentNotificationData in project gocd by gocd.

the class JsonMessageHandler2_0_Test method shouldNotHandleAgentNotificationRequest.

@Test
public void shouldNotHandleAgentNotificationRequest() throws Exception {
    thrown.expect(NotImplementedException.class);
    thrown.expectMessage(String.format("Converter for %s not supported", AgentNotificationData.class.getCanonicalName()));
    messageHandler.requestMessageForNotify(new AgentNotificationData(null, null, false, null, null, null, null, null, null, null));
}
Also used : AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) Test(org.junit.Test)

Example 3 with AgentNotificationData

use of com.thoughtworks.go.domain.notificationdata.AgentNotificationData in project gocd by gocd.

the class JsonMessageHandler3_0_Test method shouldConstructAgentNotificationRequestMessage.

@Test
public void shouldConstructAgentNotificationRequestMessage() throws Exception {
    Date transition_time = new Date();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_PATTERN_FOR_V3);
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    String time = simpleDateFormat.format(transition_time);
    AgentNotificationData agentNotificationData = new AgentNotificationData("agent_uuid", "agent_hostname", true, "127.0.0.1", "rh", "100", "enabled", "building", "building", transition_time);
    String expected = "{\n" + "    \"agent_config_state\": \"enabled\",\n" + "    \"agent_state\": \"building\",\n" + "    \"build_state\": \"building\",\n" + "    \"is_elastic\": true,\n" + "    \"free_space\": \"100\",\n" + "    \"host_name\": \"agent_hostname\",\n" + "    \"ip_address\": \"127.0.0.1\",\n" + "    \"operating_system\": \"rh\",\n" + "    \"uuid\": \"agent_uuid\",\n" + "    \"transition_time\": \"" + time + "\"\n" + "}\n";
    String message = messageHandler.requestMessageForNotify(agentNotificationData);
    JSONAssert.assertEquals(expected, message, JSONCompareMode.NON_EXTENSIBLE);
}
Also used : AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 4 with AgentNotificationData

use of com.thoughtworks.go.domain.notificationdata.AgentNotificationData in project gocd by gocd.

the class AgentStatusChangeNotifier method onAgentStatusChange.

@Override
public void onAgentStatusChange(AgentInstance agentInstance) {
    if (isAnyPluginInterestedInAgentStatus()) {
        AgentNotificationData agentNotificationData = notificationDataFrom(agentInstance);
        pluginNotificationQueue.post(new PluginNotificationMessage(NotificationExtension.AGENT_STATUS_CHANGE_NOTIFICATION, agentNotificationData));
    }
}
Also used : AgentNotificationData(com.thoughtworks.go.domain.notificationdata.AgentNotificationData)

Example 5 with AgentNotificationData

use of com.thoughtworks.go.domain.notificationdata.AgentNotificationData 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

AgentNotificationData (com.thoughtworks.go.domain.notificationdata.AgentNotificationData)6 Test (org.junit.Test)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)1 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)1 ElasticAgentRuntimeInfo (com.thoughtworks.go.server.service.ElasticAgentRuntimeInfo)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 SimpleDateFormat (java.text.SimpleDateFormat)1