Search in sources :

Example 1 with EventInformation

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);
}
Also used : EventInformationTreeBuilder(com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeBuilder) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) EventInformationTreeNode(com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeNode) File(java.io.File) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with EventInformation

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);
}
Also used : CorrelatedEventsGrouper(com.hortonworks.streamline.streams.common.event.correlation.CorrelatedEventsGrouper) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) QueryParam(javax.ws.rs.QueryParam) File(java.io.File) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with EventInformation

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);
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) Roles(com.hortonworks.streamline.streams.security.Roles) Produces(javax.ws.rs.Produces) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) BooleanUtils(org.apache.commons.lang.BooleanUtils) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) WSUtils(com.hortonworks.streamline.common.util.WSUtils) READ(com.hortonworks.streamline.streams.security.Permission.READ) TypeReference(com.fasterxml.jackson.core.type.TypeReference) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) DELETE(javax.ws.rs.DELETE) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) TopologySink(com.hortonworks.streamline.streams.catalog.TopologySink) Context(javax.ws.rs.core.Context) EventInformationTreeBuilder(com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeBuilder) OK(javax.ws.rs.core.Response.Status.OK) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Timed(com.codahale.metrics.annotation.Timed) TopologySource(com.hortonworks.streamline.streams.catalog.TopologySource) List(java.util.List) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) SchemaValidationFailedException(com.hortonworks.streamline.common.exception.SchemaValidationFailedException) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) CREATED(javax.ws.rs.core.Response.Status.CREATED) JsonIgnoreProperties(com.fasterxml.jackson.annotation.JsonIgnoreProperties) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) StringUtils(org.datanucleus.util.StringUtils) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) EventInformationTreeNode(com.hortonworks.streamline.streams.common.event.tree.EventInformationTreeNode) GET(javax.ws.rs.GET) Schema(com.hortonworks.registries.common.Schema) WRITE(com.hortonworks.streamline.streams.security.Permission.WRITE) GroupedCorrelationEvents(com.hortonworks.streamline.streams.common.event.correlation.GroupedCorrelationEvents) EventLogFileReader(com.hortonworks.streamline.streams.common.event.EventLogFileReader) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TopologyActionsService(com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) SchemaValueConverter(com.hortonworks.streamline.common.SchemaValueConverter) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TopologyComponent(com.hortonworks.streamline.streams.catalog.TopologyComponent) Collectors.toList(java.util.stream.Collectors.toList) CorrelatedEventsGrouper(com.hortonworks.streamline.streams.common.event.correlation.CorrelatedEventsGrouper) EXECUTE(com.hortonworks.streamline.streams.security.Permission.EXECUTE) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) InputStream(java.io.InputStream) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) File(java.io.File)

Example 4 with EventInformation

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);
    }
}
Also used : EventInformationBuilder(com.hortonworks.streamline.streams.common.event.EventInformationBuilder) EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 5 with EventInformation

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
}
Also used : EventInformation(com.hortonworks.streamline.streams.common.event.EventInformation) Test(org.junit.Test)

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