-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_service_from_pool.go
57 lines (47 loc) · 1.44 KB
/
remove_service_from_pool.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
package pool_client
import (
"github.com/evgeniums/go-backend-helpers/pkg/api"
"github.com/evgeniums/go-backend-helpers/pkg/api/api_client"
"github.com/evgeniums/go-backend-helpers/pkg/op_context"
"github.com/evgeniums/go-backend-helpers/pkg/pool/pool_api"
)
type RemoveServiceFromPool struct{}
func (a *RemoveServiceFromPool) Exec(client api_client.Client, ctx op_context.Context, operation api.Operation) error {
c := ctx.TraceInMethod("RemoveServiceFromPool.Exec")
defer ctx.TraceOutMethod()
err := client.Exec(ctx, operation, nil, nil)
c.SetError(err)
return err
}
func (p *PoolClient) RemoveServiceFromPool(ctx op_context.Context, poolId string, role string, idIsName ...bool) error {
// setup
var err error
c := ctx.TraceInMethod("PoolClient.RemoveServiceFromPool")
onExit := func() {
if err != nil {
c.SetError(err)
}
ctx.TraceOutMethod()
}
defer onExit()
// adjust pool ID
pId, _, err := p.poolId(ctx, poolId, idIsName...)
if err != nil {
return err
}
// prepare and exec handler
handler := &RemoveServiceFromPool{}
poolServiceResource := p.resourceForPoolServices(pId)
roleResource := api.NamedResource("role")
poolServiceResource.AddChild(roleResource)
roleResource.SetId(role)
op := pool_api.RemoveServiceFromPool()
roleResource.AddOperation(op)
err = op.Exec(ctx, api_client.MakeOperationHandler(p.Client(), handler))
if err != nil {
c.SetMessage("failed to exec operation")
return err
}
// done
return nil
}