summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhangZihao <zhangzihao@chinamobile.com>2019-06-24 11:26:35 +0800
committerZhangZihao <zhangzihao@chinamobile.com>2019-06-24 11:26:48 +0800
commit615031ac4bb36fb02e72eea9e59c9e3bcec4ab1e (patch)
tree034ad091dcbec69bfe5f1faef6e5f63d26eef44e
parent8def5ddc634d18bdf863101896a9146ec4aae3f4 (diff)
db modify
Change-Id: I848b9ac6d45dc60e93be27306cfbed97c73da51d Issue-ID: DCAEGEN2-1622 Signed-off-by: ZhangZihao <zhangzihao@chinamobile.com>
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java90
-rw-r--r--components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java45
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java8
-rw-r--r--components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DbConfigTest.java50
4 files changed, 139 insertions, 54 deletions
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
index 7e364332..bd9b742b 100644
--- a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/controller/DbController.java
@@ -24,13 +24,12 @@ import java.util.*;
import javax.servlet.http.HttpServletResponse;
-import io.swagger.annotations.*;
import org.onap.datalake.feeder.domain.Db;
import org.onap.datalake.feeder.domain.Topic;
import org.onap.datalake.feeder.repository.DbRepository;
import org.onap.datalake.feeder.repository.TopicRepository;
import org.onap.datalake.feeder.service.DbService;
-import org.onap.datalake.feeder.controller.domain.DbConfig;
+import org.onap.datalake.feeder.dto.DbConfig;
import org.onap.datalake.feeder.controller.domain.PostReturnBody;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,10 +38,7 @@ import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
-import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
/**
* This controller manages the big data storage settings. All the settings are
@@ -144,51 +140,6 @@ public class DbController {
}
- //Update Db
- @PutMapping("/{dbName}")
- @ResponseBody
- @ApiOperation(value="Update a database.")
- public PostReturnBody<DbConfig> updateDb(@PathVariable("dbName") String dbName, @RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException {
-
- if (result.hasErrors()) {
- sendError(response, 400, "Error parsing DB: " + result.toString());
- return null;
- }
-
- if(!dbName.equals(dbConfig.getName()))
- {
- sendError(response, 400, "Mismatch DB name.");
- return null;
- }
-
- Db oldDb = dbService.getDb(dbConfig.getName());
- if (oldDb == null) {
- sendError(response, 404, "Db not found: " + dbConfig.getName());
- return null;
- } else {
- oldDb.setName(dbConfig.getName());
- oldDb.setHost(dbConfig.getHost());
- oldDb.setPort(dbConfig.getPort());
- oldDb.setEnabled(dbConfig.isEnabled());
- oldDb.setLogin(dbConfig.getLogin());
- oldDb.setPass(dbConfig.getPassword());
- oldDb.setEncrypt(dbConfig.isEncrypt());
-
- if(!oldDb.getName().equals("Elecsticsearch") || !oldDb.getName().equals("Druid"))
- {
- oldDb.setDatabase(dbConfig.getDatabase());
- }
- dbRepository.save(oldDb);
- DbConfig retMsg;
- PostReturnBody<DbConfig> retBody = new PostReturnBody<>();
- retMsg = new DbConfig();
- composeRetMessagefromDbConfig(oldDb, retMsg);
- retBody.setReturnBody(retMsg);
- retBody.setStatusCode(200);
- return retBody;
- }
- }
-
//Delete a db
//the topics are missing in the return, since in we use @JsonBackReference on Db's topics
//need to the the following method to retrieve the topic list
@@ -229,6 +180,45 @@ public class DbController {
}
+ //Update Db
+ @PutMapping("")
+ @ResponseBody
+ @ApiOperation(value="Update a database.")
+ public PostReturnBody<DbConfig> updateDb(@RequestBody DbConfig dbConfig, BindingResult result, HttpServletResponse response) throws IOException {
+
+ if (result.hasErrors()) {
+ sendError(response, 400, "Error parsing DB: " + result.toString());
+ return null;
+ }
+
+ Db oldDb = dbService.getDb(dbConfig.getName());
+ if (oldDb == null) {
+ sendError(response, 404, "Db not found: " + dbConfig.getName());
+ return null;
+ } else {
+ oldDb.setHost(dbConfig.getHost());
+ oldDb.setPort(dbConfig.getPort());
+ oldDb.setEnabled(dbConfig.isEnabled());
+ oldDb.setLogin(dbConfig.getLogin());
+ oldDb.setPass(dbConfig.getPassword());
+ oldDb.setEncrypt(dbConfig.isEncrypt());
+ if (!oldDb.getName().equals("Elecsticsearch") || !oldDb.getName().equals("Druid")) {
+ oldDb.setDatabase(dbConfig.getDatabase());
+ }
+
+ dbRepository.save(oldDb);
+ DbConfig retMsg;
+ PostReturnBody<DbConfig> retBody = new PostReturnBody<>();
+ retMsg = new DbConfig();
+ composeRetMessagefromDbConfig(oldDb, retMsg);
+ retBody.setReturnBody(retMsg);
+ retBody.setStatusCode(200);
+ return retBody;
+ }
+
+ }
+
+
@PostMapping("/verify")
@ResponseBody
@ApiOperation(value="Database connection verification")
diff --git a/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java
new file mode 100644
index 00000000..0b6c54c3
--- /dev/null
+++ b/components/datalake-handler/feeder/src/main/java/org/onap/datalake/feeder/dto/DbConfig.java
@@ -0,0 +1,45 @@
+/*
+ * ============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 DB manipulation.
+ *
+ * @author Kate Hsuan
+ *
+ */
+
+@Getter
+@Setter
+public class DbConfig {
+ private String name;
+ private String host;
+ private boolean enabled;
+ private String login;
+ private String password;
+ private boolean encrypt;
+ private String database;
+ private Integer port;
+ private String poperties;
+}
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
index b0a78d63..4a6d6bee 100644
--- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/controller/DbControllerTest.java
@@ -27,7 +27,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.datalake.feeder.controller.domain.DbConfig;
+import org.onap.datalake.feeder.dto.DbConfig;
import org.onap.datalake.feeder.controller.domain.PostReturnBody;
import org.onap.datalake.feeder.domain.Db;
import org.onap.datalake.feeder.domain.Topic;
@@ -109,18 +109,18 @@ public class DbControllerTest {
DbController dbController = new DbController();
DbConfig dbConfig = getDbConfig();
when(mockBindingResult.hasErrors()).thenReturn(true);
- PostReturnBody<DbConfig> db = dbController.updateDb("Elecsticsearch", dbConfig, mockBindingResult,
+ PostReturnBody<DbConfig> db = dbController.updateDb(dbConfig, mockBindingResult,
httpServletResponse);
assertEquals(null, db);
when(mockBindingResult.hasErrors()).thenReturn(false);
setAccessPrivateFields(dbController);
- db = dbController.updateDb("Elecsticsearch", dbConfig, mockBindingResult,
+ db = dbController.updateDb(dbConfig, mockBindingResult,
httpServletResponse);
assertEquals(null, db);
when(mockBindingResult.hasErrors()).thenReturn(false);
String name = "Elecsticsearch";
when(dbRepository.findById(name)).thenReturn(Optional.of(new Db(name)));
- db = dbController.updateDb("Elecsticsearch", dbConfig, mockBindingResult,
+ db = dbController.updateDb(dbConfig, mockBindingResult,
httpServletResponse);
assertEquals(200, db.getStatusCode());
Db elecsticsearch = dbController.getDb("Elecsticsearch", httpServletResponse);
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DbConfigTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DbConfigTest.java
new file mode 100644
index 00000000..41dfd820
--- /dev/null
+++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/dto/DbConfigTest.java
@@ -0,0 +1,50 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : DATALAKE
+ * ================================================================================
+ * Copyright (C) 2018-2019 Huawei. All rights reserved.
+ * ================================================================================
+ * 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 org.junit.Test;
+import org.onap.datalake.feeder.dto.DbConfig;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class DbConfigTest {
+ @Test
+ public void testDbConfig() {
+ DbConfig dbConfig = new DbConfig();
+ dbConfig.setName("elasticsearch");
+ assertTrue("elasticsearch".equals(dbConfig.getName()));
+ dbConfig.setHost("localhost");
+ assertTrue("localhost".equals(dbConfig.getHost()));
+ dbConfig.setLogin("root");
+ assertTrue("root".equals(dbConfig.getLogin()));
+ dbConfig.setPassword("root123");
+ assertTrue("root123".equals(dbConfig.getPassword()));
+ dbConfig.setDatabase("elasticsearch");
+ assertTrue("elasticsearch".equals(dbConfig.getDatabase()));
+ dbConfig.setPort(123);
+ //assertEquals(123, dbConfig.getPort());
+ assertFalse("123".equals(dbConfig.getPort()));
+
+ dbConfig.setPoperties("driver");
+ assertTrue("driver".equals(dbConfig.getPoperties()));
+ }
+}