Repository navigation
Add more data fetchers for ECS #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
donghwikim2
wants to merge
22
commits into
Blazebit:main
from
donghwikim2:add-more-ecs-data-fetchers
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
dd2abac
Add more data fetchers for ECS
donghwikim2 0dfa333
Merge branch 'main' into add-more-ecs-data-fetchers
donghwikim2 4cfdbec
Add ECS container definition data fetcher
donghwikim2 30aca22
Initial plan
Copilot c1af763
Address PR feedback: revert import changes and add AwsContainerDefini…
Copilot 6b53ff0
Add task set data fetcher
donghwikim2 3943874
Merge pull request #4 from donghwikim2/copilot/sub-pr-2-again
donghwikim2 e38a822
Initial plan
Copilot 7d460cf
Add AwsTaskSet query to Main.java example
Copilot d9683f7
Merge pull request #5 from donghwikim2/copilot/sub-pr-2-another-one
donghwikim2 8dd5815
Initial plan
Copilot 8045755
Add AwsContainerDefinition and AwsTaskSet registrations
Copilot f356d42
Merge pull request #6 from donghwikim2/copilot/sub-pr-2-yet-again
donghwikim2 6941a24
Initial plan
Copilot 20d53aa
Address PR feedback: fix formatting and alphabetical ordering
Copilot 78c8c67
Merge pull request #7 from donghwikim2/copilot/sub-pr-2-one-more-time
donghwikim2 80dc319
Merge branch 'main' into add-more-ecs-data-fetchers
donghwikim2 990f3d3
Include additional fields in ECS describe requests
donghwikim2 664d518
Rename ECS classes to AwsEcs* for consistency
donghwikim2 c821ca7
reformat code
donghwikim2 e85377d
Merge branch 'main' into add-more-ecs-data-fetchers
donghwikim2 970c309
Batch AWS ECS service descriptions in fetcher
donghwikim2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
16 changes: 16 additions & 0 deletions
16
...aws/ecs/src/main/java/com/blazebit/query/connector/aws/ecs/AwsEcsContainerDefinition.java
This file contains hidden or 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,16 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import software.amazon.awssdk.services.ecs.model.ContainerDefinition; | ||
|
|
||
| /** | ||
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public record AwsEcsContainerDefinition( | ||
| String taskDefinitionArn, String name, ContainerDefinition payload | ||
| ) { | ||
| } |
23 changes: 23 additions & 0 deletions
23
connector/aws/ecs/src/main/java/com/blazebit/query/connector/aws/ecs/AwsEcsService.java
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import com.blazebit.query.connector.aws.base.AwsWrapper; | ||
| import software.amazon.awssdk.services.ecs.model.Service; | ||
|
|
||
| /** | ||
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public class AwsEcsService extends AwsWrapper<Service> { | ||
| public AwsEcsService(String arn, Service payload) { | ||
| super( arn, payload ); | ||
| } | ||
|
|
||
| @Override | ||
| public Service getPayload() { | ||
| return super.getPayload(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...ctor/aws/ecs/src/main/java/com/blazebit/query/connector/aws/ecs/AwsEcsTaskDefinition.java
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import com.blazebit.query.connector.aws.base.AwsWrapper; | ||
| import software.amazon.awssdk.services.ecs.model.DescribeTaskDefinitionResponse; | ||
|
|
||
| /** | ||
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public class AwsEcsTaskDefinition extends AwsWrapper<DescribeTaskDefinitionResponse> { | ||
| public AwsEcsTaskDefinition(String arn, DescribeTaskDefinitionResponse payload) { | ||
| super( arn, payload ); | ||
| } | ||
|
|
||
| @Override | ||
| public DescribeTaskDefinitionResponse getPayload() { | ||
| return super.getPayload(); | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
connector/aws/ecs/src/main/java/com/blazebit/query/connector/aws/ecs/AwsEcsTaskSet.java
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import com.blazebit.query.connector.aws.base.AwsWrapper; | ||
| import software.amazon.awssdk.services.ecs.model.TaskSet; | ||
|
|
||
| < 8000 /td> | /** | |
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public class AwsEcsTaskSet extends AwsWrapper<TaskSet> { | ||
| public AwsEcsTaskSet(String arn, TaskSet payload) { | ||
| super( arn, payload ); | ||
| } | ||
|
|
||
| @Override | ||
| public TaskSet getPayload() { | ||
| return super.getPayload(); | ||
| } | ||
| } |
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
...cs/src/main/java/com/blazebit/query/connector/aws/ecs/ContainerDefinitionDataFetcher.java
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import com.blazebit.query.connector.aws.base.AwsConnectorConfig; | ||
| import com.blazebit.query.connector.aws.base.AwsConventionContext; | ||
| import com.blazebit.query.connector.base.DataFormats; | ||
| import com.blazebit.query.spi.DataFetchContext; | ||
| import com.blazebit.query.spi.DataFetcher; | ||
| import com.blazebit.query.spi.DataFetcherException; | ||
| import com.blazebit.query.spi.DataFormat; | ||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.ecs.EcsClient; | ||
| import software.amazon.awssdk.services.ecs.EcsClientBuilder; | ||
| import software.amazon.awssdk.services.ecs.model.ContainerDefinition; | ||
| import software.amazon.awssdk.services.ecs.model.DescribeTaskDefinitionRequest; | ||
| import software.amazon.awssdk.services.ecs.model.DescribeTaskDefinitionResponse; | ||
| import software.amazon.awssdk.services.ecs.model.TaskDefinition; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public class ContainerDefinitionDataFetcher implements DataFetcher<AwsEcsContainerDefinition>, Serializable { | ||
|
|
||
| public static final ContainerDefinitionDataFetcher INSTANCE = new ContainerDefinitionDataFetcher(); | ||
|
|
||
| private ContainerDefinitionDataFetcher() { | ||
| } | ||
|
|
||
| @Override | ||
| public List<AwsEcsContainerDefinition> fetch(DataFetchContext context) { | ||
| try { | ||
| List<AwsConnectorConfig.Account> accounts = AwsConnectorConfig.ACCOUNT.getAll( context ); | ||
| SdkHttpClient sdkHttpClient = AwsConnectorConfig.HTTP_CLIENT.find( context ); | ||
| List<AwsEcsContainerDefinition> list = new ArrayList<>(); | ||
| for ( AwsConnectorConfig.Account account : accounts ) { | ||
| for ( Region region : account.getRegions() ) { | ||
| EcsClientBuilder ecsClientBuilder = EcsClient.builder() | ||
| .region( region ) | ||
| .credentialsProvider( account.getCredentialsProvider() ); | ||
| if ( sdkHttpClient != null ) { | ||
| ecsClientBuilder.httpClient( sdkHttpClient ); | ||
| } | ||
| try (EcsClient client = ecsClientBuilder.build()) { | ||
| List<String> taskDefinitionArns = client.listTaskDefinitions().taskDefinitionArns(); | ||
| for ( String taskDefinitionArn : taskDefinitionArns ) { | ||
| DescribeTaskDefinitionRequest request = DescribeTaskDefinitionRequest.builder() | ||
| .taskDefinition( taskDefinitionArn ) | ||
| .build(); | ||
| DescribeTaskDefinitionResponse response = client.describeTaskDefinition( request ); | ||
| TaskDefinition taskDefinition = response.taskDefinition(); | ||
| List<ContainerDefinition> containerDefinitions = taskDefinition.containerDefinitions(); | ||
| for ( ContainerDefinition containerDefinition : containerDefinitions ) { | ||
| list.add( new AwsEcsContainerDefinition( taskDefinition.taskDefinitionArn(), | ||
| containerDefinition.name(), containerDefinition ) ); | ||
|
donghwikim2 marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+52
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
| } | ||
| } | ||
| return list; | ||
| } | ||
| catch (RuntimeException e) { | ||
| throw new DataFetcherException( "Could not fetch container definition list", e ); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DataFormat getDataFormat() { | ||
| return DataFormats.componentMethodConvention( AwsEcsContainerDefinition.class, AwsConventionContext.INSTANCE ); | ||
| } | ||
| } | ||
89 changes: 89 additions & 0 deletions
89
connector/aws/ecs/src/main/java/com/blazebit/query/connector/aws/ecs/ServiceDataFetcher.java
This file contains hidden or 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,89 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Blazebit | ||
| */ | ||
| package com.blazebit.query.connector.aws.ecs; | ||
|
|
||
| import com.blazebit.query.connector.aws.base.AwsConnectorConfig; | ||
| import com.blazebit.query.connector.aws.base.AwsConventionContext; | ||
| import com.blazebit.query.connector.base.DataFormats; | ||
| import com.blazebit.query.spi.DataFetchContext; | ||
| import com.blazebit.query.spi.DataFetcher; | ||
| import com.blazebit.query.spi.DataFetcherException; | ||
| import com.blazebit.query.spi.DataFormat; | ||
| import software.amazon.awssdk.http.SdkHttpClient; | ||
| import software.amazon.awssdk.regions.Region; | ||
| import software.amazon.awssdk.services.ecs.EcsClient; | ||
| import software.amazon.awssdk.services.ecs.EcsClientBuilder; | ||
| import software.amazon.awssdk.services.ecs.model.DescribeServicesRequest; | ||
| import software.amazon.awssdk.services.ecs.model.DescribeServicesResponse; | ||
| import software.amazon.awssdk.services.ecs.model.Service; | ||
| import software.amazon.awssdk.services.ecs.model.ServiceField; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author Donghwi Kim | ||
| * @since 1.0.0 | ||
| */ | ||
| public class ServiceDataFetcher implements DataFetcher<AwsEcsService>, Serializable { | ||
|
|
||
| public static final ServiceDataFetcher INSTANCE = new ServiceDataFetcher(); | ||
|
|
||
| private ServiceDataFetcher() { | ||
| } | ||
|
|
||
| @Override | ||
| public List<AwsEcsService> fetch(DataFetchContext context) { | ||
| try { | ||
| List<AwsConnectorConfig.Account> accounts = AwsConnectorConfig.ACCOUNT.getAll( context ); | ||
| SdkHttpClient sdkHttpClient = AwsConnectorConfig.HTTP_CLIENT.find( context ); | ||
| List<AwsEcsService> list = new ArrayList<>(); | ||
| for ( AwsConnectorConfig.Account account : accounts ) { | ||
| for ( Region region : account.getRegions() ) { | ||
| EcsClientBuilder ecsClientBuilder = EcsClient.builder() | ||
| .region( region ) | ||
| .credentialsProvider( account.getCredentialsProvider() ); | ||
| if ( sdkHttpClient != null ) { | ||
| ecsClientBuilder.httpClient( sdkHttpClient ); | ||
| } | ||
| try (EcsClient client = ecsClientBuilder.build()) { | ||
| List<String> clusterArns = client.listClusters().clusterArns(); | ||
| for ( String clusterArn : clusterArns ) { | ||
| List<String> serviceArns = client.listServices( r -> r.cluster( clusterArn ) ) | ||
| .serviceArns(); | ||
| if ( !serviceArns.isEmpty() ) { | ||
| // AWS DescribeServices API accepts up to 10 services per request | ||
| int batchSize = 10; | ||
| for ( int i = 0; i < serviceArns.size(); i += batchSize ) { | ||
| int end = Math.min( i + batchSize, serviceArns.size() ); | ||
| List<String> batch = serviceArns.subList( i, end ); | ||
| DescribeServicesRequest request = DescribeServicesRequest.builder() | ||
| .cluster( clusterArn ) | ||
| .services( batch ) | ||
| .include( ServiceField.TAGS ) | ||
| .build(); | ||
| DescribeServicesResponse response = client.describeServices( request ); | ||
| for ( Service service : response.services() ) { | ||
| list.add( new AwsEcsService( service.serviceArn(), service ) ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return list; | ||
| } | ||
| catch (RuntimeException e) { | ||
| throw new DataFetcherException( "Could not fetch service list", e ); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public DataFormat getDataFormat() { | ||
| return DataFormats.componentMethodConvention( AwsEcsService.class, AwsConventionContext.INSTANCE ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.