forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 113
/
etl_job.go
65 lines (55 loc) · 1.91 KB
/
etl_job.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
package sls
import "encoding/json"
// This module is only used in SLS Trigger for Aliyun FunctionCompute.
type ETLJob struct {
JobName string `json:"etlJobName"`
SourceConfig *SourceConfig `json:"sourceConfig"`
TriggerConfig *TriggerConfig `json:"triggerConfig"`
FunctionConfig *FunctionConfig `json:"functionConfig"`
// TODO: change this to map[string]interface{} once log service fixes the format
FunctionParameter interface{} `json:"functionParameter"`
LogConfig *JobLogConfig `json:"logConfig"`
Enable bool `json:"enable"`
CreateTime int64 `json:"createTime"`
UpdateTime int64 `json:"updateTime"`
}
type etlJobAlias ETLJob
// This can be removed once log service returns function parameter in json type.
// "functionParameter":{"a":1} instead of "functionParameter":"{\"a\":1}"
func (job *ETLJob) UnmarshalJSON(data []byte) error {
output := etlJobAlias{}
if err := json.Unmarshal(data, &output); err != nil {
return err
}
param := map[string]interface{}{}
paramStr, ok := output.FunctionParameter.(string)
if ok {
if err := json.Unmarshal([]byte(paramStr), ¶m); err != nil {
return err
}
output.FunctionParameter = param
}
*job = ETLJob(output)
return nil
}
type SourceConfig struct {
LogstoreName string `json:"logstoreName"`
}
type TriggerConfig struct {
MaxRetryTime int `json:"maxRetryTime"`
TriggerInterval int `json:"triggerInterval"`
RoleARN string `json:"roleArn"`
}
type FunctionConfig struct {
FunctionProvider string `json:"functionProvider"`
Endpoint string `json:"endpoint"`
AccountID string `json:"accountId"`
RegionName string `json:"regionName"`
ServiceName string `json:"serviceName"`
FunctionName string `json:"functionName"`
}
type JobLogConfig struct {
Endpoint string `json:"endpoint"`
ProjectName string `json:"projectName"`
LogstoreName string `json:"logstoreName"`
}