Search in sources :

Example 1 with TopologyContextImpl

use of com.twitter.heron.common.utils.topology.TopologyContextImpl in project heron by twitter.

the class GlobalMetricsTest method testGlobalMetrics.

@Test
public void testGlobalMetrics() {
    MetricsCollector fakeCollector = new MetricsCollector(new FakeWakeableLooper(), null);
    TopologyContext fakeContext = new TopologyContextImpl(new HashMap<String, Object>(), TopologyAPI.Topology.getDefaultInstance(), new HashMap<Integer, String>(), 0, fakeCollector);
    GlobalMetrics.init(fakeContext, 5);
    GlobalMetrics.incr("mycounter");
    Map<String, Long> metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
    assertTrue(metricsContent.containsKey("mycounter"));
    assertEquals(1, metricsContent.size());
    assertEquals(new Long(1), metricsContent.get("mycounter"));
    // Increment two different counters
    GlobalMetrics.incr("mycounter1");
    GlobalMetrics.incr("mycounter2");
    GlobalMetrics.incr("mycounter1");
    metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
    assertTrue(metricsContent.containsKey("mycounter"));
    assertTrue(metricsContent.containsKey("mycounter1"));
    assertTrue(metricsContent.containsKey("mycounter2"));
    assertEquals(3L, metricsContent.size());
    assertEquals(new Long(0), metricsContent.get("mycounter"));
    assertEquals(new Long(1), metricsContent.get("mycounter2"));
    assertEquals(new Long(2), metricsContent.get("mycounter1"));
}
Also used : MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Test(org.junit.Test)

Example 2 with TopologyContextImpl

use of com.twitter.heron.common.utils.topology.TopologyContextImpl in project heron by twitter.

the class BoltInstance method start.

@Override
public void start() {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    // Initialize the GlobalMetrics
    GlobalMetrics.init(topologyContext, systemConfig.getHeronMetricsExportIntervalSec());
    boltMetrics.registerMetrics(topologyContext);
    // Delegate
    bolt.prepare(topologyContext.getTopologyConfig(), topologyContext, new OutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
    addBoltTasks();
}
Also used : OutputCollector(com.twitter.heron.api.bolt.OutputCollector) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl)

Example 3 with TopologyContextImpl

use of com.twitter.heron.common.utils.topology.TopologyContextImpl in project heron by twitter.

the class SpoutInstance method start.

@Override
public void start() {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    // Initialize the GlobalMetrics
    GlobalMetrics.init(topologyContext, systemConfig.getHeronMetricsExportIntervalSec());
    spoutMetrics.registerMetrics(topologyContext);
    spout.open(topologyContext.getTopologyConfig(), topologyContext, new SpoutOutputCollector(collector));
    // Invoke user-defined prepare task hook
    topologyContext.invokeHookPrepare();
    // Init the CustomStreamGrouping
    helper.prepareForCustomStreamGrouping();
    // Tasks happen in every time looper is waken up
    addSpoutsTasks();
    topologyState = TopologyAPI.TopologyState.RUNNING;
}
Also used : TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) SpoutOutputCollector(com.twitter.heron.api.spout.SpoutOutputCollector)

Example 4 with TopologyContextImpl

use of com.twitter.heron.common.utils.topology.TopologyContextImpl in project heron by twitter.

the class BoltInstance method readTuplesAndExecute.

@Override
public void readTuplesAndExecute(Communicator<HeronTuples.HeronTupleSet> inQueue) {
    TopologyContextImpl topologyContext = helper.getTopologyContext();
    long instanceExecuteBatchTime = systemConfig.getInstanceExecuteBatchTimeMs() * Constants.MILLISECONDS_TO_NANOSECONDS;
    long startOfCycle = System.nanoTime();
    // Read data from in Queues
    while (!inQueue.isEmpty()) {
        HeronTuples.HeronTupleSet tuples = inQueue.poll();
        // Handle the tuples
        if (tuples.hasControl()) {
            throw new RuntimeException("Bolt cannot get acks/fails from other components");
        }
        // Get meta data of tuples
        TopologyAPI.StreamId stream = tuples.getData().getStream();
        int nValues = topologyContext.getComponentOutputFields(stream.getComponentName(), stream.getId()).size();
        // We would reuse the System.nanoTime()
        long currentTime = startOfCycle;
        for (HeronTuples.HeronDataTuple dataTuple : tuples.getData().getTuplesList()) {
            // Create the value list and fill the value
            List<Object> values = new ArrayList<>(nValues);
            for (int i = 0; i < nValues; i++) {
                values.add(serializer.deserialize(dataTuple.getValues(i).toByteArray()));
            }
            // Decode the tuple
            TupleImpl t = new TupleImpl(topologyContext, stream, dataTuple.getKey(), dataTuple.getRootsList(), values, currentTime, false);
            // Delegate to the use defined bolt
            bolt.execute(t);
            // Swap
            long startTime = currentTime;
            currentTime = System.nanoTime();
            long executeLatency = currentTime - startTime;
            // Invoke user-defined execute task hook
            topologyContext.invokeHookBoltExecute(t, executeLatency);
            // Update metrics
            boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency);
        }
        // To avoid spending too much time
        if (currentTime - startOfCycle - instanceExecuteBatchTime > 0) {
            break;
        }
    }
}
Also used : TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) ArrayList(java.util.ArrayList) HeronTuples(com.twitter.heron.proto.system.HeronTuples) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) TupleImpl(com.twitter.heron.common.utils.tuple.TupleImpl)

Aggregations

TopologyContextImpl (com.twitter.heron.common.utils.topology.TopologyContextImpl)4 OutputCollector (com.twitter.heron.api.bolt.OutputCollector)1 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)1 SpoutOutputCollector (com.twitter.heron.api.spout.SpoutOutputCollector)1 TopologyContext (com.twitter.heron.api.topology.TopologyContext)1 MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)1 TupleImpl (com.twitter.heron.common.utils.tuple.TupleImpl)1 HeronTuples (com.twitter.heron.proto.system.HeronTuples)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1