Search in sources :

Example 6 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext 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, Duration.ofSeconds(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(org.apache.heron.common.utils.metrics.MetricsCollector) TopologyContextImpl(org.apache.heron.common.utils.topology.TopologyContextImpl) TopologyContext(org.apache.heron.api.topology.TopologyContext) Test(org.junit.Test)

Example 7 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class TransformOperator method prepare.

@SuppressWarnings("rawtypes")
@Override
public void prepare(Map<String, Object> map, TopologyContext topologyContext, OutputCollector outputCollector) {
    super.prepare(map, topologyContext, outputCollector);
    Context context = new ContextImpl(topologyContext, map, state);
    serializableTransformer.setup(context);
}
Also used : TopologyContext(org.apache.heron.api.topology.TopologyContext) Context(org.apache.heron.streamlet.Context) ContextImpl(org.apache.heron.streamlet.impl.ContextImpl)

Example 8 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class ComplexSink method prepare.

@SuppressWarnings("rawtypes")
@Override
public void prepare(Map<String, Object> map, TopologyContext topologyContext, OutputCollector outputCollector) {
    this.collector = outputCollector;
    Context context = new ContextImpl(topologyContext, map, state);
    sink.setup(context);
}
Also used : TopologyContext(org.apache.heron.api.topology.TopologyContext) Context(org.apache.heron.streamlet.Context) ContextImpl(org.apache.heron.streamlet.impl.ContextImpl)

Example 9 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class LaunchRunnerTest method createTopology.

public static TopologyAPI.Topology createTopology(org.apache.heron.api.Config heronConfig) {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout-1", new BaseRichSpout() {

        private static final long serialVersionUID = -762965195665496156L;

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }

        public void open(Map<String, Object> conf, TopologyContext context, SpoutOutputCollector collector) {
        }

        public void nextTuple() {
        }
    }, 2);
    builder.setBolt("bolt-1", new BaseBasicBolt() {

        private static final long serialVersionUID = -5738458486388778812L;

        public void execute(Tuple input, BasicOutputCollector collector) {
        }

        public void declareOutputFields(OutputFieldsDeclarer declarer) {
        }
    }, 1);
    HeronTopology heronTopology = builder.createTopology();
    return heronTopology.setName(TOPOLOGY_NAME).setConfig(heronConfig).setState(TopologyAPI.TopologyState.RUNNING).getTopology();
}
Also used : BaseBasicBolt(org.apache.heron.api.bolt.BaseBasicBolt) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) HeronTopology(org.apache.heron.api.HeronTopology) OutputFieldsDeclarer(org.apache.heron.api.topology.OutputFieldsDeclarer) BasicOutputCollector(org.apache.heron.api.bolt.BasicOutputCollector) SpoutOutputCollector(org.apache.heron.api.spout.SpoutOutputCollector) TopologyContext(org.apache.heron.api.topology.TopologyContext) Tuple(org.apache.heron.api.tuple.Tuple) BaseRichSpout(org.apache.heron.api.spout.BaseRichSpout)

Example 10 with TopologyContext

use of org.apache.heron.api.topology.TopologyContext in project heron by twitter.

the class JoinOperatorTest method getTopologyContext.

private TopologyContext getTopologyContext() {
    TopologyContext context = Mockito.mock(TopologyContext.class);
    Map<TopologyAPI.StreamId, TopologyAPI.Grouping> sources = Collections.singletonMap(TopologyAPI.StreamId.newBuilder().setComponentName("s1").setId("default").build(), null);
    Mockito.when(context.getThisSources()).thenReturn(sources);
    return context;
}
Also used : TopologyContext(org.apache.heron.api.topology.TopologyContext)

Aggregations

TopologyContext (org.apache.heron.api.topology.TopologyContext)12 HashMap (java.util.HashMap)4 Tuple (org.apache.heron.api.tuple.Tuple)4 Test (org.junit.Test)4 BaseBasicBolt (org.apache.heron.api.bolt.BaseBasicBolt)3 BasicOutputCollector (org.apache.heron.api.bolt.BasicOutputCollector)3 BaseRichSpout (org.apache.heron.api.spout.BaseRichSpout)3 SpoutOutputCollector (org.apache.heron.api.spout.SpoutOutputCollector)3 OutputFieldsDeclarer (org.apache.heron.api.topology.OutputFieldsDeclarer)3 TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)3 Fields (org.apache.heron.api.tuple.Fields)3 Context (org.apache.heron.streamlet.Context)3 ContextImpl (org.apache.heron.streamlet.impl.ContextImpl)3 HeronTopology (org.apache.heron.api.HeronTopology)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Config (org.apache.heron.api.Config)1 BoltDeclarer (org.apache.heron.api.topology.BoltDeclarer)1 Values (org.apache.heron.api.tuple.Values)1 MetricsCollector (org.apache.heron.common.utils.metrics.MetricsCollector)1