This is an automated email from the ASF dual-hosted git repository.
nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-paimon-webui.git
The following commit(s) were added to refs/heads/main by this push:
new 6ee3b98 [Feature] Optimize catalog controller (#76)
6ee3b98 is described below
commit 6ee3b98c8f1eb14cbf1bf692d9ebf29290b42edc
Author: Hunter <[email protected]>
AuthorDate: Wed Oct 25 15:47:19 2023 +0800
[Feature] Optimize catalog controller (#76)
---
.../paimon/web/api/catalog/PaimonService.java | 40 ++++++++++++
.../web/server/controller/CatalogController.java | 68 ++++++++------------
.../web/server/controller/DatabaseController.java | 71 +++++++++++++--------
.../web/server/controller/LoginController.java | 8 +--
.../web/server/controller/TableController.java | 73 +++++++++++-----------
.../data/dto/{LoginDto.java => CatalogDTO.java} | 31 ++++-----
.../data/dto/{LoginDto.java => DatabaseDTO.java} | 28 ++++-----
.../data/dto/{LoginDto.java => LoginDTO.java} | 4 +-
.../{model/TableInfo.java => dto/TableDTO.java} | 8 ++-
.../paimon/web/server/data/model/BaseModel.java | 2 +-
.../web/server/data/result/enums/Status.java | 1 +
.../paimon/web/server/service/CatalogService.java | 12 +++-
.../paimon/web/server/service/UserService.java | 6 +-
.../server/service/impl/CatalogServiceImpl.java | 53 ++++++++++++++--
.../web/server/service/impl/UserServiceImpl.java | 14 ++---
paimon-web-server/src/main/resources/db/ddl-h2.sql | 18 +++---
.../server/controller/CatalogControllerTest.java | 36 +++++++----
.../web/server/controller/ControllerTestBase.java | 12 ++--
.../server/controller/DatabaseControllerTest.java | 38 ++++++++---
.../web/server/controller/TableControllerTest.java | 26 ++++----
20 files changed, 344 insertions(+), 205 deletions(-)
diff --git
a/paimon-web-api/src/main/java/org/apache/paimon/web/api/catalog/PaimonService.java
b/paimon-web-api/src/main/java/org/apache/paimon/web/api/catalog/PaimonService.java
index 034505d..bd92a4c 100644
---
a/paimon-web-api/src/main/java/org/apache/paimon/web/api/catalog/PaimonService.java
+++
b/paimon-web-api/src/main/java/org/apache/paimon/web/api/catalog/PaimonService.java
@@ -79,6 +79,18 @@ public class PaimonService {
}
}
+ public void createDatabase(String databaseName, boolean ignoreIfExists) {
+ Preconditions.checkNotNull(databaseName, "Database name cannot be
null.");
+
+ try {
+ catalog.createDatabase(databaseName, ignoreIfExists);
+ } catch (Catalog.DatabaseAlreadyExistException e) {
+ throw new DatabaseException.DatabaseAlreadyExistsException(
+ String.format(
+ "The database '%s' already exists in the
catalog.", databaseName));
+ }
+ }
+
public void dropDatabase(String databaseName) {
Preconditions.checkNotNull(databaseName, "Database name cannot be
null.");
try {
@@ -93,6 +105,34 @@ public class PaimonService {
}
}
+ public void dropDatabase(String databaseName, boolean ignoreIfNotExists) {
+ Preconditions.checkNotNull(databaseName, "Database name cannot be
null.");
+ try {
+ catalog.dropDatabase(databaseName, ignoreIfNotExists, true);
+ } catch (Catalog.DatabaseNotExistException e) {
+ throw new DatabaseException.DatabaseNotExistException(
+ String.format(
+ "The database '%s' does not exist in the
catalog.", databaseName));
+ } catch (Catalog.DatabaseNotEmptyException e) {
+ throw new DatabaseException.DatabaseNotEmptyException(
+ String.format("The database '%s' is not empty.",
databaseName));
+ }
+ }
+
+ public void dropDatabase(String databaseName, boolean ignoreIfNotExists,
boolean cascade) {
+ Preconditions.checkNotNull(databaseName, "Database name cannot be
null.");
+ try {
+ catalog.dropDatabase(databaseName, ignoreIfNotExists, cascade);
+ } catch (Catalog.DatabaseNotExistException e) {
+ throw new DatabaseException.DatabaseNotExistException(
+ String.format(
+ "The database '%s' does not exist in the
catalog.", databaseName));
+ } catch (Catalog.DatabaseNotEmptyException e) {
+ throw new DatabaseException.DatabaseNotEmptyException(
+ String.format("The database '%s' is not empty.",
databaseName));
+ }
+ }
+
public List<String> listTables(String databaseName) {
Preconditions.checkNotNull(databaseName, "Database name cannot be
null.");
try {
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/CatalogController.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/CatalogController.java
index 64e166f..deb139c 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/CatalogController.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/CatalogController.java
@@ -18,20 +18,16 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.api.catalog.PaimonServiceFactory;
-import org.apache.paimon.web.server.data.enums.CatalogMode;
+import org.apache.paimon.web.server.data.dto.CatalogDTO;
import org.apache.paimon.web.server.data.model.CatalogInfo;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.data.result.enums.Status;
import org.apache.paimon.web.server.service.CatalogService;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -45,40 +41,22 @@ import java.util.List;
@RequestMapping("/api/catalog")
public class CatalogController {
- @Autowired private CatalogService catalogService;
+ private final CatalogService catalogService;
+
+ public CatalogController(CatalogService catalogService) {
+ this.catalogService = catalogService;
+ }
/**
* Create a catalog.
*
- * @param catalogInfo The catalogInfo for the catalog.
+ * @param catalogDTO The catalogDTO for the catalog.
* @return The created catalog.
*/
@PostMapping("/create")
- public R<Void> createCatalog(@RequestBody CatalogInfo catalogInfo) {
- if (!catalogService.checkCatalogNameUnique(catalogInfo)) {
- return R.failed(Status.CATALOG_NAME_IS_EXIST,
catalogInfo.getCatalogName());
- }
-
+ public R<Void> createCatalog(@RequestBody CatalogDTO catalogDTO) {
try {
- if
(catalogInfo.getCatalogType().equalsIgnoreCase(CatalogMode.FILESYSTEM.getMode()))
{
- PaimonServiceFactory.createFileSystemCatalogService(
- catalogInfo.getCatalogName(),
catalogInfo.getWarehouse());
- } else if
(catalogInfo.getCatalogType().equalsIgnoreCase(CatalogMode.HIVE.getMode())) {
- if (StringUtils.isNotBlank(catalogInfo.getHiveConfDir())) {
- PaimonServiceFactory.createHiveCatalogService(
- catalogInfo.getCatalogName(),
- catalogInfo.getWarehouse(),
- catalogInfo.getHiveUri(),
- catalogInfo.getHiveConfDir());
- } else {
- PaimonServiceFactory.createHiveCatalogService(
- catalogInfo.getCatalogName(),
- catalogInfo.getWarehouse(),
- catalogInfo.getHiveUri(),
- null);
- }
- }
- return catalogService.save(catalogInfo) ? R.succeed() : R.failed();
+ return catalogService.createCatalog(catalogDTO);
} catch (Exception e) {
log.error("Exception with creating catalog.", e);
return R.failed(Status.CATALOG_CREATE_ERROR);
@@ -97,17 +75,25 @@ public class CatalogController {
}
/**
- * Removes a catalog with given catalog name.
+ * Removes a catalog with given catalog name or catalog id.
*
- * @param catalogName The catalog name.
+ * @param catalogDTO Given the catalog name or catalog id to remove
catalog.
* @return A response indicating the success or failure of the operation.
*/
- @DeleteMapping("/remove/{catalogName}")
- public R<Void> removeCatalog(@PathVariable String catalogName) {
- QueryWrapper<CatalogInfo> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("catalog_name", catalogName);
- return catalogService.remove(queryWrapper)
- ? R.succeed()
- : R.failed(Status.CATALOG_REMOVE_ERROR);
+ @PostMapping("/remove")
+ public R<Void> removeCatalog(@RequestBody CatalogDTO catalogDTO) {
+ boolean remove;
+ if (StringUtils.isNotBlank(catalogDTO.getName())) {
+ remove =
+ catalogService.remove(
+ Wrappers.lambdaQuery(CatalogInfo.class)
+ .eq(CatalogInfo::getCatalogName,
catalogDTO.getName()));
+ } else {
+ remove =
+ catalogService.remove(
+ Wrappers.lambdaQuery(CatalogInfo.class)
+ .eq(CatalogInfo::getId,
catalogDTO.getId()));
+ }
+ return remove ? R.succeed() : R.failed(Status.CATALOG_REMOVE_ERROR);
}
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/DatabaseController.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/DatabaseController.java
index 9ab10db..d70454b 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/DatabaseController.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/DatabaseController.java
@@ -19,6 +19,7 @@
package org.apache.paimon.web.server.controller;
import org.apache.paimon.web.api.catalog.PaimonService;
+import org.apache.paimon.web.server.data.dto.DatabaseDTO;
import org.apache.paimon.web.server.data.model.CatalogInfo;
import org.apache.paimon.web.server.data.model.DatabaseInfo;
import org.apache.paimon.web.server.data.result.R;
@@ -26,13 +27,12 @@ import
org.apache.paimon.web.server.data.result.enums.Status;
import org.apache.paimon.web.server.service.CatalogService;
import org.apache.paimon.web.server.util.PaimonServiceUtils;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.DeleteMapping;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/** Database api controller. */
@Slf4j
@@ -47,23 +48,29 @@ import java.util.List;
@RequestMapping("/api/database")
public class DatabaseController {
- @Autowired private CatalogService catalogService;
+ private final CatalogService catalogService;
+
+ public DatabaseController(CatalogService catalogService) {
+ this.catalogService = catalogService;
+ }
/**
* Creates a new database based on the provided DatabaseInfo.
*
- * @param databaseInfo The DatabaseInfo object containing the details of
the new database.
+ * @param databaseDTO The DatabaseInfo object containing the details of
the new database.
* @return R<Void/> indicating the result of the operation.
*/
@PostMapping("/create")
- public R<Void> createDatabase(@RequestBody DatabaseInfo databaseInfo) {
+ public R<Void> createDatabase(@RequestBody DatabaseDTO databaseDTO) {
try {
- CatalogInfo catalogInfo =
getCatalogInfo(databaseInfo.getCatalogName());
+ CatalogInfo catalogInfo = getCatalogInfo(databaseDTO);
PaimonService service =
PaimonServiceUtils.getPaimonService(catalogInfo);
- if (service.databaseExists(databaseInfo.getDatabaseName())) {
- return R.failed(Status.DATABASE_NAME_IS_EXIST,
databaseInfo.getDatabaseName());
+ if (service.databaseExists(databaseDTO.getName())) {
+ return R.failed(Status.DATABASE_NAME_IS_EXIST,
databaseDTO.getName());
}
- service.createDatabase(databaseInfo.getDatabaseName());
+ service.createDatabase(
+ databaseDTO.getName(),
+
BooleanUtils.toBooleanDefaultIfNull(databaseDTO.isIgnoreIfExists(), false));
return R.succeed();
} catch (Exception e) {
log.error("Exception with creating database.", e);
@@ -104,18 +111,19 @@ public class DatabaseController {
/**
* Removes a database by its name.
*
- * @param databaseName The database to be removed.
- * @param catalogName The catalog to which the database to be removed
belongs.
+ * @param databaseDTO The drop database DTO.
* @return A response indicating the success or failure of the removal
operation.
- * @throws RuntimeException if the database is not found or it is not
empty.
+ * @throws RuntimeException if the database is not found, or it is not
empty.
*/
- @DeleteMapping("/drop/{databaseName}/{catalogName}")
- public R<Void> dropDatabase(
- @PathVariable String databaseName, @PathVariable String
catalogName) {
+ @PostMapping("/drop")
+ public R<Void> dropDatabase(@RequestBody DatabaseDTO databaseDTO) {
try {
- CatalogInfo catalogInfo = getCatalogInfo(catalogName);
+ CatalogInfo catalogInfo = getCatalogInfo(databaseDTO);
PaimonService service =
PaimonServiceUtils.getPaimonService(catalogInfo);
- service.dropDatabase(databaseName);
+ service.dropDatabase(
+ databaseDTO.getName(),
+
BooleanUtils.toBooleanDefaultIfNull(databaseDTO.isIgnoreIfExists(), false),
+
BooleanUtils.toBooleanDefaultIfNull(databaseDTO.isCascade(), true));
return R.succeed();
} catch (Exception e) {
log.error("Exception with dropping database.", e);
@@ -124,14 +132,27 @@ public class DatabaseController {
}
/**
- * Retrieves the associated CatalogInfo object based on the given catalog
name.
+ * Retrieves the associated CatalogInfo object based on the given catalog
id.
*
- * @param catalogName The catalog name.
+ * @param databaseDTO The database DTO.
* @return The associated CatalogInfo object, or null if it doesn't exist.
*/
- private CatalogInfo getCatalogInfo(String catalogName) {
- LambdaQueryWrapper<CatalogInfo> queryWrapper = new
LambdaQueryWrapper<>();
- queryWrapper.eq(CatalogInfo::getCatalogName, catalogName);
- return catalogService.getOne(queryWrapper);
+ private CatalogInfo getCatalogInfo(DatabaseDTO databaseDTO) {
+ CatalogInfo catalogInfo;
+ if (StringUtils.isNotBlank(databaseDTO.getCatalogId())) {
+ catalogInfo =
+ catalogService.getOne(
+ Wrappers.lambdaQuery(CatalogInfo.class)
+ .eq(CatalogInfo::getId,
databaseDTO.getCatalogId()));
+ } else {
+ catalogInfo =
+ catalogService.getOne(
+ Wrappers.lambdaQuery(CatalogInfo.class)
+ .eq(CatalogInfo::getCatalogName,
databaseDTO.getCatalogName()));
+ }
+ Objects.requireNonNull(
+ catalogInfo,
+ String.format("CatalogName: [%s] not found.",
databaseDTO.getCatalogName()));
+ return catalogInfo;
}
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
index c9ff128..e30af77 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/LoginController.java
@@ -18,7 +18,7 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.server.data.dto.LoginDto;
+import org.apache.paimon.web.server.data.dto.LoginDTO;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.data.vo.UserInfoVo;
import org.apache.paimon.web.server.service.UserService;
@@ -44,12 +44,12 @@ public class LoginController {
/**
* login by username and password.
*
- * @param loginDto login info
+ * @param loginDTO login info
* @return token string
*/
@PostMapping("/login")
- public R<UserInfoVo> login(@RequestBody LoginDto loginDto) {
- return R.succeed(userService.login(loginDto));
+ public R<UserInfoVo> login(@RequestBody LoginDTO loginDTO) {
+ return R.succeed(userService.login(loginDTO));
}
/**
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/TableController.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/TableController.java
index 07cc45f..3784640 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/TableController.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/TableController.java
@@ -24,10 +24,10 @@ import org.apache.paimon.web.api.catalog.PaimonService;
import org.apache.paimon.web.api.table.ColumnMetadata;
import org.apache.paimon.web.api.table.TableChange;
import org.apache.paimon.web.api.table.TableMetadata;
+import org.apache.paimon.web.server.data.dto.TableDTO;
import org.apache.paimon.web.server.data.model.AlterTableRequest;
import org.apache.paimon.web.server.data.model.CatalogInfo;
import org.apache.paimon.web.server.data.model.TableColumn;
-import org.apache.paimon.web.server.data.model.TableInfo;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.data.result.enums.Status;
import org.apache.paimon.web.server.service.CatalogService;
@@ -68,18 +68,18 @@ public class TableController {
/**
* Creates a table in the database based on the provided TableInfo.
*
- * @param tableInfo The TableInfo object containing information about the
table.
+ * @param tableDTO The TableDTO object containing information about the
table.
* @return R<Void/> indicating the success or failure of the operation.
*/
@PostMapping("/create")
- public R<Void> createTable(@RequestBody TableInfo tableInfo) {
+ public R<Void> createTable(@RequestBody TableDTO tableDTO) {
try {
PaimonService service =
-
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableInfo.getCatalogName()));
- List<String> partitionKeys = tableInfo.getPartitionKey();
+
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableDTO.getCatalogName()));
+ List<String> partitionKeys = tableDTO.getPartitionKey();
- Map<String, String> tableOptions = tableInfo.getTableOptions();
- List<TableColumn> tableColumns = tableInfo.getTableColumns();
+ Map<String, String> tableOptions = tableDTO.getTableOptions();
+ List<TableColumn> tableColumns = tableDTO.getTableColumns();
if (!CollectionUtils.isEmpty(tableColumns)) {
for (TableColumn tableColumn : tableColumns) {
if (tableColumn.getDefaultValue() != null
@@ -97,17 +97,16 @@ public class TableController {
TableMetadata tableMetadata =
TableMetadata.builder()
- .columns(buildColumns(tableInfo))
+ .columns(buildColumns(tableDTO))
.partitionKeys(partitionKeys)
- .primaryKeys(buildPrimaryKeys(tableInfo))
+ .primaryKeys(buildPrimaryKeys(tableDTO))
.options(tableOptions)
- .comment(tableInfo.getDescription())
+ .comment(tableDTO.getDescription())
.build();
- if (service.tableExists(tableInfo.getDatabaseName(),
tableInfo.getTableName())) {
- return R.failed(Status.TABLE_NAME_IS_EXIST,
tableInfo.getTableName());
+ if (service.tableExists(tableDTO.getDatabaseName(),
tableDTO.getTableName())) {
+ return R.failed(Status.TABLE_NAME_IS_EXIST,
tableDTO.getTableName());
}
- service.createTable(
- tableInfo.getDatabaseName(), tableInfo.getTableName(),
tableMetadata);
+ service.createTable(tableDTO.getDatabaseName(),
tableDTO.getTableName(), tableMetadata);
return R.succeed();
} catch (Exception e) {
log.error("Exception with creating table.", e);
@@ -118,16 +117,16 @@ public class TableController {
/**
* Adds a column to the table.
*
- * @param tableInfo The information of the table, including the catalog
name, database name,
+ * @param tableDTO The information of the table, including the catalog
name, database name,
* table name, and table columns.
* @return A response indicating the success or failure of the operation.
*/
@PostMapping("/column/add")
- public R<Void> addColumn(@RequestBody TableInfo tableInfo) {
+ public R<Void> addColumn(@RequestBody TableDTO tableDTO) {
try {
PaimonService service =
-
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableInfo.getCatalogName()));
- List<TableColumn> tableColumns = tableInfo.getTableColumns();
+
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableDTO.getCatalogName()));
+ List<TableColumn> tableColumns = tableDTO.getTableColumns();
List<TableChange> tableChanges = new ArrayList<>();
Map<String, String> options = new HashMap<>();
for (TableColumn tableColumn : tableColumns) {
@@ -162,7 +161,7 @@ public class TableController {
tableChanges.add(setOption);
}
}
- service.alterTable(tableInfo.getDatabaseName(),
tableInfo.getTableName(), tableChanges);
+ service.alterTable(tableDTO.getDatabaseName(),
tableDTO.getTableName(), tableChanges);
return R.succeed();
} catch (Exception e) {
log.error("Exception with adding column.", e);
@@ -269,22 +268,22 @@ public class TableController {
/**
* Adds options to a table.
*
- * @param tableInfo An object containing table information.
+ * @param tableDTO An object containing table information.
* @return If the options are successfully added, returns a successful
result object. If an
* exception occurs, returns a result object with an error status.
*/
@PostMapping("/option/add")
- public R<Void> addOption(@RequestBody TableInfo tableInfo) {
+ public R<Void> addOption(@RequestBody TableDTO tableDTO) {
List<TableChange> tableChanges = new ArrayList<>();
try {
PaimonService service =
-
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableInfo.getCatalogName()));
- Map<String, String> tableOptions = tableInfo.getTableOptions();
+
PaimonServiceUtils.getPaimonService(getCatalogInfo(tableDTO.getCatalogName()));
+ Map<String, String> tableOptions = tableDTO.getTableOptions();
for (Map.Entry<String, String> entry : tableOptions.entrySet()) {
TableChange.SetOption setOption =
TableChange.set(entry.getKey(), entry.getValue());
tableChanges.add(setOption);
}
- service.alterTable(tableInfo.getDatabaseName(),
tableInfo.getTableName(), tableChanges);
+ service.alterTable(tableDTO.getDatabaseName(),
tableDTO.getTableName(), tableChanges);
return R.succeed();
} catch (Exception e) {
log.error("Exception with adding option.", e);
@@ -386,11 +385,11 @@ public class TableController {
* Handler method for the "/getAllTables" endpoint. Retrieves information
about all tables and
* returns a response containing the table details.
*
- * @return Response object containing a list of {@link TableInfo}
representing the tables.
+ * @return Response object containing a list of {@link TableDTO}
representing the tables.
*/
@GetMapping("/getAllTables")
- public R<List<TableInfo>> getAllTables() {
- List<TableInfo> tableInfoList = new ArrayList<>();
+ public R<List<TableDTO>> getAllTables() {
+ List<TableDTO> tableDTOList = new ArrayList<>();
List<CatalogInfo> catalogInfoList = catalogService.list();
if (!CollectionUtils.isEmpty(catalogInfoList)) {
for (CatalogInfo item : catalogInfoList) {
@@ -435,8 +434,8 @@ public class TableController {
tableColumns.add(builder.build());
}
}
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO tableDTO =
+ TableDTO.builder()
.catalogName(item.getCatalogName())
.databaseName(db)
.tableName(table.name())
@@ -444,7 +443,7 @@ public class TableController {
.tableOptions(table.options())
.tableColumns(tableColumns)
.build();
- tableInfoList.add(tableInfo);
+ tableDTOList.add(tableDTO);
}
} catch (Exception e) {
throw new RuntimeException(e);
@@ -458,18 +457,18 @@ public class TableController {
}
}
}
- return R.succeed(tableInfoList);
+ return R.succeed(tableDTOList);
}
/**
* Builds a list of primary keys for the given table.
*
- * @param tableInfo The TableInfo object representing the table.
+ * @param tableDTO The TableInfo object representing the table.
* @return A list of primary keys as strings.
*/
- private List<String> buildPrimaryKeys(TableInfo tableInfo) {
+ private List<String> buildPrimaryKeys(TableDTO tableDTO) {
List<String> primaryKeys = new ArrayList<>();
- List<TableColumn> tableColumns = tableInfo.getTableColumns();
+ List<TableColumn> tableColumns = tableDTO.getTableColumns();
if (!CollectionUtils.isEmpty(tableColumns)) {
tableColumns.forEach(
item -> {
@@ -484,12 +483,12 @@ public class TableController {
/**
* Builds a list of ColumnMetadata objects for the given table.
*
- * @param tableInfo The TableInfo object representing the table.
+ * @param tableDTO The TableInfo object representing the table.
* @return A list of ColumnMetadata objects.
*/
- private List<ColumnMetadata> buildColumns(TableInfo tableInfo) {
+ private List<ColumnMetadata> buildColumns(TableDTO tableDTO) {
List<ColumnMetadata> columns = new ArrayList<>();
- List<TableColumn> tableColumns = tableInfo.getTableColumns();
+ List<TableColumn> tableColumns = tableDTO.getTableColumns();
if (!CollectionUtils.isEmpty(tableColumns)) {
tableColumns.forEach(
item -> {
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/CatalogDTO.java
similarity index 67%
copy from
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
copy to
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/CatalogDTO.java
index 1e23c7b..5380503 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/CatalogDTO.java
@@ -18,21 +18,24 @@
package org.apache.paimon.web.server.data.dto;
+import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;
-import javax.validation.constraints.NotBlank;
-
-/** login dto. */
+/** The DTO of catalog. */
@Data
-public class LoginDto {
- /** login username. */
- @NotBlank(message = "username is required")
- private String username;
- /** login password. */
- @NotBlank(message = "password is required")
- private String password;
- /** remember me flag. */
- private boolean rememberMe;
- /** ldap login flag. */
- private boolean ldapLogin;
+public class CatalogDTO {
+
+ private Integer id;
+
+ private String type;
+
+ private String name;
+
+ private String warehouse;
+
+ private String hiveUri;
+
+ private String hiveConfDir;
+
+ @TableLogic private boolean isDelete;
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/DatabaseDTO.java
similarity index 67%
copy from
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
copy to
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/DatabaseDTO.java
index 1e23c7b..5ccb736 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/DatabaseDTO.java
@@ -20,19 +20,19 @@ package org.apache.paimon.web.server.data.dto;
import lombok.Data;
-import javax.validation.constraints.NotBlank;
-
-/** login dto. */
+/** The DTO of database. */
@Data
-public class LoginDto {
- /** login username. */
- @NotBlank(message = "username is required")
- private String username;
- /** login password. */
- @NotBlank(message = "password is required")
- private String password;
- /** remember me flag. */
- private boolean rememberMe;
- /** ldap login flag. */
- private boolean ldapLogin;
+public class DatabaseDTO {
+
+ private String name;
+
+ private String catalogId;
+
+ private String catalogName;
+
+ private boolean ignoreIfExists;
+
+ private boolean cascade;
+
+ private String description;
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDTO.java
similarity index 96%
rename from
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
rename to
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDTO.java
index 1e23c7b..a52f022 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDto.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/LoginDTO.java
@@ -22,9 +22,9 @@ import lombok.Data;
import javax.validation.constraints.NotBlank;
-/** login dto. */
+/** The DTO of login. */
@Data
-public class LoginDto {
+public class LoginDTO {
/** login username. */
@NotBlank(message = "username is required")
private String username;
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/TableInfo.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/TableDTO.java
similarity index 89%
rename from
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/TableInfo.java
rename to
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/TableDTO.java
index 7420063..6e0b701 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/TableInfo.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/dto/TableDTO.java
@@ -16,7 +16,9 @@
* limitations under the License.
*/
-package org.apache.paimon.web.server.data.model;
+package org.apache.paimon.web.server.data.dto;
+
+import org.apache.paimon.web.server.data.model.TableColumn;
import lombok.AllArgsConstructor;
import lombok.Builder;
@@ -26,12 +28,12 @@ import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
-/** Table model. */
+/** The DTO of table. */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
-public class TableInfo {
+public class TableDTO {
private String catalogName;
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
index 1647519..53e7301 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/BaseModel.java
@@ -35,7 +35,7 @@ import java.util.Map;
public abstract class BaseModel implements Serializable {
/** id. */
- @TableId(type = IdType.AUTO)
+ @TableId(type = IdType.ASSIGN_ID)
private Integer id;
/** create time. */
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
index 5239e85..176bfed 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/data/result/enums/Status.java
@@ -57,6 +57,7 @@ public enum Status {
CATALOG_NAME_IS_EXIST(10301, "catalog.name.exist"),
CATALOG_CREATE_ERROR(10302, "catalog.create.error"),
CATALOG_REMOVE_ERROR(10303, "catalog.remove.error"),
+ CATALOG_NOT_EXIST(10304, "catalog.not.exists"),
/** ------------database-----------------. */
DATABASE_NAME_IS_EXIST(10401, "database.name.exist"),
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/CatalogService.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/CatalogService.java
index ecba5a1..bc17151 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/CatalogService.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/CatalogService.java
@@ -18,7 +18,9 @@
package org.apache.paimon.web.server.service;
+import org.apache.paimon.web.server.data.dto.CatalogDTO;
import org.apache.paimon.web.server.data.model.CatalogInfo;
+import org.apache.paimon.web.server.data.result.R;
import com.baomidou.mybatisplus.extension.service.IService;
@@ -31,5 +33,13 @@ public interface CatalogService extends
IService<CatalogInfo> {
* @param catalog catalog info
* @return result
*/
- boolean checkCatalogNameUnique(CatalogInfo catalog);
+ boolean checkCatalogNameUnique(CatalogDTO catalog);
+
+ /**
+ * Create a catalog.
+ *
+ * @param catalogDTO catalog for the catalog.
+ * @return The created catalog.
+ */
+ R<Void> createCatalog(CatalogDTO catalogDTO);
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
index 04ef546..b91af00 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/UserService.java
@@ -18,7 +18,7 @@
package org.apache.paimon.web.server.service;
-import org.apache.paimon.web.server.data.dto.LoginDto;
+import org.apache.paimon.web.server.data.dto.LoginDTO;
import org.apache.paimon.web.server.data.model.User;
import org.apache.paimon.web.server.data.result.exception.BaseException;
import org.apache.paimon.web.server.data.vo.UserInfoVo;
@@ -33,10 +33,10 @@ public interface UserService extends IService<User> {
/**
* login by username and password.
*
- * @param loginDto login params
+ * @param loginDTO login params
* @return {@link String}
*/
- UserInfoVo login(LoginDto loginDto) throws BaseException;
+ UserInfoVo login(LoginDTO loginDTO) throws BaseException;
/**
* Query the list of assigned user roles.
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/CatalogServiceImpl.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/CatalogServiceImpl.java
index 316459a..2af5afb 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/CatalogServiceImpl.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/CatalogServiceImpl.java
@@ -18,23 +18,66 @@
package org.apache.paimon.web.server.service.impl;
+import org.apache.paimon.web.api.catalog.PaimonServiceFactory;
+import org.apache.paimon.web.server.data.dto.CatalogDTO;
+import org.apache.paimon.web.server.data.enums.CatalogMode;
import org.apache.paimon.web.server.data.model.CatalogInfo;
+import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
import org.apache.paimon.web.server.mapper.CatalogMapper;
import org.apache.paimon.web.server.service.CatalogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
+import java.util.Objects;
+
/** CatalogServiceImpl. */
@Service
public class CatalogServiceImpl extends ServiceImpl<CatalogMapper, CatalogInfo>
implements CatalogService {
-
@Override
- public boolean checkCatalogNameUnique(CatalogInfo catalog) {
- int catalogId = catalog.getId() == null ? -1 : catalog.getId();
+ public boolean checkCatalogNameUnique(CatalogDTO catalogDTO) {
CatalogInfo info =
- this.lambdaQuery().eq(CatalogInfo::getCatalogName,
catalog.getCatalogName()).one();
- return info == null || info.getId() == catalogId;
+ this.lambdaQuery().eq(CatalogInfo::getCatalogName,
catalogDTO.getName()).one();
+ return Objects.nonNull(info);
+ }
+
+ @Override
+ public R<Void> createCatalog(CatalogDTO catalogDTO) {
+ if (checkCatalogNameUnique(catalogDTO)) {
+ return R.failed(Status.CATALOG_NAME_IS_EXIST,
catalogDTO.getName());
+ }
+
+ if
(catalogDTO.getType().equalsIgnoreCase(CatalogMode.FILESYSTEM.getMode())) {
+ PaimonServiceFactory.createFileSystemCatalogService(
+ catalogDTO.getName(), catalogDTO.getWarehouse());
+ } else if
(catalogDTO.getType().equalsIgnoreCase(CatalogMode.HIVE.getMode())) {
+ if (StringUtils.isNotBlank(catalogDTO.getHiveConfDir())) {
+ PaimonServiceFactory.createHiveCatalogService(
+ catalogDTO.getName(),
+ catalogDTO.getWarehouse(),
+ catalogDTO.getHiveUri(),
+ catalogDTO.getHiveConfDir());
+ } else {
+ PaimonServiceFactory.createHiveCatalogService(
+ catalogDTO.getName(),
+ catalogDTO.getWarehouse(),
+ catalogDTO.getHiveUri(),
+ null);
+ }
+ }
+
+ CatalogInfo catalog =
+ CatalogInfo.builder()
+ .catalogName(catalogDTO.getName())
+ .catalogType(catalogDTO.getType())
+ .hiveUri(catalogDTO.getHiveUri())
+ .warehouse(catalogDTO.getWarehouse())
+ .isDelete(false)
+ .build();
+
+ return this.save(catalog) ? R.succeed() : R.failed();
}
}
diff --git
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
index a827efe..9f059a9 100644
---
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
+++
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/service/impl/UserServiceImpl.java
@@ -18,7 +18,7 @@
package org.apache.paimon.web.server.service.impl;
-import org.apache.paimon.web.server.data.dto.LoginDto;
+import org.apache.paimon.web.server.data.dto.LoginDTO;
import org.apache.paimon.web.server.data.enums.UserType;
import org.apache.paimon.web.server.data.model.RoleMenu;
import org.apache.paimon.web.server.data.model.SysMenu;
@@ -65,16 +65,16 @@ public class UserServiceImpl extends
ServiceImpl<UserMapper, User> implements Us
/**
* login by username and password.
*
- * @param loginDto login info
+ * @param loginDTO login info
* @return {@link String}
*/
@Override
- public UserInfoVo login(LoginDto loginDto) throws BaseException {
- String username = loginDto.getUsername();
- String password = loginDto.getPassword();
+ public UserInfoVo login(LoginDTO loginDTO) throws BaseException {
+ String username = loginDTO.getUsername();
+ String password = loginDTO.getPassword();
User user =
- loginDto.isLdapLogin()
+ loginDTO.isLdapLogin()
? ldapLogin(username, password)
: localLogin(username, password);
if (!user.getEnabled()) {
@@ -87,7 +87,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,
User> implements Us
throw new UserNotBindTenantException();
}*/
- StpUtil.login(user.getId(), loginDto.isRememberMe());
+ StpUtil.login(user.getId(), loginDTO.isRememberMe());
return userInfoVo;
}
diff --git a/paimon-web-server/src/main/resources/db/ddl-h2.sql
b/paimon-web-server/src/main/resources/db/ddl-h2.sql
index ab24591..f4b06e1 100644
--- a/paimon-web-server/src/main/resources/db/ddl-h2.sql
+++ b/paimon-web-server/src/main/resources/db/ddl-h2.sql
@@ -15,7 +15,7 @@
CREATE TABLE if not exists `user`
(
- `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT
'ID',
+ `id` int(11) NOT NULL PRIMARY KEY COMMENT 'ID',
`username` varchar(50) NOT NULL COMMENT 'username',
`password` varchar(50) NULL DEFAULT NULL COMMENT 'password',
`nickname` varchar(50) NULL DEFAULT NULL COMMENT 'nickname',
@@ -31,7 +31,7 @@ CREATE TABLE if not exists `user`
CREATE TABLE if not exists `tenant`
(
- `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT
'ID',
+ `id` int(11) NOT NULL PRIMARY KEY COMMENT 'ID',
`name` varchar(64) NULL DEFAULT NULL COMMENT 'tenant name',
`description` varchar(255) NULL DEFAULT NULL COMMENT 'tenant
description',
`is_delete` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'is delete',
@@ -41,7 +41,7 @@ CREATE TABLE if not exists `tenant`
CREATE TABLE if not exists `user_tenant`
(
- `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT COMMENT 'ID',
+ `id` int(11) NOT NULL PRIMARY KEY COMMENT 'ID',
`user_id` int(11) NOT NULL COMMENT 'user id',
`tenant_id` int(11) NOT NULL COMMENT 'tenant id',
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create
time',
@@ -50,7 +50,7 @@ CREATE TABLE if not exists `user_tenant`
CREATE TABLE if not exists `sys_role`
(
- `id` int(11) not null auto_increment primary key comment
'id',
+ `id` int(11) not null primary key comment 'id',
`role_name` varchar(30) not null comment 'role name',
`role_key` varchar(100) not null comment 'role key',
`sort` int(4) not null comment 'sort',
@@ -63,7 +63,7 @@ CREATE TABLE if not exists `sys_role`
CREATE TABLE if not exists `sys_menu`
(
- `id` int(11) not null auto_increment primary key comment 'id',
+ `id` int(11) not null primary key comment 'id',
`menu_name` varchar(50) not null comment 'menu name',
`parent_id` int(11) default 0 comment 'parent id',
`sort` int(4) default 0 comment 'sort',
@@ -85,7 +85,7 @@ CREATE TABLE if not exists `sys_menu`
CREATE TABLE if not exists `user_role`
(
- `id` int(11) not null auto_increment primary key comment 'id',
+ `id` int(11) not null primary key comment 'id',
`user_id` int(11) not null comment 'user id',
`role_id` int(11) not null comment 'role id',
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create
time',
@@ -95,7 +95,7 @@ CREATE TABLE if not exists `user_role`
CREATE TABLE if not exists `role_menu`
(
- `id` int(11) not null auto_increment primary key comment 'id',
+ `id` int(11) not null primary key comment 'id',
`role_id` int(11) not null comment 'role id',
`menu_id` int(11) not null comment 'menu id',
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'create
time',
@@ -105,7 +105,7 @@ CREATE TABLE if not exists `role_menu`
CREATE TABLE if not exists `catalog`
(
- `id` int(11) not null auto_increment primary key comment 'id',
+ `id` int(11) not null primary key comment 'id',
`catalog_type` varchar(50) not null comment 'catalog type',
`catalog_name` varchar(100) not null comment 'catalog name',
`warehouse` varchar(200) not null comment 'warehouse',
@@ -118,7 +118,7 @@ CREATE TABLE if not exists `catalog`
CREATE TABLE if not exists `databases`
(
- `id` int(11) not null auto_increment primary key comment 'id',
+ `id` int(11) not null primary key comment 'id',
`database_name` varchar(50) not null comment 'database name',
`catalog_id` int(11) not null comment 'catalog id',
`description` varchar(200) comment 'description',
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java
index e96ee13..e4bd82f 100644
---
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java
@@ -18,7 +18,7 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.server.data.model.CatalogInfo;
+import org.apache.paimon.web.server.data.dto.CatalogDTO;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.util.ObjectMapperUtils;
@@ -50,17 +50,17 @@ public class CatalogControllerTest extends
ControllerTestBase {
@Test
public void testCreateCatalog() throws Exception {
- CatalogInfo catalogInfo = new CatalogInfo();
- catalogInfo.setCatalogType("filesystem");
- catalogInfo.setCatalogName(catalogName);
- catalogInfo.setWarehouse(tempFile.toUri().toString());
- catalogInfo.setDelete(false);
+ CatalogDTO catalog = new CatalogDTO();
+ catalog.setType("filesystem");
+ catalog.setName(catalogName);
+ catalog.setWarehouse(tempFile.toUri().toString());
+ catalog.setDelete(false);
String responseString =
mockMvc.perform(
MockMvcRequestBuilders.post(catalogPath +
"/create")
.cookie(cookie)
-
.content(ObjectMapperUtils.toJSON(catalogInfo))
+
.content(ObjectMapperUtils.toJSON(catalog))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -72,11 +72,25 @@ public class CatalogControllerTest extends
ControllerTestBase {
R<Void> r = ObjectMapperUtils.fromJSON(responseString, new
TypeReference<R<Void>>() {});
assertEquals(200, r.getCode());
+ CatalogDTO removeCatalog = new CatalogDTO();
+ removeCatalog.setId(1);
+ removeCatalog.setName(catalogName);
+
mockMvc.perform(
- MockMvcRequestBuilders.delete(catalogPath + "/remove/" +
catalogName)
- .cookie(cookie)
- .contentType(MediaType.APPLICATION_JSON_VALUE)
- .accept(MediaType.APPLICATION_JSON_VALUE));
+ MockMvcRequestBuilders.post(catalogPath + "/remove")
+ .cookie(cookie)
+
.content(ObjectMapperUtils.toJSON(removeCatalog))
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<Void> remove =
+ ObjectMapperUtils.fromJSON(responseString, new
TypeReference<R<Void>>() {});
+ assertEquals(200, remove.getCode());
}
@Test
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ControllerTestBase.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ControllerTestBase.java
index d0bb0a5..41a42b2 100644
---
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ControllerTestBase.java
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/ControllerTestBase.java
@@ -18,11 +18,11 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.server.data.dto.LoginDto;
+import org.apache.paimon.web.server.data.dto.LoginDTO;
+import org.apache.paimon.web.server.data.dto.TableDTO;
import org.apache.paimon.web.server.data.model.CatalogInfo;
import org.apache.paimon.web.server.data.model.DatabaseInfo;
import org.apache.paimon.web.server.data.model.TableColumn;
-import org.apache.paimon.web.server.data.model.TableInfo;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.util.ObjectMapperUtils;
import org.apache.paimon.web.server.util.PaimonDataType;
@@ -79,7 +79,7 @@ public class ControllerTestBase {
@BeforeEach
public void before() throws Exception {
- LoginDto login = new LoginDto();
+ LoginDTO login = new LoginDTO();
login.setUsername("admin");
login.setPassword("admin");
@@ -136,8 +136,8 @@ public class ControllerTestBase {
"name",
PaimonDataType.builder().type("STRING").build(), "", false, "0");
tableColumns.add(id);
tableColumns.add(name);
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO table =
+ TableDTO.builder()
.catalogName(catalogName)
.databaseName(databaseName)
.tableName(tableName)
@@ -149,7 +149,7 @@ public class ControllerTestBase {
mockMvc.perform(
MockMvcRequestBuilders.post(tablePath + "/create")
.cookie(cookie)
- .content(ObjectMapperUtils.toJSON(tableInfo))
+ .content(ObjectMapperUtils.toJSON(table))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE));
}
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java
index d23e8fd..52dc082 100644
---
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java
@@ -18,7 +18,7 @@
package org.apache.paimon.web.server.controller;
-import org.apache.paimon.web.server.data.model.DatabaseInfo;
+import org.apache.paimon.web.server.data.dto.DatabaseDTO;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.util.ObjectMapperUtils;
@@ -40,19 +40,23 @@ public class DatabaseControllerTest extends
ControllerTestBase {
private static final String databasePath = "/api/database";
+ private static final String databaseName = "test_db";
+
private static final String catalogName = "paimon_catalog";
@Test
public void testCreateDatabase() throws Exception {
- DatabaseInfo databaseInfo = new DatabaseInfo();
- databaseInfo.setDatabaseName("test_db");
- databaseInfo.setCatalogName(catalogName);
+ DatabaseDTO createDatabase = new DatabaseDTO();
+ createDatabase.setName(databaseName);
+ createDatabase.setCatalogName(catalogName);
+ createDatabase.setCatalogId("1");
+ createDatabase.setIgnoreIfExists(true);
String responseString =
mockMvc.perform(
MockMvcRequestBuilders.post(databasePath +
"/create")
.cookie(cookie)
-
.content(ObjectMapperUtils.toJSON(databaseInfo))
+
.content(ObjectMapperUtils.toJSON(createDatabase))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -64,11 +68,27 @@ public class DatabaseControllerTest extends
ControllerTestBase {
R<Void> r = ObjectMapperUtils.fromJSON(responseString, new
TypeReference<R<Void>>() {});
assertEquals(200, r.getCode());
+ DatabaseDTO dropDatabase = new DatabaseDTO();
+ dropDatabase.setCatalogName(catalogName);
+ dropDatabase.setCatalogId("1");
+ dropDatabase.setIgnoreIfExists(true);
+ dropDatabase.setCascade(true);
+
mockMvc.perform(
- MockMvcRequestBuilders.delete(databasePath + "/drop/" +
"test_db/" + catalogName)
- .cookie(cookie)
- .contentType(MediaType.APPLICATION_JSON_VALUE)
- .accept(MediaType.APPLICATION_JSON_VALUE));
+ MockMvcRequestBuilders.post(databasePath + "/drop")
+ .cookie(cookie)
+
.content(ObjectMapperUtils.toJSON(dropDatabase))
+ .contentType(MediaType.APPLICATION_JSON_VALUE)
+ .accept(MediaType.APPLICATION_JSON_VALUE))
+ .andExpect(MockMvcResultMatchers.status().isOk())
+ .andDo(MockMvcResultHandlers.print())
+ .andReturn()
+ .getResponse()
+ .getContentAsString();
+
+ R<Void> remove =
+ ObjectMapperUtils.fromJSON(responseString, new
TypeReference<R<Void>>() {});
+ assertEquals(200, remove.getCode());
}
@Test
diff --git
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/TableControllerTest.java
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/TableControllerTest.java
index f31d1d5..d1b4638 100644
---
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/TableControllerTest.java
+++
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/TableControllerTest.java
@@ -18,9 +18,9 @@
package org.apache.paimon.web.server.controller;
+import org.apache.paimon.web.server.data.dto.TableDTO;
import org.apache.paimon.web.server.data.model.AlterTableRequest;
import org.apache.paimon.web.server.data.model.TableColumn;
-import org.apache.paimon.web.server.data.model.TableInfo;
import org.apache.paimon.web.server.data.result.R;
import org.apache.paimon.web.server.util.ObjectMapperUtils;
import org.apache.paimon.web.server.util.PaimonDataType;
@@ -62,8 +62,8 @@ public class TableControllerTest extends ControllerTestBase {
"name",
PaimonDataType.builder().type("STRING").build(), "", false, "0");
tableColumns.add(id);
tableColumns.add(name);
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO table =
+ TableDTO.builder()
.catalogName(catalogName)
.databaseName(databaseName)
.tableName("test_table")
@@ -76,7 +76,7 @@ public class TableControllerTest extends ControllerTestBase {
mockMvc.perform(
MockMvcRequestBuilders.post(tablePath +
"/create")
.cookie(cookie)
-
.content(ObjectMapperUtils.toJSON(tableInfo))
+
.content(ObjectMapperUtils.toJSON(table))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -113,8 +113,8 @@ public class TableControllerTest extends ControllerTestBase
{
false,
"0");
tableColumns.add(age);
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO table =
+ TableDTO.builder()
.catalogName(catalogName)
.databaseName(databaseName)
.tableName(tableName)
@@ -127,7 +127,7 @@ public class TableControllerTest extends ControllerTestBase
{
mockMvc.perform(
MockMvcRequestBuilders.post(tablePath +
"/column/add")
.cookie(cookie)
-
.content(ObjectMapperUtils.toJSON(tableInfo))
+
.content(ObjectMapperUtils.toJSON(table))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -205,8 +205,8 @@ public class TableControllerTest extends ControllerTestBase
{
Map<String, String> option = new HashMap<>();
option.put("bucket", "2");
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO table =
+ TableDTO.builder()
.catalogName(catalogName)
.databaseName(databaseName)
.tableName(tableName)
@@ -219,7 +219,7 @@ public class TableControllerTest extends ControllerTestBase
{
mockMvc.perform(
MockMvcRequestBuilders.post(tablePath +
"/option/add")
.cookie(cookie)
-
.content(ObjectMapperUtils.toJSON(tableInfo))
+
.content(ObjectMapperUtils.toJSON(table))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk())
@@ -264,8 +264,8 @@ public class TableControllerTest extends ControllerTestBase
{
"name",
PaimonDataType.builder().type("STRING").build(), "", false, "0");
tableColumns.add(id);
tableColumns.add(name);
- TableInfo tableInfo =
- TableInfo.builder()
+ TableDTO table =
+ TableDTO.builder()
.catalogName(catalogName)
.databaseName(databaseName)
.tableName("test_table_01")
@@ -277,7 +277,7 @@ public class TableControllerTest extends ControllerTestBase
{
mockMvc.perform(
MockMvcRequestBuilders.post(tablePath + "/create")
.cookie(cookie)
- .content(ObjectMapperUtils.toJSON(tableInfo))
+ .content(ObjectMapperUtils.toJSON(table))
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaType.APPLICATION_JSON_VALUE))
.andExpect(MockMvcResultMatchers.status().isOk());