use of com.twitter.hraven.FlowEventKey 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;
}
use of com.twitter.hraven.FlowEventKey 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));
}
Aggregations