This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 5b7f6ee0b [ISSUE #3221]plugin snapshot api (#3222)
5b7f6ee0b is described below
commit 5b7f6ee0b68ec4057cb16b3774880d6c5e5dcac1
Author: likeguo <[email protected]>
AuthorDate: Fri Apr 15 10:28:17 2022 +0800
[ISSUE #3221]plugin snapshot api (#3222)
* add plugin snapshot api
* add plugin snapshot api
* add plugin snapshot api
* add plugin snapshot api
* add plugin snapshot api
---
.../src/http/http-debug-plugin-controller-api.http | 5 +
.../shenyu/admin/controller/PluginController.java | 17 +-
.../apache/shenyu/admin/mapper/PluginMapper.java | 8 +
.../shenyu/admin/model/vo/PluginSnapshotVO.java | 174 +++++++++++++++++++++
.../apache/shenyu/admin/service/PluginService.java | 8 +
.../shenyu/admin/service/SyncDataService.java | 4 +-
.../admin/service/impl/PluginServiceImpl.java | 6 +
.../src/main/resources/mappers/plugin-sqlmap.xml | 15 ++
8 files changed, 229 insertions(+), 8 deletions(-)
diff --git a/shenyu-admin/src/http/http-debug-plugin-controller-api.http
b/shenyu-admin/src/http/http-debug-plugin-controller-api.http
index 0dcfe8c68..a568d8d45 100644
--- a/shenyu-admin/src/http/http-debug-plugin-controller-api.http
+++ b/shenyu-admin/src/http/http-debug-plugin-controller-api.http
@@ -97,3 +97,8 @@ Accept: application/json
Content-Type: application/json
X-Access-Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ3MjUzNzg2fQ.37fddsUZRFVNc2pTlACHEI9oZSj9gnE5hhpK5Yaf-6s
+### active plugin snapshot
+GET http://localhost:9095/plugin/snapshot/active
+Accept: application/json
+Content-Type: application/json
+X-Access-Token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNjQ5NTg4NjYwfQ.SLXVlPz1l4TaARJF7PGbuaeMb4lDQopg4biU9e7XL1w
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
index a75a55cae..a1d01c71f 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/PluginController.java
@@ -196,11 +196,16 @@ public class PluginController {
public ShenyuAdminResult syncPluginData(@PathVariable("id")
@Existed(message = "plugin is not
existed",
provider =
PluginMapper.class) final String id) {
- boolean success = syncDataService.syncPluginData(id);
- if (success) {
- return ShenyuAdminResult.success(ShenyuResultMessage.SYNC_SUCCESS);
- } else {
- return ShenyuAdminResult.error(ShenyuResultMessage.SYNC_FAIL);
- }
+ return ShenyuAdminResult.success(syncDataService.syncPluginData(id) ?
ShenyuResultMessage.SYNC_SUCCESS : ShenyuResultMessage.SYNC_FAIL);
+ }
+
+ /**
+ * active plugin snapshot.
+ *
+ * @return list
+ */
+ @GetMapping("/snapshot/active")
+ public ShenyuAdminResult activePluginSnapshot() {
+ return ShenyuAdminResult.success(pluginService.activePluginSnapshot());
}
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
index a4ea6eb11..bcfaa1f8e 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/PluginMapper.java
@@ -21,6 +21,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.shenyu.admin.model.entity.PluginDO;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
import org.apache.shenyu.admin.validation.ExistProvider;
import java.io.Serializable;
@@ -186,4 +187,11 @@ public interface PluginMapper extends ExistProvider {
* @return existed
*/
Boolean nameExistedExclude(@Param("name") Serializable name,
@Param("exclude") List<String> exclude);
+
+ /**
+ * active plugin snapshot.
+ *
+ * @return plugin list
+ */
+ List<PluginSnapshotVO> activePluginSnapshot();
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/PluginSnapshotVO.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/PluginSnapshotVO.java
new file mode 100644
index 000000000..ca6073da9
--- /dev/null
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/model/vo/PluginSnapshotVO.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.admin.model.vo;
+
+/**
+ * PluginSnapshotVO.
+ */
+public class PluginSnapshotVO {
+
+ /**
+ * plugin id.
+ */
+ private String id;
+
+ /**
+ * plugin name.
+ */
+ private String name;
+
+ /**
+ * plugin config.
+ */
+ private String config;
+
+ /**
+ * plugin rule.
+ */
+ private String role;
+
+ /**
+ * plugin handle count.
+ */
+ private Integer handleCount;
+
+ /**
+ * plugin selector count.
+ */
+ private Integer selectorCount;
+
+ /**
+ * get id.
+ *
+ * @return id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * set id.
+ *
+ * @param id id
+ */
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ /**
+ * get name.
+ *
+ * @return name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * set name.
+ *
+ * @param name name
+ */
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ /**
+ * get config.
+ *
+ * @return config
+ */
+ public String getConfig() {
+ return config;
+ }
+
+ /**
+ * set config.
+ *
+ * @param config config
+ */
+ public void setConfig(final String config) {
+ this.config = config;
+ }
+
+ /**
+ * get role.
+ *
+ * @return role
+ */
+ public String getRole() {
+ return role;
+ }
+
+ /**
+ * set role.
+ *
+ * @param role role
+ */
+ public void setRole(final String role) {
+ this.role = role;
+ }
+
+ /**
+ * get handle count.
+ *
+ * @return value
+ */
+ public Integer getHandleCount() {
+ return handleCount;
+ }
+
+ /**
+ * set handle count.
+ *
+ * @param handleCount value
+ */
+ public void setHandleCount(final Integer handleCount) {
+ this.handleCount = handleCount;
+ }
+
+ /**
+ * get selector count.
+ *
+ * @return value
+ */
+ public Integer getSelectorCount() {
+ return selectorCount;
+ }
+
+ /**
+ * set selector count.
+ *
+ * @param selectorCount value
+ */
+ public void setSelectorCount(final Integer selectorCount) {
+ this.selectorCount = selectorCount;
+ }
+
+ @Override
+ public String toString() {
+ return "PluginSnapshotVO{"
+ + "id='" + id + '\''
+ + ", name='" + name + '\''
+ + ", config='" + config + '\''
+ + ", role='" + role + '\''
+ + ", handleCount=" + handleCount
+ + ", selectorCount=" + selectorCount
+ + '}';
+ }
+}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
index c8ded135e..38f814c99 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
@@ -22,6 +22,7 @@ import org.apache.shenyu.admin.model.dto.PluginDTO;
import org.apache.shenyu.admin.model.entity.PluginDO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
import org.apache.shenyu.admin.model.vo.PluginVO;
import org.apache.shenyu.common.dto.PluginData;
@@ -122,4 +123,11 @@ public interface PluginService {
* @return the plugin do
*/
PluginDO findByName(String name);
+
+ /**
+ * active plugin snapshot.
+ *
+ * @return plugin list
+ */
+ List<PluginSnapshotVO> activePluginSnapshot();
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SyncDataService.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SyncDataService.java
index 7088a2339..17637f317 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SyncDataService.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SyncDataService.java
@@ -23,7 +23,7 @@ import org.apache.shenyu.common.enums.DataEventTypeEnum;
* The interface Sync data service.
*/
public interface SyncDataService {
-
+
/**
* Sync all boolean.
*
@@ -31,7 +31,7 @@ public interface SyncDataService {
* @return the boolean
*/
boolean syncAll(DataEventTypeEnum type);
-
+
/**
* Sync plugin data boolean.
*
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
index 1964b30ec..285fe4327 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
@@ -36,6 +36,7 @@ import org.apache.shenyu.admin.model.entity.SelectorDO;
import org.apache.shenyu.admin.model.page.CommonPager;
import org.apache.shenyu.admin.model.page.PageResultUtils;
import org.apache.shenyu.admin.model.query.PluginQuery;
+import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
import org.apache.shenyu.admin.model.vo.PluginVO;
import org.apache.shenyu.admin.model.vo.ResourceVO;
import org.apache.shenyu.admin.service.PluginService;
@@ -301,6 +302,11 @@ public class PluginServiceImpl implements PluginService {
return pluginMapper.selectByName(name);
}
+ @Override
+ public List<PluginSnapshotVO> activePluginSnapshot() {
+ return pluginMapper.activePluginSnapshot();
+ }
+
/**
* add plugin and add plugin resource.
*
diff --git a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
index 08994ca16..d42fd2611 100644
--- a/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/plugin-sqlmap.xml
@@ -144,6 +144,21 @@
LIMIT 1
</select>
+ <select id="activePluginSnapshot"
resultType="org.apache.shenyu.admin.model.vo.PluginSnapshotVO">
+ select p.id,
+ p.name,
+ config,
+ role,
+ count(ph.id) handleCount,
+ count(s.id) selectorCount
+ from plugin p
+ left join plugin_handle ph on p.id = ph.plugin_id
+ left join selector s on p.id = s.plugin_id
+ where p.enabled = true
+ group by p.id, p.name, config, p.role, p.sort
+ order by p.sort, p.id
+ </select>
+
<insert id="insert"
parameterType="org.apache.shenyu.admin.model.entity.PluginDO">
INSERT INTO plugin
(id,