mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Refactor cluster node code
This commit is contained in:
@@ -7,21 +7,9 @@ import (
|
||||
"github.com/datarhei/core/v16/restream/app"
|
||||
)
|
||||
|
||||
func (c *cluster) ListProcesses() []store.Process {
|
||||
return c.store.ListProcesses()
|
||||
}
|
||||
|
||||
func (c *cluster) GetProcess(id app.ProcessID) (store.Process, error) {
|
||||
return c.store.GetProcess(id)
|
||||
}
|
||||
|
||||
func (c *cluster) AddProcess(origin string, config *app.Config) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessAdd(origin string, config *app.Config) error {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.AddProcess(origin, config)
|
||||
return c.forwarder.ProcessAdd(origin, config)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -34,13 +22,9 @@ func (c *cluster) AddProcess(origin string, config *app.Config) error {
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
func (c *cluster) RemoveProcess(origin string, id app.ProcessID) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessRemove(origin string, id app.ProcessID) error {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.RemoveProcess(origin, id)
|
||||
return c.forwarder.ProcessRemove(origin, id)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -53,13 +37,9 @@ func (c *cluster) RemoveProcess(origin string, id app.ProcessID) error {
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
func (c *cluster) UpdateProcess(origin string, id app.ProcessID, config *app.Config) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessUpdate(origin string, id app.ProcessID, config *app.Config) error {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.UpdateProcess(origin, id, config)
|
||||
return c.forwarder.ProcessUpdate(origin, id, config)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -73,14 +53,10 @@ func (c *cluster) UpdateProcess(origin string, id app.ProcessID, config *app.Con
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
func (c *cluster) SetProcessCommand(origin string, id app.ProcessID, command string) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessSetCommand(origin string, id app.ProcessID, command string) error {
|
||||
if command == "start" || command == "stop" {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.SetProcessCommand(origin, id, command)
|
||||
return c.forwarder.ProcessSetCommand(origin, id, command)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -94,21 +70,17 @@ func (c *cluster) SetProcessCommand(origin string, id app.ProcessID, command str
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
nodeid, err := c.proxy.FindNodeFromProcess(id)
|
||||
nodeid, err := c.manager.ProcessFindNodeID(id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("the process '%s' is not registered with any node: %w", id.String(), err)
|
||||
}
|
||||
|
||||
return c.proxy.CommandProcess(nodeid, id, command)
|
||||
return c.manager.ProcessCommand(nodeid, id, command)
|
||||
}
|
||||
|
||||
func (c *cluster) RelocateProcesses(origin string, relocations map[app.ProcessID]string) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessesRelocate(origin string, relocations map[app.ProcessID]string) error {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.RelocateProcesses(origin, relocations)
|
||||
return c.forwarder.ProcessesRelocate(origin, relocations)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -121,13 +93,9 @@ func (c *cluster) RelocateProcesses(origin string, relocations map[app.ProcessID
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
func (c *cluster) SetProcessMetadata(origin string, id app.ProcessID, key string, data interface{}) error {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return ErrDegraded
|
||||
}
|
||||
|
||||
func (c *cluster) ProcessSetMetadata(origin string, id app.ProcessID, key string, data interface{}) error {
|
||||
if !c.IsRaftLeader() {
|
||||
return c.forwarder.SetProcessMetadata(origin, id, key, data)
|
||||
return c.forwarder.ProcessSetMetadata(origin, id, key, data)
|
||||
}
|
||||
|
||||
cmd := &store.Command{
|
||||
@@ -142,12 +110,8 @@ func (c *cluster) SetProcessMetadata(origin string, id app.ProcessID, key string
|
||||
return c.applyCommand(cmd)
|
||||
}
|
||||
|
||||
func (c *cluster) GetProcessMetadata(origin string, id app.ProcessID, key string) (interface{}, error) {
|
||||
if ok, _ := c.IsDegraded(); ok {
|
||||
return nil, ErrDegraded
|
||||
}
|
||||
|
||||
p, err := c.store.GetProcess(id)
|
||||
func (c *cluster) ProcessGetMetadata(origin string, id app.ProcessID, key string) (interface{}, error) {
|
||||
p, err := c.store.ProcessGet(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -163,7 +127,3 @@ func (c *cluster) GetProcessMetadata(origin string, id app.ProcessID, key string
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (c *cluster) GetProcessNodeMap() map[string]string {
|
||||
return c.store.GetProcessNodeMap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user