Skip to content

Commit

Permalink
API to retrieve list of platform with recommended configuration (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Nov 9, 2023
1 parent 284fd97 commit 89791b1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/aws/s3/private/s3_platform_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ AWS_S3_API
const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment(
struct aws_s3_platform_info_loader *loader);

/*
* Retrieves a list of EC2 instance types with recommended configuration.
* Returns aws_array_list<aws_byte_cursor>. The caller is responsible for cleaning up the array list.
*/
AWS_S3_API
struct aws_array_list aws_s3_get_recommended_platforms(struct aws_s3_platform_info_loader *loader);

/**
* Returns true if the current process is running on an Amazon EC2 instance powered by Nitro.
*/
Expand Down
7 changes: 7 additions & 0 deletions include/aws/s3/s3.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ void aws_s3_library_clean_up(void);
AWS_S3_API
const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void);

/*
* Retrieves a list of EC2 instance types with recommended configuration.
* Returns aws_array_list<aws_byte_cursor>. The caller is responsible for cleaning up the array list.
*/
AWS_S3_API
struct aws_array_list aws_s3_get_platforms_with_recommended_config(void);

AWS_EXTERN_C_END
AWS_POP_SANE_WARNING_LEVEL

Expand Down
4 changes: 4 additions & 0 deletions source/s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ const struct aws_s3_platform_info *aws_s3_get_current_platform_info(void) {
return aws_s3_get_platform_info_for_current_environment(s_loader);
}

struct aws_array_list aws_s3_get_platforms_with_recommended_config(void) {
return aws_s3_get_recommended_platforms(s_loader);
}

void aws_s3_library_clean_up(void) {
if (!s_library_initialized) {
return;
Expand Down
19 changes: 19 additions & 0 deletions source/s3_platform_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,25 @@ const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environm
return &loader->lock_data.current_env_platform_info;
}

struct aws_array_list aws_s3_get_recommended_platforms(struct aws_s3_platform_info_loader *loader) {
struct aws_array_list array_list;
aws_mutex_lock(&loader->lock_data.lock);
aws_array_list_init_dynamic(&array_list, loader->allocator, 5, sizeof(struct aws_byte_cursor));
/* Iterate over the map and add instance types to the array list which have
* platform_info->has_recommended_configuration == true */
for (struct aws_hash_iter iter = aws_hash_iter_begin(&loader->lock_data.compute_platform_info_table);
!aws_hash_iter_done(&iter);
aws_hash_iter_next(&iter)) {
struct aws_s3_platform_info *platform_info = iter.element.value;

if (platform_info->has_recommended_configuration) {
aws_array_list_push_back(&array_list, &platform_info->instance_type);
}
}
aws_mutex_unlock(&loader->lock_data.lock);
return array_list;
}

const struct aws_s3_platform_info *aws_s3_get_platform_info_for_instance_type(
struct aws_s3_platform_info_loader *loader,
struct aws_byte_cursor instance_type_name) {
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ add_test_case(test_add_user_agent_header)

add_test_case(test_get_existing_platform_info)
add_test_case(test_get_nonexistent_platform_info)
add_test_case(test_get_platforms_with_recommended_config)
add_net_test_case(load_platform_info_from_global_state_sanity_test)

add_net_test_case(sha1_nist_test_case_1)
Expand Down
19 changes: 19 additions & 0 deletions tests/s3_platform_info_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,22 @@ static int s_load_platform_info_from_global_state_sanity_test(struct aws_allocat
}

AWS_TEST_CASE(load_platform_info_from_global_state_sanity_test, s_load_platform_info_from_global_state_sanity_test)

static int s_test_get_platforms_with_recommended_config(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

aws_s3_library_init(allocator);

struct aws_array_list recommended_platform_list = aws_s3_get_platforms_with_recommended_config();
ASSERT_TRUE(aws_array_list_length(&recommended_platform_list) > 0);
for (size_t i = 0; i < aws_array_list_length(&recommended_platform_list); ++i) {
struct aws_byte_cursor cursor;
aws_array_list_get_at(&recommended_platform_list, &cursor, i);
ASSERT_TRUE(cursor.len > 0);
}
aws_array_list_clean_up(&recommended_platform_list);
aws_s3_library_clean_up();
return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(test_get_platforms_with_recommended_config, s_test_get_platforms_with_recommended_config)

0 comments on commit 89791b1

Please sign in to comment.