-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.go
83 lines (71 loc) · 2.11 KB
/
create.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package gjobctl
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"time"
"github.com/aws/aws-sdk-go/service/glue"
)
const (
TimeoutForCreate = 5 * time.Second
)
type CreateOption struct {
JobSettingFile *string `name:"job-setting-file" short:"f" description:"job setting file in json"`
}
func (app *App) Create(ctx context.Context, opt *CreateOption) error {
ctx, cancel := context.WithTimeout(ctx, TimeoutForCreate)
defer cancel()
var fn string
if opt.JobSettingFile != nil {
fn = *opt.JobSettingFile
} else {
fn = app.getJobSettingFileName()
}
f, err := os.Open(fn)
if err != nil {
return fmt.Errorf("failed to open setting file: %w", err)
}
defer f.Close()
// JSONデータを構造体に変換
var job glue.Job
json.NewDecoder(f).Decode(&job)
if err != nil {
return fmt.Errorf("failed to decode json: %w", err)
}
sess, err := app.createAWSSession()
if err != nil {
return err
}
// Glueクライアントを作成
sv := glue.New(sess)
// Glue Jobを更新
r, err := sv.CreateJobWithContext(ctx, &glue.CreateJobInput{
CodeGenConfigurationNodes: job.CodeGenConfigurationNodes,
Command: job.Command,
Connections: job.Connections,
DefaultArguments: job.DefaultArguments,
Description: job.Description,
ExecutionClass: job.ExecutionClass,
ExecutionProperty: job.ExecutionProperty,
GlueVersion: job.GlueVersion,
LogUri: job.LogUri,
MaxRetries: job.MaxRetries,
Name: job.Name,
NonOverridableArguments: job.NonOverridableArguments,
NotificationProperty: job.NotificationProperty,
NumberOfWorkers: job.NumberOfWorkers,
Role: job.Role,
SecurityConfiguration: job.SecurityConfiguration,
SourceControlDetails: job.SourceControlDetails,
Timeout: job.Timeout,
WorkerType: job.WorkerType,
})
if err != nil {
return fmt.Errorf("failed to create Glue Job: %w", err)
}
log.Println("Successfully created Glue Job: " + *r.Name)
log.Println(job)
return nil
}