rpc_plugin_wasm.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2023-2023 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //go:build !core && wasmedge
  15. package server
  16. import (
  17. "encoding/json"
  18. "fmt"
  19. "strings"
  20. "github.com/lf-edge/ekuiper/internal/plugin"
  21. )
  22. func (t *Server) doRegister(pt plugin.PluginType, p plugin.Plugin) error {
  23. if pt == plugin.PORTABLE {
  24. return portableManager.Register(p)
  25. } else if pt == plugin.WASM {
  26. return wasmManager.Register(p)
  27. } else {
  28. return nativeManager.Register(pt, p)
  29. }
  30. }
  31. func (t *Server) doDelete(pt plugin.PluginType, name string, stopRun bool) error {
  32. if pt == plugin.PORTABLE {
  33. return portableManager.Delete(name)
  34. } else if pt == plugin.WASM {
  35. return wasmManager.Delete(name)
  36. } else {
  37. return nativeManager.Delete(pt, name, stopRun)
  38. }
  39. }
  40. func (t *Server) doDesc(pt plugin.PluginType, name string) (interface{}, error) {
  41. var (
  42. result interface{}
  43. ok bool
  44. )
  45. if pt == plugin.PORTABLE {
  46. result, ok = portableManager.GetPluginInfo(name)
  47. } else if pt == plugin.WASM {
  48. result, ok = wasmManager.GetPluginInfo(name)
  49. } else {
  50. result, ok = nativeManager.GetPluginInfo(pt, name)
  51. }
  52. if !ok {
  53. return nil, fmt.Errorf("not found")
  54. }
  55. return result, nil
  56. }
  57. func (t *Server) doShow(pt plugin.PluginType) (string, error) {
  58. var result string
  59. if pt == plugin.PORTABLE {
  60. l := portableManager.List()
  61. jb, err := json.Marshal(l)
  62. if err != nil {
  63. return "", err
  64. }
  65. return string(jb), nil
  66. } else if pt == plugin.WASM {
  67. l := portableManager.List()
  68. jb, err := json.Marshal(l)
  69. if err != nil {
  70. return "", err
  71. }
  72. return string(jb), nil
  73. } else {
  74. l := nativeManager.List(pt)
  75. if len(l) == 0 {
  76. result = "No plugin is found."
  77. } else {
  78. result = strings.Join(l, "\n")
  79. }
  80. return result, nil
  81. }
  82. }