-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
172 lines (170 loc) · 5.43 KB
/
info.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package workflow
import (
"github.com/pkg/errors"
"github.com/protoflow-labs/protoflow/pkg/graph"
"github.com/protoflow-labs/protoflow/pkg/graph/node/data"
)
// TODO breadchris separate "infer" and "collect" type information
// TODO breadchris node.Type should be passed workflow since a node's info can depend on other nodes
func (w *Workflow) GetNodeInfo(n graph.Node) (*graph.Info, error) {
var resp *graph.Info
switch n.(type) {
case *data.InputNode:
listeners := n.Subscribers()
if len(listeners) != 1 {
// TODO breadchris support multiple listeners
return nil, errors.Errorf("input node should have 1 child, got %d", len(listeners))
}
// TODO breadchris only designed for 1 child
for _, l := range listeners {
child := l.GetNode()
return w.GetNodeInfo(child)
}
//case *code.FunctionNode:
// var (
// childInputs []protoreflect.MessageDescriptor
// parentOutputs []protoreflect.MessageDescriptor
// streamingChild bool
// streamingParent bool
// )
//
// // TODO breadchris if there is no publisher to determine the input type, try to see if the type already exists
// if len(n.Publishers()) == 0 {
// return n.Type()
// }
//
// // TODO breadchris if two function nodes are connected, you can't infer the type
// // make sure an infinite loop doesn't happen
// for _, listener := range n.Subscribers() {
// child := listener.GetNode()
// switch n.(type) {
// case *code.FunctionNode:
// log.Warn().
// Str("parent", n.NormalizedName()).
// Str("child", child.NormalizedName()).
// Msg("function node connected to function node not supported yet")
// continue
// }
//
// childType, err := w.GetNodeInfo(n)
// if err != nil {
// return nil, err
// }
// if childType == nil {
// return nil, errors.Wrapf(err, "error getting node info for %s", n.NormalizedName())
// }
// if childType.Method.MethodDesc.IsStreamingClient() {
// streamingChild = true
// }
// childInputs = append(childInputs, childType.Method.MethodDesc.Input())
// }
// for _, parent := range n.Publishers() {
// switch n.(type) {
// case *code.FunctionNode:
// log.Warn().
// Str("parent", parent.NormalizedName()).
// Str("child", n.NormalizedName()).
// Msg("function node connected to function node not supported yet")
// continue
// }
//
// parentType, err := w.GetNodeInfo(n)
// if err != nil {
// return nil, err
// }
// if parentType == nil {
// return nil, errors.Wrapf(err, "error getting node info for %s", n.NormalizedName())
// }
// if parentType.Method.MethodDesc.IsStreamingServer() {
// streamingParent = true
// }
// parentOutputs = append(parentOutputs, parentType.Method.MethodDesc.Output())
// }
// inputType, err := graph.MessageFromTypes(n.NormalizedName()+"Request", parentOutputs)
// if err != nil {
// return nil, errors.Wrapf(err, "error building request message for %s", n.NormalizedName())
// }
// outputType, err := graph.MessageFromTypes(n.NormalizedName()+"Response", childInputs)
// if err != nil {
// return nil, errors.Wrapf(err, "error building response message for %s", n.NormalizedName())
// }
//
// req := builder.RpcTypeImportedMessage(inputType, streamingParent)
// res := builder.RpcTypeImportedMessage(outputType, streamingChild)
//
// // TODO breadchris this is a hack to get the name of the function
// s := builder.NewService("Service")
// b := builder.NewMethod(n.NormalizedName(), req, res)
// s.AddMethod(b)
//
// m, err := b.Build()
// if err != nil {
// return nil, err
// }
//
// mthd, err := grpc.NewMethodDescriptor(m.UnwrapMethod())
// if err != nil {
// return nil, err
// }
// return &graph.Info{
// Method: mthd,
// }, nil
//case *worknode.BucketNode:
// // TODO breadchris how do you handle file permissions?
// reqMsg := builder.NewMessage("Request")
// reqMsg = reqMsg.AddField(builder.NewField("path", builder.FieldTypeString()))
// reqMsg = reqMsg.AddField(builder.NewField("data", builder.FieldTypeBytes()))
// req := builder.RpcTypeMessage(reqMsg, true)
//
// resMsg := builder.NewMessage("Response")
// resMsg = resMsg.AddField(builder.NewField("path", builder.FieldTypeString()))
// // TODO breadchris what does this type mean if it streaming or not? sync vs async?
// res := builder.RpcTypeMessage(resMsg, false)
//
// s := builder.NewService("Service")
// b := builder.NewMethod(n.NormalizedName(), req, res)
// s.AddMethod(b)
//
// m, err := b.Build()
// if err != nil {
// return nil, err
// }
//
// mthd, err := grpc.NewMethodDescriptor(m.UnwrapMethod())
// if err != nil {
// return nil, err
// }
// resp = &graph.Type{
// Method: mthd,
// }
//case *worknode.FileNode:
// // TODO breadchris how do you handle file permissions?
// reqMsg := builder.NewMessage("Request")
// req := builder.RpcTypeMessage(reqMsg, false)
//
// resMsg := builder.NewMessage("Response")
// resMsg = resMsg.AddField(builder.NewField("path", builder.FieldTypeString()))
// // TODO breadchris what does this type mean if it streaming or not? sync vs async?
// res := builder.RpcTypeMessage(resMsg, false)
//
// s := builder.NewService("Service")
// b := builder.NewMethod(n.NormalizedName(), req, res)
// s.AddMethod(b)
//
// m, err := b.Build()
// if err != nil {
// return nil, err
// }
//
// mthd, err := grpc.NewMethodDescriptor(m.UnwrapMethod())
// if err != nil {
// return nil, err
// }
// resp = &graph.Type{
// Method: mthd,
// }
default:
return n.Type()
}
return resp, nil
}