diff options
Diffstat (limited to 'components/datalake-handler/feeder/src/main/java/org')
16 files changed, 280 insertions, 156 deletions
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java index 3e67f38a..e371af1b 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java @@ -80,5 +80,6 @@ public class ApplicationConfiguration { private String datalakeVersion; //Kibana - private String KibanaDashboardImportApi; + private String kibanaDashboardImportApi; + private Integer kibanaPort; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java index 7e364332..bd9b742b 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java @@ -24,13 +24,12 @@ import java.util.*; import javax.servlet.http.HttpServletResponse; -import io.swagger.annotations.*; import org.onap.datalake.feeder.domain.Db; import org.onap.datalake.feeder.domain.Topic; import org.onap.datalake.feeder.repository.DbRepository; import org.onap.datalake.feeder.repository.TopicRepository; import org.onap.datalake.feeder.service.DbService; -import org.onap.datalake.feeder.controller.domain.DbConfig; +import org.onap.datalake.feeder.dto.DbConfig; import org.onap.datalake.feeder.controller.domain.PostReturnBody; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,10 +38,7 @@ import org.springframework.http.MediaType; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; -import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; /** * This controller manages the big data storage settings. All the settings are @@ -144,51 +140,6 @@ public class DbController { } - //Update Db - @PutMapping("/{dbName}") - @ResponseBody - @ApiOperation(value="Update a database.") - public PostReturnBody<DbConfig> updateDb(@PathVariable("dbName") String dbName, @RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error parsing DB: " + result.toString()); - return null; - } - - if(!dbName.equals(dbConfig.getName())) - { - sendError(response, 400, "Mismatch DB name."); - return null; - } - - Db oldDb = dbService.getDb(dbConfig.getName()); - if (oldDb == null) { - sendError(response, 404, "Db not found: " + dbConfig.getName()); - return null; - } else { - oldDb.setName(dbConfig.getName()); - oldDb.setHost(dbConfig.getHost()); - oldDb.setPort(dbConfig.getPort()); - oldDb.setEnabled(dbConfig.isEnabled()); - oldDb.setLogin(dbConfig.getLogin()); - oldDb.setPass(dbConfig.getPassword()); - oldDb.setEncrypt(dbConfig.isEncrypt()); - - if(!oldDb.getName().equals("Elecsticsearch") || !oldDb.getName().equals("Druid")) - { - oldDb.setDatabase(dbConfig.getDatabase()); - } - dbRepository.save(oldDb); - DbConfig retMsg; - PostReturnBody<DbConfig> retBody = new PostReturnBody<>(); - retMsg = new DbConfig(); - composeRetMessagefromDbConfig(oldDb, retMsg); - retBody.setReturnBody(retMsg); - retBody.setStatusCode(200); - return retBody; - } - } - //Delete a db //the topics are missing in the return, since in we use @JsonBackReference on Db's topics //need to the the following method to retrieve the topic list @@ -229,6 +180,45 @@ public class DbController { } + //Update Db + @PutMapping("") + @ResponseBody + @ApiOperation(value="Update a database.") + public PostReturnBody<DbConfig> updateDb(@RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DB: " + result.toString()); + return null; + } + + Db oldDb = dbService.getDb(dbConfig.getName()); + if (oldDb == null) { + sendError(response, 404, "Db not found: " + dbConfig.getName()); + return null; + } else { + oldDb.setHost(dbConfig.getHost()); + oldDb.setPort(dbConfig.getPort()); + oldDb.setEnabled(dbConfig.isEnabled()); + oldDb.setLogin(dbConfig.getLogin()); + oldDb.setPass(dbConfig.getPassword()); + oldDb.setEncrypt(dbConfig.isEncrypt()); + if (!oldDb.getName().equals("Elecsticsearch") || !oldDb.getName().equals("Druid")) { + oldDb.setDatabase(dbConfig.getDatabase()); + } + + dbRepository.save(oldDb); + DbConfig retMsg; + PostReturnBody<DbConfig> retBody = new PostReturnBody<>(); + retMsg = new DbConfig(); + composeRetMessagefromDbConfig(oldDb, retMsg); + retBody.setReturnBody(retMsg); + retBody.setStatusCode(200); + return retBody; + } + + } + + @PostMapping("/verify") @ResponseBody @ApiOperation(value="Database connection verification") diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java index db789a47..35d206bb 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java @@ -20,8 +20,11 @@ package org.onap.datalake.feeder.controller;
+import java.util.ArrayList;
import java.util.List;
+import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.dto.DesignTypeConfig;
import org.onap.datalake.feeder.service.DesignTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
@@ -34,7 +37,6 @@ import io.swagger.annotations.ApiOperation; *
* @author guochunmeng
*/
-@CrossOrigin(origins = "*")
@RestController
@RequestMapping(value = "/designTypes", produces = { MediaType.APPLICATION_JSON_VALUE })
public class DesignTypeController {
@@ -44,11 +46,9 @@ public class DesignTypeController { @GetMapping("")
@ResponseBody
- @ApiOperation(value="List all designTypes names")
- public List<String> getTemplateTypeName() {
-
- return designTypeService.listNames();
-
+ @ApiOperation(value="List all designTypes")
+ public List<DesignTypeConfig> getDesignType() {
+ return designTypeService.getDesignTypes();
}
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java index cb3ff344..2844facd 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java @@ -44,7 +44,6 @@ import java.util.List; * * @author guochunmeng */ -@CrossOrigin(origins = "*") @RestController @RequestMapping(value = "/portals", produces = { MediaType.APPLICATION_JSON_VALUE }) public class PortalController { @@ -70,17 +69,8 @@ public class PortalController { Portal portal = null; try { portal = portalRepository.findById(portalConfig.getName()).get(); - if (portalConfig.getEnabled() == false) { - log.info("Disable portal "+portalConfig.getName()); - portal.setPort(null); - portal.setHost(null); - portal.setLogin(null); - portal.setPass(null); - portal.setEnabled(false); - }else { - log.info("Update portal "+portalConfig); - portalService.fillPortalConfiguration(portalConfig, portal); - } + log.info("Update portal "+portalConfig); + portalService.fillPortalConfiguration(portalConfig, portal); portalRepository.save(portal); return mkPostReturnBody(200, portal); } catch (Exception e) { diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java index 7b717268..fa35b3ba 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java @@ -35,7 +35,6 @@ import org.springframework.web.bind.annotation.*; import io.swagger.annotations.ApiOperation; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; @@ -46,7 +45,6 @@ import javax.servlet.http.HttpServletResponse; * * @author guochunmeng */ -@CrossOrigin(origins = "*") @RestController @RequestMapping(value = "/portalDesigns", produces = MediaType.APPLICATION_JSON_VALUE) public class PortalDesignController { @@ -132,17 +130,7 @@ public class PortalDesignController { @ResponseBody @ApiOperation(value="List all PortalDesigns") public List<PortalDesignConfig> queryAllPortalDesign(){ - - List<PortalDesign> portalDesignList = null; - List<PortalDesignConfig> portalDesignConfigList = new ArrayList<>(); - portalDesignList = (List<PortalDesign>) portalDesignRepository.findAll(); - if (portalDesignList != null && portalDesignList.size() > 0) { - log.info("PortalDesignList is not null"); - for (PortalDesign portalDesign : portalDesignList) { - portalDesignConfigList.add(portalDesign.getPortalDesignConfig()); - } - } - return portalDesignConfigList; + return portalDesignService.queryAllPortalDesign(); } @@ -154,21 +142,20 @@ public class PortalDesignController { PortalDesign portalDesign = null; try { portalDesign = portalDesignRepository.findById(id).get(); - if (portalDesign.getDesignType() != null && portalDesign.getDesignType().getName().startsWith("Kibana")) { - boolean flag = portalDesignService.deployKibanaImport(portalDesign); + boolean flag; + try { + flag = portalDesignService.deploy(portalDesign); if (flag) { + portalDesign.setSubmitted(true); + portalDesignRepository.save(portalDesign); + response.setStatus(204); + } else { sendError(response, 400, "DeployPortalDesign failed, id: "+id); } - } else if (portalDesign.getDesignType() != null && portalDesign.getDesignType().getName().startsWith("Elasticsearch")) { - //TODO Elasticsearch template import - sendError(response, 400, "DeployPortalDesign failed, id: "+id); - } else { - //TODO Druid import - sendError(response, 400, "DeployPortalDesign failed, id: "+id); + } catch (Exception e) { + log.debug("The request failed", e.getMessage()); + sendError(response, 400, "The request failed : "+e.getMessage()); } - portalDesign.setSubmitted(true); - portalDesignRepository.save(portalDesign); - response.setStatus(204); } catch (Exception e) { log.debug("PortalDesign is null", e.getMessage()); sendError(response, 400, "PortalDesign not found, id: "+id); @@ -189,4 +176,4 @@ public class PortalDesignController { response.sendError(sc, msg); } -} +}
\ No newline at end of file diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java index 2784be33..93cec8bb 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java @@ -49,7 +49,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.CrossOrigin; + import io.swagger.annotations.ApiOperation; @@ -65,7 +65,6 @@ import io.swagger.annotations.ApiOperation; * @contributor Kate Hsuan @ QCT */ -@CrossOrigin(origins = "*") @RestController @RequestMapping(value = "/topics", produces = { MediaType.APPLICATION_JSON_VALUE })//, consumes= {MediaType.APPLICATION_JSON_UTF8_VALUE}) public class TopicController { diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java index a7716451..62a7c0c6 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java @@ -24,6 +24,7 @@ package org.onap.datalake.feeder.domain; import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.Getter; import lombok.Setter; +import org.onap.datalake.feeder.dto.DesignTypeConfig; import javax.persistence.*; @@ -53,4 +54,12 @@ public class DesignType { @Column(name = "`note`") private String note; + public DesignTypeConfig getDesignTypeConfig() { + + DesignTypeConfig designTypeConfig = new DesignTypeConfig(); + designTypeConfig.setDesignType(getName()); + designTypeConfig.setDisplay(getDisplay()); + return designTypeConfig; + } + } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java index 5b1be038..3a39b4e6 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java @@ -72,18 +72,13 @@ public class PortalDesign { PortalDesignConfig portalDesignConfig = new PortalDesignConfig(); portalDesignConfig.setId(getId()); - portalDesignConfig.setBody(getBody()); - portalDesignConfig.setName(getName()); - portalDesignConfig.setNote(getNote()); - portalDesignConfig.setSubmitted(getSubmitted()); - portalDesignConfig.setTopic(getTopic().getName()); - portalDesignConfig.setDesignType(getDesignType().getName()); + portalDesignConfig.setDisplay(getDesignType().getDisplay()); return portalDesignConfig; } 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 acb48aef..c171c569 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 @@ -161,14 +161,20 @@ public class Topic { tConfig.setAggregateArrayPath(getAggregateArrayPath()); tConfig.setFlattenArrayPath(getFlattenArrayPath()); tConfig.setTtl(getTtl()); + Set<Db> topicDb = getDbs(); List<String> dbList = new ArrayList<>(); + List<String> enabledDbList = new ArrayList<>(); if (topicDb != null) { for (Db item : topicDb) { dbList.add(item.getName()); + if(item.isEnabled()) { + enabledDbList.add(item.getName()); + } } } tConfig.setSinkdbs(dbList); + tConfig.setEnabledSinkdbs(enabledDbList); return tConfig; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/domain/DbConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java index 557b545c..0b6c54c3 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/domain/DbConfig.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java @@ -17,7 +17,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.onap.datalake.feeder.controller.domain; +package org.onap.datalake.feeder.dto; import lombok.Getter; @@ -40,6 +40,6 @@ public class DbConfig { private String password; private boolean encrypt; private String database; - private int port; + private Integer port; private String poperties; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java new file mode 100644 index 00000000..a4ed6d33 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignTypeConfig.java @@ -0,0 +1,40 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 QCT + *================================================================================= + * 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.dto; + +import lombok.Getter; +import lombok.Setter; + +/** + * JSON request body for DesignType Config. + * + * @author guochunmeng + * + */ +@Setter +@Getter +public class DesignTypeConfig { + + private String designType; + + private String display; + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java index a696d3ec..49e1cde5 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java @@ -47,4 +47,6 @@ public class PortalDesignConfig { private String designType; + private String display; + } 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 8dfe1b16..70778bb3 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 @@ -45,6 +45,7 @@ public class TopicConfig { private String login; private String password; private List<String> sinkdbs; + private List<String> enabledSinkdbs;//only include enabled db private boolean enabled; private boolean saveRaw; private String dataFormat; @@ -63,27 +64,27 @@ public class TopicConfig { } public boolean supportHdfs() { - return containDb("HDFS"); + return supportDb("HDFS"); } public boolean supportElasticsearch() { - return containDb("Elasticsearch");//TODO string hard codes + return supportDb("Elasticsearch");//TODO string hard codes } public boolean supportCouchbase() { - return containDb("Couchbase"); + return supportDb("Couchbase"); } public boolean supportDruid() { - return containDb("Druid"); + return supportDb("Druid"); } public boolean supportMongoDB() { - return containDb("MongoDB"); + return supportDb("MongoDB"); } - private boolean containDb(String dbName) { - return (sinkdbs != null && sinkdbs.contains(dbName)); + private boolean supportDb(String dbName) { + return (enabledSinkdbs != null && enabledSinkdbs.contains(dbName)); } //extract DB id from JSON attributes, support multiple attributes @@ -128,7 +129,7 @@ public class TopicConfig { @Override public String toString() { - return name; + return String.format("Topic %s(enabled=%s, enabledSinkdbs=%s)", name, enabled, enabledSinkdbs); } @Override diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java index eafc4bf9..86baebf8 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java @@ -24,7 +24,10 @@ import java.util.ArrayList; import java.util.List;
import org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.dto.DesignTypeConfig;
import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -35,22 +38,25 @@ import org.springframework.stereotype.Service; */
@Service
public class DesignTypeService {
-
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
@Autowired
DesignTypeRepository designTypeRepository;
-
- public List<String> listNames(){
-
- List<String> names = new ArrayList<>();
-
- Iterable<DesignType> ret = designTypeRepository.findAll();
+
+ public List<DesignTypeConfig> getDesignTypes(){
- for(DesignType designType:ret) {
-
- names.add(designType.getName());
-
+ List<DesignType> designTypeList = null;
+ List<DesignTypeConfig> designTypeConfigList = new ArrayList<>();
+ designTypeList = (List<DesignType>)designTypeRepository.findAll();
+ if (designTypeList != null && designTypeList.size() > 0) {
+ log.info("DesignTypeList is not null");
+ for(DesignType designType : designTypeList) {
+ designTypeConfigList.add(designType.getDesignTypeConfig());
+ }
}
- return names;
+ return designTypeConfigList;
}
+
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java index 3f1aabd2..33093ee0 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java @@ -20,12 +20,10 @@ package org.onap.datalake.feeder.service;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
import java.util.Optional;
-import com.google.gson.Gson;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.domain.DesignType;
import org.onap.datalake.feeder.domain.Portal;
@@ -35,6 +33,8 @@ import org.onap.datalake.feeder.dto.PortalDesignConfig; import org.onap.datalake.feeder.repository.DesignTypeRepository;
import org.onap.datalake.feeder.repository.PortalDesignRepository;
import org.onap.datalake.feeder.util.HttpClientUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -46,7 +46,11 @@ import org.springframework.stereotype.Service; @Service
public class PortalDesignService {
-
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ static String POST_FLAG;
+
@Autowired
private PortalDesignRepository portalDesignRepository;
@@ -59,6 +63,9 @@ public class PortalDesignService { @Autowired
private ApplicationConfiguration applicationConfiguration;
+ @Autowired
+ private DbService dbService;
+
public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception
{
PortalDesign portalDesign = new PortalDesign();
@@ -73,13 +80,9 @@ public class PortalDesignService { private void fillPortalDesign(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws IllegalArgumentException {
portalDesign.setId(portalDesignConfig.getId());
-
portalDesign.setBody(portalDesignConfig.getBody());
-
portalDesign.setName(portalDesignConfig.getName());
-
portalDesign.setNote(portalDesignConfig.getNote());
-
portalDesign.setSubmitted(portalDesignConfig.getSubmitted());
if (portalDesignConfig.getTopic() != null) {
@@ -108,13 +111,46 @@ public class PortalDesignService { }
- private String kibanaImportUrl(String host, Integer port){
- return "http://"+host+":"+port+applicationConfiguration.getKibanaDashboardImportApi();
+ public List<PortalDesignConfig> queryAllPortalDesign(){
+
+ List<PortalDesign> portalDesignList = null;
+ List<PortalDesignConfig> portalDesignConfigList = new ArrayList<>();
+ portalDesignList = (List<PortalDesign>) portalDesignRepository.findAll();
+ if (portalDesignList != null && portalDesignList.size() > 0) {
+ log.info("PortalDesignList is not null");
+ for (PortalDesign portalDesign : portalDesignList) {
+ portalDesignConfigList.add(portalDesign.getPortalDesignConfig());
+ }
+ }
+ return portalDesignConfigList;
+ }
+
+
+ public boolean deploy(PortalDesign portalDesign){
+ boolean flag =true;
+ String designTypeName = portalDesign.getDesignType().getName();
+ if (portalDesign.getDesignType() != null && "kibana_db".equals(designTypeName)) {
+ flag = deployKibanaImport(portalDesign);
+ } else if (portalDesign.getDesignType() != null && "kibana_visual".equals(designTypeName)) {
+ //TODO
+ flag =false;
+ } else if (portalDesign.getDesignType() != null && "kibana_search".equals(designTypeName)) {
+ //TODO
+ flag = false;
+ } else if (portalDesign.getDesignType() != null && "es_mapping".equals(designTypeName)) {
+ flag = postEsMappingTemplate(portalDesign, portalDesign.getTopic().getName().toLowerCase());
+ } else if (portalDesign.getDesignType() != null && "druid_kafka_spec".equals(designTypeName)) {
+ //TODO
+ flag =false;
+ } else {
+ flag =false;
+ }
+ return flag;
}
- public boolean deployKibanaImport(PortalDesign portalDesign) {
- boolean flag = false;
+ private boolean deployKibanaImport(PortalDesign portalDesign) throws RuntimeException {
+ POST_FLAG = "KibanaDashboardImport";
String requestBody = portalDesign.getBody();
Portal portal = portalDesign.getDesignType().getPortal();
String portalHost = portal.getHost();
@@ -128,26 +164,32 @@ public class PortalDesignService { } else {
url = kibanaImportUrl(portalHost, portalPort);
}
+ return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
- //Send httpclient to kibana
- String kibanaResponse = HttpClientUtil.sendPostToKibana(url, requestBody);
- Gson gson = new Gson();
- Map<String, Object> map = new HashMap<>();
- map = gson.fromJson(kibanaResponse, map.getClass());
- List objectsList = (List) map.get("objects");
-
- if (objectsList != null && objectsList.size() > 0) {
- Map<String, Object> map2 = new HashMap<>();
- for (int i = 0; i < objectsList.size(); i++){
- map2 = (Map<String, Object>)objectsList.get(i);
- for(String key : map2.keySet()){
- if ("error".equals(key)) {
- return true;
- }
- }
- }
+ }
+
+
+ private String kibanaImportUrl(String host, Integer port){
+ if (port == null) {
+ port = applicationConfiguration.getKibanaPort();
}
- return flag;
+ return "http://"+host+":"+port+applicationConfiguration.getKibanaDashboardImportApi();
+ }
+
+
+ /**
+ * successed resp:
+ * {
+ * "acknowledged": true
+ * }
+ * @param portalDesign
+ * @param templateName
+ * @return flag
+ */
+ public boolean postEsMappingTemplate(PortalDesign portalDesign, String templateName) throws RuntimeException {
+ POST_FLAG = "ElasticsearchMappingTemplate";
+ String requestBody = portalDesign.getBody();
+ return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
}
}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java index b02139f3..459e8ef9 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java @@ -20,6 +20,7 @@ package org.onap.datalake.feeder.util; +import com.google.gson.Gson; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; @@ -29,6 +30,10 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * HttpClient * @@ -37,7 +42,13 @@ import org.apache.http.util.EntityUtils; */ public class HttpClientUtil { - public static String sendPostToKibana(String url, String json){ + private final static String KIBANA_DASHBOARD_IMPORT = "KibanaDashboardImport"; + + private final static String ELASTICSEARCH_MAPPING_TEMPLATE = "ElasticsearchMappingTemplate"; + + public static boolean sendPostHttpClient(String url, String json, String postFlag){ + + boolean flag = true; HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); String response = null; @@ -55,10 +66,55 @@ public class HttpClientUtil { String result = EntityUtils.toString(res.getEntity()); response = result; } + Gson gson = new Gson(); + Map<String, Object> map = new HashMap<>(); + map = gson.fromJson(response, map.getClass()); + switch (postFlag) { + case KIBANA_DASHBOARD_IMPORT: + flag = flagOfKibanaDashboardImport(map); + break; + case ELASTICSEARCH_MAPPING_TEMPLATE : + flag = flagOfPostEsMappingTemplate(map); + break; + } } catch (Exception e) { throw new RuntimeException(e); } - return response; + return flag; + } + + + private static boolean flagOfKibanaDashboardImport(Map<String, Object> map) { + + boolean flag = true; + List objectsList = (List) map.get("objects"); + + if (objectsList != null && objectsList.size() > 0) { + Map<String, Object> map2 = new HashMap<>(); + for (int i = 0; i < objectsList.size(); i++){ + map2 = (Map<String, Object>)objectsList.get(i); + for(String key : map2.keySet()){ + if ("error".equals(key)) { + return false; + } + } + } + } + return flag; + } + + + private static boolean flagOfPostEsMappingTemplate(Map<String, Object> map) { + + boolean flag = true; + for(String key : map.keySet()){ + if ("acknowledged".equals(key) && (boolean) map.get("acknowledged") == true) { + break; + } else { + flag = false; + } + } + return flag; } } |