forked from choria-io/go-choria
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: R.I.Pienaar <[email protected]>
- Loading branch information
Showing
9 changed files
with
450 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
metadata :name => "executor", | ||
:description => "Choria Process Executor Management", | ||
:author => "R.I.Pienaar <[email protected]>", | ||
:license => "Apache-2.0", | ||
:version => "0.29.4", | ||
:url => "https://choria.io", | ||
:provider => "golang", | ||
:timeout => 20 | ||
|
||
|
||
action "status", :description => "Requests the status of a job by ID" do | ||
display :always | ||
|
||
input :id, | ||
:prompt => "Job ID", | ||
:description => "The unique ID for the job", | ||
:type => :string, | ||
:validation => '.', | ||
:maxlength => 20, | ||
:optional => false | ||
|
||
|
||
|
||
|
||
output :action, | ||
:description => "The RPC Action that started the process", | ||
:type => "string", | ||
:display_as => "Action" | ||
|
||
output :agent, | ||
:description => "The RPC Agent that started the process", | ||
:type => "string", | ||
:display_as => "Agent" | ||
|
||
output :caller, | ||
:description => "The Caller ID who started the process", | ||
:type => "string", | ||
:display_as => "Caller" | ||
|
||
output :exit_code, | ||
:description => "The exit code the process terminated with", | ||
:type => "integer", | ||
:display_as => "Exit Code" | ||
|
||
output :pid, | ||
:description => "The OS Process ID", | ||
:type => "integer", | ||
:display_as => "Pid" | ||
|
||
output :requestid, | ||
:description => "The Request ID that started the process", | ||
:type => "string", | ||
:display_as => "Request ID" | ||
|
||
output :running, | ||
:description => "Indicates if the process is still running", | ||
:type => "boolean", | ||
:display_as => "Running" | ||
|
||
output :start_time, | ||
:description => "Time that the process started", | ||
:type => "string", | ||
:display_as => "Started" | ||
|
||
output :started, | ||
:description => "Indicates if the process was started", | ||
:type => "boolean", | ||
:display_as => "Started" | ||
|
||
output :stderr_bytes, | ||
:description => "The number of bytes of STDERR output available", | ||
:type => "integer", | ||
:display_as => "STDERR Bytes" | ||
|
||
output :stdout_bytes, | ||
:description => "The number of bytes of STDOUT output available", | ||
:type => "integer", | ||
:display_as => "STDOUT Bytes" | ||
|
||
output :terminate_time, | ||
:description => "Time that the process terminated", | ||
:type => "string", | ||
:display_as => "Terminated" | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
{ | ||
"$schema": "https://choria.io/schemas/mcorpc/ddl/v1/agent.json", | ||
"metadata": { | ||
"license": "Apache-2.0", | ||
"author": "R.I.Pienaar \u003c[email protected]\u003e", | ||
"timeout": 20, | ||
"name": "executor", | ||
"version": "0.29.4", | ||
"url": "https://choria.io", | ||
"description": "Choria Process Executor Management", | ||
"provider": "golang" | ||
}, | ||
"actions": [ | ||
{ | ||
"action": "status", | ||
"input": { | ||
"id": { | ||
"prompt": "Job ID", | ||
"description": "The unique ID for the job", | ||
"type": "string", | ||
"maxlength": 20, | ||
"validation": ".", | ||
"optional": false | ||
} | ||
}, | ||
"output": { | ||
"action": { | ||
"description": "The RPC Action that started the process", | ||
"display_as": "Action", | ||
"type": "string" | ||
}, | ||
"agent": { | ||
"description": "The RPC Agent that started the process", | ||
"display_as": "Agent", | ||
"type": "string" | ||
}, | ||
"caller": { | ||
"description": "The Caller ID who started the process", | ||
"display_as": "Caller", | ||
"type": "string" | ||
}, | ||
"exit_code": { | ||
"description": "The exit code the process terminated with", | ||
"display_as": "Exit Code", | ||
"type": "integer" | ||
}, | ||
"pid": { | ||
"description": "The OS Process ID", | ||
"display_as": "Pid", | ||
"type": "integer" | ||
}, | ||
"requestid": { | ||
"description": "The Request ID that started the process", | ||
"display_as": "Request ID", | ||
"type": "string" | ||
}, | ||
"running": { | ||
"description": "Indicates if the process is still running", | ||
"display_as": "Running", | ||
"type": "boolean" | ||
}, | ||
"started": { | ||
"description": "Indicates if the process was started", | ||
"display_as": "Started", | ||
"type": "boolean" | ||
}, | ||
"start_time": { | ||
"description": "Time that the process started", | ||
"display_as": "Started", | ||
"type": "string" | ||
}, | ||
"terminate_time": { | ||
"description": "Time that the process terminated", | ||
"display_as": "Terminated", | ||
"type": "string" | ||
}, | ||
"stdout_bytes": { | ||
"description": "The number of bytes of STDOUT output available", | ||
"display_as": "STDOUT Bytes", | ||
"type": "integer" | ||
}, | ||
"stderr_bytes": { | ||
"description": "The number of bytes of STDERR output available", | ||
"display_as": "STDERR Bytes", | ||
"type": "integer" | ||
} | ||
}, | ||
"display": "always", | ||
"description": "Requests the status of a job by ID" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package executor | ||
|
||
import ( | ||
"github.com/choria-io/go-choria/build" | ||
"github.com/choria-io/go-choria/providers/agent/mcorpc" | ||
"github.com/choria-io/go-choria/server" | ||
"github.com/choria-io/go-choria/server/agents" | ||
) | ||
|
||
var metadata = &agents.Metadata{ | ||
Name: "executor", | ||
Description: "Choria Process Executor Management", | ||
Author: "R.I.Pienaar <[email protected]>", | ||
Version: build.Version, | ||
License: build.License, | ||
Timeout: 20, | ||
URL: "https://choria.io", | ||
} | ||
|
||
func New(mgr server.AgentManager) (*mcorpc.Agent, error) { | ||
log := mgr.Logger() | ||
agent := mcorpc.New("executor", metadata, mgr.Choria(), log) | ||
|
||
agent.SetActivationChecker(func() bool { | ||
return mgr.Choria().Configuration().Choria.ExecutorEnabled | ||
}) | ||
|
||
agent.MustRegisterAction("status", statusAction) | ||
|
||
return agent, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package executor | ||
|
||
import ( | ||
"context" | ||
"github.com/choria-io/go-choria/inter" | ||
"github.com/choria-io/go-choria/providers/agent/mcorpc" | ||
"github.com/choria-io/go-choria/providers/execution" | ||
"time" | ||
) | ||
|
||
type StatusRequest struct { | ||
JobID string `json:"id"` | ||
} | ||
|
||
type StatusResponse struct { | ||
Started bool `json:"started"` | ||
StartTime time.Time `json:"start_time"` | ||
TerminateTime time.Time `json:"terminate_time"` | ||
ExitCode int `json:"exit_code"` | ||
Running bool `json:"running"` | ||
Agent string `json:"agent"` | ||
Action string `json:"action"` | ||
RequestID string `json:"requestid"` | ||
Caller string `json:"caller"` | ||
Pid int `json:"pid"` | ||
StdoutBytes int `json:"stdout_bytes"` | ||
StderrBytes int `json:"stderr_bytes"` | ||
} | ||
|
||
func statusAction(ctx context.Context, req *mcorpc.Request, reply *mcorpc.Reply, agent *mcorpc.Agent, conn inter.ConnectorInfo) { | ||
spool := agent.Config.Choria.ExecutorSpool | ||
|
||
if spool == "" { | ||
abort(reply, "Executor spool is not configured") | ||
return | ||
} | ||
|
||
args := &StatusRequest{} | ||
if !mcorpc.ParseRequestData(args, req, reply) { | ||
return | ||
} | ||
|
||
p, err := execution.Load(spool, args.JobID) | ||
if err != nil { | ||
reply.Statuscode = mcorpc.Aborted | ||
reply.Statusmsg = err.Error() | ||
abort(reply, "Could not load job: %v", err) | ||
return | ||
} | ||
|
||
resp := &StatusResponse{ | ||
Running: p.IsRunning(), | ||
StartTime: p.StartTime, | ||
TerminateTime: p.TerminateTime, | ||
Agent: p.Agent, | ||
Action: p.Action, | ||
RequestID: p.RequestID, | ||
Caller: p.Caller, | ||
Pid: -1, | ||
ExitCode: -1, | ||
} | ||
|
||
resp.Started, err = p.HasStarted() | ||
if err != nil { | ||
abort(reply, "Could not check if job is started: %v", err) | ||
return | ||
} | ||
|
||
if resp.Started { | ||
resp.Pid, err = p.ParsePid() | ||
if err != nil { | ||
abort(reply, "Could not parse pid: %v", err) | ||
return | ||
} | ||
} | ||
|
||
if !resp.Running && resp.Started { | ||
resp.ExitCode, err = p.ParseExitCode() | ||
if err != nil { | ||
abort(reply, "Could not parse exit code: %v", err) | ||
return | ||
} | ||
|
||
b, _ := p.Stderr() | ||
resp.StderrBytes = len(b) | ||
|
||
b, _ = p.Stdout() | ||
resp.StdoutBytes = len(b) | ||
} | ||
|
||
reply.Data = resp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2025, R.I. Pienaar and the Choria Project contributors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package executor | ||
|
||
import ( | ||
"fmt" | ||
"github.com/choria-io/go-choria/providers/agent/mcorpc" | ||
) | ||
|
||
func abort(reply *mcorpc.Reply, format string, a ...any) { | ||
reply.Statuscode = mcorpc.Aborted | ||
reply.Statusmsg = fmt.Sprintf(format, a...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.