mirror of
https://github.com/datarhei/core.git
synced 2025-10-19 06:14:45 +08:00
Simply return error as-is, check process list length
This commit is contained in:
@@ -154,7 +154,7 @@ func (p *Manager) NodeGet(id string) (*Node, error) {
|
|||||||
|
|
||||||
node, ok := p.nodes[id]
|
node, ok := p.nodes[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("node not found")
|
return nil, fmt.Errorf("node not found: %s", id)
|
||||||
}
|
}
|
||||||
|
|
||||||
return node, nil
|
return node, nil
|
||||||
@@ -538,7 +538,7 @@ func (p *Manager) ProcessList(options client.ProcessListOptions) []api.Process {
|
|||||||
func (p *Manager) ProcessGet(nodeid string, id app.ProcessID, filter []string) (api.Process, error) {
|
func (p *Manager) ProcessGet(nodeid string, id app.ProcessID, filter []string) (api.Process, error) {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return api.Process{}, fmt.Errorf("node not found: %w", err)
|
return api.Process{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := node.Core().ProcessList(client.ProcessListOptions{
|
list, err := node.Core().ProcessList(client.ProcessListOptions{
|
||||||
@@ -550,13 +550,17 @@ func (p *Manager) ProcessGet(nodeid string, id app.ProcessID, filter []string) (
|
|||||||
return api.Process{}, err
|
return api.Process{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(list) == 0 {
|
||||||
|
return api.Process{}, fmt.Errorf("process not found")
|
||||||
|
}
|
||||||
|
|
||||||
return list[0], nil
|
return list[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Manager) ProcessAdd(nodeid string, config *app.Config, metadata map[string]interface{}) error {
|
func (p *Manager) ProcessAdd(nodeid string, config *app.Config, metadata map[string]interface{}) error {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("node not found: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessAdd(config, metadata)
|
return node.Core().ProcessAdd(config, metadata)
|
||||||
@@ -565,7 +569,7 @@ func (p *Manager) ProcessAdd(nodeid string, config *app.Config, metadata map[str
|
|||||||
func (p *Manager) ProcessDelete(nodeid string, id app.ProcessID) error {
|
func (p *Manager) ProcessDelete(nodeid string, id app.ProcessID) error {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("node not found: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessDelete(id)
|
return node.Core().ProcessDelete(id)
|
||||||
@@ -574,7 +578,7 @@ func (p *Manager) ProcessDelete(nodeid string, id app.ProcessID) error {
|
|||||||
func (p *Manager) ProcessUpdate(nodeid string, id app.ProcessID, config *app.Config, metadata map[string]interface{}) error {
|
func (p *Manager) ProcessUpdate(nodeid string, id app.ProcessID, config *app.Config, metadata map[string]interface{}) error {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("node not found: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessUpdate(id, config, metadata)
|
return node.Core().ProcessUpdate(id, config, metadata)
|
||||||
@@ -583,7 +587,7 @@ func (p *Manager) ProcessUpdate(nodeid string, id app.ProcessID, config *app.Con
|
|||||||
func (p *Manager) ProcessReportSet(nodeid string, id app.ProcessID, report *app.Report) error {
|
func (p *Manager) ProcessReportSet(nodeid string, id app.ProcessID, report *app.Report) error {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("node not found: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessReportSet(id, report)
|
return node.Core().ProcessReportSet(id, report)
|
||||||
@@ -592,7 +596,7 @@ func (p *Manager) ProcessReportSet(nodeid string, id app.ProcessID, report *app.
|
|||||||
func (p *Manager) ProcessCommand(nodeid string, id app.ProcessID, command string) error {
|
func (p *Manager) ProcessCommand(nodeid string, id app.ProcessID, command string) error {
|
||||||
node, err := p.NodeGet(nodeid)
|
node, err := p.NodeGet(nodeid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("node not found: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessCommand(id, command)
|
return node.Core().ProcessCommand(id, command)
|
||||||
@@ -604,7 +608,7 @@ func (p *Manager) ProcessProbe(nodeid string, id app.ProcessID) (api.Probe, erro
|
|||||||
probe := api.Probe{
|
probe := api.Probe{
|
||||||
Log: []string{fmt.Sprintf("the node %s where the process %s should reside on, doesn't exist", nodeid, id.String())},
|
Log: []string{fmt.Sprintf("the node %s where the process %s should reside on, doesn't exist", nodeid, id.String())},
|
||||||
}
|
}
|
||||||
return probe, fmt.Errorf("node not found: %w", err)
|
return probe, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessProbe(id)
|
return node.Core().ProcessProbe(id)
|
||||||
@@ -616,7 +620,7 @@ func (p *Manager) ProcessProbeConfig(nodeid string, config *app.Config) (api.Pro
|
|||||||
probe := api.Probe{
|
probe := api.Probe{
|
||||||
Log: []string{fmt.Sprintf("the node %s where the process config should be probed on, doesn't exist", nodeid)},
|
Log: []string{fmt.Sprintf("the node %s where the process config should be probed on, doesn't exist", nodeid)},
|
||||||
}
|
}
|
||||||
return probe, fmt.Errorf("node not found: %w", err)
|
return probe, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return node.Core().ProcessProbeConfig(config)
|
return node.Core().ProcessProbeConfig(config)
|
||||||
|
Reference in New Issue
Block a user