use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.
the class TopologyTestRunResource method getEventTreeOfTestRunTopologyHistory.
@GET
@Path("/topologies/{topologyId}/testhistories/{historyId}/events/tree/{rootEventId}")
public Response getEventTreeOfTestRunTopologyHistory(@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);
EventInformationTreeNode rootEventNode = new EventInformationTreeBuilder(events).constructEventTree(rootEventId);
if (rootEventNode == null) {
throw BadRequestException.message("Can't find provided root event " + rootEventId + " from events.");
}
return WSUtils.respondEntity(rootEventNode, OK);
}
use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.
the class TopologyTestRunResource method getRootEventsOfTestRunTopologyHistory.
@GET
@Path("/topologies/{topologyId}/testhistories/{historyId}/events/root")
public Response getRootEventsOfTestRunTopologyHistory(@Context UriInfo urlInfo, @PathParam("topologyId") Long topologyId, @PathParam("historyId") Long historyId, @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);
List<com.hortonworks.registries.common.QueryParam> qps = com.hortonworks.registries.common.QueryParam.params(TopologySource.TOPOLOGYID, topologyId.toString(), TopologySource.VERSIONID, catalogService.getCurrentVersionId(topologyId).toString());
Set<String> sourceNames = catalogService.listTopologySources(qps).stream().map(TopologyComponent::getName).collect(Collectors.toSet());
return WSUtils.respondEntities(new CorrelatedEventsGrouper(events).groupByRelatedSourceEvents(sourceNames), OK);
}
use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.
the class TopologyTestRunResource method getEventsOfTestRunTopologyHistory.
private Response getEventsOfTestRunTopologyHistory(Long topologyId, Long historyId, String componentName, SecurityContext securityContext) throws IOException {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, READ);
File eventLogFile = getEventLogFile(topologyId, historyId);
Stream<EventInformation> eventsStream = eventLogFileReader.loadEventLogFileAsStream(eventLogFile);
if (!StringUtils.isEmpty(componentName)) {
eventsStream = eventsStream.filter(event -> {
String eventComponentName = event.getComponentName();
return eventComponentName != null && eventComponentName.equals(componentName);
});
}
return WSUtils.respondEntities(eventsStream.collect(toList()), OK);
}
use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.
the class TestRunEventLogger method writeEvent.
// Writing event to file should be mutually exclusive.
// We don't need to worry about performance since it's just for testing topology locally.
public synchronized void writeEvent(long timestamp, String componentName, String streamId, Set<String> targetComponents, StreamlineEvent event) {
try (FileWriter fw = new FileWriter(eventLogFilePath, true)) {
LOG.debug("writing event to file " + eventLogFilePath);
EventInformationBuilder informationBuilder = new EventInformationBuilder();
EventInformation eventInfo = informationBuilder.build(timestamp, componentName, streamId, targetComponents, event);
fw.write(objectMapper.writeValueAsString(eventInfo) + "\n");
fw.flush();
} catch (FileNotFoundException e) {
LOG.error("Can't open file for write: " + eventLogFilePath);
throw new RuntimeException(e);
} catch (IOException e) {
LOG.error("Fail to write event to output file " + eventLogFilePath + " : exception occurred.", e);
throw new RuntimeException(e);
}
}
use of com.hortonworks.streamline.streams.common.event.EventInformation in project streamline by hortonworks.
the class GroupedCorrelationEventsTest method testGroupedCorrelationPlacingEventsMatchedRootIdFirst.
@Test
public void testGroupedCorrelationPlacingEventsMatchedRootIdFirst() throws IOException {
long timestamp = System.currentTimeMillis();
Map<String, EventInformation> testEventsMap = new HashMap<>();
/*
<SOURCE1> <PROJECTION> <AGGREGATION> <JOIN> <SINK>
e1, e2 -> e4 (e1), e5 (e2) -> e6 (e4 & e5) -> e7 (e6 & e3) ->
<SOURCE2>
e3 /
*/
EventInformation event1 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("PROJECTION"), "1", Collections.emptySet(), Collections.emptySet(), TEST_FIELDS_AND_VALUES);
testEventsMap.put(event1.getEventId(), event1);
EventInformation event2 = new EventInformation(timestamp, "SOURCE1", "default", Collections.singleton("PROJECTION"), "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, "PROJECTION", "default", Collections.singleton("AGGREGATION"), "4", Sets.newHashSet("1"), Sets.newHashSet("1"), TEST_FIELDS_AND_VALUES);
testEventsMap.put(event4.getEventId(), event4);
EventInformation event5 = new EventInformation(timestamp, "PROJECTION", "default", Collections.singleton("AGGREGATION"), "5", Sets.newHashSet("2"), Sets.newHashSet("2"), TEST_FIELDS_AND_VALUES);
testEventsMap.put(event5.getEventId(), event5);
EventInformation event6 = new EventInformation(timestamp, "AGGREGATION", "default", Collections.singleton("JOIN"), "6", Sets.newHashSet("1", "2"), Sets.newHashSet("4", "5"), TEST_FIELDS_AND_VALUES);
testEventsMap.put(event6.getEventId(), event6);
EventInformation event7 = new EventInformation(timestamp, "JOIN", "default", Collections.singleton("SINK"), "7", Sets.newHashSet("1", "2", "3"), Sets.newHashSet("6", "3"), TEST_FIELDS_AND_VALUES);
testEventsMap.put(event7.getEventId(), event7);
// 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", "2"), 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("3"), new HashSet<>(source2.getOutputEventIds()));
GroupedCorrelationEvents.SortedComponentGroupedEvents projection = componentGroupedEvents.get("PROJECTION");
Assert.assertEquals("PROJECTION", projection.getComponentName());
Assert.assertFalse(projection.isContainingSelectedEvent());
// guarantee: selected event placed first
Assert.assertEquals(Lists.newArrayList("1", "2"), projection.getInputEventIds());
// guarantee: events which contains selected event as one of root ids placed earlier
Assert.assertEquals(Lists.newArrayList("4", "5"), projection.getOutputEventIds());
GroupedCorrelationEvents.SortedComponentGroupedEvents aggregation = componentGroupedEvents.get("AGGREGATION");
Assert.assertEquals("AGGREGATION", aggregation.getComponentName());
Assert.assertFalse(aggregation.isContainingSelectedEvent());
// guarantee: events which contains selected event as one of root ids placed earlier
Assert.assertEquals(Lists.newArrayList("4", "5"), aggregation.getInputEventIds());
// no sequence guarantee
Assert.assertEquals(Lists.newArrayList("6"), aggregation.getOutputEventIds());
GroupedCorrelationEvents.SortedComponentGroupedEvents join = componentGroupedEvents.get("JOIN");
Assert.assertEquals("JOIN", join.getComponentName());
Assert.assertFalse(join.isContainingSelectedEvent());
// guarantee: events which contains selected event as one of root ids placed earlier
Assert.assertEquals(Lists.newArrayList("6", "3"), join.getInputEventIds());
// no sequence guarantee
Assert.assertEquals(Sets.newHashSet("7"), new HashSet<>(join.getOutputEventIds()));
GroupedCorrelationEvents.SortedComponentGroupedEvents sink = componentGroupedEvents.get("SINK");
Assert.assertEquals("SINK", sink.getComponentName());
Assert.assertFalse(sink.isContainingSelectedEvent());
// no sequence guarantee
Assert.assertEquals(Sets.newHashSet("7"), 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.assertTrue(source1.isContainingSelectedEvent());
Assert.assertTrue(source1.getInputEventIds().isEmpty());
// guarantee: selected event placed first
Assert.assertEquals(Lists.newArrayList("2", "1"), source1.getOutputEventIds());
projection = componentGroupedEvents.get("PROJECTION");
Assert.assertEquals("PROJECTION", projection.getComponentName());
Assert.assertFalse(projection.isContainingSelectedEvent());
// guarantee: selected event placed first
Assert.assertEquals(Lists.newArrayList("2", "1"), projection.getInputEventIds());
// guarantee: events which contains selected event as one of root ids placed earlier
Assert.assertEquals(Lists.newArrayList("5", "4"), projection.getOutputEventIds());
aggregation = componentGroupedEvents.get("AGGREGATION");
Assert.assertEquals("AGGREGATION", aggregation.getComponentName());
Assert.assertFalse(aggregation.isContainingSelectedEvent());
// guarantee: events which contains selected event as one of root ids placed earlier
Assert.assertEquals(Lists.newArrayList("5", "4"), aggregation.getInputEventIds());
// no sequence guarantee
Assert.assertEquals(Lists.newArrayList("6"), aggregation.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"), source2.getOutputEventIds());
// other components are same
}
Aggregations