Skip to content

Commit

Permalink
Wait for the install status reached to the end (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
felicityzhao9 authored Nov 8, 2024
1 parent 2115b14 commit fdb632d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
63 changes: 63 additions & 0 deletions ggdeploymentd/src/deployment_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,46 @@ static GglError deployment_status_callback(void *ctx, GglObject data) {
return GGL_ERR_INVALID;
}

static GglError wait_for_install_status(GglBufVec component_vec) {
// TODO: hack
ggl_sleep(5);

for (size_t i = 0; i < component_vec.buf_list.len; i++) {
// Add .install into the component name
static uint8_t install_comp_name[PATH_MAX];
GglByteVec install_comp_name_vec = GGL_BYTE_VEC(install_comp_name);
GglError ret = ggl_byte_vec_append(
&install_comp_name_vec, component_vec.buf_list.bufs[i]
);
ggl_byte_vec_append(&install_comp_name_vec, GGL_STR(".install"));
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to generate the install component name.");
return ret;
}
GGL_LOGD(
"Awaiting %.*s to finish.",
(int) install_comp_name_vec.buf.len,
install_comp_name_vec.buf.data
);

GglError method_error = GGL_ERR_OK;
ret = ggl_sub_response(
GGL_STR("/aws/ggl/gghealthd"),
GGL_STR("subscribe_to_lifecycle_completion"),
GGL_MAP({ GGL_STR("component_name"),
GGL_OBJ_BUF(install_comp_name_vec.buf) }),
deployment_status_callback,
NULL,
&method_error,
300
);
if ((ret != GGL_ERR_OK) || (method_error != GGL_ERR_OK)) {
return GGL_ERR_FAILURE;
}
}
return GGL_ERR_OK;
}

static GglError wait_for_deployment_status(GglMap resolved_components) {
GGL_LOGT("Beginning wait for deployment completion");
// TODO: hack
Expand Down Expand Up @@ -2210,6 +2250,12 @@ static void handle_deployment(
}

if (updated_comp_name_vec.buf_list.len != 0) {
// collect all component names that have relevant install service
// files
static GglBuffer install_comp_name_buf[MAX_COMP_NAME_BUF_SIZE];
GglBufVec install_comp_name_buf_vec
= GGL_BUF_VEC(install_comp_name_buf);

// process all install files first
for (size_t i = 0; i < updated_comp_name_vec.buf_list.len; i++) {
static uint8_t install_service_file_path_buf[PATH_MAX];
Expand Down Expand Up @@ -2250,6 +2296,17 @@ static void handle_deployment(
);
} else { // relevant install service file exists

// add relevant component name into the vector
ret = ggl_buf_vec_push(
&install_comp_name_buf_vec,
updated_comp_name_vec.buf_list.bufs[i]
);
if (ret != GGL_ERR_OK) {
GGL_LOGE("Failed to add the install component name "
"into vector");
return;
}

// run link command
static uint8_t link_command_buf[PATH_MAX];
GglByteVec link_command_vec
Expand Down Expand Up @@ -2325,6 +2382,12 @@ static void handle_deployment(
}
}

// wait for all the install status
ret = wait_for_install_status(install_comp_name_buf_vec);
if (ret != GGL_ERR_OK) {
return;
}

// process all run or startup files after install only
for (size_t i = 0; i < updated_comp_name_vec.buf_list.len; i++) {
static uint8_t service_file_path_buf[PATH_MAX];
Expand Down
14 changes: 14 additions & 0 deletions gghealthd/src/bus_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ static pthread_mutex_t bump_alloc_mutex = PTHREAD_MUTEX_INITIALIZER;

// Check a component's version field in ggconfigd for proof of existence
GglError verify_component_exists(GglBuffer component_name) {
// Remove .install if at the end of the component name
GglBuffer install_ext = GGL_STR(".install");
if ((component_name.len > install_ext.len)
&& ggl_buffer_eq(
ggl_buffer_substr(
component_name, component_name.len - install_ext.len, SIZE_MAX
),
install_ext
)) {
component_name = ggl_buffer_substr(
component_name, 0, component_name.len - install_ext.len
);
}

if ((component_name.data == NULL) || (component_name.len == 0)
|| (component_name.len > 128U)) {
return GGL_ERR_RANGE;
Expand Down

0 comments on commit fdb632d

Please sign in to comment.