Dashboard and esTemplate 87/88987/13
authorZhangZihao <zhangzihao@chinamobile.com>
Fri, 31 May 2019 02:55:37 +0000 (10:55 +0800)
committerZihao Zhang <zhangzihao@chinamobile.com>
Thu, 6 Jun 2019 03:43:19 +0000 (03:43 +0000)
Change-Id: Id87cb7846ac50ab5e0deee9582479c41aa4e5484
Issue-ID: DCAEGEN2-1329
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
18 files changed:
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/config/ApplicationConfiguration.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DesignTypeController.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalDesignController.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/TopicController.java
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/PortalDesign.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalDesignConfig.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/DesignTypeRepository.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalDesignRepository.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignTypeService.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalDesignService.java [new file with mode: 0755]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/util/HttpClientUtil.java [new file with mode: 0644]
components/datalake-handler/feeder/src/main/resources/application.properties

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 (executable)
index 0000000..db789a4
--- /dev/null
@@ -0,0 +1,54 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : DataLake\r
+ * ================================================================================\r
+ * Copyright 2019 China Mobile\r
+ *=================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.datalake.feeder.controller;\r
+\r
+import java.util.List;\r
+\r
+import org.onap.datalake.feeder.service.DesignTypeService;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.http.MediaType;\r
+import org.springframework.web.bind.annotation.*;\r
+\r
+import io.swagger.annotations.ApiOperation;\r
+\r
+/**\r
+ * This controller manages designType settings\r
+ *\r
+ * @author guochunmeng\r
+ */\r
+@CrossOrigin(origins = "*")\r
+@RestController\r
+@RequestMapping(value = "/designTypes", produces = { MediaType.APPLICATION_JSON_VALUE })\r
+public class DesignTypeController {\r
+       \r
+       @Autowired\r
+       private DesignTypeService designTypeService;\r
+       \r
+       @GetMapping("")\r
+       @ResponseBody\r
+       @ApiOperation(value="List all designTypes names")\r
+    public List<String> getTemplateTypeName() {\r
+\r
+        return designTypeService.listNames();\r
+\r
+    }\r
+    \r
+}\r
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 (file)
index 0000000..cb3ff34
--- /dev/null
@@ -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 (file)
index 0000000..7b71726
--- /dev/null
@@ -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);            
+       }
+    
+}
index 88f573a..2784be3 100644 (file)
@@ -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 (file)
index 0000000..3e730c1
--- /dev/null
@@ -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 (file)
index 0000000..d2214dc
--- /dev/null
@@ -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 (file)
index 0000000..5b1be03
--- /dev/null
@@ -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 (file)
index 0000000..76b1ceb
--- /dev/null
@@ -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 (executable)
index 0000000..a696d3e
--- /dev/null
@@ -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 (executable)
index 0000000..e7ab48a
--- /dev/null
@@ -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 (file)
index 0000000..181bc11
--- /dev/null
@@ -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 (file)
index 0000000..f4ce0ee
--- /dev/null
@@ -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 (executable)
index 0000000..eafc4bf
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : DataLake\r
+ * ================================================================================\r
+ * Copyright 2019 China Mobile\r
+ *=================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.datalake.feeder.service;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.onap.datalake.feeder.domain.DesignType;\r
+import org.onap.datalake.feeder.repository.DesignTypeRepository;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
+\r
+/**\r
+ * Service for designTypes\r
+ *\r
+ * @author guochunmeng\r
+ */\r
+@Service\r
+public class DesignTypeService {\r
+       \r
+       @Autowired\r
+       DesignTypeRepository designTypeRepository;\r
+       \r
+       public List<String> listNames(){\r
+               \r
+               List<String> names = new ArrayList<>();\r
+               \r
+               Iterable<DesignType> ret = designTypeRepository.findAll();\r
+               \r
+               for(DesignType designType:ret) {\r
+                       \r
+                       names.add(designType.getName());\r
+                       \r
+               }\r
+               \r
+               return names;\r
+       }\r
+}\r
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 (executable)
index 0000000..3f1aabd
--- /dev/null
@@ -0,0 +1,153 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : DataLake\r
+ * ================================================================================\r
+ * Copyright 2019 China Mobile\r
+ *=================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.datalake.feeder.service;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Optional;\r
+\r
+import com.google.gson.Gson;\r
+import org.onap.datalake.feeder.config.ApplicationConfiguration;\r
+import org.onap.datalake.feeder.domain.DesignType;\r
+import org.onap.datalake.feeder.domain.Portal;\r
+import org.onap.datalake.feeder.domain.PortalDesign;\r
+import org.onap.datalake.feeder.domain.Topic;\r
+import org.onap.datalake.feeder.dto.PortalDesignConfig;\r
+import org.onap.datalake.feeder.repository.DesignTypeRepository;\r
+import org.onap.datalake.feeder.repository.PortalDesignRepository;\r
+import org.onap.datalake.feeder.util.HttpClientUtil;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.stereotype.Service;\r
+\r
+/**\r
+ * Service for portalDesigns\r
+ *\r
+ * @author guochunmeng\r
+ */\r
+\r
+@Service\r
+public class PortalDesignService {\r
+       \r
+    @Autowired\r
+    private PortalDesignRepository portalDesignRepository;\r
+\r
+    @Autowired\r
+       private TopicService topicService;\r
+\r
+       @Autowired\r
+       private DesignTypeRepository designTypeRepository;\r
+\r
+       @Autowired\r
+       private ApplicationConfiguration applicationConfiguration;\r
+\r
+       public PortalDesign fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig) throws Exception\r
+       {\r
+               PortalDesign portalDesign = new PortalDesign();\r
+               fillPortalDesign(portalDesignConfig, portalDesign);\r
+               return portalDesign;\r
+       }\r
+       public void fillPortalDesignConfiguration(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws Exception\r
+       {\r
+               fillPortalDesign(portalDesignConfig, portalDesign);\r
+       }\r
+\r
+       private void fillPortalDesign(PortalDesignConfig portalDesignConfig, PortalDesign portalDesign) throws IllegalArgumentException {\r
+\r
+               portalDesign.setId(portalDesignConfig.getId());\r
+\r
+               portalDesign.setBody(portalDesignConfig.getBody());\r
+\r
+               portalDesign.setName(portalDesignConfig.getName());\r
+\r
+               portalDesign.setNote(portalDesignConfig.getNote());\r
+\r
+               portalDesign.setSubmitted(portalDesignConfig.getSubmitted());\r
+\r
+               if (portalDesignConfig.getTopic() != null) {\r
+                       Topic topic = topicService.getTopic(portalDesignConfig.getTopic());\r
+                       if (topic == null) throw new IllegalArgumentException("topic is null");\r
+                       portalDesign.setTopic(topic);\r
+               }else {\r
+                       throw new IllegalArgumentException("Can not find topic in DB, topic name: "+portalDesignConfig.getTopic());\r
+               }\r
+\r
+               if (portalDesignConfig.getDesignType() != null) {\r
+                       DesignType designType = designTypeRepository.findById(portalDesignConfig.getDesignType()).get();\r
+                       if (designType == null) throw new IllegalArgumentException("designType is null");\r
+                       portalDesign.setDesignType(designType);\r
+               }else {\r
+                       throw new IllegalArgumentException("Can not find designType in Design_type, designType name "+portalDesignConfig.getDesignType());\r
+               }\r
+\r
+       }\r
+\r
+       \r
+       public PortalDesign getPortalDesign(Integer id) {\r
+               \r
+               Optional<PortalDesign> ret = portalDesignRepository.findById(id);\r
+               return ret.isPresent() ? ret.get() : null;\r
+       }\r
+\r
+\r
+       private String kibanaImportUrl(String host, Integer port){\r
+               return "http://"+host+":"+port+applicationConfiguration.getKibanaDashboardImportApi();\r
+       }\r
+\r
+\r
+       public boolean deployKibanaImport(PortalDesign portalDesign) {\r
+               boolean flag = false;\r
+               String requestBody = portalDesign.getBody();\r
+               Portal portal = portalDesign.getDesignType().getPortal();\r
+               String portalHost = portal.getHost();\r
+               Integer portalPort = portal.getPort();\r
+               String url = "";\r
+\r
+               if (portalHost == null || portalPort == null) {\r
+                       String dbHost = portal.getDb().getHost();\r
+                       Integer dbPort = portal.getDb().getPort();\r
+                       url = kibanaImportUrl(dbHost, dbPort);\r
+               } else {\r
+                       url = kibanaImportUrl(portalHost, portalPort);\r
+               }\r
+\r
+               //Send httpclient to kibana\r
+               String kibanaResponse = HttpClientUtil.sendPostToKibana(url, requestBody);\r
+               Gson gson = new Gson();\r
+               Map<String, Object> map = new HashMap<>();\r
+               map = gson.fromJson(kibanaResponse, map.getClass());\r
+               List objectsList = (List) map.get("objects");\r
+\r
+               if (objectsList != null && objectsList.size() > 0) {\r
+                       Map<String, Object> map2 = new HashMap<>();\r
+                       for (int i = 0; i < objectsList.size(); i++){\r
+                               map2 = (Map<String, Object>)objectsList.get(i);\r
+                               for(String key : map2.keySet()){\r
+                                       if ("error".equals(key)) {\r
+                                               return true;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               return flag;\r
+       }\r
+\r
+}\r
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 (file)
index 0000000..28efd15
--- /dev/null
@@ -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 (file)
index 0000000..b02139f
--- /dev/null
@@ -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;
+    }
+
+}
index a105473..ed167f3 100644 (file)
@@ -57,4 +57,7 @@ logging.level.org.onap.datalake=DEBUG
 
 #####################Verison
 datalakeVersion=0.0.1
+
+#####################KibanaDashboardImportApi
+KibanaDashboardImportApi=/api/kibana/dashboards/import?exclude=index-pattern