Modified resp topicConfig and add getTopicName() 86/99786/6
authorZhangZihao <zhangzihao@chinamobile.com>
Thu, 19 Dec 2019 03:30:21 +0000 (11:30 +0800)
committerZihao Zhang <zhangzihao@chinamobile.com>
Thu, 9 Jan 2020 07:53:05 +0000 (07:53 +0000)
Change-Id: I06db2663534c970b76244f462da66d2c72b11f12
Issue-ID: DCAEGEN2-1877
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
components/datalake-handler/feeder/src/assembly/scripts/init_db.sql
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicNameController.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Topic.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/TopicConfig.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/TopicService.java

index 8a91427..3f495e2 100644 (file)
@@ -2,7 +2,7 @@
 * ============LICENSE_START=======================================================\r
 * ONAP : DATALAKE\r
 * ================================================================================\r
-* Copyright 2019 China Mobile\r
+* Copyright 2019-2020 China Mobile\r
 *=================================================================================\r
 * Licensed under the Apache License, Version 2.0 (the "License");\r
 * you may not use this file except in compliance with the License.\r
@@ -98,7 +98,7 @@ CREATE TABLE `kafka` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r
 \r
 CREATE TABLE `topic` (\r
-  `id` int(11) NOT NULL,\r
+  `id` int(11) NOT NULL AUTO_INCREMENT,\r
   `aggregate_array_path` varchar(255) DEFAULT NULL,\r
   `correlate_cleared_message` bit(1) NOT NULL DEFAULT b'0',\r
   `data_format` varchar(255) DEFAULT NULL,\r
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 (file)
index 0000000..570dcd1
--- /dev/null
@@ -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;
+    }
+}
index 0de004d..fcbe613 100644 (file)
@@ -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;
        }
 
index 1bdad2e..c865ec9 100644 (file)
@@ -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);
index 2f0761a..3b1c2cc 100644 (file)
@@ -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());