diff options
author | ZhangZihao <zhangzihao@chinamobile.com> | 2019-12-19 11:30:21 +0800 |
---|---|---|
committer | Zihao Zhang <zhangzihao@chinamobile.com> | 2020-01-09 07:53:05 +0000 |
commit | 101636b49968dab8a409861d48bcdc6e75df50ee (patch) | |
tree | 9666831ff36ebd33ca5dbed70982363f9a35da9f /components/datalake-handler | |
parent | 92e8f1cbcc012db160e8f681e14710cc52149b2a (diff) |
Modified resp topicConfig and add getTopicName()
Change-Id: I06db2663534c970b76244f462da66d2c72b11f12
Issue-ID: DCAEGEN2-1877
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
Diffstat (limited to 'components/datalake-handler')
5 files changed, 86 insertions, 8 deletions
diff --git a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql index 8a914270..3f495e2d 100644 --- a/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql +++ b/components/datalake-handler/feeder/src/assembly/scripts/init_db.sql @@ -2,7 +2,7 @@ * ============LICENSE_START=======================================================
* ONAP : DATALAKE
* ================================================================================
-* Copyright 2019 China Mobile
+* Copyright 2019-2020 China Mobile
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ CREATE TABLE `kafka` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `topic` (
- `id` int(11) NOT NULL,
+ `id` int(11) NOT NULL AUTO_INCREMENT,
`aggregate_array_path` varchar(255) DEFAULT NULL,
`correlate_cleared_message` bit(1) NOT NULL DEFAULT b'0',
`data_format` varchar(255) DEFAULT NULL,
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java new file mode 100644 index 00000000..570dcd1c --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019-2020 China Mobile + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.datalake.feeder.controller; + +import io.swagger.annotations.ApiOperation; +import org.onap.datalake.feeder.domain.TopicName; +import org.onap.datalake.feeder.repository.TopicNameRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping(value = "/topicNames", produces = { MediaType.APPLICATION_JSON_VALUE }) +public class TopicNameController { + + @Autowired + private TopicNameRepository topicNameRepository; + + @GetMapping("") + @ResponseBody + @ApiOperation(value="List all topicNames") + public List<String> list() { + Iterable<TopicName> ret = topicNameRepository.findAll(); + List<String> retString = new ArrayList<>(); + for(TopicName item : ret) { + retString.add(item.getId()); + } + return retString; + } +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java index 0de004d4..fcbe613e 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : DataLake * ================================================================================ -* Copyright 2019 China Mobile +* Copyright 2019-2020 China Mobile *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.Map; +import java.util.HashMap; import javax.persistence.Column; import javax.persistence.Entity; @@ -33,6 +35,8 @@ import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.GenerationType; +import javax.persistence.GeneratedValue; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; @@ -57,6 +61,7 @@ import lombok.Setter; public class Topic { @Id @Column(name = "`id`") + @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @ManyToOne(fetch = FetchType.EAGER) @@ -201,16 +206,27 @@ public class Topic { Set<Db> topicDb = getDbs(); List<Integer> dbList = new ArrayList<>(); List<Integer> enabledDbList = new ArrayList<>(); + List<String> enabledDbList2 = new ArrayList<>(); if (topicDb != null) { for (Db item : topicDb) { dbList.add(item.getId()); if(item.isEnabled()) { enabledDbList.add(item.getId()); + enabledDbList2.add(item.getDbType().getId()); } } } tConfig.setSinkdbs(dbList); tConfig.setEnabledSinkdbs(enabledDbList); + Map<String,Integer> map = new HashMap<>(); + for (String string : enabledDbList2) { + if(map.containsKey(string)) { + map.put(string, map.get(string).intValue()+1); + }else { + map.put(string, new Integer(1)); + } + } + tConfig.setCountsDb(map); Set<Kafka> topicKafka = getKafkas(); List<Integer> kafkaList = new ArrayList<>(); @@ -220,6 +236,7 @@ public class Topic { } } tConfig.setKafkas(kafkaList); + tConfig.setCountsKafka(kafkaList.size()); return tConfig; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java index 1bdad2ec..c865ec91 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : DataLake * ================================================================================ - * Copyright 2019 QCT + * Copyright 2019-2020 QCT *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import lombok.Getter; import lombok.Setter; import java.util.List; +import java.util.Map; /** * JSON request body for Topic manipulation. @@ -37,7 +38,7 @@ import java.util.List; public class TopicConfig { - private int id; + private Integer id; private String name; private String login; private String password; @@ -52,7 +53,9 @@ public class TopicConfig { private String aggregateArrayPath; private String flattenArrayPath; private List<Integer> kafkas; - + private Map<String,Integer> countsDb; + private int countsKafka; + @Override public String toString() { return String.format("TopicConfig %s(enabled=%s, enabledSinkdbs=%s)", name, enabled, enabledSinkdbs); diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java index 2f0761ab..3b1c2ccf 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : DATALAKE * ================================================================================ -* Copyright 2019 China Mobile +* Copyright 2019-2020 China Mobile *================================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ import org.onap.datalake.feeder.domain.Db; import org.onap.datalake.feeder.domain.EffectiveTopic; import org.onap.datalake.feeder.domain.Kafka; import org.onap.datalake.feeder.domain.Topic; +import org.onap.datalake.feeder.domain.TopicName; import org.onap.datalake.feeder.repository.DbRepository; import org.onap.datalake.feeder.repository.KafkaRepository; import org.onap.datalake.feeder.repository.TopicNameRepository; @@ -147,7 +148,10 @@ public class TopicService { private void fillTopic(TopicConfig tConfig, Topic topic) { Set<Db> relateDb = new HashSet<>(); topic.setId(tConfig.getId()); - topic.setTopicName(topicNameRepository.findById(tConfig.getName()).get()); + Optional<TopicName> t = topicNameRepository.findById(tConfig.getName()); + if (!t.isPresent()) + throw new IllegalArgumentException("Can not find topicName in TopicName, topic name " + tConfig.getName()); + topic.setTopicName(t.get()); topic.setLogin(tConfig.getLogin()); topic.setPass(tConfig.getPassword()); topic.setEnabled(tConfig.isEnabled()); |