Search in sources :

Example 1 with TopologyContext

use of backtype.storm.task.TopologyContext in project jstorm by alibaba.

the class Worker method worker_output_tasks.

/**
     * get current task's output task list
     */
public static Set<Integer> worker_output_tasks(WorkerData workerData) {
    ContextMaker context_maker = workerData.getContextMaker();
    Set<Integer> taskIds = workerData.getTaskids();
    StormTopology topology = workerData.getSysTopology();
    Set<Integer> rtn = new HashSet<>();
    for (Integer taskId : taskIds) {
        TopologyContext context = context_maker.makeTopologyContext(topology, taskId, null);
        // <StreamId, <ComponentId, Grouping>>
        Map<String, Map<String, Grouping>> targets = context.getThisTargets();
        for (Map<String, Grouping> e : targets.values()) {
            for (String componentId : e.keySet()) {
                List<Integer> tasks = context.getComponentTasks(componentId);
                rtn.addAll(tasks);
            }
        }
    }
    return rtn;
}
Also used : StormTopology(backtype.storm.generated.StormTopology) Grouping(backtype.storm.generated.Grouping) TopologyContext(backtype.storm.task.TopologyContext)

Example 2 with TopologyContext

use of backtype.storm.task.TopologyContext in project jstorm by alibaba.

the class ContextMaker method makeTopologyContext.

public TopologyContext makeTopologyContext(StormTopology topology, Integer taskId, clojure.lang.Atom openOrPrepareWasCalled) {
    Map stormConf = workerData.getStormConf();
    String topologyId = workerData.getTopologyId();
    HashMap<String, Map<String, Fields>> componentToStreamToFields = workerData.generateComponentToStreamToFields(topology);
    return new TopologyContext(topology, stormConf, workerData.getTasksToComponent(), workerData.getComponentToSortedTasks(), componentToStreamToFields, topologyId, resourcePath, workerId, taskId, workerData.getPort(), workerTasks, workerData.getDefaultResources(), workerData.getUserResources(), workerData.getExecutorData(), workerData.getRegisteredMetrics(), openOrPrepareWasCalled, workerData.getZkCluster());
}
Also used : TopologyContext(backtype.storm.task.TopologyContext) WorkerTopologyContext(backtype.storm.task.WorkerTopologyContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TopologyContext

use of backtype.storm.task.TopologyContext in project pulsar by yahoo.

the class PulsarBoltTest method testSharedProducer.

@Test
public void testSharedProducer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    PulsarBolt otherBolt = new PulsarBolt(pulsarBoltConf, new ClientConfiguration());
    MockOutputCollector otherMockCollector = new MockOutputCollector();
    OutputCollector collector = new OutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-bolt-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherBolt.prepare(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
    otherBolt.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.publishers.size(), 1);
}
Also used : OutputCollector(backtype.storm.task.OutputCollector) PersistentTopicStats(com.yahoo.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 4 with TopologyContext

use of backtype.storm.task.TopologyContext in project pulsar by yahoo.

the class PulsarSpoutTest method testSharedConsumer.

@Test
public void testSharedConsumer() throws Exception {
    PersistentTopicStats topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    PulsarSpout otherSpout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    MockSpoutOutputCollector otherMockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(otherMockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(1);
    otherSpout.open(Maps.newHashMap(), context, collector);
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
    otherSpout.close();
    topicStats = admin.persistentTopics().getStats(topic);
    Assert.assertEquals(topicStats.subscriptions.get(subscriptionName).consumers.size(), 1);
}
Also used : SpoutOutputCollector(backtype.storm.spout.SpoutOutputCollector) PersistentTopicStats(com.yahoo.pulsar.common.policies.data.PersistentTopicStats) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration) Test(org.testng.annotations.Test)

Example 5 with TopologyContext

use of backtype.storm.task.TopologyContext in project pulsar by yahoo.

the class PulsarSpoutTest method setup.

@Override
protected void setup() throws Exception {
    super.internalSetup();
    super.producerBaseSetup();
    pulsarSpoutConf = new PulsarSpoutConfiguration();
    pulsarSpoutConf.setServiceUrl(serviceUrl);
    pulsarSpoutConf.setTopic(topic);
    pulsarSpoutConf.setSubscriptionName(subscriptionName);
    pulsarSpoutConf.setMessageToValuesMapper(messageToValuesMapper);
    pulsarSpoutConf.setFailedRetriesTimeout(1, TimeUnit.SECONDS);
    pulsarSpoutConf.setMaxFailedRetries(2);
    pulsarSpoutConf.setSharedConsumerEnabled(true);
    pulsarSpoutConf.setMetricsTimeIntervalInSecs(60);
    consumerConf = new ConsumerConfiguration();
    consumerConf.setSubscriptionType(SubscriptionType.Shared);
    spout = new PulsarSpout(pulsarSpoutConf, new ClientConfiguration(), consumerConf);
    mockCollector = new MockSpoutOutputCollector();
    SpoutOutputCollector collector = new SpoutOutputCollector(mockCollector);
    TopologyContext context = mock(TopologyContext.class);
    when(context.getThisComponentId()).thenReturn("test-spout-" + methodName);
    when(context.getThisTaskId()).thenReturn(0);
    spout.open(Maps.newHashMap(), context, collector);
    producer = pulsarClient.createProducer(topic);
}
Also used : SpoutOutputCollector(backtype.storm.spout.SpoutOutputCollector) ConsumerConfiguration(com.yahoo.pulsar.client.api.ConsumerConfiguration) TopologyContext(backtype.storm.task.TopologyContext) ClientConfiguration(com.yahoo.pulsar.client.api.ClientConfiguration)

Aggregations

TopologyContext (backtype.storm.task.TopologyContext)17 SpoutOutputCollector (backtype.storm.spout.SpoutOutputCollector)7 ClientConfiguration (com.yahoo.pulsar.client.api.ClientConfiguration)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 PersistentTopicStats (com.yahoo.pulsar.common.policies.data.PersistentTopicStats)3 Test (org.testng.annotations.Test)3 OutputCollector (backtype.storm.task.OutputCollector)2 Config (backtype.storm.Config)1 GlobalStreamId (backtype.storm.generated.GlobalStreamId)1 Grouping (backtype.storm.generated.Grouping)1 StormTopology (backtype.storm.generated.StormTopology)1 ITaskHook (backtype.storm.hooks.ITaskHook)1 SpoutOutputCollectorImpl (backtype.storm.spout.SpoutOutputCollectorImpl)1 OutputCollectorImpl (backtype.storm.task.OutputCollectorImpl)1 WorkerTopologyContext (backtype.storm.task.WorkerTopologyContext)1 TopologyBuilder (backtype.storm.topology.TopologyBuilder)1 Tuple (backtype.storm.tuple.Tuple)1 TupleImpl (backtype.storm.tuple.TupleImpl)1 AsyncLoopThread (com.alibaba.jstorm.callback.AsyncLoopThread)1