rpc_plugin_portable.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 portable && rpc && core && !plugin
  15. // +build portable,rpc,core,!plugin
  16. package server
  17. import (
  18. "encoding/json"
  19. "fmt"
  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 {
  26. return fmt.Errorf("native plugin support is disabled")
  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 fmt.Errorf("native plugin support is disabled")
  34. }
  35. }
  36. func (t *Server) doDesc(pt plugin.PluginType, name string) (interface{}, error) {
  37. if pt == plugin.PORTABLE {
  38. r, ok := portableManager.GetPluginInfo(name)
  39. if !ok {
  40. return nil, fmt.Errorf("not found")
  41. }
  42. return r, nil
  43. } else {
  44. return nil, fmt.Errorf("native plugin support is disabled")
  45. }
  46. }
  47. func (t *Server) doShow(pt plugin.PluginType) (string, error) {
  48. if pt == plugin.PORTABLE {
  49. l := portableManager.List()
  50. jb, err := json.Marshal(l)
  51. if err != nil {
  52. return "", err
  53. }
  54. return string(jb), nil
  55. } else {
  56. return "", fmt.Errorf("native plugin support is disabled")
  57. }
  58. }