use of org.talend.esb.sam.common.event.Event 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.common.event.Event in project tesb-rt-se by Talend.
the class AbstractListenerImpl method processStop.
/**
* Process stop.
*
* @param endpoint the endpoint
* @param eventType the event type
*/
protected void processStop(Endpoint endpoint, EventTypeEnum eventType) {
if (!sendLifecycleEvent) {
return;
}
Event event = createEvent(endpoint, eventType);
monitoringServiceClient.putEvents(Collections.singletonList(event));
if (LOG.isLoggable(Level.INFO)) {
LOG.info("Send " + eventType + " event to SAM Server successful!");
}
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class AbstractListenerImpl method processStart.
/**
* Process start.
*
* @param endpoint the endpoint
* @param eventType the event type
*/
protected void processStart(Endpoint endpoint, EventTypeEnum eventType) {
if (!sendLifecycleEvent) {
return;
}
Event event = createEvent(endpoint, eventType);
queue.add(event);
}
use of org.talend.esb.sam.common.event.Event in project tesb-rt-se by Talend.
the class AbstractListenerImpl method createEvent.
/**
* Creates the event for endpoint with specific type.
*
* @param endpoint the endpoint
* @param type the type
* @return the event
*/
private Event createEvent(Endpoint endpoint, EventTypeEnum type) {
Event event = new Event();
MessageInfo messageInfo = new MessageInfo();
Originator originator = new Originator();
event.setMessageInfo(messageInfo);
event.setOriginator(originator);
Date date = new Date();
event.setTimestamp(date);
event.setEventType(type);
messageInfo.setPortType(endpoint.getBinding().getBindingInfo().getService().getInterface().getName().toString());
String transportType = null;
if (endpoint.getBinding() instanceof SoapBinding) {
SoapBinding soapBinding = (SoapBinding) endpoint.getBinding();
if (soapBinding.getBindingInfo() instanceof SoapBindingInfo) {
SoapBindingInfo soapBindingInfo = (SoapBindingInfo) soapBinding.getBindingInfo();
transportType = soapBindingInfo.getTransportURI();
}
}
messageInfo.setTransportType((transportType != null) ? transportType : "Unknown transport type");
originator.setProcessId(Converter.getPID());
try {
InetAddress inetAddress = InetAddress.getLocalHost();
originator.setIp(inetAddress.getHostAddress());
originator.setHostname(inetAddress.getHostName());
} catch (UnknownHostException e) {
originator.setHostname("Unknown hostname");
originator.setIp("Unknown ip address");
}
String address = endpoint.getEndpointInfo().getAddress();
event.getCustomInfo().put("address", address);
return event;
}
use of org.talend.esb.sam.common.event.Event 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");
}
Aggregations