2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 China Mobile
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.datalake.feeder.service;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
27 import javax.annotation.PostConstruct;
29 import org.apache.zookeeper.WatchedEvent;
30 import org.apache.zookeeper.Watcher;
31 import org.apache.zookeeper.ZooKeeper;
32 import org.onap.datalake.feeder.config.ApplicationConfiguration;
33 import org.onap.datalake.feeder.domain.Topic;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
40 * This service will handle all the communication with Kafka
46 public class DmaapService {
48 private final Logger log = LoggerFactory.getLogger(this.getClass());
51 private ApplicationConfiguration config;
54 private TopicService topicService;
62 //get all topic names from Zookeeper
63 public List<String> getTopics() {
65 Watcher watcher = new Watcher() {
67 public void process(WatchedEvent event) {
68 // TODO monitor new topics
72 ZooKeeper zk = new ZooKeeper(config.getDmaapZookeeperHostPort(), 10000, watcher);
73 List<String> topics = zk.getChildren("/brokers/topics", false);
75 } catch (Exception e) {
76 log.error("Can not get topic list from Zookeeper, for testing, going to use hard coded topic list.", e);
81 public List<String> getActiveTopics() throws IOException {
82 List<String> allTopics = new ArrayList<>(getTopics());
84 List<String> ret = new ArrayList<>();
85 for (String topicStr : allTopics) {
86 Topic topic = topicService.getEffectiveTopic(topicStr, true);
87 if (topic.isEnabled()) {