Search in sources :

Example 1 with FlowEvent

use of com.twitter.hraven.FlowEvent in project ambrose by twitter.

the class HRavenStatsReadService method getEventsSinceId.

@SuppressWarnings("rawtypes")
@Override
public List<Event> getEventsSinceId(String workflowId, int eventId, int maxEvents) throws IOException {
    Preconditions.checkArgument(maxEvents > 0);
    WorkflowId id = WorkflowId.parseString(workflowId);
    FlowEventKey flowEventKey = new FlowEventKey(toFlowKey(id), eventId);
    List<FlowEvent> flowEventList = flowEventService.getFlowEventsSince(flowEventKey);
    // TODO push this limit into the FlowEventService
    int numElems = 0;
    List<Event> workflowEvents = Lists.newArrayListWithCapacity(maxEvents);
    for (FlowEvent flowEvent : flowEventList) {
        if (numElems >= maxEvents) {
            break;
        }
        String eventDataJson = flowEvent.getEventDataJSON();
        try {
            Event event = Event.fromJson(eventDataJson);
            numElems++;
            workflowEvents.add(event);
        } catch (JsonMappingException e) {
            LOG.error("Could not deserialize json: " + eventDataJson, e);
        }
    }
    return workflowEvents;
}
Also used : FlowEvent(com.twitter.hraven.FlowEvent) FlowEventKey(com.twitter.hraven.FlowEventKey) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Event(com.twitter.ambrose.model.Event) FlowEvent(com.twitter.hraven.FlowEvent) WorkflowId(com.twitter.ambrose.model.WorkflowId)

Example 2 with FlowEvent

use of com.twitter.hraven.FlowEvent in project ambrose by twitter.

the class HRavenStatsWriteService method pushEvent.

@SuppressWarnings("unchecked")
@Override
public void pushEvent(String workflowId, Event event) throws IOException {
    String eventDataJson = event.toJson();
    switch(event.getType()) {
        case WORKFLOW_PROGRESS:
            updateWorkflowProgress((Map<Event.WorkflowProgressField, String>) event.getPayload());
            break;
        case JOB_STARTED:
            updateJobStarted((DAGNode) event.getPayload());
            break;
        case JOB_FAILED:
        case JOB_FINISHED:
            updateJobComplete((DAGNode) event.getPayload(), event.getType());
            break;
        default:
            break;
    }
    Preconditions.checkNotNull(flowKey, String.format("Can not push event type %s because flowKey is not set", event.getType()));
    FlowEventKey eventKey = new FlowEventKey(flowKey, event.getId());
    FlowEvent flowEvent = new FlowEvent(eventKey);
    flowEvent.setTimestamp(event.getTimestamp());
    flowEvent.setFramework(JobDescFactory.getFramework(jobConf));
    flowEvent.setType(event.getType().name());
    if (eventDataJson != null) {
        flowEvent.setEventDataJSON(eventDataJson);
    }
    hRavenPool.submit(new HRavenEventRunnable(flowEventService, flowEvent));
}
Also used : FlowEvent(com.twitter.hraven.FlowEvent) FlowEventKey(com.twitter.hraven.FlowEventKey)

Aggregations

FlowEvent (com.twitter.hraven.FlowEvent)2 FlowEventKey (com.twitter.hraven.FlowEventKey)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Event (com.twitter.ambrose.model.Event)1 WorkflowId (com.twitter.ambrose.model.WorkflowId)1