Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
0f23c128
Verified
Commit
0f23c128
authored
8 months ago
by
Malte Bauch
Browse files
Options
Downloads
Patches
Plain Diff
Use same connection for plugins
parent
8ad9894b
No related branches found
No related tags found
1 merge request
!1074
Resolve "Too many open files"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controller/nucleus/plugin.go
+49
-28
49 additions, 28 deletions
controller/nucleus/plugin.go
with
49 additions
and
28 deletions
controller/nucleus/plugin.go
+
49
−
28
View file @
0f23c128
...
@@ -16,6 +16,13 @@ import (
...
@@ -16,6 +16,13 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson"
)
)
type
pluginConnection
struct
{
client
*
hcplugin
.
Client
model
shared
.
DeviceModel
}
var
pluginClients
=
make
(
map
[
uuid
.
UUID
]
pluginConnection
,
0
)
// Plugin is the controllers internal representation of a plugin.
// Plugin is the controllers internal representation of a plugin.
type
Plugin
struct
{
type
Plugin
struct
{
UUID
uuid
.
UUID
UUID
uuid
.
UUID
...
@@ -66,6 +73,11 @@ func NewPlugin(id uuid.UUID, execPath string) (*Plugin, error) {
...
@@ -66,6 +73,11 @@ func NewPlugin(id uuid.UUID, execPath string) (*Plugin, error) {
}
}
}
}
pluginClients
[
id
]
=
pluginConnection
{
client
:
client
,
model
:
model
,
}
return
&
Plugin
{
return
&
Plugin
{
UUID
:
id
,
UUID
:
id
,
client
:
client
,
client
:
client
,
...
@@ -78,43 +90,52 @@ func NewPlugin(id uuid.UUID, execPath string) (*Plugin, error) {
...
@@ -78,43 +90,52 @@ func NewPlugin(id uuid.UUID, execPath string) (*Plugin, error) {
// NewPluginThroughReattachConfig creates a new Plugin through a reattach config.
// NewPluginThroughReattachConfig creates a new Plugin through a reattach config.
func
NewPluginThroughReattachConfig
(
loadedPlugin
plugin
.
LoadedPlugin
)
(
plugin
.
Plugin
,
error
)
{
func
NewPluginThroughReattachConfig
(
loadedPlugin
plugin
.
LoadedPlugin
)
(
plugin
.
Plugin
,
error
)
{
client
:=
hcplugin
.
NewClient
(
&
hcplugin
.
ClientConfig
{
//client := hcplugin.NewClient(&hcplugin.ClientConfig{
HandshakeConfig
:
shared
.
Handshake
,
// HandshakeConfig: shared.Handshake,
Plugins
:
shared
.
PluginMap
,
// Plugins: shared.PluginMap,
Reattach
:
&
loadedPlugin
.
ReattachConfig
,
// Reattach: &loadedPlugin.ReattachConfig,
AllowedProtocols
:
[]
hcplugin
.
Protocol
{
hcplugin
.
ProtocolGRPC
},
// AllowedProtocols: []hcplugin.Protocol{hcplugin.ProtocolGRPC},
})
//})
// create a client that is within the AllowedProtocols. In this case this
//// create a client that is within the AllowedProtocols. In this case this
// returns a gRPCClient. Allows to connect through gRPC.
//// returns a gRPCClient. Allows to connect through gRPC.
gRPCClient
,
err
:=
client
.
Client
()
//gRPCClient, err := client.Client()
//if err != nil {
// return nil, err
//}
//// Request the plugin. This returns the gRPC client from the
//// DeviceModelPlugin. This can then be casted to the interface that we are
//// exposing through the plugin (in this case "DeviceModel").
//raw, err := gRPCClient.Dispense("deviceModel")
//if err != nil {
// return nil, err
//}
//// cast the raw plugin to the DeviceModel interface. This allows to call
//// methods on the plugin as if it were a normal DeviceModel instance but
//// actually they are executed on the plugin sent through gRPC.
//model, ok := raw.(shared.DeviceModel)
//if !ok {
// return nil, customerrs.InvalidTypeAssertionError{
// Value: model,
// Type: (*shared.DeviceModel)(nil),
// }
//}
pluginId
,
err
:=
uuid
.
Parse
(
loadedPlugin
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
// Request the plugin. This returns the gRPC client from the
pc
,
ok
:=
pluginClients
[
pluginId
]
// DeviceModelPlugin. This can then be casted to the interface that we are
// exposing through the plugin (in this case "DeviceModel").
raw
,
err
:=
gRPCClient
.
Dispense
(
"deviceModel"
)
if
err
!=
nil
{
return
nil
,
err
}
// cast the raw plugin to the DeviceModel interface. This allows to call
// methods on the plugin as if it were a normal DeviceModel instance but
// actually they are executed on the plugin sent through gRPC.
model
,
ok
:=
raw
.
(
shared
.
DeviceModel
)
if
!
ok
{
if
!
ok
{
return
nil
,
customerrs
.
InvalidTypeAssertionError
{
return
nil
,
fmt
.
Errorf
(
"plugin not found"
)
Value
:
model
,
Type
:
(
*
shared
.
DeviceModel
)(
nil
),
}
}
}
return
&
Plugin
{
return
&
Plugin
{
UUID
:
uuid
.
MustParse
(
loadedPlugin
.
ID
),
UUID
:
uuid
.
MustParse
(
loadedPlugin
.
ID
),
client
:
client
,
client
:
pc
.
client
,
DeviceModel
:
model
,
DeviceModel
:
pc
.
model
,
manifest
:
&
loadedPlugin
.
Manifest
,
manifest
:
&
loadedPlugin
.
Manifest
,
state
:
plugin
.
INITIALIZED
,
state
:
plugin
.
INITIALIZED
,
},
nil
},
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment