rpc_plugin_native.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 plugin && rpc && core && !portable
  15. // +build plugin,rpc,core,!portable
  16. package server
  17. import (
  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 fmt.Errorf("portable plugin support is disabled")
  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 fmt.Errorf("portable plugin support is disabled")
  32. } else {
  33. return nativeManager.Delete(pt, name, stopRun)
  34. }
  35. }
  36. func (t *Server) doDesc(pt plugin.PluginType, name string) (interface{}, error) {
  37. if pt == plugin.PORTABLE {
  38. return nil, fmt.Errorf("portable plugin support is disabled")
  39. } else {
  40. r, ok := nativeManager.GetPluginInfo(pt, name)
  41. if !ok {
  42. return nil, fmt.Errorf("not found")
  43. }
  44. return r, nil
  45. }
  46. }
  47. func (t *Server) doShow(pt plugin.PluginType) (string, error) {
  48. var result string
  49. if pt == plugin.PORTABLE {
  50. return "", fmt.Errorf("portable plugin support is disabled")
  51. } else {
  52. l := nativeManager.List(pt)
  53. if len(l) == 0 {
  54. result = "No plugin is found."
  55. } else {
  56. result = strings.Join(l, "\n")
  57. }
  58. return result, nil
  59. }
  60. }