-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates CLI and Worker to used shared benthos builder (#2882)
- Loading branch information
1 parent
8628960
commit 9a06f7e
Showing
44 changed files
with
5,814 additions
and
4,989 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package sync_cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
mgmtv1alpha1 "github.com/nucleuscloud/neosync/backend/gen/go/protos/mgmt/v1alpha1" | ||
) | ||
|
||
func createJob( | ||
cmd *cmdConfig, | ||
sourceConnection *mgmtv1alpha1.Connection, | ||
destinationConnection *mgmtv1alpha1.Connection, | ||
sourceSchema []*mgmtv1alpha1.DatabaseColumn, | ||
) (*mgmtv1alpha1.Job, error) { | ||
sourceConnOpts, err := toJobSourceOption(sourceConnection) | ||
if err != nil { | ||
return nil, err | ||
} | ||
jobId := uuid.NewString() | ||
if cmd.Source.ConnectionOpts != nil && cmd.Source.ConnectionOpts.JobId != nil && *cmd.Source.ConnectionOpts.JobId != "" { | ||
jobId = *cmd.Source.ConnectionOpts.JobId | ||
} | ||
return &mgmtv1alpha1.Job{ | ||
Id: jobId, | ||
Name: "cli-sync", | ||
AccountId: *cmd.AccountId, | ||
Source: &mgmtv1alpha1.JobSource{ | ||
Options: sourceConnOpts, | ||
}, | ||
Destinations: []*mgmtv1alpha1.JobDestination{toJobDestination(cmd, destinationConnection)}, | ||
Mappings: toJobMappings(sourceSchema), | ||
}, nil | ||
} | ||
|
||
func toJobDestination(cmd *cmdConfig, destinationConnection *mgmtv1alpha1.Connection) *mgmtv1alpha1.JobDestination { | ||
return &mgmtv1alpha1.JobDestination{ | ||
ConnectionId: destinationConnection.Id, | ||
Id: uuid.NewString(), | ||
Options: cmdConfigToDestinationConnectionOptions(cmd), | ||
} | ||
} | ||
|
||
func toJobSourceOption(sourceConnection *mgmtv1alpha1.Connection) (*mgmtv1alpha1.JobSourceOptions, error) { | ||
switch sourceConnection.ConnectionConfig.Config.(type) { | ||
case *mgmtv1alpha1.ConnectionConfig_PgConfig: | ||
return &mgmtv1alpha1.JobSourceOptions{ | ||
Config: &mgmtv1alpha1.JobSourceOptions_Postgres{ | ||
Postgres: &mgmtv1alpha1.PostgresSourceConnectionOptions{ | ||
ConnectionId: sourceConnection.Id, | ||
}, | ||
}, | ||
}, nil | ||
case *mgmtv1alpha1.ConnectionConfig_MysqlConfig: | ||
return &mgmtv1alpha1.JobSourceOptions{ | ||
Config: &mgmtv1alpha1.JobSourceOptions_Mysql{ | ||
Mysql: &mgmtv1alpha1.MysqlSourceConnectionOptions{ | ||
ConnectionId: sourceConnection.Id, | ||
}, | ||
}, | ||
}, nil | ||
case *mgmtv1alpha1.ConnectionConfig_AwsS3Config: | ||
return &mgmtv1alpha1.JobSourceOptions{ | ||
Config: &mgmtv1alpha1.JobSourceOptions_AwsS3{ | ||
AwsS3: &mgmtv1alpha1.AwsS3SourceConnectionOptions{ | ||
ConnectionId: sourceConnection.Id, | ||
}, | ||
}, | ||
}, nil | ||
default: | ||
return nil, fmt.Errorf("unsupported connection type") | ||
} | ||
} | ||
|
||
// if is generated and not idenity then set to generate default | ||
func toJobMappings(sourceSchema []*mgmtv1alpha1.DatabaseColumn) []*mgmtv1alpha1.JobMapping { | ||
mappings := []*mgmtv1alpha1.JobMapping{} | ||
|
||
for _, colInfo := range sourceSchema { | ||
mappings = append(mappings, &mgmtv1alpha1.JobMapping{ | ||
Schema: colInfo.Schema, | ||
Table: colInfo.Table, | ||
Column: colInfo.Column, | ||
Transformer: toTransformer(colInfo), | ||
}) | ||
} | ||
|
||
return mappings | ||
} | ||
|
||
func toTransformer(colInfo *mgmtv1alpha1.DatabaseColumn) *mgmtv1alpha1.JobMappingTransformer { | ||
if colInfo.GeneratedType != nil && colInfo.GetGeneratedType() != "" { | ||
return &mgmtv1alpha1.JobMappingTransformer{ | ||
Config: &mgmtv1alpha1.TransformerConfig{ | ||
Config: &mgmtv1alpha1.TransformerConfig_GenerateDefaultConfig{ | ||
GenerateDefaultConfig: &mgmtv1alpha1.GenerateDefault{}, | ||
}, | ||
}, | ||
} | ||
} | ||
return &mgmtv1alpha1.JobMappingTransformer{ | ||
Config: &mgmtv1alpha1.TransformerConfig{ | ||
Config: &mgmtv1alpha1.TransformerConfig_PassthroughConfig{ | ||
PassthroughConfig: &mgmtv1alpha1.Passthrough{}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.