refact: to use go-dbw CreateItems, DeleteItems (#4974)
* refact: to use go-dbw CreateItems, DeleteItems Latest version of go-dbw updated the signature of CreateItems(...) and DeleteItems(...) on a happy note this latest version of go-dbw actually does batch inserts and updates for this functions. * all: regenerate protos with new protoc-gen-go version
This commit is contained in:
167 files changed
+2254
-2248
No files matched your search
@@ -437,7 +437,7 @@ func (r *SetSyncJob) upsertAndCleanHosts(
|
||||
{
|
||||
if len(hi.ipsToRemove) > 0 {
|
||||
oplogMsgs := make([]*oplog.Message, 0, len(hi.ipsToRemove))
|
||||
count, err := w.DeleteItems(ctx, hi.ipsToRemove.toArray(), db.NewOplogMsgs(&oplogMsgs))
|
||||
count, err := w.DeleteItems(ctx, hi.ipsToRemove.toSlice(), db.NewOplogMsgs(&oplogMsgs))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -452,8 +452,8 @@ func (r *SetSyncJob) upsertAndCleanHosts(
|
||||
Target: db.Constraint("host_ip_address_pkey"),
|
||||
Action: db.DoNothing(true),
|
||||
}
|
||||
if err := w.CreateItems(ctx, hi.ipsToAdd.toArray(), db.NewOplogMsgs(&oplogMsgs), db.WithOnConflict(onConflict)); err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("adding ips %v for host %q", hi.ipsToAdd.toArray(), ret.GetPublicId())))
|
||||
if err := w.CreateItems(ctx, hi.ipsToAdd.toSlice(), db.NewOplogMsgs(&oplogMsgs), db.WithOnConflict(onConflict)); err != nil {
|
||||
return errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("adding ips %v for host %q", hi.ipsToAdd.toSlice(), ret.GetPublicId())))
|
||||
}
|
||||
msgs = append(msgs, oplogMsgs...)
|
||||
}
|
||||
@@ -463,7 +463,7 @@ func (r *SetSyncJob) upsertAndCleanHosts(
|
||||
{
|
||||
if len(hi.dnsNamesToRemove) > 0 {
|
||||
oplogMsgs := make([]*oplog.Message, 0, len(hi.dnsNamesToRemove))
|
||||
count, err := w.DeleteItems(ctx, hi.dnsNamesToRemove.toArray(), db.NewOplogMsgs(&oplogMsgs))
|
||||
count, err := w.DeleteItems(ctx, hi.dnsNamesToRemove.toSlice(), db.NewOplogMsgs(&oplogMsgs))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -478,7 +478,7 @@ func (r *SetSyncJob) upsertAndCleanHosts(
|
||||
Target: db.Constraint("host_dns_name_pkey"),
|
||||
Action: db.DoNothing(true),
|
||||
}
|
||||
if err := w.CreateItems(ctx, hi.dnsNamesToAdd.toArray(), db.NewOplogMsgs(&oplogMsgs), db.WithOnConflict(onConflict)); err != nil {
|
||||
if err := w.CreateItems(ctx, hi.dnsNamesToAdd.toSlice(), db.NewOplogMsgs(&oplogMsgs), db.WithOnConflict(onConflict)); err != nil {
|
||||
return err
|
||||
}
|
||||
msgs = append(msgs, oplogMsgs...)
|
||||
|
||||
@@ -138,9 +138,9 @@ func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet
|
||||
}
|
||||
}
|
||||
|
||||
var preferredEndpoints []any
|
||||
var preferredEndpoints []*host.PreferredEndpoint
|
||||
if s.PreferredEndpoints != nil {
|
||||
preferredEndpoints = make([]any, 0, len(s.PreferredEndpoints))
|
||||
preferredEndpoints = make([]*host.PreferredEndpoint, 0, len(s.PreferredEndpoints))
|
||||
for i, e := range s.PreferredEndpoints {
|
||||
obj, err := host.NewPreferredEndpoint(ctx, s.PublicId, uint32(i+1), e)
|
||||
if err != nil {
|
||||
@@ -392,9 +392,9 @@ func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet
|
||||
}
|
||||
|
||||
// Get the preferred endpoints to write out.
|
||||
var preferredEndpoints []any
|
||||
var preferredEndpoints []*host.PreferredEndpoint
|
||||
if endpointOp == endpointOpUpdate {
|
||||
preferredEndpoints = make([]any, 0, len(newSet.PreferredEndpoints))
|
||||
preferredEndpoints = make([]*host.PreferredEndpoint, 0, len(newSet.PreferredEndpoints))
|
||||
for i, e := range newSet.PreferredEndpoints {
|
||||
obj, err := host.NewPreferredEndpoint(ctx, newSet.PublicId, uint32(i+1), e)
|
||||
if err != nil {
|
||||
@@ -454,7 +454,7 @@ func (r *Repository) UpdateSet(ctx context.Context, projectId string, s *HostSet
|
||||
case endpointOpDelete, endpointOpUpdate:
|
||||
if len(currentSet.PreferredEndpoints) > 0 {
|
||||
// Delete all old endpoint entries.
|
||||
var peps []any
|
||||
var peps []*host.PreferredEndpoint
|
||||
for i := 1; i <= len(currentSet.PreferredEndpoints); i++ {
|
||||
p := host.AllocPreferredEndpoint()
|
||||
p.HostSetId, p.Priority = currentSet.GetPublicId(), uint32(i)
|
||||
|
||||
@@ -5,6 +5,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"sort"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -13,22 +14,30 @@ import (
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
)
|
||||
|
||||
// valueToInterfaceMap is a map that has a function to convert values into an
|
||||
// array
|
||||
// valueToInterfaceMap is a map that has a function to convert values into a
|
||||
// slice
|
||||
type valueToInterfaceMap map[string]any
|
||||
|
||||
func (m valueToInterfaceMap) toArray() []any {
|
||||
func (m valueToInterfaceMap) toSlice() any {
|
||||
switch {
|
||||
case m == nil:
|
||||
return nil
|
||||
case len(m) == 0:
|
||||
return make([]any, 0)
|
||||
default:
|
||||
ret := make([]any, 0, len(m))
|
||||
for _, v := range m {
|
||||
ret = append(ret, v)
|
||||
var valueType reflect.Type
|
||||
existingValues := make([]any, 0, len(m))
|
||||
for _, value := range m {
|
||||
valueType = reflect.TypeOf(value) // Assume all values are the same type
|
||||
existingValues = append(existingValues, value)
|
||||
}
|
||||
return ret
|
||||
// Create a slice of the concrete type
|
||||
sliceType := reflect.SliceOf(valueType)
|
||||
sliceValue := reflect.MakeSlice(sliceType, len(m), len(m))
|
||||
for i := 0; i < len(m); i++ {
|
||||
sliceValue.Index(i).Set(reflect.ValueOf(existingValues[i]))
|
||||
}
|
||||
return sliceValue.Interface()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.33.0
|
||||
// protoc-gen-go v1.34.2
|
||||
// protoc (unknown)
|
||||
// source: controller/storage/host/plugin/store/v1/host.proto
|
||||
|
||||
@@ -811,7 +811,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_rawDescGZIP() []byt
|
||||
}
|
||||
|
||||
var file_controller_storage_host_plugin_store_v1_host_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
|
||||
var file_controller_storage_host_plugin_store_v1_host_proto_goTypes = []interface{}{
|
||||
var file_controller_storage_host_plugin_store_v1_host_proto_goTypes = []any{
|
||||
(*HostCatalog)(nil), // 0: controller.storage.host.plugin.store.v1.HostCatalog
|
||||
(*HostSet)(nil), // 1: controller.storage.host.plugin.store.v1.HostSet
|
||||
(*HostCatalogSecret)(nil), // 2: controller.storage.host.plugin.store.v1.HostCatalogSecret
|
||||
@@ -842,7 +842,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_init() {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[0].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*HostCatalog); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -854,7 +854,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[1].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*HostSet); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -866,7 +866,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[2].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*HostCatalogSecret); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -878,7 +878,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[3].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*Host); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -890,7 +890,7 @@ func file_controller_storage_host_plugin_store_v1_host_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_controller_storage_host_plugin_store_v1_host_proto_msgTypes[4].Exporter = func(v any, i int) any {
|
||||
switch v := v.(*HostSetMember); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
|
||||
@@ -125,10 +125,10 @@ func TestHost(t testing.TB, conn *db.DB, catId, externId string, opt ...Option)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, w.Create(ctx, host1))
|
||||
|
||||
var ipAddresses []any
|
||||
var ipAddresses []*host.IpAddress
|
||||
if len(host1.GetIpAddresses()) > 0 {
|
||||
sort.Strings(host1.IpAddresses)
|
||||
ipAddresses = make([]any, 0, len(host1.GetIpAddresses()))
|
||||
ipAddresses = make([]*host.IpAddress, 0, len(host1.GetIpAddresses()))
|
||||
for _, a := range host1.GetIpAddresses() {
|
||||
obj, err := host.NewIpAddress(ctx, host1.PublicId, a)
|
||||
require.NoError(t, err)
|
||||
@@ -137,10 +137,10 @@ func TestHost(t testing.TB, conn *db.DB, catId, externId string, opt ...Option)
|
||||
require.NoError(t, w.CreateItems(ctx, ipAddresses))
|
||||
}
|
||||
|
||||
var dnsNames []any
|
||||
var dnsNames []*host.DnsName
|
||||
if len(host1.GetDnsNames()) > 0 {
|
||||
sort.Strings(host1.DnsNames)
|
||||
dnsNames = make([]any, 0, len(host1.GetDnsNames()))
|
||||
dnsNames = make([]*host.DnsName, 0, len(host1.GetDnsNames()))
|
||||
for _, n := range host1.GetDnsNames() {
|
||||
obj, err := host.NewDnsName(ctx, host1.PublicId, n)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in new issue
Block a user