rpc_plugin_hasnative.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 && plugin)
  15. package server
  16. import (
  17. "fmt"
  18. "strings"
  19. "github.com/lf-edge/ekuiper/internal/pkg/model"
  20. "github.com/lf-edge/ekuiper/internal/plugin"
  21. )
  22. func (t *Server) RegisterPlugin(arg *model.PluginDesc, reply *string) error {
  23. p, err := getPluginByJson(arg, plugin.FUNCTION)
  24. if err != nil {
  25. return fmt.Errorf("Register plugin functions error: %s", err)
  26. }
  27. if len(p.GetSymbols()) == 0 {
  28. return fmt.Errorf("Register plugin functions error: Missing function list.")
  29. }
  30. err = nativeManager.RegisterFuncs(p.GetName(), p.GetSymbols())
  31. if err != nil {
  32. return fmt.Errorf("Create plugin error: %s", err)
  33. } else {
  34. *reply = fmt.Sprintf("Plugin %s is created.", p.GetName())
  35. }
  36. return nil
  37. }
  38. func (t *Server) ShowUdfs(_ int, reply *string) error {
  39. l := nativeManager.ListSymbols()
  40. if len(l) == 0 {
  41. l = append(l, "No udf is found.")
  42. }
  43. *reply = strings.Join(l, "\n")
  44. return nil
  45. }
  46. func (t *Server) DescUdf(arg string, reply *string) error {
  47. m, ok := nativeManager.GetPluginBySymbol(plugin.FUNCTION, arg)
  48. if !ok {
  49. return fmt.Errorf("Describe udf error: not found")
  50. } else {
  51. j := map[string]string{
  52. "name": arg,
  53. "plugin": m,
  54. }
  55. r, err := marshalDesc(j)
  56. if err != nil {
  57. return fmt.Errorf("Describe udf error: %v", err)
  58. }
  59. *reply = r
  60. }
  61. return nil
  62. }