rpc_plugin_both.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2022 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 || (rpc && portable && plugin)
  15. package server
  16. import (
  17. "encoding/json"
  18. "fmt"
  19. "github.com/lf-edge/ekuiper/internal/plugin"
  20. "strings"
  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 {
  26. return nativeManager.Register(pt, p)
  27. }
  28. }
  29. func (t *Server) doDelete(pt plugin.PluginType, name string, stopRun bool) error {
  30. if pt == plugin.PORTABLE {
  31. return portableManager.Delete(name)
  32. } else {
  33. return nativeManager.Delete(pt, name, stopRun)
  34. }
  35. }
  36. func (t *Server) doDesc(pt plugin.PluginType, name string) (interface{}, error) {
  37. var (
  38. result interface{}
  39. ok bool
  40. )
  41. if pt == plugin.PORTABLE {
  42. result, ok = portableManager.GetPluginInfo(name)
  43. } else {
  44. result, ok = nativeManager.GetPluginInfo(pt, name)
  45. }
  46. if !ok {
  47. return nil, fmt.Errorf("not found")
  48. }
  49. return result, nil
  50. }
  51. func (t *Server) doShow(pt plugin.PluginType) (string, error) {
  52. var result string
  53. if pt == plugin.PORTABLE {
  54. l := portableManager.List()
  55. jb, err := json.Marshal(l)
  56. if err != nil {
  57. return "", err
  58. }
  59. return string(jb), nil
  60. } else {
  61. l := nativeManager.List(pt)
  62. if len(l) == 0 {
  63. result = "No plugin is found."
  64. } else {
  65. result = strings.Join(l, "\n")
  66. }
  67. return result, nil
  68. }
  69. }