Skip to content

Commit

Permalink
refactor(orc8r): Replace multi.go with hashicorp/go-multierror module (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzurbonsen authored and emakeev committed Aug 5, 2022
1 parent f8f041e commit e9a0cd9
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 346 deletions.
2 changes: 1 addition & 1 deletion cwf/cloud/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jxskiss/base62 v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cwf/cloud/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
2 changes: 2 additions & 0 deletions cwf/gateway/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ require (
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/ishidawataru/sctp v0.0.0-20191218070446-00ab2ac2db07 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
4 changes: 3 additions & 1 deletion cwf/gateway/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
2 changes: 1 addition & 1 deletion cwf/k8s/cwf_operator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iP
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
Expand Down
2 changes: 1 addition & 1 deletion dp/cloud/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jxskiss/base62 v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions dp/cloud/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
2 changes: 1 addition & 1 deletion feg/cloud/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require (
github.com/google/uuid v1.1.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jxskiss/base62 v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions feg/cloud/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
2 changes: 2 additions & 0 deletions feg/gateway/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.1.2
github.com/hashicorp/go-multierror v1.1.1
github.com/ishidawataru/sctp v0.0.0-20191218070446-00ab2ac2db07
github.com/labstack/echo/v4 v4.2.1
github.com/mennanov/fieldmask-utils v0.5.0
Expand Down Expand Up @@ -93,6 +94,7 @@ require (
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
Expand Down
3 changes: 2 additions & 1 deletion feg/gateway/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,9 @@ github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"sync"

"github.com/golang/glog"
"github.com/hashicorp/go-multierror"

fegprotos "magma/feg/cloud/go/protos"
"magma/feg/gateway/multiplex"
"magma/feg/gateway/policydb"
"magma/feg/gateway/services/session_proxy/credit_control/gx"
"magma/feg/gateway/services/session_proxy/credit_control/gy"
"magma/lte/cloud/go/protos"
"magma/orc8r/lib/go/merrors"
orcprotos "magma/orc8r/lib/go/protos"
)

Expand Down Expand Up @@ -219,12 +219,14 @@ func (srv *CentralSessionControllers) Enable(
ctx context.Context,
void *orcprotos.Void,
) (*orcprotos.Void, error) {
multiError := merrors.NewMulti()
errs := &multierror.Error{}
for i, controller := range srv.centralControllers {
_, err := controller.Enable(ctx, void)
multiError = multiError.AddFmt(err, "error(%d):", i+1)
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error(%d): %v", i+1, err))
}
}
return &orcprotos.Void{}, multiError.AsError()
return &orcprotos.Void{}, errs.ErrorOrNil()
}

// GetHealthStatus retrieves a health status object which contains the current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"time"

"github.com/golang/glog"
"github.com/hashicorp/go-multierror"
"github.com/thoas/go-funk"

fegprotos "magma/feg/cloud/go/protos"
Expand All @@ -30,7 +31,6 @@ import (
"magma/feg/gateway/services/session_proxy/credit_control/gy"
"magma/feg/gateway/services/session_proxy/metrics"
"magma/lte/cloud/go/protos"
"magma/orc8r/lib/go/merrors"
orcprotos "magma/orc8r/lib/go/protos"
)

Expand Down Expand Up @@ -340,20 +340,20 @@ func (srv *CentralSessionController) Enable(
ctx context.Context,
void *orcprotos.Void,
) (*orcprotos.Void, error) {
multiError := merrors.NewMulti()
errs := &multierror.Error{}
if !srv.cfg.DisableGx {
err := srv.policyClient.EnableConnections()
if err != nil {
multiError.Add(fmt.Errorf("An error occurred while enabling connections; policyClient err: %s", err))
errs = multierror.Append(errs, fmt.Errorf("An error occurred while enabling connections; policyClient err: %s", err))
}
}
if !srv.cfg.DisableGy {
err := srv.creditClient.EnableConnections()
if err != nil {
multiError.Add(fmt.Errorf("An error occurred while enabling connections; creditClient err: %s", err))
errs = multierror.Append(errs, fmt.Errorf("An error occurred while enabling connections; creditClient err: %s", err))
}
}
return &orcprotos.Void{}, multiError.AsError()
return &orcprotos.Void{}, errs.ErrorOrNil()
}

// GetHealthStatus retrieves a health status object which contains the current
Expand Down
11 changes: 7 additions & 4 deletions feg/gateway/services/swx_proxy/servicers/multiple_swx_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (
"context"
"fmt"

"github.com/hashicorp/go-multierror"

fegprotos "magma/feg/cloud/go/protos"
"magma/feg/gateway/multiplex"
"magma/orc8r/lib/go/merrors"
orcprotos "magma/orc8r/lib/go/protos"
)

Expand Down Expand Up @@ -129,13 +130,15 @@ func (s *SwxProxies) Disable(ctx context.Context, req *fegprotos.DisableMessage)

// Calls Enable on each swx proxy
func (s *SwxProxies) Enable(ctx context.Context, req *orcprotos.Void) (*orcprotos.Void, error) {
multiError := merrors.NewMulti()
errs := &multierror.Error{}
for i, proxy := range s.proxies {
proxy.connMan.Enable()
_, err := proxy.connMan.GetConnection(proxy.smClient, proxy.config.ServerCfg)
multiError = multiError.AddFmt(err, "error(%d):", i+1)
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error(%d): %v", i+1, err))
}
}
return &orcprotos.Void{}, multiError.AsError()
return &orcprotos.Void{}, errs.ErrorOrNil()
}

// Calls GetHealthStatus on each Swx Proxy
Expand Down
2 changes: 1 addition & 1 deletion lte/cloud/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.2
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-multierror v1.1.1
github.com/influxdata/tdigest v0.0.1
github.com/labstack/echo v3.3.10+incompatible
github.com/lib/pq v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions lte/cloud/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down
2 changes: 1 addition & 1 deletion orc8r/cloud/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.1.2
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-multierror v1.1.1
github.com/imdario/mergo v0.3.5
github.com/jxskiss/base62 v1.0.0
github.com/labstack/echo v3.3.10+incompatible
Expand Down
3 changes: 2 additions & 1 deletion orc8r/cloud/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,9 @@ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjh
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-msgpack v0.5.4/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/bmatcuk/doublestar"
"github.com/golang/glog"
"github.com/golang/protobuf/ptypes"
"github.com/hashicorp/go-multierror"
"golang.org/x/crypto/bcrypt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand All @@ -36,7 +37,6 @@ import (
certprotos "magma/orc8r/cloud/go/services/certifier/protos"
"magma/orc8r/cloud/go/services/certifier/storage"
"magma/orc8r/cloud/go/services/tenants"
"magma/orc8r/lib/go/merrors"
"magma/orc8r/lib/go/protos"
"magma/orc8r/lib/go/security/cert"
unarylib "magma/orc8r/lib/go/service/middleware/unary"
Expand Down Expand Up @@ -297,27 +297,27 @@ func (srv *CertifierServer) CollectGarbageImpl(ctx context.Context) (int, error)
if err != nil {
return 0, err
}
var multiErr *merrors.Multi
errs := &multierror.Error{}
count := 0
for _, sn := range snList.Sns {
certInfo, err := srv.getCertInfo(sn)
if err != nil {
multiErr.AddFmt(err, "'%s' get info error:", sn)
errs = multierror.Append(errs, fmt.Errorf("'%s' get info error: %v", sn, err))
}
notAfter, _ := ptypes.Timestamp(certInfo.NotAfter)
notAfter = notAfter.Add(CollectGarbageAfter)
if time.Now().UTC().After(notAfter) {
err = srv.store.DeleteCertInfo(sn)
if err != nil {
multiErr.AddFmt(err, "'%s' delete error:", sn)
errs = multierror.Append(errs, fmt.Errorf("'%s' delete error: %v", sn, err))
} else {
count += 1
}
}
}
if multiErr.AsError() != nil {
glog.Errorf("Failed to delete certificate[s]: %v", multiErr)
return count, status.Error(codes.Internal, multiErr.Error())
if errs.ErrorOrNil() != nil {
glog.Errorf("Failed to delete certificate[s]: %v", errs)
return count, status.Error(codes.Internal, errs.Error())
}
return count, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"

"github.com/golang/glog"
"github.com/hashicorp/go-multierror"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

Expand All @@ -28,7 +29,6 @@ import (
"magma/orc8r/cloud/go/services/state/indexer"
"magma/orc8r/cloud/go/services/state/protos"
state_types "magma/orc8r/cloud/go/services/state/types"
"magma/orc8r/lib/go/merrors"
)

const (
Expand Down Expand Up @@ -117,39 +117,36 @@ func setSecondaryStates(ctx context.Context, networkID string, states state_type
if len(sessionIDToIMSI) == 0 && len(cTeidToHwId) == 0 {
return stateErrors, nil
}
multiError := merrors.NewMulti()
errs := &multierror.Error{}
if len(sessionIDToIMSI) != 0 {
err := directoryd.MapSessionIDsToIMSIs(ctx, networkID, sessionIDToIMSI)
multiError = multiError.AddFmt(err, "failed to update directoryd mapping of session IDs to IMSIs %+v", sessionIDToIMSI)
errs = errsAppend(errs, "failed to update directoryd mapping of session IDs to IMSIs %+v %v", sessionIDToIMSI, err)
}
if len(cTeidToHwId) != 0 {
err := directoryd.MapSgwCTeidToHWID(ctx, networkID, cTeidToHwId)
multiError = multiError.AddFmt(err, "failed to update directoryd mapping of control plane teid To HwID %+v", sessionIDToIMSI)
errs = errsAppend(errs, "failed to update directoryd mapping of control plane teid To HwID %+v %v", sessionIDToIMSI, err)
}
if len(uTeidToHwId) != 0 {
err := directoryd.MapSgwUTeidToHWID(ctx, networkID, uTeidToHwId)
multiError = multiError.AddFmt(err, "failed to update directoryd mapping of user plane teid To HwID %+v", sessionIDToIMSI)
errs = errsAppend(errs, "failed to update directoryd mapping of user plane teid To HwID %+v %v", sessionIDToIMSI, err)
}

// multiError will only be nil if both updates succeeded
return stateErrors, multiError.AsError()
// errs will only be nil if both updates succeeded
return stateErrors, errs.ErrorOrNil()
}

// unsetSecondaryStates removes {sessionID -> IMSI} and {TEID -> HWID} mappings
func unsetSecondaryStates(ctx context.Context, networkID string, states state_types.StatesByID) (state_types.StateErrors, error) {
sessionIDToIMSI, cTeidToHwId, uTeidToHwId, stateErrors := getMappings(states)
multiError := merrors.NewMulti()
errs := &multierror.Error{}

err := unsetTeids(ctx, controlPlaneTeid, networkID, cTeidToHwId)
multiError = multiError.Add(err)

errs = multierror.Append(errs, err)
err = unsetTeids(ctx, userPlaneTeid, networkID, uTeidToHwId)
multiError = multiError.Add(err)

errs = multierror.Append(errs, err)
err = unsetSessionIDs(ctx, networkID, sessionIDToIMSI)
multiError = multiError.Add(err)

return stateErrors, multiError.AsError()
errs = multierror.Append(errs, err)
return stateErrors, errs.ErrorOrNil()
}

// unsetTeids removes teidType {TEID -> TEID} mappings
Expand Down Expand Up @@ -279,3 +276,11 @@ func getTeidToHwIdPair(tType teidType, record *directoryd_types.DirectoryRecord)
}
return teids, hwid, err
}

// errsAppend concatenates message, sessionIDToIMSI and err into a new error message and appends to errs
func errsAppend(errs *multierror.Error, message string, sessionIDToIMSI map[string]string, err error) *multierror.Error {
if err != nil {
errs = multierror.Append(errs, fmt.Errorf(message, sessionIDToIMSI, err))
}
return errs
}

0 comments on commit e9a0cd9

Please sign in to comment.