use of com.twitter.ambrose.model.Event in project ambrose by twitter.
the class InMemoryStatsServiceTest method testGetEventsMax.
@Test
public void testGetEventsMax() throws IOException {
for (Event event : testEvents) {
service.pushEvent(workflowId, event);
}
int sinceId = -1;
Event foundEvent;
for (Event event : testEvents) {
Iterator<Event> foundEvents = service.getEventsSinceId(workflowId, sinceId, 1).iterator();
foundEvent = foundEvents.next();
assertEqualWorkflows(event, foundEvent);
assertFalse("Wrong number of events returned", foundEvents.hasNext());
sinceId = foundEvent.getId();
}
}
use of com.twitter.ambrose.model.Event in project ambrose by twitter.
the class InMemoryStatsServiceTest method testGetEventsSince.
@Test
public void testGetEventsSince() throws IOException {
for (Event event : testEvents) {
service.pushEvent(workflowId, event);
}
// first, peek at the first eventId
Collection<Event> allEvents = service.getEventsSinceId(workflowId, -1);
int sinceId = allEvents.iterator().next().getId();
// get all events since the first
Collection<Event> events = service.getEventsSinceId(workflowId, sinceId);
Iterator<Event> foundEvents = events.iterator();
assertEquals("Wrong number of events returned", testEvents.length - 1, events.size());
for (Event sentEvent : testEvents) {
if (sentEvent.getId() <= sinceId) {
continue;
}
assertEqualWorkflows(sentEvent, foundEvents.next());
}
assertFalse("Wrong number of events returned", foundEvents.hasNext());
}
use of com.twitter.ambrose.model.Event in project ambrose by twitter.
the class PigJobTest method testFromJson.
@Test
public void testFromJson() throws IOException {
String json = "{\n" + " \"type\" : \"JOB_STARTED\",\n" + " \"payload\" : {\n" + " \"name\" : \"scope-29\",\n" + " \"job\" : {\n" + " \"runtime\" : \"pig\",\n" + " \"id\" : \"job_local_0001\",\n" + " \"aliases\" : [ \"A\", \"AA\", \"B\", \"C\" ],\n" + " \"features\" : [ \"GROUP_BY\", \"COMBINER\", \"MAP_PARTIALAGG\" ],\n" + " \"metrics\" : {\n" + " \"somemetric\": 123\n" + " } \n" + " },\n" + " \"successorNames\" : [ ]\n" + " },\n" + " \"id\" : 1,\n" + " \"timestamp\" : 1373560988033\n" + "}";
Event event = Event.fromJson(json);
PigJob job = ((DAGNode<PigJob>) event.getPayload()).getJob();
assertEquals("job_local_0001", job.getId());
assertArrayEquals(new String[] { "A", "AA", "B", "C" }, job.getAliases());
assertArrayEquals(new String[] { "GROUP_BY", "COMBINER", "MAP_PARTIALAGG" }, job.getFeatures());
assertNotNull(job.getMetrics());
assertEquals(123, job.getMetrics().get("somemetric"));
}
use of com.twitter.ambrose.model.Event in project ambrose by twitter.
the class AmbroseHivePreHook method waitBetween.
/**
* Waiting <tt>ambrose.wf.between.sleep.seconds</tt> before processing the
* next statement (workflow) in the submitted script
*
* @param hookContext
* @param reporter
* @param queryId
*/
private void waitBetween(HookContext hookContext, EmbeddedAmbroseHiveProgressReporter reporter, String queryId) {
Configuration conf = hookContext.getConf();
boolean justStarted = conf.getBoolean(SCRIPT_STARTED_PARAM, true);
if (justStarted) {
conf.setBoolean(SCRIPT_STARTED_PARAM, false);
} else {
// sleeping between workflows
int sleepTimeMs = conf.getInt(WF_BETWEEN_SLEEP_SECS_PARAM, 10);
try {
LOG.info("One workflow complete, sleeping for " + sleepTimeMs + " sec(s) before moving to the next one if exists. Hit ctrl-c to exit.");
Thread.sleep(sleepTimeMs * 1000L);
// send progressbar reset event
Map<WorkflowProgressField, String> eventData = Maps.newHashMapWithExpectedSize(1);
eventData.put(WorkflowProgressField.workflowProgress, "0");
reporter.pushEvent(queryId, new Event.WorkflowProgressEvent(eventData));
reporter.saveEventStack();
reporter.reset();
} catch (InterruptedException e) {
LOG.warn("Sleep interrupted", e);
}
}
}
use of com.twitter.ambrose.model.Event in project ambrose by twitter.
the class EmbeddedAmbroseHiveProgressReporter method initInternal.
@SuppressWarnings("unchecked")
private void initInternal() {
try {
Field eventMapField = AmbroseHiveUtil.getInternalField(InMemoryStatsService.class, "eventMap");
_eventMap = (SortedMap<Integer, Event<?>>) eventMapField.get(service);
} catch (Exception e) {
LOG.fatal("Can't access to eventMap/dagNodeNameMap fields at " + InMemoryStatsService.class.getName() + "!");
throw new RuntimeException("Incompatible Hive API found!", e);
}
}
Aggregations