From 1c5f2090e436482988cc0ddb64b34845c9f31cda Mon Sep 17 00:00:00 2001 From: Patrick Zhang Date: Wed, 11 Dec 2024 00:54:39 +0000 Subject: [PATCH] Support architecture field for RCC call --- ggdeploymentd/src/deployment_handler.c | 54 +++++++++++++++++--------- ggl-recipe/include/ggl/recipe.h | 2 + ggl-recipe/src/recipe.c | 2 +- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/ggdeploymentd/src/deployment_handler.c b/ggdeploymentd/src/deployment_handler.c index 0d84b0426..589f5745b 100644 --- a/ggdeploymentd/src/deployment_handler.c +++ b/ggdeploymentd/src/deployment_handler.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -819,31 +820,46 @@ static GglError generate_resolve_component_candidates_body( GglBuffer component_requirements, GglByteVec *body_vec ) { - GglError byte_vec_ret = GGL_ERR_OK; - ggl_byte_vec_chain_append( - &byte_vec_ret, body_vec, GGL_STR("{\"componentCandidates\": [") + // TODO: Support platform attributes for platformOverride configuration + GglMap platform_attributes = GGL_MAP( + { GGL_STR("runtime"), GGL_OBJ_BUF(GGL_STR("aws_nucleus_lite")) }, + { GGL_STR("os"), GGL_OBJ_BUF(GGL_STR("linux")) }, + { GGL_STR("architecture"), GGL_OBJ_BUF(get_current_architecture()) } ); - ggl_byte_vec_chain_append( - &byte_vec_ret, body_vec, GGL_STR("{\"componentName\": \"") + GglMap platform_info = GGL_MAP( + { GGL_STR("name"), GGL_OBJ_BUF(GGL_STR("linux")) }, + { GGL_STR("attributes"), GGL_OBJ_MAP(platform_attributes) } ); - ggl_byte_vec_chain_append(&byte_vec_ret, body_vec, component_name); - ggl_byte_vec_chain_append( - &byte_vec_ret, - body_vec, - GGL_STR("\",\"versionRequirements\": {\"requirements\": \"") + + GglMap version_requirements_map + = GGL_MAP({ GGL_STR("requirements"), + GGL_OBJ_BUF(component_requirements) }); + + GglMap component_map = GGL_MAP( + { GGL_STR("componentName"), GGL_OBJ_BUF(component_name) }, + { GGL_STR("versionRequirements"), + GGL_OBJ_MAP(version_requirements_map) } ); - ggl_byte_vec_chain_append(&byte_vec_ret, body_vec, component_requirements); - ggl_byte_vec_chain_append(&byte_vec_ret, body_vec, GGL_STR("\"}}")); - // TODO: Include architecture requirements if any - ggl_byte_vec_chain_append( - &byte_vec_ret, - body_vec, - GGL_STR("],\"platform\": { \"attributes\": { \"os\" : \"linux\", " - "\"runtime\" : \"aws_nucleus_lite\" " - "},\"name\": \"linux\"}}") + GglList candidates_list = GGL_LIST(GGL_OBJ_MAP(component_map)); + + GglMap request_body = GGL_MAP( + { GGL_STR("componentCandidates"), GGL_OBJ_LIST(candidates_list) }, + { GGL_STR("platform"), GGL_OBJ_MAP(platform_info) } ); + + static uint8_t rcc_buf[4096]; + GglBuffer rcc_body = GGL_BUF(rcc_buf); + GglError ret = ggl_json_encode(GGL_OBJ_MAP(request_body), &rcc_body); + if (ret != GGL_ERR_OK) { + GGL_LOGE("Error while encoding body for ResolveComponentCandidates call" + ); + return ret; + } + + GglError byte_vec_ret = GGL_ERR_OK; + ggl_byte_vec_chain_append(&byte_vec_ret, body_vec, rcc_body); ggl_byte_vec_chain_push(&byte_vec_ret, body_vec, '\0'); GGL_LOGD("Body for call: %s", body_vec->buf.data); diff --git a/ggl-recipe/include/ggl/recipe.h b/ggl-recipe/include/ggl/recipe.h index a2b0fee40..49aad4880 100644 --- a/ggl-recipe/include/ggl/recipe.h +++ b/ggl-recipe/include/ggl/recipe.h @@ -37,4 +37,6 @@ GglError select_linux_manifest( GglMap recipe_map, GglMap *out_selected_linux_manifest ); +GglBuffer get_current_architecture(void); + #endif diff --git a/ggl-recipe/src/recipe.c b/ggl-recipe/src/recipe.c index b31d2c338..867bd6647 100644 --- a/ggl-recipe/src/recipe.c +++ b/ggl-recipe/src/recipe.c @@ -224,7 +224,7 @@ static GglError lifecycle_selection( return GGL_ERR_OK; } -static GglBuffer get_current_architecture(void) { +GglBuffer get_current_architecture(void) { GglBuffer current_arch = { 0 }; #if defined(__x86_64__) current_arch = GGL_STR("amd64");