@@ -49,58 +49,9 @@ func (c *Client) AllocFS() *AllocFS {
49
49
return & AllocFS {client : c }
50
50
}
51
51
52
- // getNodeClient returns a Client that will dial the node. If the QueryOptions
53
- // is set, the function will ensure that it is initialized and that the Params
54
- // field is valid.
55
- func (a * AllocFS ) getNodeClient (node * Node , allocID string , q * * QueryOptions ) (* Client , error ) {
56
- if node .HTTPAddr == "" {
57
- return nil , fmt .Errorf ("http addr of the node where alloc %q is running is not advertised" , allocID )
58
- }
59
-
60
- region := ""
61
- if q != nil && * q != nil && (* q ).Region != "" {
62
- region = (* q ).Region
63
- } else if a .client .config .Region != "" {
64
- // Use the region from the client
65
- region = a .client .config .Region
66
- } else {
67
- // Use the region from the agent
68
- agentRegion , err := a .client .Agent ().Region ()
69
- if err != nil {
70
- return nil , err
71
- }
72
- region = agentRegion
73
- }
74
-
75
- // Get an API client for the node
76
- conf := a .client .config .CopyConfig (node .HTTPAddr , node .TLSEnabled )
77
- conf .TLSConfig .TLSServerName = fmt .Sprintf ("client.%s.nomad" , region )
78
- nodeClient , err := NewClient (conf )
79
- if err != nil {
80
- return nil , err
81
- }
82
-
83
- // Set the query params
84
- if q == nil {
85
- return nodeClient , nil
86
- }
87
-
88
- if * q == nil {
89
- * q = & QueryOptions {}
90
- }
91
- if actQ := * q ; actQ .Params == nil {
92
- actQ .Params = make (map [string ]string )
93
- }
94
- return nodeClient , nil
95
- }
96
-
97
52
// List is used to list the files at a given path of an allocation directory
98
53
func (a * AllocFS ) List (alloc * Allocation , path string , q * QueryOptions ) ([]* AllocFileInfo , * QueryMeta , error ) {
99
- node , _ , err := a .client .Nodes ().Info (alloc .NodeID , & QueryOptions {})
100
- if err != nil {
101
- return nil , nil , err
102
- }
103
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
54
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
104
55
if err != nil {
105
56
return nil , nil , err
106
57
}
@@ -117,11 +68,7 @@ func (a *AllocFS) List(alloc *Allocation, path string, q *QueryOptions) ([]*Allo
117
68
118
69
// Stat is used to stat a file at a given path of an allocation directory
119
70
func (a * AllocFS ) Stat (alloc * Allocation , path string , q * QueryOptions ) (* AllocFileInfo , * QueryMeta , error ) {
120
- node , _ , err := a .client .Nodes ().Info (alloc .NodeID , & QueryOptions {})
121
- if err != nil {
122
- return nil , nil , err
123
- }
124
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
71
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
125
72
if err != nil {
126
73
return nil , nil , err
127
74
}
@@ -138,12 +85,7 @@ func (a *AllocFS) Stat(alloc *Allocation, path string, q *QueryOptions) (*AllocF
138
85
// ReadAt is used to read bytes at a given offset until limit at the given path
139
86
// in an allocation directory. If limit is <= 0, there is no limit.
140
87
func (a * AllocFS ) ReadAt (alloc * Allocation , path string , offset int64 , limit int64 , q * QueryOptions ) (io.ReadCloser , error ) {
141
- node , _ , err := a .client .Nodes ().Info (alloc .NodeID , & QueryOptions {})
142
- if err != nil {
143
- return nil , err
144
- }
145
-
146
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
88
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
147
89
if err != nil {
148
90
return nil , err
149
91
}
@@ -161,12 +103,7 @@ func (a *AllocFS) ReadAt(alloc *Allocation, path string, offset int64, limit int
161
103
// Cat is used to read contents of a file at the given path in an allocation
162
104
// directory
163
105
func (a * AllocFS ) Cat (alloc * Allocation , path string , q * QueryOptions ) (io.ReadCloser , error ) {
164
- node , _ , err := a .client .Nodes ().Info (alloc .NodeID , & QueryOptions {})
165
- if err != nil {
166
- return nil , err
167
- }
168
-
169
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
106
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
170
107
if err != nil {
171
108
return nil , err
172
109
}
@@ -190,12 +127,7 @@ func (a *AllocFS) Cat(alloc *Allocation, path string, q *QueryOptions) (io.ReadC
190
127
func (a * AllocFS ) Stream (alloc * Allocation , path , origin string , offset int64 ,
191
128
cancel <- chan struct {}, q * QueryOptions ) (<- chan * StreamFrame , error ) {
192
129
193
- node , _ , err := a .client .Nodes ().Info (alloc .NodeID , q )
194
- if err != nil {
195
- return nil , err
196
- }
197
-
198
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
130
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
199
131
if err != nil {
200
132
return nil , err
201
133
}
@@ -259,14 +191,12 @@ func (a *AllocFS) Stream(alloc *Allocation, path, origin string, offset int64,
259
191
func (a * AllocFS ) Logs (alloc * Allocation , follow bool , task , logType , origin string ,
260
192
offset int64 , cancel <- chan struct {}, q * QueryOptions ) (<- chan * StreamFrame , error ) {
261
193
262
- node , _ , err := a .client .Nodes (). Info (alloc .NodeID , q )
194
+ nodeClient , err := a .client .GetNodeClient (alloc .NodeID , q )
263
195
if err != nil {
264
196
return nil , err
265
197
}
266
-
267
- nodeClient , err := a .getNodeClient (node , alloc .ID , & q )
268
- if err != nil {
269
- return nil , err
198
+ if q == nil {
199
+ q = & QueryOptions {}
270
200
}
271
201
q .Params ["follow" ] = strconv .FormatBool (follow )
272
202
q .Params ["task" ] = task
0 commit comments