Skip to content

Commit 60d4264

Browse files
authored
Add table aws_batch_queue (#2486)
1 parent d26ab9e commit 60d4264

File tree

6 files changed

+394
-0
lines changed

6 files changed

+394
-0
lines changed

aws/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
119119
"aws_backup_selection": tableAwsBackupSelection(ctx),
120120
"aws_backup_vault": tableAwsBackupVault(ctx),
121121
"aws_backup_job": tableAwsBackupJob(ctx),
122+
"aws_batch_queue": tableAwsBatchQueue(ctx),
122123
"aws_cloudcontrol_resource": tableAwsCloudControlResource(ctx),
123124
"aws_cloudformation_stack": tableAwsCloudFormationStack(ctx),
124125
"aws_cloudformation_stack_resource": tableAwsCloudFormationStackResource(ctx),

aws/service.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/aws/aws-sdk-go-v2/service/auditmanager"
3535
"github.com/aws/aws-sdk-go-v2/service/autoscaling"
3636
"github.com/aws/aws-sdk-go-v2/service/backup"
37+
"github.com/aws/aws-sdk-go-v2/service/batch"
3738
"github.com/aws/aws-sdk-go-v2/service/cloudcontrol"
3839
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
3940
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
@@ -326,6 +327,20 @@ func BackupClient(ctx context.Context, d *plugin.QueryData) (*backup.Client, err
326327
return backup.NewFromConfig(*cfg), nil
327328
}
328329

330+
func BatchClient(ctx context.Context, d *plugin.QueryData) (*batch.Client, error) {
331+
conf, err := getClientForQuerySupportedRegion(ctx, d, AWS_BATCH_SERVICE_ID)
332+
if err != nil {
333+
return nil, err
334+
}
335+
336+
if conf == nil {
337+
return nil, nil
338+
}
339+
340+
client := batch.NewFromConfig(*conf)
341+
return client, nil
342+
}
343+
329344
func CloudControlClient(ctx context.Context, d *plugin.QueryData) (*cloudcontrol.Client, error) {
330345
// CloudControl returns GeneralServiceException in a lot of situations, which
331346
// AWS SDK treats as retryable. This is frustrating because we end up retrying

aws/table_aws_batch_queue.go

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/batch"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
9+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
10+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
11+
)
12+
13+
func tableAwsBatchQueue(_ context.Context) *plugin.Table {
14+
return &plugin.Table{
15+
Name: "aws_batch_queue",
16+
Description: "AWS Batch Queue",
17+
Get: &plugin.GetConfig{
18+
KeyColumns: plugin.SingleColumn("job_queue_name"),
19+
IgnoreConfig: &plugin.IgnoreConfig{
20+
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"JobQueueNotFoundException"}),
21+
},
22+
Hydrate: getBatchQueue,
23+
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
24+
},
25+
List: &plugin.ListConfig{
26+
Hydrate: listBatchQueues,
27+
Tags: map[string]string{"service": "batch", "action": "DescribeJobQueues"},
28+
},
29+
GetMatrixItemFunc: SupportedRegionMatrix(AWS_BATCH_SERVICE_ID),
30+
Columns: awsRegionalColumns([]*plugin.Column{
31+
{
32+
Name: "job_queue_name",
33+
Description: "The name of the job queue",
34+
Type: proto.ColumnType_STRING,
35+
},
36+
{
37+
Name: "arn",
38+
Description: "The Amazon Resource Name (ARN) of the job queue",
39+
Type: proto.ColumnType_STRING,
40+
Transform: transform.FromField("JobQueueArn"),
41+
},
42+
{
43+
Name: "state",
44+
Description: "The state of the job queue (ENABLED or DISABLED)",
45+
Type: proto.ColumnType_STRING,
46+
},
47+
{
48+
Name: "status",
49+
Description: "The status of the job queue (CREATING, UPDATING, DELETING, or DELETED)",
50+
Type: proto.ColumnType_STRING,
51+
},
52+
{
53+
Name: "priority",
54+
Description: "The priority of the job queue",
55+
Type: proto.ColumnType_INT,
56+
},
57+
{
58+
Name: "compute_environment_order",
59+
Description: "The compute environments that are attached to the job queue and the order in which job placement is preferred",
60+
Type: proto.ColumnType_JSON,
61+
},
62+
{
63+
Name: "scheduling_policy_arn",
64+
Description: "The ARN of the scheduling policy",
65+
Type: proto.ColumnType_STRING,
66+
},
67+
{
68+
Name: "status_reason",
69+
Description: "A short, human-readable string to provide additional details about the current status of the job queue",
70+
Type: proto.ColumnType_STRING,
71+
},
72+
73+
// Standard columns for all tables
74+
{
75+
Name: "tags",
76+
Description: "The tags assigned to the job queue",
77+
Type: proto.ColumnType_JSON,
78+
},
79+
{
80+
Name: "title",
81+
Description: resourceInterfaceDescription("title"),
82+
Type: proto.ColumnType_STRING,
83+
Transform: transform.FromField("JobQueueName"),
84+
},
85+
{
86+
Name: "akas",
87+
Description: resourceInterfaceDescription("akas"),
88+
Type: proto.ColumnType_JSON,
89+
Transform: transform.FromField("JobQueueArn").Transform(transform.EnsureStringArray),
90+
},
91+
}),
92+
}
93+
}
94+
95+
func listBatchQueues(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
96+
// Create service client
97+
svc, err := BatchClient(ctx, d)
98+
if err != nil {
99+
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "client_error", err)
100+
return nil, err
101+
}
102+
103+
// Unsupported region check
104+
if svc == nil {
105+
return nil, nil
106+
}
107+
108+
// Limiting the results
109+
maxLimit := int32(100)
110+
if d.QueryContext.Limit != nil {
111+
limit := int32(*d.QueryContext.Limit)
112+
if limit < maxLimit {
113+
maxLimit = limit
114+
}
115+
}
116+
117+
input := &batch.DescribeJobQueuesInput{
118+
MaxResults: aws.Int32(maxLimit),
119+
}
120+
121+
paginator := batch.NewDescribeJobQueuesPaginator(svc, input)
122+
for paginator.HasMorePages() {
123+
output, err := paginator.NextPage(ctx)
124+
if err != nil {
125+
plugin.Logger(ctx).Error("aws_batch_queue.listBatchQueues", "api_error", err)
126+
return nil, err
127+
}
128+
129+
for _, queue := range output.JobQueues {
130+
d.StreamListItem(ctx, queue)
131+
132+
// Context can be cancelled due to manual cancellation or the limit has been hit
133+
if d.RowsRemaining(ctx) == 0 {
134+
return nil, nil
135+
}
136+
}
137+
}
138+
139+
return nil, nil
140+
}
141+
142+
func getBatchQueue(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
143+
queueName := d.EqualsQualString("job_queue_name")
144+
if queueName == "" {
145+
return nil, nil
146+
}
147+
148+
// Create service client
149+
svc, err := BatchClient(ctx, d)
150+
if err != nil {
151+
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "client_error", err)
152+
return nil, err
153+
}
154+
155+
// Unsupported region check
156+
if svc == nil {
157+
return nil, nil
158+
}
159+
160+
input := &batch.DescribeJobQueuesInput{
161+
JobQueues: []string{queueName},
162+
}
163+
164+
output, err := svc.DescribeJobQueues(ctx, input)
165+
if err != nil {
166+
plugin.Logger(ctx).Error("aws_batch_queue.getBatchQueue", "api_error", err)
167+
return nil, err
168+
}
169+
170+
if len(output.JobQueues) == 0 {
171+
return nil, nil
172+
}
173+
174+
return output.JobQueues[0], nil
175+
}

0 commit comments

Comments
 (0)