Search in sources :

Example 6 with EventInformation

use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.

the class GroupedCorrelationEventsTest method testBuildGroupedCorrelationEvents.

@Test
public void testBuildGroupedCorrelationEvents() throws IOException {
    long timestamp = System.currentTimeMillis();
    Map<String, EventInformation> testEventsMap = new HashMap<>();
    /*
         <SOURCE1>                  <JOIN>               <AGGREGATION>      <SINK>
             e1         -> e4 (e1 & e2), e5 (e1 & e3) ->  e6 (e4 & e5)  ->

         <SOURCE2>
           e2, e3       /
        */
    EventInformation event1 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("JOIN"), "1", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event1.getEventId(), event1);
    EventInformation event2 = new EventInformation(timestamp, "SOURCE2", "default", Collections.singleton("JOIN"), "2", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event2.getEventId(), event2);
    EventInformation event3 = new EventInformation(timestamp, "SOURCE2", "default", Collections.singleton("JOIN"), "3", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event3.getEventId(), event3);
    EventInformation event4 = new EventInformation(timestamp, "JOIN", "default", Collections.singleton("AGGREGATION"), "4", Sets.newHashSet("1", "2"), Sets.newHashSet("1", "2"), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event4.getEventId(), event4);
    EventInformation event5 = new EventInformation(timestamp, "JOIN", "default", Collections.singleton("AGGREGATION"), "5", Sets.newHashSet("1", "3"), Sets.newHashSet("1", "3"), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event5.getEventId(), event5);
    EventInformation event6 = new EventInformation(timestamp, "AGGREGATION", "default", Collections.singleton("SINK"), "6", Sets.newHashSet("1", "2", "3"), Sets.newHashSet("5", "6"), TEST_FIELDS_AND_VALUES);
    testEventsMap.put(event6.getEventId(), event6);
    // event 1 is being selected
    GroupedCorrelationEvents sut = new GroupedCorrelationEvents(testEventsMap, "1");
    Map<String, EventInformation> allEvents = sut.getAllEvents();
    Assert.assertEquals(testEventsMap, allEvents);
    Map<String, GroupedCorrelationEvents.SortedComponentGroupedEvents> componentGroupedEvents = sut.getComponentGroupedEvents();
    GroupedCorrelationEvents.SortedComponentGroupedEvents source1 = componentGroupedEvents.get("SOURCE1");
    Assert.assertEquals("SOURCE1", source1.getComponentName());
    Assert.assertTrue(source1.isContainingSelectedEvent());
    Assert.assertTrue(source1.getInputEventIds().isEmpty());
    // guarantee: selected event placed first
    Assert.assertEquals(Lists.newArrayList("1"), source1.getOutputEventIds());
    GroupedCorrelationEvents.SortedComponentGroupedEvents source2 = componentGroupedEvents.get("SOURCE2");
    Assert.assertEquals("SOURCE2", source2.getComponentName());
    Assert.assertFalse(source2.isContainingSelectedEvent());
    Assert.assertTrue(source2.getInputEventIds().isEmpty());
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("2", "3"), new HashSet<>(source2.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents join = componentGroupedEvents.get("JOIN");
    Assert.assertEquals("JOIN", join.getComponentName());
    Assert.assertFalse(join.isContainingSelectedEvent());
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("1", "2", "3"), new HashSet<>(join.getInputEventIds()));
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("4", "5"), new HashSet<>(join.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents aggregation = componentGroupedEvents.get("AGGREGATION");
    Assert.assertEquals("AGGREGATION", aggregation.getComponentName());
    Assert.assertFalse(aggregation.isContainingSelectedEvent());
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("4", "5"), new HashSet<>(aggregation.getInputEventIds()));
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("6"), new HashSet<>(aggregation.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents sink = componentGroupedEvents.get("SINK");
    Assert.assertEquals("SINK", sink.getComponentName());
    Assert.assertFalse(sink.isContainingSelectedEvent());
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("6"), new HashSet<>(sink.getInputEventIds()));
    Assert.assertTrue(sink.getOutputEventIds().isEmpty());
    // event 2 is being selected
    sut = new GroupedCorrelationEvents(testEventsMap, "2");
    componentGroupedEvents = sut.getComponentGroupedEvents();
    source1 = componentGroupedEvents.get("SOURCE1");
    Assert.assertEquals("SOURCE1", source1.getComponentName());
    Assert.assertFalse(source1.isContainingSelectedEvent());
    Assert.assertTrue(source1.getInputEventIds().isEmpty());
    // no sequence guarantee
    Assert.assertEquals(Sets.newHashSet("1"), new HashSet<>(source1.getOutputEventIds()));
    source2 = componentGroupedEvents.get("SOURCE2");
    Assert.assertEquals("SOURCE2", source2.getComponentName());
    Assert.assertTrue(source2.isContainingSelectedEvent());
    Assert.assertTrue(source2.getInputEventIds().isEmpty());
    // guarantee: selected event placed first
    Assert.assertEquals(Lists.newArrayList("2", "3"), source2.getOutputEventIds());
    // other components are same
    // event 3 is being selected
    sut = new GroupedCorrelationEvents(testEventsMap, "3");
    componentGroupedEvents = sut.getComponentGroupedEvents();
    source2 = componentGroupedEvents.get("SOURCE2");
    Assert.assertEquals("SOURCE2", source2.getComponentName());
    Assert.assertTrue(source2.isContainingSelectedEvent());
    Assert.assertTrue(source2.getInputEventIds().isEmpty());
    // guarantee: selected event placed first
    Assert.assertEquals(Lists.newArrayList("3", "2"), source2.getOutputEventIds());
// other components are same
}
Also used : EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) Test(org.junit.Test)

Example 7 with EventInformation

use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.

the class CorrelatedEventsGrouperTest method testGroupEvents.

@Test
public void testGroupEvents() throws Exception {
    long timestamp = System.currentTimeMillis();
    List<EventInformation> testEvents = new ArrayList<>();
    /*
         <SOURCE1>         <AGGREGATION>            <JOIN>         <PROJECTION>      <SINK>
           e1, e2     ->   e4 (e1 & e2)      ->  e5 (e4 & e3)  ->      e6        ->

                  <SOURCE2>
                     e3                      /

           .... and more
        */
    EventInformation event1 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("AGGREGATION"), "1", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event1);
    EventInformation event2 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("AGGREGATION"), "2", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event2);
    EventInformation event3 = new EventInformation(timestamp, "SOURCE2", "default", Collections.singleton("JOIN"), "3", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event3);
    EventInformation event4 = new EventInformation(timestamp, "AGGREGATION", "default", Collections.singleton("JOIN"), "4", Sets.newHashSet("1", "2"), Sets.newHashSet("1", "2"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event4);
    EventInformation event5 = new EventInformation(timestamp, "JOIN", "default", Collections.singleton("PROJECTION"), "5", Sets.newHashSet("1", "2", "3"), Sets.newHashSet("4", "3"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event5);
    EventInformation event6 = new EventInformation(timestamp, "PROJECTION", "default", Collections.singleton("SINK"), "6", Sets.newHashSet("1", "2", "3"), Sets.newHashSet("5"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event6);
    // below two events are not correlated to root event
    EventInformation event7 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("AGGREGATION"), "7", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event7);
    EventInformation event8 = new EventInformation(timestamp, "SOURCE2", "default", Collections.singleton("JOIN"), "8", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event8);
    CorrelatedEventsGrouper eventsGrouper = new CorrelatedEventsGrouper(testEvents);
    GroupedCorrelationEvents groupedEvents = eventsGrouper.groupByComponent(event3.getEventId());
    Map<String, EventInformation> allEvents = groupedEvents.getAllEvents();
    // only 1 ~ 6
    Assert.assertEquals(6, allEvents.size());
    Assert.assertFalse(allEvents.containsKey("7"));
    Assert.assertFalse(allEvents.containsKey("8"));
    Map<String, GroupedCorrelationEvents.SortedComponentGroupedEvents> componentGroupedEvents = groupedEvents.getComponentGroupedEvents();
    GroupedCorrelationEvents.SortedComponentGroupedEvents source1 = componentGroupedEvents.get("SOURCE1");
    Assert.assertEquals("SOURCE1", source1.getComponentName());
    Assert.assertFalse(source1.isContainingSelectedEvent());
    Assert.assertTrue(source1.getInputEventIds().isEmpty());
    Assert.assertEquals(Sets.newHashSet("1", "2"), new HashSet<>(source1.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents source2 = componentGroupedEvents.get("SOURCE2");
    Assert.assertEquals("SOURCE2", source2.getComponentName());
    Assert.assertTrue(source2.isContainingSelectedEvent());
    Assert.assertTrue(source2.getInputEventIds().isEmpty());
    Assert.assertEquals(Sets.newHashSet("3"), new HashSet<>(source2.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents aggregation = componentGroupedEvents.get("AGGREGATION");
    Assert.assertEquals("AGGREGATION", aggregation.getComponentName());
    Assert.assertFalse(aggregation.isContainingSelectedEvent());
    Assert.assertEquals(Sets.newHashSet("1", "2"), new HashSet<>(aggregation.getInputEventIds()));
    Assert.assertEquals(Sets.newHashSet("4"), new HashSet<>(aggregation.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents join = componentGroupedEvents.get("JOIN");
    Assert.assertEquals("JOIN", join.getComponentName());
    Assert.assertFalse(join.isContainingSelectedEvent());
    Assert.assertEquals(Sets.newHashSet("4", "3"), new HashSet<>(join.getInputEventIds()));
    Assert.assertEquals(Sets.newHashSet("5"), new HashSet<>(join.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents projection = componentGroupedEvents.get("PROJECTION");
    Assert.assertEquals("PROJECTION", projection.getComponentName());
    Assert.assertFalse(projection.isContainingSelectedEvent());
    Assert.assertEquals(Sets.newHashSet("5"), new HashSet<>(projection.getInputEventIds()));
    Assert.assertEquals(Sets.newHashSet("6"), new HashSet<>(projection.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents sink = componentGroupedEvents.get("SINK");
    Assert.assertEquals("SINK", sink.getComponentName());
    Assert.assertFalse(sink.isContainingSelectedEvent());
    Assert.assertEquals(Sets.newHashSet("6"), new HashSet<>(sink.getInputEventIds()));
    Assert.assertTrue(sink.getOutputEventIds().isEmpty());
}
Also used : EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) Test(org.junit.Test)

Example 8 with EventInformation

use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.

the class CorrelatedEventsGrouperTest method testGroupEventsWithSplitProcessor.

@Test
public void testGroupEventsWithSplitProcessor() throws Exception {
    long timestamp = System.currentTimeMillis();
    List<EventInformation> testEvents = new ArrayList<>();
    /*
         <SOURCE>    <SPLIT>       <PROJECTION1>        <SINK1>
           e1     ->     e2     ->      e3         ->

                                \   <PROJECTION2>
                                        e4         ->

                                \   <PROJECTION3>
                                        e5         ->
        */
    EventInformation event1 = new EventInformation(timestamp, "SOURCE", "default", Collections.singleton("SPLIT"), "1", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
    testEvents.add(event1);
    EventInformation event2 = new EventInformation(timestamp, "SPLIT", "stream1", Sets.newHashSet("PROJECTION1", "PROJECTION2", "PROJECTION3"), "2", Sets.newHashSet("1"), Sets.newHashSet("1"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event2);
    EventInformation event3 = new EventInformation(timestamp, "PROJECTION1", "default", Collections.singleton("SINK1"), "3", Sets.newHashSet("1"), Sets.newHashSet("2"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event3);
    EventInformation event4 = new EventInformation(timestamp, "PROJECTION2", "default", Collections.singleton("SINK2"), "4", Sets.newHashSet("1"), Sets.newHashSet("2"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event4);
    EventInformation event5 = new EventInformation(timestamp, "PROJECTION3", "default", Collections.singleton("SINK3"), "5", Sets.newHashSet("1"), Sets.newHashSet("2"), TEST_FIELDS_AND_VALUES);
    testEvents.add(event5);
    CorrelatedEventsGrouper eventsGrouper = new CorrelatedEventsGrouper(testEvents);
    GroupedCorrelationEvents groupedEvents = eventsGrouper.groupByComponent(event1.getEventId());
    Map<String, EventInformation> allEvents = groupedEvents.getAllEvents();
    Assert.assertEquals(5, allEvents.size());
    Map<String, GroupedCorrelationEvents.SortedComponentGroupedEvents> componentGroupedEvents = groupedEvents.getComponentGroupedEvents();
    GroupedCorrelationEvents.SortedComponentGroupedEvents source = componentGroupedEvents.get("SOURCE");
    Assert.assertEquals("SOURCE", source.getComponentName());
    Assert.assertTrue(source.isContainingSelectedEvent());
    Assert.assertTrue(source.getInputEventIds().isEmpty());
    Assert.assertEquals(Sets.newHashSet("1"), new HashSet<>(source.getOutputEventIds()));
    GroupedCorrelationEvents.SortedComponentGroupedEvents split = componentGroupedEvents.get("SPLIT");
    Assert.assertEquals("SPLIT", split.getComponentName());
    Assert.assertFalse(split.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("1"), split.getInputEventIds());
    Assert.assertEquals(Collections.singletonList("2"), split.getOutputEventIds());
    GroupedCorrelationEvents.SortedComponentGroupedEvents projection1 = componentGroupedEvents.get("PROJECTION1");
    Assert.assertEquals("PROJECTION1", projection1.getComponentName());
    Assert.assertFalse(projection1.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("2"), projection1.getInputEventIds());
    Assert.assertEquals(Collections.singletonList("3"), projection1.getOutputEventIds());
    GroupedCorrelationEvents.SortedComponentGroupedEvents projection2 = componentGroupedEvents.get("PROJECTION2");
    Assert.assertEquals("PROJECTION2", projection2.getComponentName());
    Assert.assertFalse(projection2.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("2"), projection2.getInputEventIds());
    Assert.assertEquals(Collections.singletonList("4"), projection2.getOutputEventIds());
    GroupedCorrelationEvents.SortedComponentGroupedEvents projection3 = componentGroupedEvents.get("PROJECTION3");
    Assert.assertEquals("PROJECTION3", projection3.getComponentName());
    Assert.assertFalse(projection3.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("2"), projection3.getInputEventIds());
    Assert.assertEquals(Collections.singletonList("5"), projection3.getOutputEventIds());
    GroupedCorrelationEvents.SortedComponentGroupedEvents sink1 = componentGroupedEvents.get("SINK1");
    Assert.assertEquals("SINK1", sink1.getComponentName());
    Assert.assertFalse(sink1.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("3"), sink1.getInputEventIds());
    Assert.assertTrue(sink1.getOutputEventIds().isEmpty());
    GroupedCorrelationEvents.SortedComponentGroupedEvents sink2 = componentGroupedEvents.get("SINK2");
    Assert.assertEquals("SINK2", sink2.getComponentName());
    Assert.assertFalse(sink2.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("4"), sink2.getInputEventIds());
    Assert.assertTrue(sink2.getOutputEventIds().isEmpty());
    GroupedCorrelationEvents.SortedComponentGroupedEvents sink3 = componentGroupedEvents.get("SINK3");
    Assert.assertEquals("SINK3", sink3.getComponentName());
    Assert.assertFalse(sink3.isContainingSelectedEvent());
    Assert.assertEquals(Collections.singletonList("5"), sink3.getInputEventIds());
    Assert.assertTrue(sink3.getOutputEventIds().isEmpty());
}
Also used : EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) Test(org.junit.Test)

Example 9 with EventInformation

use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.

the class CorrelatedEventsGrouper method findAndAddParentsIfNecessary.

private void findAndAddParentsIfNecessary(Map<String, EventInformation> allEventsMap, Map<String, EventInformation> relatedEventsMap, Map<String, EventInformation> eventsToAddMap, EventInformation event) {
    Set<String> parentIds = event.getParentIds();
    for (String parentId : parentIds) {
        if (!relatedEventsMap.containsKey(parentId) && !eventsToAddMap.containsKey(parentId)) {
            // find and add parent to relatedEventsMap
            EventInformation parent = allEventsMap.get(parentId);
            if (parent == null) {
                throw new RuntimeException("Failed to find parent event: logged event information may be corrupted.");
            }
            eventsToAddMap.put(parent.getEventId(), parent);
            // newly found parent event may have parent event(s) as well... find them as well
            findAndAddParentsIfNecessary(allEventsMap, relatedEventsMap, eventsToAddMap, parent);
        }
    }
}
Also used : EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation)

Example 10 with EventInformation

use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.

the class TopologyTestRunResource method getGroupedCorrelatedEventsOfTestRunTopologyHistory.

@GET
@Path("/topologies/{topologyId}/testhistories/{historyId}/events/correlated/{rootEventId}")
public Response getGroupedCorrelatedEventsOfTestRunTopologyHistory(@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, @PathParam("historyId") Long historyId, @PathParam("rootEventId") String rootEventId, @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
    File eventLogFile = getEventLogFile(topologyId, historyId);
    List<EventInformation> events = eventLogFileReader.loadEventLogFile(eventLogFile);
    GroupedCorrelationEvents groupedEvents = new CorrelatedEventsGrouper(events).groupByComponent(rootEventId);
    if (!groupedEvents.getAllEvents().containsKey(rootEventId)) {
        throw BadRequestException.message("Can't find provided root event " + rootEventId + " from events.");
    }
    return WSUtils.respondEntity(groupedEvents, OK);
}
Also used : CorrelatedEventsGrouper(com.hortonworks.streamline.streams.common.event.correlation.CorrelatedEventsGrouper) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) GroupedCorrelationEvents(com.hortonworks.streamline.streams.common.event.correlation.GroupedCorrelationEvents) File(java.io.File) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

EventInformation (com.hortonworks.streamline.streams.common.event.EventInformation)11 File (java.io.File)5 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Test (org.junit.Test)4 CorrelatedEventsGrouper (com.hortonworks.streamline.streams.common.event.correlation.CorrelatedEventsGrouper)3 EventInformationTreeBuilder (com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeBuilder)3 EventInformationTreeNode (com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeNode)3 GroupedCorrelationEvents (com.hortonworks.streamline.streams.common.event.correlation.GroupedCorrelationEvents)2 IOException (java.io.IOException)2 QueryParam (javax.ws.rs.QueryParam)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Schema (com.hortonworks.registries.common.Schema)1 SchemaValueConverter (com.hortonworks.streamline.common.SchemaValueConverter)1 SchemaValidationFailedException (com.hortonworks.streamline.common.exception.SchemaValidationFailedException)1 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)1 EntityNotFoundException (com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException)1