use of org.talend.esb.sam._2011._03.common.EventType in project tesb-rt-se by Talend.
the class AgentActivator method start.
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
if (!checkConfig(context)) {
return;
}
if (monitoringService == null) {
initWsClient(context);
}
EventType serverStartEvent = createEventType(EventEnumType.SERVER_START);
putEvent(serverStartEvent);
LOG.info("Send SERVER_START event to SAM Server successful!");
}
use of org.talend.esb.sam._2011._03.common.EventType in project tesb-rt-se by Talend.
the class MonitoringServiceWrapper method putEvents.
/**
* Sends all events to the web service. Events will be transformed with mapper before sending.
*
* @param events the events
*/
public void putEvents(List<Event> events) {
Exception lastException;
List<EventType> eventTypes = new ArrayList<EventType>();
for (Event event : events) {
EventType eventType = EventMapper.map(event);
eventTypes.add(eventType);
}
int i = 0;
lastException = null;
while (i < numberOfRetries) {
try {
monitoringService.putEvents(eventTypes);
break;
} catch (Exception e) {
lastException = e;
i++;
}
if (i < numberOfRetries) {
try {
Thread.sleep(delayBetweenRetry);
} catch (InterruptedException e) {
break;
}
}
}
if (i == numberOfRetries) {
throw new MonitoringException("1104", "Could not send events to monitoring service after " + numberOfRetries + " retries.", lastException, events);
}
}
use of org.talend.esb.sam._2011._03.common.EventType in project tesb-rt-se by Talend.
the class EventMapperTest method testEventMapper2.
@Test
public void testEventMapper2() throws IOException {
Event event = new Event();
event.setContent("testContent");
MessageInfo messageInfo = EasyMock.createMock(MessageInfo.class);
EasyMock.expect(messageInfo.getMessageId()).andReturn("MessageId").anyTimes();
EasyMock.expect(messageInfo.getFlowId()).andReturn("FlowId").anyTimes();
EasyMock.expect(messageInfo.getPortType()).andReturn("PortType").anyTimes();
EasyMock.expect(messageInfo.getOperationName()).andReturn("OperationName").anyTimes();
EasyMock.expect(messageInfo.getTransportType()).andReturn("TransportType").anyTimes();
EasyMock.replay(messageInfo);
event.setMessageInfo(messageInfo);
Originator originator = EasyMock.createMock(Originator.class);
EasyMock.expect(originator.getProcessId()).andReturn("ProcessId").anyTimes();
EasyMock.expect(originator.getIp()).andReturn("Ip").anyTimes();
EasyMock.expect(originator.getHostname()).andReturn("Hostname").anyTimes();
EasyMock.expect(originator.getCustomId()).andReturn("CustomId").anyTimes();
EasyMock.expect(originator.getPrincipal()).andReturn("Principal").anyTimes();
EasyMock.replay(originator);
event.setOriginator(originator);
event.getCustomInfo().put("testKey", "testValue");
EventType eventOut = EventMapper.map(event);
DataHandler dh = eventOut.getContent();
String outContent = getContent(dh);
Assert.assertEquals(event.getContent(), outContent);
Assert.assertEquals(eventOut.getOriginator().getProcessId(), event.getOriginator().getProcessId());
Assert.assertEquals(eventOut.getOriginator().getIp(), event.getOriginator().getIp());
Assert.assertEquals(eventOut.getOriginator().getHostname(), event.getOriginator().getHostname());
Assert.assertEquals(eventOut.getOriginator().getCustomId(), event.getOriginator().getCustomId());
Assert.assertEquals(eventOut.getOriginator().getPrincipal(), event.getOriginator().getPrincipal());
Assert.assertEquals(eventOut.getMessageInfo().getMessageId(), event.getMessageInfo().getMessageId());
Assert.assertEquals(eventOut.getMessageInfo().getFlowId(), event.getMessageInfo().getFlowId());
Assert.assertSame(eventOut.getMessageInfo().getPorttype().getLocalPart(), event.getMessageInfo().getPortType());
Assert.assertEquals(eventOut.getMessageInfo().getOperationName(), event.getMessageInfo().getOperationName());
Assert.assertEquals(eventOut.getMessageInfo().getTransport(), event.getMessageInfo().getTransportType());
Assert.assertEquals(eventOut.getCustomInfo().getItem().get(0).getValue(), "testValue");
Assert.assertEquals(eventOut.getCustomInfo().getItem().get(0).getKey(), "testKey");
}
use of org.talend.esb.sam._2011._03.common.EventType in project tesb-rt-se by Talend.
the class EventTypeMapperTest method testEmpty.
/**
* Test with empty eventType parts to check for Nullpointer exceptions
*/
@Test
public void testEmpty() {
EventType eventType = new EventType();
EventTypeMapper.map(eventType);
eventType.setCustomInfo(new CustomInfoType());
EventTypeMapper.map(eventType);
eventType.setMessageInfo(new MessageInfoType());
EventTypeMapper.map(eventType);
eventType.setOriginator(new OriginatorType());
EventTypeMapper.map(eventType);
}
use of org.talend.esb.sam._2011._03.common.EventType in project tesb-rt-se by Talend.
the class MonitoringServiceFullTest method testSendEvents.
// @Before
// public void setUp() throws Exception {
// executeSqlScript("create.sql", true);
// }
@Test
public void testSendEvents() throws PutEventsFault, MalformedURLException, URISyntaxException {
Client client = ClientProxy.getClient(monitoringService);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy clientConfig = new HTTPClientPolicy();
clientConfig.setReceiveTimeout(100000);
conduit.setClient(clientConfig);
jdbcTemplate.update("delete from EVENTS");
List<EventType> events = new ArrayList<EventType>();
EventType eventType = new EventType();
eventType.setEventType(EventEnumType.REQ_OUT);
URL messageContentFile = this.getClass().getResource("/testmessage.xml").toURI().toURL();
eventType.setContent(new DataHandler(messageContentFile));
CustomInfoType ciType = new CustomInfoType();
CustomInfoType.Item prop1 = new CustomInfoType.Item();
prop1.setKey("mykey1");
prop1.setValue("myValue1");
ciType.getItem().add(prop1);
CustomInfoType.Item prop2 = new CustomInfoType.Item();
prop2.setKey("mykey2");
prop2.setValue("myValue2");
ciType.getItem().add(prop2);
eventType.setCustomInfo(ciType);
MessageInfoType mit = new MessageInfoType();
mit.setFlowId("uuid");
eventType.setMessageInfo(mit);
events.add(eventType);
String result = monitoringService.putEvents(events);
Assert.assertEquals("success", result);
long id = jdbcTemplate.queryForObject("select id from EVENTS", Long.class);
Event readEvent = eventRepository.readEvent(id);
Assert.assertEquals(EventTypeEnum.REQ_OUT, readEvent.getEventType());
Map<String, String> customInfo = readEvent.getCustomInfo();
Assert.assertEquals("myValue1", customInfo.get("mykey1"));
Assert.assertEquals("myValue2", customInfo.get("mykey2"));
}
Aggregations