-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecflow_grpc_client.go
93 lines (77 loc) · 2.13 KB
/
ecflow_grpc_client.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package ecflow_checker
import (
"context"
"encoding/json"
"fmt"
pb "github.com/perillaroc/ecflow-checker/ecflowclient"
"github.com/perillaroc/workflow-model-go"
"google.golang.org/grpc"
_ "google.golang.org/grpc/encoding/gzip"
"log"
)
type EcflowClient struct {
Target string
Connection *grpc.ClientConn
Context context.Context
ServiceClient pb.EcflowClientServiceClient
}
func (c *EcflowClient) Connect() error {
opts := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.UseCompressor("gzip"))}
var err error
c.Connection, err = grpc.Dial(c.Target, opts...)
if err != nil {
return err
}
c.ServiceClient = pb.NewEcflowClientServiceClient(c.Connection)
c.Context = context.Background()
return nil
}
func (c *EcflowClient) Close() {
c.Connection.Close()
}
func (c *EcflowClient) CollectStatusRecords(owner string, repo string, host string, port string) {
r, err := c.ServiceClient.CollectStatusRecords(c.Context, &pb.StatusRequest{
Owner: owner,
Repo: repo,
Host: host,
Port: port,
})
if err != nil {
log.Fatalf("Could not get status: %v", err)
}
log.Printf("Size of records: %d\n", len(r.StatusMap))
bunch := workflowmodel.Bunch{}
for path, status := range r.StatusMap {
bunch.AddNodeStatus(workflowmodel.NodeStatusRecord{Path: path, Status: status})
}
for _, suite := range bunch.Children {
fmt.Printf("%s\n", suite.NodePath())
}
}
func (c *EcflowClient) CollectNode(
owner string, repo string, host string, port string, path string) (*workflowmodel.WorkflowNode, error) {
r, err := c.ServiceClient.CollectNode(c.Context, &pb.NodeRequest{
Owner: owner,
Repo: repo,
Host: host,
Port: port,
Path: path,
})
if err != nil {
err = fmt.Errorf("Could not get status: %v\n", err)
return nil, err
}
if r.ResponseStatus != nil && r.ResponseStatus.HasError {
err = fmt.Errorf("CollectNode has error: %s\n", r.ResponseStatus.ErrorString)
return nil, err
}
var node workflowmodel.WorkflowNode
err = json.Unmarshal([]byte(r.Node), &node)
if err != nil {
err = fmt.Errorf("json.Unmarshal failed: %v\n", err)
return nil, err
}
return &node, err
}