mirror of
https://github.com/datarhei/core.git
synced 2025-10-16 21:10:41 +08:00
Refactor cluster node code
This commit is contained in:
98
cluster/forwarder/process.go
Normal file
98
cluster/forwarder/process.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package forwarder
|
||||
|
||||
import (
|
||||
apiclient "github.com/datarhei/core/v16/cluster/client"
|
||||
"github.com/datarhei/core/v16/restream/app"
|
||||
)
|
||||
|
||||
func (f *Forwarder) ProcessAdd(origin string, config *app.Config) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
r := apiclient.AddProcessRequest{
|
||||
Config: *config,
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessAdd(origin, r))
|
||||
}
|
||||
|
||||
func (f *Forwarder) ProcessUpdate(origin string, id app.ProcessID, config *app.Config) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
r := apiclient.UpdateProcessRequest{
|
||||
Config: *config,
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessUpdate(origin, id, r))
|
||||
}
|
||||
|
||||
func (f *Forwarder) ProcessSetCommand(origin string, id app.ProcessID, command string) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
r := apiclient.SetProcessCommandRequest{
|
||||
Command: command,
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessSetCommand(origin, id, r))
|
||||
}
|
||||
|
||||
func (f *Forwarder) ProcessSetMetadata(origin string, id app.ProcessID, key string, data interface{}) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
r := apiclient.SetProcessMetadataRequest{
|
||||
Metadata: data,
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessSetMetadata(origin, id, key, r))
|
||||
}
|
||||
|
||||
func (f *Forwarder) ProcessRemove(origin string, id app.ProcessID) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessRemove(origin, id))
|
||||
}
|
||||
|
||||
func (f *Forwarder) ProcessesRelocate(origin string, relocations map[app.ProcessID]string) error {
|
||||
if origin == "" {
|
||||
origin = f.ID
|
||||
}
|
||||
|
||||
r := apiclient.RelocateProcessesRequest{
|
||||
Map: relocations,
|
||||
}
|
||||
|
||||
f.lock.RLock()
|
||||
client := f.client
|
||||
f.lock.RUnlock()
|
||||
|
||||
return reconstructError(client.ProcessesRelocate(origin, r))
|
||||
}
|
Reference in New Issue
Block a user