@@ -3,6 +3,7 @@ package volume
3
3
import (
4
4
"context"
5
5
6
+ "github.com/mitchellh/mapstructure"
6
7
enginetypes "github.com/projecteru2/core/engine/types"
7
8
"github.com/projecteru2/core/resources"
8
9
"github.com/projecteru2/core/resources/volume/models"
@@ -36,11 +37,10 @@ func (v *Plugin) GetDeployArgs(ctx context.Context, nodeName string, deployCount
36
37
}
37
38
38
39
resp := & resources.GetDeployArgsResponse {}
39
- err = resources . ToResp (map [string ]interface {}{
40
+ return resp , mapstructure . Decode (map [string ]interface {}{
40
41
"engine_args" : engineArgs ,
41
42
"resource_args" : resourceArgs ,
42
43
}, resp )
43
- return resp , err
44
44
}
45
45
46
46
// GetReallocArgs .
@@ -60,12 +60,11 @@ func (v *Plugin) GetReallocArgs(ctx context.Context, nodeName string, originReso
60
60
}
61
61
62
62
resp := & resources.GetReallocArgsResponse {}
63
- err = resources . ToResp (map [string ]interface {}{
63
+ return resp , mapstructure . Decode (map [string ]interface {}{
64
64
"engine_args" : engineArgs ,
65
65
"delta" : delta ,
66
66
"resource_args" : resourceArgs ,
67
67
}, resp )
68
- return resp , err
69
68
}
70
69
71
70
// GetRemapArgs .
@@ -81,10 +80,9 @@ func (v *Plugin) GetRemapArgs(ctx context.Context, nodeName string, workloadMap
81
80
}
82
81
83
82
resp := & resources.GetRemapArgsResponse {}
84
- err = resources . ToResp (map [string ]interface {}{
83
+ return resp , mapstructure . Decode (map [string ]interface {}{
85
84
"engine_args" : engineArgs ,
86
85
}, resp )
87
- return resp , err
88
86
}
89
87
90
88
// GetNodesDeployCapacity .
@@ -100,11 +98,10 @@ func (v *Plugin) GetNodesDeployCapacity(ctx context.Context, nodeNames []string,
100
98
}
101
99
102
100
resp := & resources.GetNodesDeployCapacityResponse {}
103
- err = resources . ToResp (map [string ]interface {}{
101
+ return resp , mapstructure . Decode (map [string ]interface {}{
104
102
"nodes" : nodesDeployCapacity ,
105
103
"total" : total ,
106
104
}, resp )
107
- return resp , err
108
105
}
109
106
110
107
// GetMostIdleNode .
@@ -115,11 +112,10 @@ func (v *Plugin) GetMostIdleNode(ctx context.Context, nodeNames []string) (*reso
115
112
}
116
113
117
114
resp := & resources.GetMostIdleNodeResponse {}
118
- err = resources . ToResp (map [string ]interface {}{
115
+ return resp , mapstructure . Decode (map [string ]interface {}{
119
116
"node" : nodeName ,
120
117
"priority" : priority ,
121
118
}, resp )
122
- return resp , err
123
119
}
124
120
125
121
// GetNodeResourceInfo .
@@ -168,11 +164,10 @@ func (v *Plugin) SetNodeResourceUsage(ctx context.Context, nodeName string, reso
168
164
}
169
165
170
166
resp := & resources.SetNodeResourceUsageResponse {}
171
- err = resources . ToResp (map [string ]interface {}{
167
+ return resp , mapstructure . Decode (map [string ]interface {}{
172
168
"before" : before ,
173
169
"after" : after ,
174
170
}, resp )
175
- return resp , err
176
171
}
177
172
178
173
// SetNodeResourceCapacity .
@@ -205,11 +200,10 @@ func (v *Plugin) SetNodeResourceCapacity(ctx context.Context, nodeName string, r
205
200
}
206
201
207
202
resp := & resources.SetNodeResourceCapacityResponse {}
208
- err = resources . ToResp (map [string ]interface {}{
203
+ return resp , mapstructure . Decode (map [string ]interface {}{
209
204
"before" : before ,
210
205
"after" : after ,
211
206
}, resp )
212
- return resp , err
213
207
}
214
208
215
209
// SetNodeResourceInfo .
@@ -250,11 +244,10 @@ func (v *Plugin) AddNode(ctx context.Context, nodeName string, resourceOpts core
250
244
}
251
245
252
246
resp := & resources.AddNodeResponse {}
253
- err = resources . ToResp (map [string ]interface {}{
247
+ return resp , mapstructure . Decode (map [string ]interface {}{
254
248
"capacity" : nodeResourceInfo .Capacity ,
255
249
"usage" : nodeResourceInfo .Usage ,
256
250
}, resp )
257
- return resp , err
258
251
}
259
252
260
253
// RemoveNode .
@@ -304,18 +297,16 @@ func (v *Plugin) getNodeResourceInfo(ctx context.Context, nodeName string, workl
304
297
}
305
298
306
299
resp := & resources.GetNodeResourceInfoResponse {}
307
- err = resources . ToResp (map [string ]interface {}{
300
+ return resp , mapstructure . Decode (map [string ]interface {}{
308
301
"resource_info" : nodeResourceInfo ,
309
302
"diffs" : diffs ,
310
303
}, resp )
311
- return resp , err
312
304
}
313
305
314
306
// GetMetricsDescription .
315
307
func (v * Plugin ) GetMetricsDescription (ctx context.Context ) (* resources.GetMetricsDescriptionResponse , error ) {
316
308
resp := & resources.GetMetricsDescriptionResponse {}
317
- err := resources .ToResp (v .v .GetMetricsDescription (), resp )
318
- return resp , err
309
+ return resp , mapstructure .Decode (v .v .GetMetricsDescription (), resp )
319
310
}
320
311
321
312
// ResolveNodeResourceInfoToMetrics .
@@ -330,6 +321,5 @@ func (v *Plugin) ResolveNodeResourceInfoToMetrics(ctx context.Context, podName s
330
321
331
322
metrics := v .v .ResolveNodeResourceInfoToMetrics (podName , nodeName , capacity , usage )
332
323
resp := & resources.ResolveNodeResourceInfoToMetricsResponse {}
333
- err := resources .ToResp (metrics , resp )
334
- return resp , err
324
+ return resp , mapstructure .Decode (metrics , resp )
335
325
}
0 commit comments