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:bugfix] fix namespace sync error #5765

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
2 changes: 0 additions & 2 deletions db/init/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2452,5 +2452,3 @@ CREATE TABLE `namespace_user_rel` (
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'date_created',
`date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'date_updated'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='namespace user relation ';

INSERT INTO `namespace_user_rel` (`id`, `namespace_id`, `user_id`) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 additions & 1 deletion db/init/ob/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2393,4 +2393,3 @@ CREATE TABLE `namespace_user_rel` (
`date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'date_updated'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='namespace user relation ';

INSERT INTO `namespace_user_rel` (`id`, `namespace_id`, `user_id`) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 additions & 1 deletion db/init/og/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2790,4 +2790,3 @@ COMMENT ON COLUMN "public"."namespace_user_rel"."user_id" IS 'user_id';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_updated" IS 'update time';

INSERT INTO "public"."namespace_user_rel" ("id", "namespace_id", "user_id") VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 additions & 1 deletion db/init/oracle/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3020,4 +3020,3 @@ comment on column NAMESPACE_USER_REL.date_created
comment on column NAMESPACE_USER_REL.date_updated
is 'update time';

INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX("namespace_user_rel" (id)) */ INTO "namespace_user_rel" (id, namespace_id, user_id) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 additions & 1 deletion db/init/pg/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2912,4 +2912,3 @@ COMMENT ON COLUMN "public"."namespace_user_rel"."user_id" IS 'user_id';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_updated" IS 'update time';

INSERT INTO "public"."namespace_user_rel" ("id", "namespace_id", "user_id") VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 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 @@ -290,4 +290,3 @@ CREATE TABLE `namespace_user_rel` (
`date_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'date_updated'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='namespace user relation ';

INSERT INTO `namespace_user_rel` (`id`, `namespace_id`, `user_id`) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 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 @@ -332,4 +332,3 @@ COMMENT ON COLUMN "public"."namespace_user_rel"."user_id" IS 'user_id';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_updated" IS 'update time';

INSERT INTO "public"."namespace_user_rel" ("id", "namespace_id", "user_id") VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 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 @@ -396,4 +396,3 @@ comment on column NAMESPACE_USER_REL.date_created
comment on column NAMESPACE_USER_REL.date_updated
is 'update time';

INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX("namespace_user_rel" (id)) */ INTO "namespace_user_rel" (id, namespace_id, user_id) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
1 change: 0 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 @@ -333,4 +333,3 @@ COMMENT ON COLUMN "public"."namespace_user_rel"."user_id" IS 'user_id';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_created" IS 'create time';
COMMENT ON COLUMN "public"."namespace_user_rel"."date_updated" IS 'update time';

INSERT INTO "public"."namespace_user_rel" ("id", "namespace_id", "user_id") VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ public interface SyncDataService {
* @return the boolean
*/
boolean syncPluginData(String id);

/**
* Sync plugin data boolean.
*
* @param namespaceId the namespace id
* @param pluginId the plugin id
* @return the boolean
*/
boolean syncPluginData(String namespaceId, String pluginId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ public ShenyuAdminResult syncPluginAll(@Valid @RequestBody final NamespaceSyncDT
}

/**
* Sync plugin data of namespace.
* sync plugin data.
*
* @param id the id
* @return the mono
* @param pluginId the plugin id
* @param namespaceId the namespace id
* @return {@linkplain ShenyuAdminResult}
*/
@PutMapping("/syncPluginData")
public ShenyuAdminResult syncPluginData(@Existed(message = "namespace plugin is not existed", provider = NamespacePluginRelMapper.class)
@RequestParam("id") final String id) {
return ShenyuAdminResult.success(syncDataService.syncPluginData(id) ? ShenyuResultMessage.SYNC_SUCCESS : ShenyuResultMessage.SYNC_FAIL);
public ShenyuAdminResult syncPluginData(@RequestParam("id") final String pluginId, @RequestParam("namespaceId") final String namespaceId) {
return ShenyuAdminResult.success(syncDataService.syncPluginData(namespaceId, pluginId) ? ShenyuResultMessage.SYNC_SUCCESS : ShenyuResultMessage.SYNC_FAIL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public interface NamespacePluginService extends PageService<NamespacePluginQuery
* @return {@linkplain PluginVO}
*/
NamespacePluginVO findById(String id);


/**
* find by namespaceId and pluginId.
*
* @param namespaceId namespaceId.
* @param pluginId pluginId.
* @return {@linkplain NamespacePluginVO}
*/
NamespacePluginVO findByNamespaceIdAndPluginId(String namespaceId, String pluginId);

/**
* Update string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public NamespacePluginServiceImpl(final NamespacePluginRelMapper namespacePlugin
public NamespacePluginVO findById(final String id) {
return namespacePluginRelMapper.selectById(id);
}


@Override
public NamespacePluginVO findByNamespaceIdAndPluginId(final String namespaceId, final String pluginId) {
return namespacePluginRelMapper.selectByPluginIdAndNamespaceId(pluginId, namespaceId);
}

@Override
public NamespacePluginVO create(final String namespaceId, final String pluginId) {
NamespacePluginVO existNamespacePluginVO = namespacePluginRelMapper.selectByPluginIdAndNamespaceId(pluginId, namespaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public NamespaceVO findByNamespaceId(final String namespaceId) {

@Override
public List<NamespaceVO> list(final String name) {

if (SessionUtil.isAdmin()) {
List<NamespaceDO> allList = namespaceMapper.selectAll();
return allList.stream().map(NamespaceTransfer.INSTANCE::mapToVo).collect(Collectors.toList());
}

List<String> namespaceIds = namespaceUserService.listNamespaceIdByUserId(SessionUtil.visitorId());

if (CollectionUtils.isEmpty(namespaceIds)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,32 @@ public boolean syncPluginData(final String id) {
}
return true;
}

@Override
public boolean syncPluginData(final String namespaceId, final String pluginId) {

NamespacePluginVO namespacePluginVO = namespacePluginService.findByNamespaceIdAndPluginId(namespaceId, pluginId);
if (Objects.isNull(namespacePluginVO) || Objects.isNull(namespacePluginVO.getPluginId())) {
LOG.error("namespace plugin is not existed");
return false;
}
eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, DataEventTypeEnum.UPDATE,
Collections.singletonList(PluginTransfer.INSTANCE.mapToData(namespacePluginVO))));

List<SelectorData> selectorDataList = selectorService.findByPluginIdAndNamespaceId(namespacePluginVO.getPluginId(), namespacePluginVO.getNamespaceId());

if (!CollectionUtils.isEmpty(selectorDataList)) {
eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, DataEventTypeEnum.REFRESH, selectorDataList));

List<String> selectorIdList = selectorDataList.stream().map(SelectorData::getId)
.collect(Collectors.toList());
for (String selectorId : selectorIdList) {
discoveryUpstreamService.refreshBySelectorId(selectorId);
}
List<RuleData> allRuleDataList = ruleService.findBySelectorIdList(selectorIdList);

eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.RULE, DataEventTypeEnum.REFRESH, allRuleDataList));
}
return true;
}
}
1 change: 0 additions & 1 deletion shenyu-admin/src/main/resources/sql-script/h2/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1422,4 +1422,3 @@ CREATE TABLE IF NOT EXISTS `namespace_user_rel`
PRIMARY KEY (`id`)
);

INSERT INTO `namespace_user_rel` (`id`, `namespace_id`, `user_id`) VALUES ('1852580590991884288', '649330b6-c2d7-4edc-be8e-8a54df9eb385', '1');
Loading