juzhiyuan commented on a change in pull request #1430:
URL: https://github.com/apache/apisix-dashboard/pull/1430#discussion_r570677576
##########
File path: api/internal/handler/tool/tool.go
##########
@@ -48,3 +68,44 @@ func (h *Handler) Version(_ droplet.Context) (interface{},
error) {
Version: version,
}, nil
}
+
+func (h *Handler) VersionMatch(c droplet.Context) (interface{}, error) {
+ _, version := utils.GetHashAndVersion()
+ var output VersionMatchOutput
+ output.DashboardVersion = version
+
+ matchedVersion := utils.GetMatchedVersion(version)
+
+ var notMatchedNodes = make([]nodes, 0)
+ _, err := h.serverInfoStore.List(c.Context(), store.ListInput{
+ Predicate: func(obj interface{}) bool {
+ serverInfo := obj.(*entity.ServerInfo)
+
+ if serverInfo.Version != matchedVersion {
+ notMatchedNodes = append(notMatchedNodes, nodes{
+ Hostname: serverInfo.Hostname,
+ Version: serverInfo.Version,
+ })
+ }
+ return false
+ },
+ })
+
+ if err != nil {
+ return nil, err
+ }
+
+ output.NotMatchedNodes = notMatchedNodes
+ if len(output.NotMatchedNodes) == 0 {
+ output.Matched = true
+ } else {
+ // TODO: move this to utils
+ return &data.SpecCodeResponse{StatusCode: http.StatusOK,
Response: data.Response{
+ Data: &output,
+ Code: 2000001,
+ Message: "The version of manager-api and apisix are not
matched.",
Review comment:
```suggestion
Message: "The manager-api and apache apisix are
mismatched.",
```
##########
File path: api/internal/handler/tool/tool.go
##########
@@ -17,28 +17,48 @@
package tool
import (
+ "net/http"
+
"github.com/gin-gonic/gin"
"github.com/shiningrush/droplet"
+ "github.com/shiningrush/droplet/data"
wgin "github.com/shiningrush/droplet/wrapper/gin"
+ "github.com/apisix/manager-api/internal/core/entity"
+ "github.com/apisix/manager-api/internal/core/store"
"github.com/apisix/manager-api/internal/handler"
"github.com/apisix/manager-api/internal/utils"
)
type Handler struct {
+ serverInfoStore store.Interface
}
type InfoOutput struct {
Hash string `json:"commit_hash"`
Version string `json:"version"`
}
+type nodes struct {
+ Hostname string `json:"hostname"`
+ Version string `json:"version"`
+}
+
+type VersionMatchOutput struct {
+ Matched bool `json:"matched"`
+ DashboardVersion string `json:"dashboard_version"`
+ NotMatchedNodes []nodes `json:"not_matched_nodes"`
Review comment:
recommend using `mismatched_nodes`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]