Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feat]Selector module adapts to namespace transformation #5604

Merged
merged 52 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
cb6e4dd
commit
Jul 21, 2024
dcfca2f
commit
Jul 23, 2024
3538f37
first draft,not verified
Jul 30, 2024
28e6b82
simplify verified
Aug 1, 2024
f8e34d2
simplify verified
Aug 1, 2024
a9c9ee8
Merge branch 'master' into feat_namespace_selector
Aug 1, 2024
819795c
commit
Aug 2, 2024
6c08ca3
commit
Aug 2, 2024
a079729
fix
Aug 2, 2024
4b6320e
fix e2e checkstyle
Aug 2, 2024
7254839
fix e2e
Aug 3, 2024
a70e70b
fix test
Aug 3, 2024
3ea5c2a
fix
Aug 3, 2024
5717cfd
fix
Aug 3, 2024
fc6c199
fix test
Aug 3, 2024
81596fd
fix
Aug 3, 2024
8d5f265
fix
Aug 3, 2024
e1d4d0b
trigger ci
Aug 3, 2024
2c6c556
trigger ci
Aug 3, 2024
3c34e70
fix sql
Aug 3, 2024
b92f2c4
fix sql
Aug 3, 2024
1872673
fix sql
Aug 3, 2024
10043f7
fix
Aug 3, 2024
d897c83
trigger ci
Aug 3, 2024
2e96d3b
trigger ci
Aug 3, 2024
8ede359
fix
Aug 3, 2024
afd48db
trigger ci
Aug 3, 2024
e1643a7
Merge branch 'master' into feat_namespace_selector
xcsnx Aug 5, 2024
a2d9acb
fix
Aug 5, 2024
751517b
Merge remote-tracking branch 'origin/feat_namespace_selector' into fe…
Aug 5, 2024
9020a0d
fix
Aug 5, 2024
9d983d3
fix
Aug 5, 2024
61a174c
Merge branch 'master' into feat_namespace_selector
xcsnx Aug 5, 2024
170e2f9
fix
Aug 5, 2024
42923bb
Merge remote-tracking branch 'origin/feat_namespace_selector' into fe…
Aug 5, 2024
50a9992
trigger ci
Aug 5, 2024
e53fe79
trigger ci
Aug 5, 2024
84794c1
fix
Aug 9, 2024
819ead1
Merge branch 'master' into feat_namespace_selector
xcsnx Aug 9, 2024
5cddb9a
trigger ci
Aug 9, 2024
6d3efda
trigger ci
Aug 9, 2024
0c3760a
trigger ci
Aug 9, 2024
e5400b3
fix cr
Aug 10, 2024
c478cfa
fix cr
Aug 10, 2024
1d8bd87
fix comment
Aug 14, 2024
0d298f9
fix comment
Aug 14, 2024
657565a
fix
Aug 14, 2024
eef3764
fix
Aug 14, 2024
c036ca0
trigger ci
Aug 14, 2024
c65b27e
trigger ci
Aug 14, 2024
f5d8e92
Merge branch 'master' into feat_namespace_selector
xcsnx Aug 15, 2024
a55baa5
fix cr
Aug 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2370,3 +2370,5 @@ 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 ('1792779493541343265', '1346358560427216896', '1792749362445840484', '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 ('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`;
4 changes: 4 additions & 0 deletions db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2673,3 +2673,7 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272
INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
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';

4 changes: 4 additions & 0 deletions db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2857,3 +2857,7 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343265', '1346358560427216896', '1792749362445840484');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485');
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, object_id, resource_id) VALUES ('1792779493541343267', '1346358560427216896', '1792749362445840486');


ALTER TABLE selector ADD namespace_id VARCHAR2(50) NULL;
COMMENT ON COLUMN selector.namespace_id IS 'namespaceId';
2 changes: 2 additions & 0 deletions db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2791,3 +2791,5 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343265', '13463585604272
INSERT INTO "public"."permission" VALUES ('1792779493541343266', '1346358560427216896', '1792749362445840485', '2024-06-25 20:00:00.000', '2024-06-25 20:00:00.000');
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';
7 changes: 7 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,10 @@ INSERT INTO `shenyu`.`permission` (`id`, `object_id`, `resource_id`, `date_creat

/* add column into dashboard_user table */
ALTER TABLE `shenyu`.`dashboard_user` ADD COLUMN `client_id` varchar(32) NULL DEFAULT NULL COMMENT 'client id';


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

UPDATE selector
SET namespace_id = '649330b6-c2d7-4edc-be8e-8a54df9eb385'
WHERE namespaceId IS NULL;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-og.sql
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,8 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272
/* add column into dashboard_user table */
ALTER TABLE "public"."dashboard_user" ADD COLUMN client_id VARCHAR(32) NULL;
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;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-oracle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,8 @@ INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX (permission(id)) */ INTO permission (id, o
/* add column into dashboard_user table */
ALTER TABLE dashboard_user ADD client_id VARCHAR(32) NULL;
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;
5 changes: 5 additions & 0 deletions db/upgrade/2.6.1-upgrade-2.7.0-pg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,8 @@ INSERT INTO "public"."permission" VALUES ('1792779493541343267', '13463585604272
/* add column into dashboard_user table */
ALTER TABLE "public"."dashboard_user" ADD COLUMN client_id VARCHAR(32) NULL;
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;
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.SelectorMapper;
import org.apache.shenyu.admin.model.dto.BatchCommonDTO;
import org.apache.shenyu.admin.model.dto.BatchNamespaceCommonDTO;
import org.apache.shenyu.admin.model.dto.SelectorDTO;
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 selector controller.
*/
Expand All @@ -66,29 +64,37 @@ public SelectorController(final SelectorService selectorService) {
* @param name selector name.
* @param currentPage current page.
* @param pageSize page size.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("")
public AdminResult<CommonPager<SelectorVO>> querySelectors(final String pluginId, final String name,
@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize) {
@RequestParam @NotNull final Integer currentPage,
@RequestParam @NotNull final Integer pageSize,
@Valid @Existed(message = "namespaceId is not existed",
provider = NamespaceMapper.class) final String namespaceId
) {
final SelectorQueryCondition condition = new SelectorQueryCondition();
condition.setUserId(SessionUtil.visitor().getUserId());
condition.setPlugin(ListUtil.of(pluginId));
condition.setKeyword(name);
condition.setNamespaceId(namespaceId);
return searchAdaptor(new PageCondition<>(currentPage, pageSize, condition));
}

/**
* detail selector.
*
* @param id selector id.
* @param namespaceId namespaceId.
* @return {@linkplain ShenyuAdminResult}
*/
@GetMapping("/{id}")
@GetMapping("/{id}/{namespaceId}")
public ShenyuAdminResult detailSelector(@PathVariable("id") @Valid
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id) {
SelectorVO selectorVO = selectorService.findById(id);
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id,
@PathVariable("namespaceId") @Valid
@Existed(provider = NamespaceMapper.class, message = "namespaceId is not existed") final String namespaceId) {
SelectorVO selectorVO = selectorService.findById(id, namespaceId);
return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, selectorVO);
}

Expand All @@ -113,8 +119,7 @@ public ShenyuAdminResult createSelector(@Valid @RequestBody final SelectorDTO se
*/
@PutMapping("/{id}")
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid
@Existed(provider = SelectorMapper.class,
message = "selector is not existed") final String id,
@Existed(provider = SelectorMapper.class, message = "selector is not existed") final String id,
@Valid @RequestBody final SelectorDTO selectorDTO) {
selectorDTO.setId(id);
Integer updateCount = selectorService.createOrUpdate(selectorDTO);
Expand All @@ -129,7 +134,7 @@ public ShenyuAdminResult updateSelector(@PathVariable("id") @Valid
*/
@PostMapping("/batchEnabled")
public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO batchCommonDTO) {
if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled())) {
if (!selectorService.enabled(batchCommonDTO.getIds(), batchCommonDTO.getEnabled(), batchCommonDTO.getNamespaceId())) {
return ShenyuAdminResult.error(ShenyuResultMessage.NOT_FOUND_EXCEPTION);
}
return ShenyuAdminResult.success(ShenyuResultMessage.ENABLE_SUCCESS);
Expand All @@ -138,12 +143,12 @@ public ShenyuAdminResult batchEnabled(@Valid @RequestBody final BatchCommonDTO b
/**
* delete Selectors.
*
* @param ids primary key.
* @param batchNamespaceCommonDTO batchNamespaceCommonDTO.
* @return {@linkplain ShenyuAdminResult}
*/
@DeleteMapping("/batch")
public ShenyuAdminResult deleteSelector(@RequestBody @NotEmpty final List<@NotBlank String> ids) {
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
Integer deleteCount = selectorService.delete(ids);
public ShenyuAdminResult deleteSelector(@Valid @RequestBody final BatchNamespaceCommonDTO batchNamespaceCommonDTO) {
Integer deleteCount = selectorService.delete(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.
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
*
* @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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface NamespaceMapper extends ExistProvider {


/**
* selectAll.
* selectAllByNamespaceId.
*
* @param name name.
* @return namespaceDOList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,19 @@ public interface NamespacePluginRelMapper extends ExistProvider {
/**
* select plugin by namespacePluginId.
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
*
* @param id primary key.
* @param pluginId primary key.
* @param namespaceId namespace id.
* @return {@linkplain PluginVO}
*/
NamespacePluginVO selectById(String id, String namespaceId);
NamespacePluginVO selectByPluginIdAndNamespaceId(String pluginId, String namespaceId);
xcsnx marked this conversation as resolved.
Show resolved Hide resolved

/**
* select plugin by pluginId.
*
* @param pluginId primary key.
* @param namespaceId namespace id.
* @return {@linkplain PluginVO}
*/
NamespacePluginVO selectByPluginId(String pluginId, String namespaceId);
NamespacePluginVO selectByPluginId(String pluginId);

/**
* search by condition.
Expand Down Expand Up @@ -114,7 +113,7 @@ public interface NamespacePluginRelMapper extends ExistProvider {
* @param namespaceId namespace id.
* @return {@linkplain NamespacePluginRelDO}
*/
List<NamespacePluginVO> selectByIds(List<String> ids, String namespaceId);
List<NamespacePluginVO> selectByIdsAndNamespaceId(List<String> ids, String namespaceId);


/**
Expand All @@ -124,22 +123,22 @@ public interface NamespacePluginRelMapper extends ExistProvider {
* @param namespaceId namespace id.
* @return rows int
*/
int deleteByIds(List<String> ids, String namespaceId);
int deleteByIdsAndNamespaceId(List<String> ids, String namespaceId);

/**
* select all.
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
*
* @param namespaceId namespace id.
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
* @return {@linkplain List}
*/
List<NamespacePluginVO> selectAll(String namespaceId);
List<NamespacePluginVO> selectAllByNamespaceId(String namespaceId);

/**
* select all.
*
* @return {@linkplain List}
*/
List<NamespacePluginVO> selectAll();
List<NamespacePluginVO> selectAllByNamespaceId();

/**
* enable data by a list of ids.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ public interface ProxySelectorMapper extends ExistProvider {
int update(ProxySelectorDO proxySelectorDO);

/**
* selectById.
* selectByIdAndNamespaceId.
*
* @param id id
* @return ProxySelectorDO
*/
ProxySelectorDO selectById(@Param("id") String id);

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

/**
* deleteByIds.
* deleteByIdsAndNamespaceId.
*
* @param ids id list
* @return rows int
Expand All @@ -113,7 +113,7 @@ public interface ProxySelectorMapper extends ExistProvider {
List<ProxySelectorDO> selectByDiscoveryId(@Param("discoveryId") String discoveryId);

/**
* selectAll.
* selectAllByNamespaceId.
*
* @return ProxySelectorDOList
*/
Expand Down
Loading
Loading