Search in sources :

Example 1 with EventType

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!");
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType)

Example 2 with EventType

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);
    }
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) MonitoringException(org.talend.esb.sam.common.event.MonitoringException) ArrayList(java.util.ArrayList) Event(org.talend.esb.sam.common.event.Event) MonitoringException(org.talend.esb.sam.common.event.MonitoringException)

Example 3 with EventType

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");
}
Also used : Originator(org.talend.esb.sam.common.event.Originator) EventType(org.talend.esb.sam._2011._03.common.EventType) Event(org.talend.esb.sam.common.event.Event) DataHandler(javax.activation.DataHandler) MessageInfo(org.talend.esb.sam.common.event.MessageInfo) Test(org.junit.Test)

Example 4 with EventType

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);
}
Also used : CustomInfoType(org.talend.esb.sam._2011._03.common.CustomInfoType) EventType(org.talend.esb.sam._2011._03.common.EventType) OriginatorType(org.talend.esb.sam._2011._03.common.OriginatorType) MessageInfoType(org.talend.esb.sam._2011._03.common.MessageInfoType) Test(org.junit.Test)

Example 5 with 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"));
}
Also used : EventType(org.talend.esb.sam._2011._03.common.EventType) ArrayList(java.util.ArrayList) DataHandler(javax.activation.DataHandler) URL(java.net.URL) HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) CustomInfoType(org.talend.esb.sam._2011._03.common.CustomInfoType) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Event(org.talend.esb.sam.common.event.Event) Client(org.apache.cxf.endpoint.Client) MessageInfoType(org.talend.esb.sam._2011._03.common.MessageInfoType) Test(org.junit.Test)

Aggregations

EventType (org.talend.esb.sam._2011._03.common.EventType)9 DataHandler (javax.activation.DataHandler)4 Test (org.junit.Test)4 Event (org.talend.esb.sam.common.event.Event)4 CustomInfoType (org.talend.esb.sam._2011._03.common.CustomInfoType)3 MessageInfoType (org.talend.esb.sam._2011._03.common.MessageInfoType)3 OriginatorType (org.talend.esb.sam._2011._03.common.OriginatorType)3 ArrayList (java.util.ArrayList)2 InetAddress (java.net.InetAddress)1 URL (java.net.URL)1 UnknownHostException (java.net.UnknownHostException)1 Date (java.util.Date)1 Client (org.apache.cxf.endpoint.Client)1 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)1 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1 MessageInfo (org.talend.esb.sam.common.event.MessageInfo)1 MonitoringException (org.talend.esb.sam.common.event.MonitoringException)1 Originator (org.talend.esb.sam.common.event.Originator)1