Search in sources :

Example 76 with StormTopology

use of org.apache.storm.generated.StormTopology in project open-kilda by telstra.

the class StatsTopologyTest method setupOnce.

@BeforeClass
public static void setupOnce() throws Exception {
    Properties configOverlay = getZooKeeperProperties(STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT, ROOT_NODE);
    configOverlay.putAll(getKafkaProperties(STATS_TOPOLOGY_TEST_KAFKA_PORT));
    configOverlay.setProperty("opentsdb.metric.prefix", METRIC_PREFIX);
    AbstractStormTest.startZooKafka(configOverlay);
    setStartSignal(STATS_TOPOLOGY_TEST_ZOOKEEPER_PORT, ROOT_NODE, COMPONENT_NAME, RUN_ID);
    AbstractStormTest.startStorm(COMPONENT_NAME, RUN_ID);
    LaunchEnvironment launchEnvironment = makeLaunchEnvironment();
    launchEnvironment.setupOverlay(configOverlay);
    persistenceManager = InMemoryGraphPersistenceManager.newInstance();
    persistenceManager.install();
    StatsTopology statsTopology = new StatsTopology(launchEnvironment, persistenceManager);
    statsTopologyConfig = statsTopology.getConfig();
    StormTopology stormTopology = statsTopology.createTopology();
    Config config = stormConfig();
    cluster.submitTopology(StatsTopologyTest.class.getSimpleName(), config, stormTopology);
    otsdbConsumer = new TestKafkaConsumer(statsTopologyConfig.getKafkaOtsdbTopic(), kafkaConsumerProperties(UUID.randomUUID().toString(), COMPONENT_NAME, RUN_ID));
    otsdbConsumer.start();
    flowRepository = persistenceManager.getRepositoryFactory().createFlowRepository();
    switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
    sleep(TOPOLOGY_START_TIMEOUT);
}
Also used : TestKafkaConsumer(org.openkilda.wfm.topology.TestKafkaConsumer) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) LaunchEnvironment(org.openkilda.wfm.LaunchEnvironment) Properties(java.util.Properties) BeforeClass(org.junit.BeforeClass)

Example 77 with StormTopology

use of org.apache.storm.generated.StormTopology in project pancm_project by xuwujing.

the class WordCountApp method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 * @throws InterruptedException     the interrupted exception
 * @throws AlreadyAliveException    the already alive exception
 * @throws InvalidTopologyException the invalid topology exception
 */
public static void main(String[] args) throws InterruptedException, AlreadyAliveException, InvalidTopologyException {
    // 定义拓扑
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word-reader", new WordReader());
    builder.setBolt("word-normalizer", new WordNormalizer()).shuffleGrouping("word-reader");
    builder.setBolt("word-counter", new WordCounter()).fieldsGrouping("word-normalizer", new Fields("word"));
    StormTopology topology = builder.createTopology();
    // 配置
    Config conf = new Config();
    String fileName = "words.txt";
    conf.put("fileName", fileName);
    conf.setDebug(false);
    // 运行拓扑
    System.out.println("开始...");
    if (args != null && args.length > 0) {
        // 有参数时,表示向集群提交作业,并把第一个参数当做topology名称
        System.out.println("远程模式");
        try {
            StormSubmitter.submitTopology(args[0], conf, topology);
        } catch (AuthorizationException e) {
            e.printStackTrace();
        }
    } else {
        // 没有参数时,本地提交
        // 启动本地模式
        System.out.println("本地模式");
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("Getting-Started-Topologie", conf, topology);
        Thread.sleep(5000);
        // 关闭本地集群
        cluster.shutdown();
    }
    System.out.println("结束");
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AuthorizationException(org.apache.storm.generated.AuthorizationException) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology)

Example 78 with StormTopology

use of org.apache.storm.generated.StormTopology in project pancm_project by xuwujing.

the class WordCountApp method main.

/**
 * The entry point of application.
 *
 * @param args the input arguments
 * @throws InterruptedException     the interrupted exception
 * @throws AlreadyAliveException    the already alive exception
 * @throws InvalidTopologyException the invalid topology exception
 */
public static void main(String[] args) throws InterruptedException, AlreadyAliveException, InvalidTopologyException {
    // 定义拓扑
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("word-reader", new WordReader());
    builder.setBolt("word-normalizer", new WordNormalizer()).shuffleGrouping("word-reader");
    builder.setBolt("word-counter", new WordCounter()).fieldsGrouping("word-normalizer", new Fields("word"));
    StormTopology topology = builder.createTopology();
    // 配置
    Config conf = new Config();
    String fileName = "words.txt";
    conf.put("fileName", fileName);
    conf.setDebug(false);
    // 运行拓扑
    System.out.println("开始...");
    if (args != null && args.length > 0) {
        // 有参数时,表示向集群提交作业,并把第一个参数当做topology名称
        System.out.println("远程模式");
        try {
            StormSubmitter.submitTopology(args[0], conf, topology);
        } catch (AuthorizationException e) {
            e.printStackTrace();
        }
    } else {
        // 没有参数时,本地提交
        // 启动本地模式
        System.out.println("本地模式");
        LocalCluster cluster = new LocalCluster();
        cluster.submitTopology("Getting-Started-Topologie", conf, topology);
        Thread.sleep(5000);
        // 关闭本地集群
        cluster.shutdown();
    }
    System.out.println("结束");
}
Also used : LocalCluster(org.apache.storm.LocalCluster) Fields(org.apache.storm.tuple.Fields) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) AuthorizationException(org.apache.storm.generated.AuthorizationException) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology)

Example 79 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class TopologyDetails method getComponents.

/**
     * Returns a representation of the non-system components of the topology graph
     * Each Component object in the returning map is populated with the list of its
     * parents, children and execs assigned to that component.
     * @return a map of components
     */
public Map<String, Component> getComponents() {
    Map<String, Component> all_comp = new HashMap<>();
    StormTopology storm_topo = this.topology;
    // spouts
    if (storm_topo.get_spouts() != null) {
        for (Map.Entry<String, SpoutSpec> spoutEntry : storm_topo.get_spouts().entrySet()) {
            if (!Utils.isSystemId(spoutEntry.getKey())) {
                Component newComp;
                if (all_comp.containsKey(spoutEntry.getKey())) {
                    newComp = all_comp.get(spoutEntry.getKey());
                    newComp.execs = componentToExecs(newComp.id);
                } else {
                    newComp = new Component(spoutEntry.getKey());
                    newComp.execs = componentToExecs(newComp.id);
                    all_comp.put(spoutEntry.getKey(), newComp);
                }
                newComp.type = Component.ComponentType.SPOUT;
                for (Map.Entry<GlobalStreamId, Grouping> spoutInput : spoutEntry.getValue().get_common().get_inputs().entrySet()) {
                    newComp.parents.add(spoutInput.getKey().get_componentId());
                    if (!all_comp.containsKey(spoutInput.getKey().get_componentId())) {
                        all_comp.put(spoutInput.getKey().get_componentId(), new Component(spoutInput.getKey().get_componentId()));
                    }
                    all_comp.get(spoutInput.getKey().get_componentId()).children.add(spoutEntry.getKey());
                }
            }
        }
    }
    // bolts
    if (storm_topo.get_bolts() != null) {
        for (Map.Entry<String, Bolt> boltEntry : storm_topo.get_bolts().entrySet()) {
            if (!Utils.isSystemId(boltEntry.getKey())) {
                Component newComp;
                if (all_comp.containsKey(boltEntry.getKey())) {
                    newComp = all_comp.get(boltEntry.getKey());
                    newComp.execs = componentToExecs(newComp.id);
                } else {
                    newComp = new Component(boltEntry.getKey());
                    newComp.execs = componentToExecs(newComp.id);
                    all_comp.put(boltEntry.getKey(), newComp);
                }
                newComp.type = Component.ComponentType.BOLT;
                for (Map.Entry<GlobalStreamId, Grouping> boltInput : boltEntry.getValue().get_common().get_inputs().entrySet()) {
                    newComp.parents.add(boltInput.getKey().get_componentId());
                    if (!all_comp.containsKey(boltInput.getKey().get_componentId())) {
                        all_comp.put(boltInput.getKey().get_componentId(), new Component(boltInput.getKey().get_componentId()));
                    }
                    all_comp.get(boltInput.getKey().get_componentId()).children.add(boltEntry.getKey());
                }
            }
        }
    }
    return all_comp;
}
Also used : HashMap(java.util.HashMap) StormTopology(org.apache.storm.generated.StormTopology) Grouping(org.apache.storm.generated.Grouping) Bolt(org.apache.storm.generated.Bolt) SpoutSpec(org.apache.storm.generated.SpoutSpec) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) Component(org.apache.storm.scheduler.resource.Component) HashMap(java.util.HashMap) Map(java.util.Map)

Example 80 with StormTopology

use of org.apache.storm.generated.StormTopology in project storm by apache.

the class Nimbus method computeExecutors.

private List<List<Integer>> computeExecutors(String topoId, StormBase base) throws KeyNotFoundException, AuthorizationException, IOException, InvalidTopologyException {
    BlobStore store = blobStore;
    assert (base != null);
    Map<String, Integer> compToExecutors = base.get_component_executors();
    Map<String, Object> topoConf = readTopoConfAsNimbus(topoId, store);
    StormTopology topology = readStormTopologyAsNimbus(topoId, store);
    List<List<Integer>> ret = new ArrayList<>();
    if (compToExecutors != null) {
        Map<Integer, String> taskInfo = StormCommon.stormTaskInfo(topology, topoConf);
        Map<String, List<Integer>> compToTaskList = Utils.reverseMap(taskInfo);
        for (Entry<String, List<Integer>> entry : compToTaskList.entrySet()) {
            List<Integer> comps = entry.getValue();
            comps.sort(null);
            Integer numExecutors = compToExecutors.get(entry.getKey());
            if (numExecutors != null) {
                List<List<Integer>> partitioned = Utils.partitionFixed(numExecutors, comps);
                for (List<Integer> partition : partitioned) {
                    ret.add(Arrays.asList(partition.get(0), partition.get(partition.size() - 1)));
                }
            }
        }
    }
    return ret;
}
Also used : StormTopology(org.apache.storm.generated.StormTopology) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BlobStore(org.apache.storm.blobstore.BlobStore) LocalFsBlobStore(org.apache.storm.blobstore.LocalFsBlobStore)

Aggregations

StormTopology (org.apache.storm.generated.StormTopology)162 Config (org.apache.storm.Config)72 HashMap (java.util.HashMap)67 Test (org.junit.Test)59 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)44 Map (java.util.Map)35 ArrayList (java.util.ArrayList)29 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)27 Test (org.junit.jupiter.api.Test)26 List (java.util.List)24 Bolt (org.apache.storm.generated.Bolt)23 Values (org.apache.storm.tuple.Values)23 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)22 Cluster (org.apache.storm.scheduler.Cluster)22 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)22 Topologies (org.apache.storm.scheduler.Topologies)22 Fields (org.apache.storm.tuple.Fields)22 INimbus (org.apache.storm.scheduler.INimbus)21 TopologyDef (org.apache.storm.flux.model.TopologyDef)20 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)20