Open Kilda Java Documentation
KafkaLoggerTopology.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.wfm.topology.utils;
17 
20 
21 import org.apache.storm.Config;
22 import org.apache.storm.generated.StormTopology;
23 import org.apache.storm.topology.TopologyBuilder;
24 import org.slf4j.event.Level;
25 
48 public class KafkaLoggerTopology extends AbstractTopology<KafkaLoggerTopologyConfig> {
50  super(env, KafkaLoggerTopologyConfig.class);
51  }
52 
53  @Override
54  public StormTopology createTopology() {
55  final String topic = topologyConfig.getKafkaSpeakerTopic();
56  final String name = String.format("%s_%s_%d", getTopologyName(), topic, System.currentTimeMillis());
57  final Integer parallelism = topologyConfig.getParallelism();
58 
59  TopologyBuilder builder = new TopologyBuilder();
60 
61  String spoutId = "KafkaSpout-" + topic;
62  builder.setSpout(spoutId, createKafkaSpout(topic, name), parallelism);
63  LoggerBolt logger = new LoggerBolt()
64  .withLevel(topologyConfig.getLoggerLevel())
65  .withWatermark(topologyConfig.getLoggerWatermark());
66 
67  builder.setBolt("Logger", logger, parallelism)
68  .shuffleGrouping(spoutId);
69 
70  return builder.createTopology();
71  }
72 
73  @Override
74  protected Config makeStormConfig() {
75  Config config = super.makeStormConfig();
76  Level level = this.topologyConfig.getLoggerLevel();
77 
78  config.setDebug(level == Level.DEBUG || level == Level.TRACE);
79 
80  return config;
81  }
82 
83  public static void main(String[] args) {
84  try {
86  (new KafkaLoggerTopology(env)).setup();
87  } catch (Exception e) {
88  System.exit(handleLaunchException(e));
89  }
90  }
91 }
name
Definition: setup.py:24
static int handleLaunchException(Exception error)
KafkaSpout< String, String > createKafkaSpout(String topic, String spoutId)