@@ -30,79 +30,60 @@ const (
3030)
3131
3232func CreateResourcePoolWaitHandler (ctx context.Context , api sfs.DefaultAPI , projectId , region , resourcePoolId string ) * wait.AsyncActionHandler [sfs.GetResourcePoolResponse ] {
33- handler := wait .New (func () (waitFinished bool , resourcePool * sfs.GetResourcePoolResponse , err error ) {
34- resourcePool , err = api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ()
35- if err != nil {
36- return false , resourcePool , err
37- }
38- if resourcePool == nil ||
39- resourcePool .ResourcePool == nil ||
40- resourcePool .ResourcePool .Id == nil ||
41- resourcePool .ResourcePool .State == nil {
42- return false , resourcePool , fmt .Errorf ("create failed for resourcepool with id %s, the response is not valid (state missing)" , resourcePoolId )
43- }
44- if * resourcePool .ResourcePool .Id == resourcePoolId {
45- switch * resourcePool .ResourcePool .State {
46- case ResourcePoolStateCreated :
47- return true , resourcePool , err
48- default :
49- return false , resourcePool , err
50- }
51- }
33+ waitConfig := wait.WaiterHelper [sfs.GetResourcePoolResponse , string ]{
34+ FetchInstance : api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ,
35+ GetState : GetStateResourcePool ,
36+ ActiveState : []string {ResourcePoolStateCreated },
37+ ErrorState : []string {},
38+ }
5239
53- return false , nil , nil
54- })
40+ handler := wait .New (waitConfig .Wait ())
5541
5642 handler .SetTimeout (10 * time .Minute )
5743 return handler
5844}
5945
6046func UpdateResourcePoolWaitHandler (ctx context.Context , api sfs.DefaultAPI , projectId , region , resourcePoolId string ) * wait.AsyncActionHandler [sfs.GetResourcePoolResponse ] {
61- handler := wait .New (func () (waitFinished bool , resourcePool * sfs.GetResourcePoolResponse , err error ) {
62- resourcePool , err = api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ()
63- if err != nil {
64- return false , resourcePool , err
65- }
66- if resourcePool == nil ||
67- resourcePool .ResourcePool == nil ||
68- resourcePool .ResourcePool .Id == nil ||
69- resourcePool .ResourcePool .State == nil {
70- return false , resourcePool , fmt .Errorf ("update failed for resourcepool with id %s, the response is not valid (state missing)" , resourcePoolId )
71- }
72- if * resourcePool .ResourcePool .Id == resourcePoolId {
73- switch * resourcePool .ResourcePool .State {
74- case ResourcePoolStateCreated :
75- return true , resourcePool , err
76- default :
77- return false , resourcePool , err
78- }
79- }
47+ waitConfig := wait.WaiterHelper [sfs.GetResourcePoolResponse , string ]{
48+ FetchInstance : api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ,
49+ GetState : GetStateResourcePool ,
50+ ActiveState : []string {ResourcePoolStateCreated },
51+ ErrorState : []string {},
52+ }
8053
81- return false , nil , nil
82- })
54+ handler := wait .New (waitConfig .Wait ())
8355
8456 handler .SetTimeout (10 * time .Minute )
8557 return handler
8658}
8759
8860func DeleteResourcePoolWaitHandler (ctx context.Context , api sfs.DefaultAPI , projectId , region , resourcePoolId string ) * wait.AsyncActionHandler [sfs.GetResourcePoolResponse ] {
89- handler := wait .New (func () (waitFinished bool , resourcePool * sfs.GetResourcePoolResponse , err error ) {
90- resourcePool , err = api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ()
91- if err != nil {
92- var oapiError * oapierror.GenericOpenAPIError
93- if errors .As (err , & oapiError ) {
94- if statusCode := oapiError .StatusCode ; statusCode == http .StatusNotFound || statusCode == http .StatusGone {
95- return true , resourcePool , nil
96- }
97- }
98- }
99- return false , nil , nil
100- })
61+ waitConfig := wait.WaiterHelper [sfs.GetResourcePoolResponse , string ]{
62+ FetchInstance : api .GetResourcePool (ctx , projectId , region , resourcePoolId ).Execute ,
63+ GetState : GetStateResourcePool ,
64+ ActiveState : []string {},
65+ ErrorState : []string {},
66+ }
67+
68+ handler := wait .New (waitConfig .Wait ())
10169
10270 handler .SetTimeout (10 * time .Minute )
10371 return handler
10472}
10573
74+ func GetStateResourcePool (response * sfs.GetResourcePoolResponse ) (string , error ) {
75+ if response == nil {
76+ return "" , errors .New ("empty response" )
77+ }
78+ if response .ResourcePool == nil {
79+ return "" , errors .New ("resource pool is nil" )
80+ }
81+ if response .ResourcePool .State == nil {
82+ return "" , errors .New ("resource pool state is nil" )
83+ }
84+ return * response .ResourcePool .State , nil
85+ }
86+
10687func CreateShareWaitHandler (ctx context.Context , api sfs.DefaultAPI , projectId , region , resourcePoolId , shareId string ) * wait.AsyncActionHandler [sfs.GetShareResponse ] {
10788 handler := wait .New (func () (waitFinished bool , share * sfs.GetShareResponse , err error ) {
10889 share , err = api .GetShare (ctx , projectId , region , resourcePoolId , shareId ).Execute ()
0 commit comments