diff options
Diffstat (limited to 'components/datalake-handler/feeder/src')
18 files changed, 1169 insertions, 0 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 73067182..2bcd0a39 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 @@ -70,4 +70,7 @@ public class ApplicationConfiguration { //Version private String datalakeVersion; + + //Kibana + private String KibanaDashboardImportApi; } 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 new file mode 100755 index 00000000..db789a47 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java @@ -0,0 +1,54 @@ +/*
+ * ============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 java.util.List;
+
+import org.onap.datalake.feeder.service.DesignTypeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.bind.annotation.*;
+
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * This controller manages designType settings
+ *
+ * @author guochunmeng
+ */
+@CrossOrigin(origins = "*")
+@RestController
+@RequestMapping(value = "/designTypes", produces = { MediaType.APPLICATION_JSON_VALUE })
+public class DesignTypeController {
+
+ @Autowired
+ private DesignTypeService designTypeService;
+
+ @GetMapping("")
+ @ResponseBody
+ @ApiOperation(value="List all designTypes names")
+ public List<String> getTemplateTypeName() {
+
+ return designTypeService.listNames();
+
+ }
+
+}
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 new file mode 100644 index 00000000..cb3ff344 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java @@ -0,0 +1,125 @@ +/* + * ============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 io.swagger.annotations.ApiOperation; +import org.onap.datalake.feeder.controller.domain.PostReturnBody; +import org.onap.datalake.feeder.domain.Portal; +import org.onap.datalake.feeder.dto.PortalConfig; +import org.onap.datalake.feeder.repository.PortalRepository; +import org.onap.datalake.feeder.service.PortalService; +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 javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * This controller manages Portal settings + * + * + * @author guochunmeng + */ +@CrossOrigin(origins = "*") +@RestController +@RequestMapping(value = "/portals", produces = { MediaType.APPLICATION_JSON_VALUE }) +public class PortalController { + + private final Logger log = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private PortalRepository portalRepository; + + @Autowired + private PortalService portalService; + + @PutMapping("") + @ResponseBody + @ApiOperation("update portal") + public PostReturnBody<PortalConfig> updatePortal(@RequestBody PortalConfig portalConfig, BindingResult result, HttpServletResponse response) throws IOException { + + if (result.hasErrors()) { + sendError(response, 400, "Error binding PortalConfig: "+result.toString()); + return null; + } + + 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); + } + portalRepository.save(portal); + return mkPostReturnBody(200, portal); + } catch (Exception e) { + log.debug("Update or delete portal failed, Portal: "+portalConfig, e.getMessage()); + sendError(response, 400, "Error update or delete portal: "+portal); + return null; + } + } + + + @GetMapping("") + @ResponseBody + @ApiOperation(value = "List all portals") + public List<PortalConfig> getPortals() { + + List<Portal> portalList = null; + List<PortalConfig> portalConfigList = new ArrayList<>(); + portalList = (List<Portal>)portalRepository.findAll(); + if (portalList != null && portalList.size() > 0) { + log.info("PortalList is not null"); + for(Portal portal : portalList) { + portalConfigList.add(portal.getPortalConfig()); + } + } + return portalConfigList; + } + + + private void sendError(HttpServletResponse response, int sc, String msg) throws IOException { + log.info(msg); + response.sendError(sc, msg); + } + + + private PostReturnBody<PortalConfig> mkPostReturnBody(int statusCode, Portal portal) { + PostReturnBody<PortalConfig> retBody = new PostReturnBody<>(); + retBody.setStatusCode(statusCode); + retBody.setReturnBody(portal.getPortalConfig()); + return retBody; + } + +}
\ 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 new file mode 100644 index 00000000..7b717268 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java @@ -0,0 +1,192 @@ +/* + * ============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.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + + +/** + * This controller manages portalDesign settings + * + * @author guochunmeng + */ +@CrossOrigin(origins = "*") +@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(){ + + 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; + } + + + @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(); + if (portalDesign.getDesignType() != null && portalDesign.getDesignType().getName().startsWith("Kibana")) { + boolean flag = portalDesignService.deployKibanaImport(portalDesign); + if (flag) { + 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); + } + 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); + } + + } + + + 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); + } + +} 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 88f573a1..2784be33 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,6 +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; @@ -64,6 +65,7 @@ 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 new file mode 100644 index 00000000..3e730c14 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java @@ -0,0 +1,53 @@ +/* + * ============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.domain; + + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.*; + +/** + * Domain class representing design_type + * + * @author guochunmeng + */ +@Getter +@Setter +@Entity +@Table(name = "design_type") +public class DesignType { + + @Id + @Column(name = "`name`") + private String name; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="portal") + @JsonBackReference + private Portal portal; + + @Column(name = "`note`") + private String note; + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java new file mode 100644 index 00000000..d2214dce --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java @@ -0,0 +1,79 @@ +/* + * ============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.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; +import org.onap.datalake.feeder.dto.PortalConfig; + +import javax.persistence.*; + +/** + * Domain class representing portal + * + * @author guochunmeng + */ + +@Getter +@Setter +@Entity +@Table(name = "portal") +public class Portal { + + @Id + @Column(name = "`name`") + private String name; + + @Column(name = "`enabled`") + private Boolean enabled; + + @Column(name = "`host`") + private String host; + + @Column(name = "`port`") + private Integer port; + + @Column(name = "`login`") + private String login; + + @Column(name = "`pass`") + private String pass; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "related_db") + @JsonBackReference + private Db db; + + public PortalConfig getPortalConfig() { + PortalConfig portalConfig = new PortalConfig(); + + portalConfig.setName(getName()); + portalConfig.setLogin(getLogin()); + portalConfig.setPass(getPass()); + portalConfig.setEnabled(getEnabled()); + portalConfig.setHost(getHost()); + portalConfig.setPort(getPort()); + portalConfig.setDb(getDb().getName()); + + return portalConfig; + } +} 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 new file mode 100644 index 00000000..5b1be038 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java @@ -0,0 +1,90 @@ +/* + * ============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.domain; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import lombok.Getter; +import lombok.Setter; + +import javax.persistence.*; + +import org.onap.datalake.feeder.dto.PortalDesignConfig; + +/** + * Domain class representing portal_design + * + * @author guochunmeng + */ + +@Getter +@Setter +@Entity +@Table(name = "portal_design") +public class PortalDesign { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + private Integer id; + + @Column(name = "`name`") + private String name; + + @Column(name = "`submitted`") + private Boolean submitted; + + @Column(name = "`body`") + private String body; + + @Column(name = "`note`") + private String note; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "topic") + @JsonBackReference + private Topic topic; + + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name = "type") + @JsonBackReference + private DesignType designType; + + public PortalDesignConfig getPortalDesignConfig() { + + 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()); + + return portalDesignConfig; + } +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java new file mode 100644 index 00000000..76b1ceb7 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java @@ -0,0 +1,50 @@ +/* + * ============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 Portal Config. + * + * @author guochunmeng + * + */ +@Setter +@Getter +public class PortalConfig { + + private String name; + + private Boolean enabled; + + private String host; + + private Integer port; + + private String login; + + private String pass; + + private String db; + +} 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 new file mode 100755 index 00000000..a696d3ec --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java @@ -0,0 +1,50 @@ +/* + * ============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.dto; + +import lombok.Getter; +import lombok.Setter; + +/** + * JSON request body for portalDesign Config. + * + * @author guochunmeng + */ + +@Getter +@Setter +public class PortalDesignConfig { + + private Integer id; + + private String name; + + private Boolean submitted; + + private String body; + + private String note; + + private String topic; + + private String designType; + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignTypeRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignTypeRepository.java new file mode 100755 index 00000000..e7ab48a2 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignTypeRepository.java @@ -0,0 +1,35 @@ +/* + * ============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.repository; + +import org.onap.datalake.feeder.domain.DesignType; +import org.springframework.data.repository.CrudRepository; + +/** + * DesignType Repository + * + * @author guochunmeng + */ + +public interface DesignTypeRepository extends CrudRepository<DesignType, String> { + + +} 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/PortalDesignRepository.java new file mode 100644 index 00000000..181bc115 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java @@ -0,0 +1,39 @@ +/* + * ============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.repository; + +import org.onap.datalake.feeder.domain.PortalDesign; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; + +import java.util.List; + +/** + * PortalDesign Repository + * + * @author guochunmeng + */ + +public interface PortalDesignRepository extends CrudRepository<PortalDesign, Integer> { + + PortalDesign findByName(String name); + +} diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java new file mode 100644 index 00000000..f4ce0ee5 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java @@ -0,0 +1,42 @@ +/* + * ============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.repository; + +import org.onap.datalake.feeder.domain.Portal; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.Repository; + +import java.util.List; + +/** + * Portal Repository + * + * @author guochunmeng + */ + +public interface PortalRepository extends CrudRepository<Portal, String> { + + List<Portal> findByEnabled(Boolean enabled); + +} 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 new file mode 100755 index 00000000..eafc4bf9 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java @@ -0,0 +1,56 @@ +/*
+ * ============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 org.onap.datalake.feeder.domain.DesignType;
+import org.onap.datalake.feeder.repository.DesignTypeRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Service for designTypes
+ *
+ * @author guochunmeng
+ */
+@Service
+public class DesignTypeService {
+
+ @Autowired
+ DesignTypeRepository designTypeRepository;
+
+ public List<String> listNames(){
+
+ List<String> names = new ArrayList<>();
+
+ Iterable<DesignType> ret = designTypeRepository.findAll();
+
+ for(DesignType designType:ret) {
+
+ names.add(designType.getName());
+
+ }
+
+ return names;
+ }
+}
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 new file mode 100755 index 00000000..3f1aabd2 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java @@ -0,0 +1,153 @@ +/*
+ * ============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.HashMap;
+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;
+import org.onap.datalake.feeder.domain.PortalDesign;
+import org.onap.datalake.feeder.domain.Topic;
+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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Service for portalDesigns
+ *
+ * @author guochunmeng
+ */
+
+@Service
+public class PortalDesignService {
+
+ @Autowired
+ private PortalDesignRepository portalDesignRepository;
+
+ @Autowired
+ private TopicService topicService;
+
+ @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) {
+ Topic topic = topicService.getTopic(portalDesignConfig.getTopic());
+ if (topic == null) throw new IllegalArgumentException("topic is null");
+ portalDesign.setTopic(topic);
+ }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;
+ }
+
+
+ private String kibanaImportUrl(String host, Integer port){
+ return "http://"+host+":"+port+applicationConfiguration.getKibanaDashboardImportApi();
+ }
+
+
+ public boolean deployKibanaImport(PortalDesign portalDesign) {
+ boolean flag = false;
+ 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);
+ }
+
+ //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;
+ }
+ }
+ }
+ }
+ return flag;
+ }
+
+}
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java new file mode 100644 index 00000000..28efd150 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java @@ -0,0 +1,79 @@ +/* + * ============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 org.onap.datalake.feeder.domain.Portal; +import org.onap.datalake.feeder.dto.PortalConfig; +import org.onap.datalake.feeder.repository.PortalRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * Service for portals + * + * @author guochunmeng + * + */ +@Service +public class PortalService { + + @Autowired + private PortalRepository portalRepository; + + public Portal fillPortalConfiguration(PortalConfig portalConfig) + { + Portal portal = new Portal(); + fillPortal(portalConfig, portal); + return portal; + } + public void fillPortalConfiguration(PortalConfig portalConfig, Portal portal) + { + fillPortal(portalConfig, portal); + } + + private void fillPortal(PortalConfig portalConfig, Portal portal) { + + portal.setName(portalConfig.getName()); + portal.setLogin(portalConfig.getLogin()); + portal.setPass(portalConfig.getPass()); + portal.setEnabled(portalConfig.getEnabled()); + portal.setHost(portalConfig.getHost()); + portal.setPort(portalConfig.getPort()); + + } + + + public List<String> listNames(boolean enabled){ + + List<String> names = new ArrayList<>(); + Iterable<Portal> ret = portalRepository.findByEnabled(enabled); + for(Portal portal:ret) { + names.add(portal.getName()); + } + + return names; + } + +} 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 new file mode 100644 index 00000000..b02139f3 --- /dev/null +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java @@ -0,0 +1,64 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : DCAE + * ================================================================================ + * 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.util; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; + +/** + * HttpClient + * + * @author guochunmeng + * + */ +public class HttpClientUtil { + + public static String sendPostToKibana(String url, String json){ + HttpClient client = new DefaultHttpClient(); + HttpPost post = new HttpPost(url); + String response = null; + try { + StringEntity s = new StringEntity(json); + s.setContentEncoding("UTF-8"); + s.setContentType("application/json"); + post.setEntity(s); + post.setHeader("kbn-xsrf","true"); + post.setHeader("Accept", "*/*"); + post.setHeader("Connection", "Keep-Alive"); + HttpResponse res = client.execute(post); + if(res.getStatusLine().getStatusCode() == HttpStatus.SC_OK){ + HttpEntity entity = res.getEntity(); + String result = EntityUtils.toString(res.getEntity()); + response = result; + } + } catch (Exception e) { + throw new RuntimeException(e); + } + return response; + } + +} diff --git a/components/datalake-handler/feeder/src/main/resources/application.properties b/components/datalake-handler/feeder/src/main/resources/application.properties index 7bbbac05..faf27583 100644 --- a/components/datalake-handler/feeder/src/main/resources/application.properties +++ b/components/datalake-handler/feeder/src/main/resources/application.properties @@ -57,4 +57,7 @@ logging.level.org.onap.datalake=DEBUG #####################Verison datalakeVersion=0.0.1 + +#####################KibanaDashboardImportApi +KibanaDashboardImportApi=/api/kibana/dashboards/import?exclude=index-pattern |