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"));
}
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();
}
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;
}
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;
}
}
}
Aggregations