Skip to content

Commit

Permalink
[type:feat]Rule and MetaData module adapts to namespace transformation (
Browse files Browse the repository at this point in the history
#5618)

* commit

* commit

* first draft,not verified

* simplify verified

* simplify verified

* commit

* commit

* fix

* fix e2e checkstyle

* fix e2e

* fix test

* fix

* fix

* fix test

* fix

* fix

* trigger ci

* trigger ci

* fix sql

* fix sql

* fix sql

* fix

* trigger ci

* trigger ci

* fix

* trigger ci

* fix

* fix

* fix

* fix

* trigger ci

* trigger ci

* fix

* trigger ci

* trigger ci

* trigger ci

* fix cr

* fix cr

* commit

* commit

* support e2e

* commit meta_data

* commit

* commit

* commit

* commit

* commit

* commit

* fix

* fix

* fix unit test

* fix unit test

* fix unit test

* fix unit test

* fix unit test

* fix unit test

* fix unit test

* trigger ci

* trigger ci

* merge fix

* support ocean base

---------

Co-authored-by: ‘xcsnx’ <‘[email protected]’>
Co-authored-by: VampireAchao <[email protected]>
Co-authored-by: aias00 <[email protected]>
Co-authored-by: moremind <[email protected]>
  • Loading branch information
5 people authored Sep 2, 2024
1 parent 2b70353 commit 77756d8
Show file tree
Hide file tree
Showing 77 changed files with 930 additions and 373 deletions.
6 changes: 5 additions & 1 deletion db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2371,4 +2371,8 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');

ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;
ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';
6 changes: 5 additions & 1 deletion db/init/ob/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2371,4 +2371,8 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');

ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;
ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';
5 changes: 5 additions & 0 deletions db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2677,3 +2677,8 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272
ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';
8 changes: 7 additions & 1 deletion db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2860,4 +2860,10 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o


ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';

ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN rule.namespace_id IS 'namespaceId';

ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId';
8 changes: 7 additions & 1 deletion db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2792,4 +2792,10 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343266', '13463585604272
INSERT INTO "public"."permission" VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');

ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';
16 changes: 15 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,18 @@ ALTER TABLE `shenyu`.`selector` ADD COLUMN `namespace_id` varchar(50) NULL COMME

UPDATE selector
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespaceId IS NULL;
WHERE namespace_id IS NULL;


ALTER TABLE `shenyu`.`rule` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId' AFTER `match_restful`;

UPDATE rule
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;

ALTER TABLE `shenyu`.`meta_data` ADD COLUMN `namespace_id` varchar(50) NULL COMMENT 'namespaceId';

UPDATE meta_data
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespace_id IS NULL;

12 changes: 11 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-og.sql
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,14 @@ COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id';
ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
12 changes: 11 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,14 @@ COMMENT ON COLUMN dashboard_user.client_id IS 'client id';
ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';

UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE selector SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE rule ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN rule.namespace_id IS 'namespaceId';

UPDATE rule SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE meta_data ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN meta_data.namespace_id IS 'namespaceId';

UPDATE meta_data SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
12 changes: 11 additions & 1 deletion db/upgrade/2.6.1-upgrade-2.7.0-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,14 @@ COMMENT ON COLUMN "public"."dashboard_user".client_id IS 'client id';
ALTER TABLE "public"."selector" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."selector"."namespace_id" IS 'namespaceId';

UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
UPDATE "public"."selector" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."rule" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."rule"."namespace_id" IS 'namespaceId';

UPDATE "public"."rule" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;

ALTER TABLE "public"."meta_data" ADD COLUMN namespace_id VARCHAR(50) NULL;
COMMENT ON COLUMN "public"."meta_data"."namespace_id" IS 'namespaceId';

UPDATE "public"."meta_data" SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385' WHERE namespace_id IS NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

package org.apache.shenyu.admin.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO;
import org.apache.shenyu.admin.model.dto.MetaDataDTO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageParameter;
Expand All @@ -28,6 +32,7 @@
import org.apache.shenyu.admin.model.vo.MetaDataVO;
import org.apache.shenyu.admin.service.MetaDataService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
import org.apache.shenyu.admin.validation.annotation.Existed;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -37,12 +42,6 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
* The type Meta data controller.
*/
Expand All @@ -61,14 +60,17 @@ public MetaDataController(final MetaDataService metaDataService) {
* @param path the path
* @param currentPage the current page
* @param pageSize the page size
* @param namespaceId namespaceId.
* @return the shenyu result
*/
@GetMapping("/queryList")
@RequiresPermissions("system:meta:list")
public ShenyuAdminResult queryList(final String path,
@RequestParam @NotNull(message = "currentPage not null") final Integer currentPage,
@RequestParam @NotNull(message = "pageSize not null") final Integer pageSize) {
CommonPager<MetaDataVO> commonPager = metaDataService.listByPage(new MetaDataQuery(path, new PageParameter(currentPage, pageSize)));
@RequestParam @NotNull(message = "pageSize not null") final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId) {
CommonPager<MetaDataVO> commonPager = metaDataService.listByPage(new MetaDataQuery(path, new PageParameter(currentPage, pageSize), namespaceId));
return ShenyuAdminResult.success(ShenyuResultMessage.QUERY_SUCCESS, commonPager);
}

Expand Down Expand Up @@ -98,12 +100,15 @@ public ShenyuAdminResult findAllGroup() {
* Get detail of metadata.
*
* @param id the id
* @param namespaceId namespaceId.
* @return the shenyu result
*/
@GetMapping("/{id}")
@GetMapping("/{id}/{namespaceId}")
@RequiresPermissions("system:meta:edit")
public ShenyuAdminResult detail(@PathVariable("id") final String id) {
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findById(id));
public ShenyuAdminResult detail(@PathVariable("id") final String id,
@PathVariable("namespaceId") @Valid
@Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) {
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, metaDataService.findByIdAndNamespaceId(id, namespaceId));
}

/**
Expand All @@ -121,26 +126,14 @@ public ShenyuAdminResult createOrUpdate(@Valid @RequestBody final MetaDataDTO me
/**
* Batch deleted metadata.
*
* @param ids the ids
* @return the shenyu result
*/
@PostMapping("/batchDeleted")
@RequiresPermissions("system:meta:delete")
public ShenyuAdminResult batchDeleted(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
Integer deleteCount = metaDataService.delete(ids);
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount);
}

/**
* Batch deleted metadata.
*
* @param ids the ids
* @param batchNamespaceCommonDTO batchNamespaceCommonDTO.
* @return the shenyu result
*/
@DeleteMapping("/batchDeleted")
@RequiresPermissions("system:meta:delete")
public ShenyuAdminResult batchDelete(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
return batchDeleted(ids);
public ShenyuAdminResult batchDeleted(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) {
Integer deleteCount = metaDataService.deleteByIdsAndNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId());
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount);
}

/**
Expand All @@ -152,7 +145,7 @@ public ShenyuAdminResult batchDelete(@RequestBody @NotEmpty final List<@NotBlank
@PostMapping("/batchEnabled")
@RequiresPermissions("system:meta:disable")
public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) {
final String result = metaDataService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled());
final String result = metaDataService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId());
if (StringUtils.isNoneBlank(result)) {
return ShenyuAdminResult.error(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

package org.apache.shenyu.admin.controller;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.mapper.NamespaceMapper;
import org.apache.shenyu.admin.mapper.RuleMapper;
import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO;
import org.apache.shenyu.admin.model.dto.RuleDTO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageCondition;
Expand All @@ -41,12 +45,6 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
* this is rule controller.
*/
Expand All @@ -66,30 +64,37 @@ public RuleController(final RuleService ruleService) {
* @param name rule name.
* @param currentPage current page.
* @param pageSize page size.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("")
public AdminResult<CommonPager<RuleVO>> queryRules(final String selectorId, final String name,
@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize) {
@RequestParam @NotNull final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId) {
final RuleQueryCondition condition = new RuleQueryCondition();
condition.setUserId(SessionUtil.visitor().getUserId());
condition.setSelectors(ListUtil.of(selectorId));
condition.setKeyword(name);
condition.setNamespaceId(namespaceId);
return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition));
}

/**
* detail rule.
*
* @param id rule id.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("/{id}")
@GetMapping("/{id}/{namespaceId}")
public ShenyuAdminResult detailRule(@PathVariable("id") @Valid
@Existed(provider = RuleMapper.class,
message = "rule is not existed") final String id) {
RuleVO ruleVO = ruleService.findById(id);
message = "rule is not existed") final String id,
@PathVariable("namespaceId") @Valid
@Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) {
RuleVO ruleVO = ruleService.findByIdAndNamespaceId(id, namespaceId);
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, ruleVO);
}

Expand Down Expand Up @@ -130,7 +135,7 @@ public ShenyuAdminResult updateRule(@PathVariable("id") @Valid
*/
@PostMapping("/batchEnabled")
public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) {
if (!ruleService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())) {
if (!ruleService.enabledByIdsAndNamespaceId(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) {
return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION);
}
return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS);
Expand All @@ -139,12 +144,12 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b
/**
* delete rules.
*
* @param ids primary key.
* @param batchNamespaceCommonDTO batchNamespaceCommonDTO.
* @return {@linkplain ShenyuAdminResult}
*/
@DeleteMapping("/batch")
public ShenyuAdminResult deleteRules(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
Integer deleteCount = ruleService.delete(ids);
public ShenyuAdminResult deleteRules(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) {
Integer deleteCount = ruleService.deleteByIdsAndNamespaceId(batchNamespaceCommonDTO.getIds(), batchNamespaceCommonDTO.getNamespaceId());
return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, deleteCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface DiscoveryMapper extends ExistProvider {
DiscoveryDO selectById(String id);

/**
* selectAll.
* selectAllByNamespaceId.
*
* @return discoveryDOList
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public interface DiscoveryUpstreamMapper extends ExistProvider {
Boolean existed(@Param("id") Serializable key);

/**
* selectByIds.
* selectByIdsAndNamespaceId.
*
* @param ids id list
* @return discoveryUpstreamDO list
*/
List<DiscoveryUpstreamDO> selectByIds(@Param("ids") List<String> ids);

/**
* selectAll.
* selectAllByNamespaceId.
*
* @return discoveryUpstreamDO list
*/
Expand Down Expand Up @@ -102,7 +102,7 @@ public interface DiscoveryUpstreamMapper extends ExistProvider {
int updateSelective(DiscoveryUpstreamDO discoveryUpstreamDO);

/**
* deleteByIds.
* deleteByIdsAndNamespaceId.
*
* @param ids id list
* @return rows int
Expand Down
Loading

0 comments on commit 77756d8

Please sign in to comment.