diff options
Diffstat (limited to 'components/datalake-handler/feeder/src/main/java/org')
10 files changed, 389 insertions, 416 deletions
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java new file mode 100644 index 00000000..0cac567c --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignController.java @@ -0,0 +1,179 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DataLake + * ================================================================================ + * Copyright 2019 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 org.onap.datalake.feeder.controller.domain.PostReturnBody; +import org.onap.datalake.feeder.domain.Design; +import org.onap.datalake.feeder.dto.DesignConfig; +import org.onap.datalake.feeder.repository.DesignRepository; +import org.onap.datalake.feeder.service.DesignService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.*; + +import io.swagger.annotations.ApiOperation; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + + +/** + * This controller manages design settings + * + * @author guochunmeng + */ +@RestController +@RequestMapping(value = "/designs", produces = MediaType.APPLICATION_JSON_VALUE) +public class DesignController { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private DesignRepository designRepository; + + @Autowired + private DesignService designService; + + @PostMapping("") + @ResponseBody + @ApiOperation(value="Create a design.") + public PostReturnBody<DesignConfig> createDesign(@RequestBody DesignConfig designConfig, BindingResult result, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DesignConfig: "+result.toString()); + return null; + } + + Design design = null; + try { + design = designService.fillDesignConfiguration(designConfig); + } catch (Exception e) { + log.debug("FillDesignConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage()); + return null; + } + designRepository.save(design); + log.info("Design save successed"); + return mkPostReturnBody(200, design); + } + + + @PutMapping("{id}") + @ResponseBody + @ApiOperation(value="Update a design.") + public PostReturnBody<DesignConfig> updateDesign(@RequestBody DesignConfig designConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error parsing DesignConfig: "+result.toString()); + return null; + } + + Design design = designService.getDesign(id); + if (design != null) { + try { + designService.fillDesignConfiguration(designConfig, design); + } catch (Exception e) { + log.debug("FillDesignConfiguration failed", e.getMessage()); + sendError(response, 400, "Error FillDesignConfiguration: "+e.getMessage()); + return null; + } + designRepository.save(design); + log.info("Design update successed"); + return mkPostReturnBody(200, design); + } else { + sendError(response, 400, "Design not found: "+id); + return null; + } + + } + + + @DeleteMapping("/{id}") + @ResponseBody + @ApiOperation(value="delete a design.") + public void deleteDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{ + + Design oldDesign = designService.getDesign(id); + if (oldDesign == null) { + sendError(response, 400, "design not found "+id); + } else { + designRepository.delete(oldDesign); + response.setStatus(204); + } + } + + + @GetMapping("") + @ResponseBody + @ApiOperation(value="List all Designs") + public List<DesignConfig> queryAllDesign(){ + return designService.queryAllDesign(); + } + + + @PostMapping("/deploy/{id}") + @ResponseBody + @ApiOperation(value="Design deploy") + public void deployDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException { + + Design design = null; + try { + design = designRepository.findById(id).get(); + boolean flag; + try { + flag = designService.deploy(design); + if (flag) { + design.setSubmitted(true); + designRepository.save(design); + response.setStatus(204); + } else { + sendError(response, 400, "DeployDesign failed, id: "+id); + } + } catch (Exception e) { + log.debug("The request failed", e.getMessage()); + sendError(response, 400, "The request failed : "+e.getMessage()); + } + } catch (Exception e) { + log.debug("Design is null", e.getMessage()); + sendError(response, 400, "Design not found, id: "+id); + } + + } + + + private PostReturnBody<DesignConfig> mkPostReturnBody(int statusCode, Design design) { + PostReturnBody<DesignConfig> retBody = new PostReturnBody<>(); + retBody.setStatusCode(statusCode); + retBody.setReturnBody(design.getDesignConfig()); + return retBody; + } + + private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { + log.info(msg); + 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/PortalDesignController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java deleted file mode 100644 index fa35b3ba..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 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 org.onap.datalake.feeder.controller.domain.PostReturnBody; -import org.onap.datalake.feeder.domain.PortalDesign; -import org.onap.datalake.feeder.dto.PortalDesignConfig; -import org.onap.datalake.feeder.repository.PortalDesignRepository; -import org.onap.datalake.feeder.service.PortalDesignService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import io.swagger.annotations.ApiOperation; - -import java.io.IOException; -import java.util.List; - -import javax.servlet.http.HttpServletResponse; - - -/** - * This controller manages portalDesign settings - * - * @author guochunmeng - */ -@RestController -@RequestMapping(value = "/portalDesigns", produces = MediaType.APPLICATION_JSON_VALUE) -public class PortalDesignController { - - private final Logger log = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private PortalDesignRepository portalDesignRepository; - - @Autowired - private PortalDesignService portalDesignService; - - @PostMapping("") - @ResponseBody - @ApiOperation(value="Create a portalDesign.") - public PostReturnBody<PortalDesignConfig> createPortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString()); - return null; - } - - PortalDesign portalDesign = null; - try { - portalDesign = portalDesignService.fillPortalDesignConfiguration(portalDesignConfig); - } catch (Exception e) { - log.debug("FillPortalDesignConfiguration failed", e.getMessage()); - sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage()); - return null; - } - portalDesignRepository.save(portalDesign); - log.info("PortalDesign save successed"); - return mkPostReturnBody(200, portalDesign); - } - - - @PutMapping("{id}") - @ResponseBody - @ApiOperation(value="Update a portalDesign.") - public PostReturnBody<PortalDesignConfig> updatePortalDesign(@RequestBody PortalDesignConfig portalDesignConfig, BindingResult result, @PathVariable Integer id, HttpServletResponse response) throws IOException { - - if (result.hasErrors()) { - sendError(response, 400, "Error parsing PortalDesignConfig: "+result.toString()); - return null; - } - - PortalDesign portalDesign = portalDesignService.getPortalDesign(id); - if (portalDesign != null) { - try { - portalDesignService.fillPortalDesignConfiguration(portalDesignConfig, portalDesign); - } catch (Exception e) { - log.debug("FillPortalDesignConfiguration failed", e.getMessage()); - sendError(response, 400, "Error FillPortalDesignConfiguration: "+e.getMessage()); - return null; - } - portalDesignRepository.save(portalDesign); - log.info("PortalDesign update successed"); - return mkPostReturnBody(200, portalDesign); - } else { - sendError(response, 400, "PortalDesign not found: "+id); - return null; - } - - } - - - @DeleteMapping("/{id}") - @ResponseBody - @ApiOperation(value="delete a portalDesign.") - public void deletePortalDesign(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException{ - - PortalDesign oldPortalDesign= portalDesignService.getPortalDesign(id); - if (oldPortalDesign == null) { - sendError(response, 400, "portalDesign not found "+id); - } else { - portalDesignRepository.delete(oldPortalDesign); - response.setStatus(204); - } - } - - - @GetMapping("") - @ResponseBody - @ApiOperation(value="List all PortalDesigns") - public List<PortalDesignConfig> queryAllPortalDesign(){ - return portalDesignService.queryAllPortalDesign(); - } - - - @PostMapping("/deploy/{id}") - @ResponseBody - @ApiOperation(value="PortalDesign deploy") - public void deployPortalDesign(@PathVariable Integer id, HttpServletResponse response) throws IOException { - - PortalDesign portalDesign = null; - try { - portalDesign = portalDesignRepository.findById(id).get(); - 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); - } - } catch (Exception e) { - log.debug("The request failed", e.getMessage()); - sendError(response, 400, "The request failed : "+e.getMessage()); - } - } catch (Exception e) { - log.debug("PortalDesign is null", e.getMessage()); - sendError(response, 400, "PortalDesign not found, id: "+id); - } - - } - - - private PostReturnBody<PortalDesignConfig> mkPostReturnBody(int statusCode, PortalDesign portalDesign) { - PostReturnBody<PortalDesignConfig> retBody = new PostReturnBody<>(); - retBody.setStatusCode(statusCode); - retBody.setReturnBody(portalDesign.getPortalDesignConfig()); - return retBody; - } - - private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { - log.info(msg); - response.sendError(sc, msg); - } - -}
\ No newline at end of file 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/Design.java index 1cbf4e59..dde17b33 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/Design.java @@ -28,7 +28,7 @@ import java.util.Set; import javax.persistence.*; -import org.onap.datalake.feeder.dto.PortalDesignConfig; +import org.onap.datalake.feeder.dto.DesignConfig; /** * Domain class representing design @@ -40,7 +40,7 @@ import org.onap.datalake.feeder.dto.PortalDesignConfig; @Setter @Entity @Table(name = "design") -public class PortalDesign { +public class Design { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -75,19 +75,18 @@ public class PortalDesign { @JoinTable(name = "map_db_design", joinColumns = { @JoinColumn(name = "design_id") }, inverseJoinColumns = { @JoinColumn(name = "db_id") }) protected Set<Db> dbs; - public PortalDesignConfig getPortalDesignConfig() { + public DesignConfig getDesignConfig() { - PortalDesignConfig portalDesignConfig = new PortalDesignConfig(); - - portalDesignConfig.setId(getId()); - portalDesignConfig.setBody(getBody()); - portalDesignConfig.setName(getName()); - portalDesignConfig.setNote(getNote()); - portalDesignConfig.setSubmitted(getSubmitted()); - portalDesignConfig.setTopic(getTopicName().getId()); - portalDesignConfig.setDesignType(getDesignType().getId()); - portalDesignConfig.setDisplay(getDesignType().getName()); - - return portalDesignConfig; + DesignConfig designConfig = new DesignConfig(); + + designConfig.setId(getId()); + designConfig.setBody(getBody()); + designConfig.setName(getName()); + designConfig.setNote(getNote()); + designConfig.setSubmitted(getSubmitted()); + designConfig.setTopicName(getTopicName().getId()); + designConfig.setDesignType(getDesignType().getId()); + + return designConfig; } } 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 83e1666a..dd327ea0 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 @@ -61,7 +61,7 @@ public class DesignType { private DbType dbType; @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "designType") - protected Set<PortalDesign> designs = new HashSet<>(); + protected Set<Design> designs = new HashSet<>(); @Column(name = "`note`") private String note; @@ -69,8 +69,10 @@ public class DesignType { public DesignTypeConfig getDesignTypeConfig() { DesignTypeConfig designTypeConfig = new DesignTypeConfig(); - designTypeConfig.setDesignType(getName()); - //designTypeConfig.setDisplay(getDisplay()); + + designTypeConfig.setId(getId()); + designTypeConfig.setName(getName()); + return designTypeConfig; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java index 35e6ea54..83227ada 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/TopicName.java @@ -49,7 +49,7 @@ public class TopicName { @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName") - protected Set<PortalDesign> designs; + protected Set<Design> designs; @OneToMany(fetch = FetchType.LAZY, mappedBy = "topicName") 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/DesignConfig.java index 49e1cde5..d115529d 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/DesignConfig.java @@ -31,22 +31,14 @@ import lombok.Setter; @Getter @Setter -public class PortalDesignConfig { +public class DesignConfig { private Integer id; - private String name; - private Boolean submitted; - private String body; - private String note; - - private String topic; - + private String topicName; private String designType; - private String display; - } 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 index a4ed6d33..ddedf38b 100644 --- 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 @@ -33,8 +33,7 @@ import lombok.Setter; @Getter public class DesignTypeConfig { - private String designType; - - private String display; + private String id; + private String name; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java index 181bc115..f144e905 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignRepository.java @@ -20,20 +20,17 @@ package org.onap.datalake.feeder.repository; -import org.onap.datalake.feeder.domain.PortalDesign; -import org.springframework.data.jpa.repository.Query; +import org.onap.datalake.feeder.domain.Design; import org.springframework.data.repository.CrudRepository; -import java.util.List; - /** - * PortalDesign Repository + * Design Repository * * @author guochunmeng */ -public interface PortalDesignRepository extends CrudRepository<PortalDesign, Integer> { +public interface DesignRepository extends CrudRepository<Design, Integer> { - PortalDesign findByName(String name); + Design findByName(String name); } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java new file mode 100755 index 00000000..61411a4d --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java @@ -0,0 +1,182 @@ +/*
+ * ============LICENSE_START=======================================================
+ * ONAP : DataLake
+ * ================================================================================
+ * Copyright 2019 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.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+
+import org.onap.datalake.feeder.config.ApplicationConfiguration;
+import org.onap.datalake.feeder.domain.*;
+import org.onap.datalake.feeder.domain.Design;
+import org.onap.datalake.feeder.dto.DesignConfig;
+import org.onap.datalake.feeder.enumeration.DesignTypeEnum;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.onap.datalake.feeder.repository.DesignRepository;
+import org.onap.datalake.feeder.repository.TopicNameRepository;
+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;
+
+/**
+ * Service for portalDesigns
+ *
+ * @author guochunmeng
+ */
+
+@Service
+public class DesignService {
+
+ private final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ static String POST_FLAG;
+
+ @Autowired
+ private DesignRepository designRepository;
+
+ @Autowired
+ private TopicNameRepository topicNameRepository;
+
+ @Autowired
+ private DesignTypeRepository designTypeRepository;
+
+ @Autowired
+ private ApplicationConfiguration applicationConfiguration;
+
+ public Design fillDesignConfiguration(DesignConfig designConfig) {
+ Design design = new Design();
+ fillDesign(designConfig, design);
+ return design;
+ }
+
+ public void fillDesignConfiguration(DesignConfig designConfig, Design design) {
+ fillDesign(designConfig, design);
+ }
+
+ private void fillDesign(DesignConfig designConfig, Design design) throws IllegalArgumentException {
+
+ design.setId(designConfig.getId());
+ design.setBody(designConfig.getBody());
+ design.setName(designConfig.getName());
+ design.setNote(designConfig.getNote());
+ design.setSubmitted(designConfig.getSubmitted());
+
+ if (designConfig.getTopicName() == null)
+ throw new IllegalArgumentException("Can not find topicName in tpoic_name, topic name: " + designConfig.getTopicName());
+ Optional<TopicName> topicName = topicNameRepository.findById(designConfig.getTopicName());
+ if (!topicName.isPresent())
+ throw new IllegalArgumentException("topicName is null " + designConfig.getTopicName());
+ design.setTopicName(topicName.get());
+
+
+ if (designConfig.getDesignType() == null)
+ throw new IllegalArgumentException("Can not find designType in design_type, designType id " + designConfig.getDesignType());
+ Optional<DesignType> designType = designTypeRepository.findById(designConfig.getDesignType());
+ if (!designType.isPresent())
+ throw new IllegalArgumentException("designType is null");
+ design.setDesignType(designType.get());
+
+ }
+
+ public Design getDesign(Integer id) {
+
+ Optional<Design> ret = designRepository.findById(id);
+ return ret.isPresent() ? ret.get() : null;
+ }
+
+ public List<DesignConfig> queryAllDesign() {
+
+ List<Design> designList = null;
+ List<DesignConfig> designConfigList = new ArrayList<>();
+ designList = (List<Design>) designRepository.findAll();
+ if (designList != null && designList.size() > 0) {
+ log.info("PortalDesignList is not null");
+ for (Design design : designList) {
+ designConfigList.add(design.getDesignConfig());
+ }
+ }
+ return designConfigList;
+ }
+
+ public boolean deploy(Design design) {
+ DesignType designType = design.getDesignType();
+ DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());
+
+ switch (designTypeEnum) {
+ case KIBANA_DB:
+ return deployKibanaImport(design);
+ case ES_MAPPING:
+ return postEsMappingTemplate(design, design.getTopicName().getId().toLowerCase());
+ default:
+ log.error("Not implemented {}", designTypeEnum);
+ return false;
+ }
+ }
+
+ private boolean deployKibanaImport(Design design) throws RuntimeException {
+ POST_FLAG = "KibanaDashboardImport";
+ String requestBody = design.getBody();
+ Portal portal = design.getDesignType().getPortal();
+ String portalHost = portal.getHost();
+ Integer portalPort = portal.getPort();
+ String url = "";
+
+ if (portalHost == null || portalPort == null) {
+ String dbHost = portal.getDb().getHost();
+ Integer dbPort = portal.getDb().getPort();
+ url = kibanaImportUrl(dbHost, dbPort);
+ } else {
+ url = kibanaImportUrl(portalHost, portalPort);
+ }
+ return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
+
+ }
+
+ private String kibanaImportUrl(String host, Integer port) {
+ if (port == null) {
+ port = applicationConfiguration.getKibanaPort();
+ }
+ return "http://" + host + ":" + port + applicationConfiguration.getKibanaDashboardImportApi();
+ }
+
+ /**
+ * successed resp: { "acknowledged": true }
+ *
+ * @param design
+ * @param templateName
+ * @return flag
+ */
+ public boolean postEsMappingTemplate(Design design, String templateName) throws RuntimeException {
+ POST_FLAG = "ElasticsearchMappingTemplate";
+ String requestBody = design.getBody();
+
+ //FIXME
+ Set<Db> dbs = design.getDbs();
+ //submit to each ES in dbs
+
+ //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
+ return false;
+ }
+
+}
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 deleted file mode 100755 index 408e4971..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java +++ /dev/null @@ -1,198 +0,0 @@ -/*
- * ============LICENSE_START=======================================================
- * ONAP : DataLake
- * ================================================================================
- * Copyright 2019 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.service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-
-import org.onap.datalake.feeder.config.ApplicationConfiguration;
-import org.onap.datalake.feeder.domain.Db;
-import org.onap.datalake.feeder.domain.DbType;
-import org.onap.datalake.feeder.domain.DesignType;
-import org.onap.datalake.feeder.domain.Portal;
-import org.onap.datalake.feeder.domain.PortalDesign;
-import org.onap.datalake.feeder.domain.Topic;
-import org.onap.datalake.feeder.domain.TopicName;
-import org.onap.datalake.feeder.dto.PortalDesignConfig;
-import org.onap.datalake.feeder.enumeration.DbTypeEnum;
-import org.onap.datalake.feeder.enumeration.DesignTypeEnum;
-import org.onap.datalake.feeder.repository.DesignTypeRepository;
-import org.onap.datalake.feeder.repository.PortalDesignRepository;
-import org.onap.datalake.feeder.repository.TopicNameRepository;
-import org.onap.datalake.feeder.service.db.CouchbaseService;
-import org.onap.datalake.feeder.service.db.DbStoreService;
-import org.onap.datalake.feeder.service.db.ElasticsearchService;
-import org.onap.datalake.feeder.service.db.HdfsService;
-import org.onap.datalake.feeder.service.db.MongodbService;
-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;
-
-/**
- * Service for portalDesigns
- *
- * @author guochunmeng
- */
-
-@Service
-public class PortalDesignService {
-
- private final Logger log = LoggerFactory.getLogger(this.getClass());
-
- static String POST_FLAG;
-
- @Autowired
- private PortalDesignRepository portalDesignRepository;
-
- @Autowired
- private TopicNameRepository topicNameRepository;
-
- @Autowired
- private DesignTypeRepository designTypeRepository;
-
- @Autowired
- private ApplicationConfiguration applicationConfiguration;
-
- public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception {
- PortalDesign portalDesign = new PortalDesign();
- fillPortalDesign(portalDesignConfig, portalDesign);
- return portalDesign;
- }
-
- public void fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws Exception {
- fillPortalDesign(portalDesignConfig, portalDesign);
- }
-
- 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) {
- Optional<TopicName> topicName = topicNameRepository.findById(portalDesignConfig.getTopic());
- if (topicName.isPresent()) {
- portalDesign.setTopicName(topicName.get());
- } else {
- throw new IllegalArgumentException("topic is null " + portalDesignConfig.getTopic());
- }
- } else {
- throw new IllegalArgumentException("Can not find topic in DB, topic name: " + portalDesignConfig.getTopic());
- }
-
- if (portalDesignConfig.getDesignType() != null) {
- DesignType designType = designTypeRepository.findById(portalDesignConfig.getDesignType()).get();
- if (designType == null)
- throw new IllegalArgumentException("designType is null");
- portalDesign.setDesignType(designType);
- } else {
- throw new IllegalArgumentException("Can not find designType in Design_type, designType name " + portalDesignConfig.getDesignType());
- }
-
- }
-
- public PortalDesign getPortalDesign(Integer id) {
-
- Optional<PortalDesign> ret = portalDesignRepository.findById(id);
- return ret.isPresent() ? ret.get() : null;
- }
-
- 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) {
- DesignType designType = portalDesign.getDesignType();
- DesignTypeEnum designTypeEnum = DesignTypeEnum.valueOf(designType.getId());
-
- switch (designTypeEnum) {
- case KIBANA_DB:
- return deployKibanaImport(portalDesign);
- case ES_MAPPING:
- return postEsMappingTemplate(portalDesign, portalDesign.getTopicName().getId().toLowerCase());
- default:
- log.error("Not implemented {}", designTypeEnum);
- return false;
- }
- }
-
- private boolean deployKibanaImport(PortalDesign portalDesign) throws RuntimeException {
- POST_FLAG = "KibanaDashboardImport";
- String requestBody = portalDesign.getBody();
- Portal portal = portalDesign.getDesignType().getPortal();
- String portalHost = portal.getHost();
- Integer portalPort = portal.getPort();
- String url = "";
-
- if (portalHost == null || portalPort == null) {
- String dbHost = portal.getDb().getHost();
- Integer dbPort = portal.getDb().getPort();
- url = kibanaImportUrl(dbHost, dbPort);
- } else {
- url = kibanaImportUrl(portalHost, portalPort);
- }
- return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_FLAG);
-
- }
-
- private String kibanaImportUrl(String host, Integer port) {
- if (port == null) {
- port = applicationConfiguration.getKibanaPort();
- }
- 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();
-
- //FIXME
- Set<Db> dbs = portalDesign.getDbs();
- //submit to each ES in dbs
-
- //return HttpClientUtil.sendPostHttpClient("http://"+dbService.getElasticsearch().getHost()+":9200/_template/"+templateName, requestBody, POST_FLAG);
- return false;
- }
-
-}
|