@@ -20,74 +20,11 @@ After successful registration, the planner will call the functions **_NextState_
2020[ gRPC] ( https://grpc.io/ ) . The bi-directional streaming is implemented on ** _ NextState_ ** which has demonstrated an
2121improvement on the planner's performance.
2222
23- ## Implementing new plugins
23+ ## Using GRPC to launch an actuator
2424
25- To implement a new actuator plugin, the developer needs to follow these steps:
25+ The [ plugins_helper] ( ../plugins/plugins_helper.go ) provides a function that can be used to connect an actuator with the
26+ rest of the framework. To do so, the user will need to provide the GRPC endpoint and port for the actuator as well as
27+ for the plugin manager:
2628
27- 1 . Implement the new Actuator callbacks (NextState, Perform and Effect).
28- 2 . Create a plugin stub by calling ** _ plugins.NewActuatorPluginStub_ ** .
29- 3 . Set actuator callbacks for the stub.
30- 4 . Start the Plugin server (listens for actuator gRPC calls).
31- 5 . Register with the plugin-manager.
32- 6 . Wait for termination.
33- 7 . Stop the plugin stub.
34-
35- Skeleton code for an actuator plugin can hence look like this:
36-
37- package main
38-
39- import (
40- "os"
41- "os/signal"
42-
43- plugins "github.com/intel/intent-driven-orchestrationpkg/api/plugins/v1alpha1"
44- "github.com/intel/intent-driven-orchestration/pkg/common"
45- "github.com/intel/intent-driven-orchestration/pkg/controller"
46- "github.com/intel/intent-driven-orchestration/pkg/planner"
47- "github.com/intel/intent-driven-orchestration/pkg/planner/actuators"
48- "k8s.io/klog/v2"
49- ...
50- )
51-
52- func NextState(state *common.State, goal *common.State, profiles map[string]common.Profile)
53- ([] common.State, []float64, []planner.Action) {
54- klog.V(1).InfoS("Invoked NextState() callback")
55- return ...
56- }
57-
58- func Perform(state *common.State, plan []planner.Action) {
59- klog.V(1).InfoS("Invoked Perform() callback")
60- return ...
61- }
62-
63- func (s *RmpodPluginHandler) Effect(state *common.State, profiles map[string]common.Profile) {
64- klog.V(1).InfoS("Invoked Effect() callback")
65- return ...
66- }
67-
68- func main() {
69- klog.InitFlags(nil)
70- ...
71- stub := plugins.NewActuatorPluginStub("plugin name", "plugin endpoint", some-port, "plugin-manager-service", 33333)
72- stub.SetNextStateFunc(NextState)
73- stub.SetPerformFunc(Perform)
74- stub.SetEffectFunc(Effect)
75- err = stub.Start()
76- if err != nil {
77- klog.Fatalf("Error starting plugin server: %s", err)
78- }
79- err = stub.Register()
80- if err != nil {
81- klog.Fatalf("Error registering plugin: %s", err)
82- }
83- signalChan := make(chan os.Signal, 1)
84- signal.Notify(signalChan, os.Interrupt)
85- <-signalChan
86- err = stub.Stop()
87- if err != nil {
88- klog.Fatalf("Error stopping plugin server: %s", err)
89- }
90- }
91-
92- Example usage in the current set of supported plugins can be found in the plugins folder under the root directory of the
93- repository.
29+ actuator := <...>
30+ plugins.StartActuatorPlugin(actuator, "localhost", 12345, "localhost", "33333")
0 commit comments