Search in sources :

Example 1 with Event

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();
    }
}
Also used : Event(com.twitter.ambrose.model.Event) Test(org.junit.Test)

Example 2 with Event

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());
}
Also used : Event(com.twitter.ambrose.model.Event) Test(org.junit.Test)

Example 3 with Event

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"));
}
Also used : Event(com.twitter.ambrose.model.Event) DAGNode(com.twitter.ambrose.model.DAGNode) Test(org.junit.Test)

Example 4 with Event

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);
        }
    }
}
Also used : WorkflowProgressField(com.twitter.ambrose.model.Event.WorkflowProgressField) Configuration(org.apache.hadoop.conf.Configuration) Event(com.twitter.ambrose.model.Event)

Example 5 with Event

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);
    }
}
Also used : Field(java.lang.reflect.Field) Event(com.twitter.ambrose.model.Event) IOException(java.io.IOException)

Aggregations

Event (com.twitter.ambrose.model.Event)10 Test (org.junit.Test)4 DAGNode (com.twitter.ambrose.model.DAGNode)3 IOException (java.io.IOException)2 Configuration (org.apache.hadoop.conf.Configuration)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 EmbeddedAmbroseHiveProgressReporter (com.twitter.ambrose.hive.reporter.EmbeddedAmbroseHiveProgressReporter)1 WorkflowProgressField (com.twitter.ambrose.model.Event.WorkflowProgressField)1 Job (com.twitter.ambrose.model.Job)1 WorkflowId (com.twitter.ambrose.model.WorkflowId)1 FlowEvent (com.twitter.hraven.FlowEvent)1 FlowEventKey (com.twitter.hraven.FlowEventKey)1 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 RunningJob (org.apache.hadoop.mapred.RunningJob)1 JobStats (org.apache.pig.tools.pigstats.JobStats)1