-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_ovh_cloud_data_job.go
165 lines (156 loc) · 4.69 KB
/
table_ovh_cloud_data_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package ovh
import (
"context"
"fmt"
"time"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
func tableOvhCloudDataJob() *plugin.Table {
return &plugin.Table{
Name: "ovh_cloud_data_job",
Description: "A data job is processed by OVH by Apache Spark.",
List: &plugin.ListConfig{
KeyColumns: plugin.SingleColumn("project_id"),
Hydrate: listDataJob,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"project_id", "id"}),
Hydrate: getDataJob,
},
HydrateConfig: []plugin.HydrateConfig{
{Func: getDataJobInfo},
},
Columns: []*plugin.Column{
{
Name: "project_id",
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("project_id"),
Description: "Project ID.",
},
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "UUID of the job.",
},
{
Name: "name",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "name of the job.",
},
{
Name: "region",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Openstack region of the job.",
},
{
Name: "container_name",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Name of the container where the code and the log of the job is.",
},
{
Name: "engine",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Engine of the job.",
},
{
Name: "engine_version",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Version of the engine.",
},
{
Name: "started_at",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_TIMESTAMP,
Description: "Start date of the job.",
Transform: transform.FromField("StartDate"),
},
{
Name: "ended_at",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_TIMESTAMP,
Description: "End date of the job.",
Transform: transform.FromField("EndDate"),
},
{
Name: "created_at",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_TIMESTAMP,
Description: "Creation date of the job.",
Transform: transform.FromField("CreationDate"),
},
{
Name: "status",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Current state of the job.",
},
{
Name: "ttl",
Hydrate: getDataJobInfo,
Type: proto.ColumnType_STRING,
Description: "Maximum 'Time To Live' (in RFC3339 (duration)) of this job, after which it will be automatically terminated.",
},
},
}
}
type Job struct {
ID string `json:"id"`
Name string `json:"name"`
Region string `json:"region"`
ContainerName string `json:"containerName"`
Engine string `json:"engine"`
EngineVersion string `json:"engineVersion"`
StartDate time.Time `json:"startDate"`
EndDate time.Time `json:"endDate"`
CreationDate time.Time `json:"creationDate"`
Status string `json:"status"`
TTL string `json:"ttl"`
}
func getDataJobInfo(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
job := h.Item.(Job)
projectId := d.EqualsQuals["project_id"].GetStringValue()
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_data_job.getDataJobInfo", "connection_error", err)
return nil, err
}
err = client.Get(fmt.Sprintf("/cloud/project/%s/dataProcessing/jobs/%s", projectId, job.ID), &job)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_data_job.getDataJobInfo", err)
return nil, err
}
return job, nil
}
func listDataJob(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
client, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_data_job.listDataJobInfo", "connection_error", err)
return nil, err
}
projectId := d.EqualsQuals["project_id"].GetStringValue()
var jobIds []string
err = client.Get(fmt.Sprintf("/cloud/project/%s/dataProcessing/jobs", projectId), &jobIds)
if err != nil {
plugin.Logger(ctx).Error("ovh_cloud_data_job.listDataJobInfo", err)
return nil, err
}
for _, jobId := range jobIds {
var job Job
job.ID = jobId
d.StreamListItem(ctx, job)
}
return nil, nil
}
func getDataJob(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
id := d.EqualsQuals["id"].GetStringValue()
var job Job
job.ID = id
return job, nil
}