nolint:dupl
(ctx context.Context, sourceClient *managedplugin.Client, destinationsClients managedplugin.Clients, sourceSpec specs.Source, destinationSpecs []specs.Destination, uid string, noMigrate bool)
| 23 | |
| 24 | // nolint:dupl |
| 25 | func syncConnectionV1(ctx context.Context, sourceClient *managedplugin.Client, destinationsClients managedplugin.Clients, sourceSpec specs.Source, destinationSpecs []specs.Destination, uid string, noMigrate bool) error { |
| 26 | var mt metrics.Metrics |
| 27 | var exitReason = ExitReasonStopped |
| 28 | defer func() { |
| 29 | if oldAnalyticsClient != nil { |
| 30 | log.Info().Msg("Sending sync summary to " + oldAnalyticsClient.Host()) |
| 31 | if err := oldAnalyticsClient.SendSyncMetrics(context.Background(), sourceSpec, destinationSpecs, uid, &mt, exitReason); err != nil { |
| 32 | log.Warn().Err(err).Msg("Failed to send sync summary") |
| 33 | } |
| 34 | } |
| 35 | }() |
| 36 | // https://github.com/golang/go/issues/41087 |
| 37 | syncTime := time.Now().UTC().Truncate(time.Microsecond) |
| 38 | destinationStrings := make([]string, len(destinationsClients)) |
| 39 | for i := range destinationsClients { |
| 40 | destinationStrings[i] = destinationSpecs[i].VersionString() |
| 41 | } |
| 42 | log.Info().Str("source", sourceSpec.VersionString()).Strs("destinations", destinationStrings).Time("sync_time", syncTime).Msg("Start sync") |
| 43 | defer log.Info().Str("source", sourceSpec.VersionString()).Strs("destinations", destinationStrings).Time("sync_time", syncTime).Msg("End sync") |
| 44 | |
| 45 | sourcePbClient := source.NewSourceClient(sourceClient.Conn) |
| 46 | destinationsPbClients := make([]destination.DestinationClient, len(destinationsClients)) |
| 47 | for i := range destinationsClients { |
| 48 | destinationsPbClients[i] = destination.NewDestinationClient(destinationsClients[i].Conn) |
| 49 | } |
| 50 | |
| 51 | specBytes, err := json.Marshal(CLISourceSpecToPbSpec(sourceSpec)) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | if _, err := sourcePbClient.Init(ctx, &source.Init_Request{ |
| 56 | Spec: specBytes, |
| 57 | }); err != nil { |
| 58 | return err |
| 59 | } |
| 60 | tablesRes, err := sourcePbClient.GetDynamicTables(ctx, &source.GetDynamicTables_Request{}) |
| 61 | if err != nil { |
| 62 | return err |
| 63 | } |
| 64 | for i := range destinationsClients { |
| 65 | destSpecBytes, err := json.Marshal(CLIDestinationSpecToPbSpec(destinationSpecs[i])) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | if _, err := destinationsPbClients[i].Configure(ctx, &base.Configure_Request{ |
| 70 | Config: destSpecBytes, |
| 71 | }); err != nil { |
| 72 | return err |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | if !noMigrate { |
| 77 | migrateStart := time.Now().UTC() |
| 78 | fmt.Printf("Starting migration for: %s -> %s\n", sourceSpec.VersionString(), destinationStrings) |
| 79 | for i := range destinationsClients { |
| 80 | if _, err := destinationsPbClients[i].Migrate(ctx, &destination.Migrate_Request{ |
| 81 | Tables: tablesRes.Tables, |
| 82 | }); err != nil { |
no test coverage detected