-
Notifications
You must be signed in to change notification settings - Fork 51
/
remote_execution_node.go
70 lines (57 loc) · 1.18 KB
/
remote_execution_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"io"
"golang.org/x/crypto/ssh"
"github.com/reconquest/hierr-go"
"github.com/reconquest/runcmd"
)
type remoteExecutionNode struct {
node *distributedLockNode
command runcmd.CmdWorker
stdin io.WriteCloser
stdout io.WriteCloser
stderr io.WriteCloser
exitCode int
}
func (node *remoteExecutionNode) wait() error {
err := node.command.Wait()
if err != nil {
_ = node.stdout.Close()
_ = node.stderr.Close()
if sshErrors, ok := err.(*ssh.ExitError); ok {
node.exitCode = sshErrors.Waitmsg.ExitStatus()
return fmt.Errorf(
`%s had failed to evaluate command, `+
`remote command exited with non-zero code: %d`,
node.node.String(),
node.exitCode,
)
}
return hierr.Errorf(
err,
`%s failed to finish execution, unexpected error`,
node.node.String(),
)
}
err = node.stdout.Close()
if err != nil {
return hierr.Errorf(
err,
`%s can't close stdout`,
node.node.String(),
)
}
err = node.stderr.Close()
if err != nil {
return hierr.Errorf(
err,
`%s can't close stderr`,
node.node.String(),
)
}
return nil
}
func (node *remoteExecutionNode) String() string {
return node.node.String()
}