Open Kilda Java Documentation
KafkaParameters.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;
17 
18 import static java.util.Collections.singletonList;
19 
25 
26 import com.sabre.oss.conf4j.factory.jdkproxy.JdkProxyStaticConfigurationFactory;
27 import com.sabre.oss.conf4j.source.PropertiesConfigurationSource;
28 
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.util.Properties;
32 
33 public class KafkaParameters {
34  private static final String CONFIG_FILE = "/atdd.properties";
35 
36  private final KafkaConfig kafkaConfig;
37  private final KafkaTopicsConfig kafkaTopicsConfig;
38 
39  public KafkaParameters() throws IOException {
40  Properties properties = new Properties();
41 
42  try (InputStream input = getClass().getResourceAsStream(CONFIG_FILE)) {
43  if (input == null) {
44  throw new IOException("Can't find " + CONFIG_FILE);
45  }
46  properties.load(input);
47  }
48 
49  PropertiesConfigurationSource source = new PropertiesConfigurationSource(properties);
50  JdkProxyStaticConfigurationFactory factory = new JdkProxyStaticConfigurationFactory();
51 
52  EnvironmentConfig environmentConfig = factory.createConfiguration(EnvironmentConfig.class, source);
53  String namingPrefix = environmentConfig.getNamingPrefix();
54  KafkaNamingStrategy namingStrategy = new KafkaNamingStrategy(namingPrefix != null ? namingPrefix : "");
55 
56  // Apply the environment prefix to Kafka topics and groups in the configuration.
57  factory.setConfigurationValueProcessors(
58  singletonList(new KafkaNamingForConfigurationValueProcessor(namingStrategy)));
59 
60  kafkaConfig = factory.createConfiguration(KafkaConfig.class, source);
61  kafkaTopicsConfig = factory.createConfiguration(KafkaTopicsConfig.class, source);
62  }
63 
64  public String getBootstrapServers() {
65  return kafkaConfig.getHosts();
66  }
67 
68  public String getControlTopic() {
69  return kafkaTopicsConfig.getCtrlTopic();
70  }
71 
72  public String getDiscoTopic() {
73  return kafkaTopicsConfig.getTopoDiscoTopic();
74  }
75 }
source
Definition: nodes.py:53