diff options
author | 2019-07-16 16:49:27 +0800 | |
---|---|---|
committer | 2019-07-17 02:37:42 +0000 | |
commit | 9cf94ff1acf4764085acf5b340b876ab82829e5f (patch) | |
tree | 879f66bb951af91d56a64d2a21839c7ab1e586bf /components/datalake-handler/feeder/src/main/java/org | |
parent | c4c391b68ed1a30b3b398c56efadf28b2f33388d (diff) |
design modify 2
Change-Id: I839bee562f03e12de9a3a4bfcd25f4db5fee6f7e
Issue-ID: DCAEGEN2-1658
Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
Diffstat (limited to 'components/datalake-handler/feeder/src/main/java/org')
10 files changed, 40 insertions, 387 deletions
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 deleted file mode 100644 index 2844facd..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/PortalController.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.controller; - -import 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 - */ -@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(); - 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/domain/Design.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java index dde17b33..faf3755e 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Design.java @@ -24,6 +24,8 @@ import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import javax.persistence.*; @@ -86,6 +88,16 @@ public class Design { designConfig.setSubmitted(getSubmitted()); designConfig.setTopicName(getTopicName().getId()); designConfig.setDesignType(getDesignType().getId()); + designConfig.setDesignTypeName(getDesignType().getName()); + + Set<Db> designDb = getDbs(); + List<Integer> dbList = new ArrayList<>(); + if (designDb != null) { + for (Db item : designDb) { + dbList.add(item.getId()); + } + } + designConfig.setDbs(dbList); return designConfig; } diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java index dd327ea0..14026fe0 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/DesignType.java @@ -49,12 +49,6 @@ public class DesignType { @Column(name = "`name`") private String name; - //To be removed - @ManyToOne(fetch=FetchType.EAGER) - @JoinColumn(name="portal") - @JsonBackReference - private Portal portal; - @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="db_type_id", nullable = false) @JsonBackReference 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 deleted file mode 100644 index d2214dce..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/domain/Portal.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.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/dto/DesignConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java index d115529d..34256004 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DesignConfig.java @@ -23,6 +23,8 @@ package org.onap.datalake.feeder.dto; import lombok.Getter; import lombok.Setter; +import java.util.List; + /** * JSON request body for portalDesign Config. * @@ -40,5 +42,7 @@ public class DesignConfig { private String note; private String topicName; private String designType; + private String designTypeName;//UI show name + private List<Integer> dbs; } 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 deleted file mode 100644 index 76b1ceb7..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/PortalConfig.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============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/repository/PortalRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java deleted file mode 100644 index f4ce0ee5..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/PortalRepository.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.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/repository/TopicRepository.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java index b4dd6374..8f72dfed 100644 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/repository/TopicRepository.java @@ -19,9 +19,6 @@ */
package org.onap.datalake.feeder.repository;
-import java.util.List;
-
-import org.onap.datalake.feeder.domain.Portal;
import org.onap.datalake.feeder.domain.Topic;
import org.springframework.data.repository.CrudRepository;
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java index 61411a4d..4ba4f8f7 100755 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java +++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/DesignService.java @@ -24,12 +24,14 @@ import java.util.ArrayList; import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.HashSet;
import org.onap.datalake.feeder.config.ApplicationConfiguration;
import org.onap.datalake.feeder.domain.*;
import org.onap.datalake.feeder.domain.Design;
import org.onap.datalake.feeder.dto.DesignConfig;
import org.onap.datalake.feeder.enumeration.DesignTypeEnum;
+import org.onap.datalake.feeder.repository.DbRepository;
import org.onap.datalake.feeder.repository.DesignTypeRepository;
import org.onap.datalake.feeder.repository.DesignRepository;
import org.onap.datalake.feeder.repository.TopicNameRepository;
@@ -64,6 +66,9 @@ public class DesignService { @Autowired
private ApplicationConfiguration applicationConfiguration;
+ @Autowired
+ private DbRepository dbRepository;
+
public Design fillDesignConfiguration(DesignConfig designConfig) {
Design design = new Design();
fillDesign(designConfig, design);
@@ -89,7 +94,6 @@ public class DesignService { throw new IllegalArgumentException("topicName is null " + designConfig.getTopicName());
design.setTopicName(topicName.get());
-
if (designConfig.getDesignType() == null)
throw new IllegalArgumentException("Can not find designType in design_type, designType id " + designConfig.getDesignType());
Optional<DesignType> designType = designTypeRepository.findById(designConfig.getDesignType());
@@ -97,6 +101,23 @@ public class DesignService { throw new IllegalArgumentException("designType is null");
design.setDesignType(designType.get());
+ Set<Db> dbs = new HashSet<>();
+ if (designConfig.getDbs() != null) {
+ for (Integer item : designConfig.getDbs()) {
+ Optional<Db> db = dbRepository.findById(item);
+ if (db.isPresent()) {
+ dbs.add(db.get());
+ }
+ }
+ if (dbs.size() > 0)
+ design.setDbs(dbs);
+ else {
+ design.getDbs().clear();
+ design.setDbs(dbs);
+ }
+ } else {
+ design.setDbs(dbs);
+ }
}
public Design getDesign(Integer id) {
@@ -111,7 +132,7 @@ public class DesignService { List<DesignConfig> designConfigList = new ArrayList<>();
designList = (List<Design>) designRepository.findAll();
if (designList != null && designList.size() > 0) {
- log.info("PortalDesignList is not null");
+ log.info("DesignList is not null");
for (Design design : designList) {
designConfigList.add(design.getDesignConfig());
}
@@ -137,18 +158,8 @@ public class DesignService { private boolean deployKibanaImport(Design design) throws RuntimeException {
POST_FLAG = "KibanaDashboardImport";
String requestBody = design.getBody();
- Portal portal = design.getDesignType().getPortal();
- String portalHost = portal.getHost();
- Integer portalPort = portal.getPort();
String url = "";
-
- if (portalHost == null || portalPort == null) {
- String dbHost = portal.getDb().getHost();
- Integer dbPort = portal.getDb().getPort();
- url = kibanaImportUrl(dbHost, dbPort);
- } else {
- url = kibanaImportUrl(portalHost, portalPort);
- }
+ //TODO
return HttpClientUtil.sendPostHttpClient(url, requestBody, POST_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 deleted file mode 100644 index 28efd150..00000000 --- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/service/PortalService.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * ONAP : DataLake - * ================================================================================ - * Copyright 2019 China Mobile - *================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.datalake.feeder.service; - - -import 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; - } - -} |