Skip to content

Commit

Permalink
Update job state details
Browse files Browse the repository at this point in the history
  • Loading branch information
shapovalovts committed Aug 24, 2024
1 parent 2a3a62b commit 5b27970
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/srv/cloud/wm_gate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

-record(mstate, {spool = "" :: string(), children = #{} :: #{}, pem_data = <<>> :: binary()}).

-define(CONNECTION_AWAIT_TIMEOUT, timer:seconds(3)).
-define(CONNECTION_AWAIT_TIMEOUT, timer:seconds(5)).
-define(GATE_RESPONSE_TIMEOUT, 5 * 60 * 1000).
-define(AZURE_CONT_HEADERS, [<<"containerregistryuser">>, <<"containerregistrypass">>]).

Expand Down Expand Up @@ -300,13 +300,13 @@ do_partition_create(Remote, Creds, Options, #mstate{spool = Spool, pem_data = Pe
[{<<"osversion">>, list_to_binary(maps:get(image_name, Options, ""))},
{<<"containerimage">>, list_to_binary(maps:get(container_image, Options))},
{<<"flavorname">>, list_to_binary(maps:get(flavor_name, Options, ""))},
{<<"username">>, list_to_binary(maps:get(user_name, Options))},
{<<"username">>, list_to_binary(maps:get(user_name, Options, ""))},
{<<"count">>, integer_to_binary(ExtraNodesCount)},
{<<"jobid">>, list_to_binary(maps:get(job_id, Options))},
{<<"partname">>, list_to_binary(maps:get(part_name, Options, ""))},
{<<"runtime">>, list_to_binary(get_runtime_parameters_string(Remote))},
{<<"location">>, list_to_binary(wm_entity:get(location, Remote))},
{<<"ports">>, list_to_binary(maps:get(ports, Options))}],
{<<"ports">>, list_to_binary(maps:get(ports, Options, ""))}],
Headers = generate_headers(Creds, [], ExtraHeaders), %TODO make remote-dependent exclude list
HeadersWithoutCredentials = hide_credentials_from_headers(Headers, Creds),
?LOG_DEBUG("Partition creation POST HTTP headers: ~p", [HeadersWithoutCredentials]),
Expand Down
43 changes: 20 additions & 23 deletions src/srv/cloud/wm_gate_parsers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,27 @@ fill_image_params([{B, _} | T], Image) when not is_binary(B) ->
fill_image_params(T, Image);
fill_image_params([{<<"id">>, Value} | T], Image) ->
fill_image_params(T, wm_entity:set({id, binary_to_list(Value)}, Image));
fill_image_params([{<<"status">>, Value} | T], Image) ->
fill_image_params(T, wm_entity:set({status, binary_to_list(Value)}, Image));
fill_image_params([{<<"name">>, Value} | T], Image) ->
fill_image_params(T, wm_entity:set({name, binary_to_list(Value)}, Image));
fill_image_params([{<<"extra">>, {struct, List}} | T], Image) ->
fill_image_params(T, fill_image_extra(List, Image));
fill_image_params([{_, null} | T], Image) ->
fill_image_params(T, Image);
fill_image_params([{<<"created">>, Value} | T], Image) ->
fill_image_params(T, wm_entity:set({created, binary_to_list(Value)}, Image));
fill_image_params([{<<"updated">>, Value} | T], Image) ->
fill_image_params(T, wm_entity:set({updated, binary_to_list(Value)}, Image));
fill_image_params([_ | T], Image) ->
fill_image_params(T, Image).

-spec fill_image_extra([{binary(), binary()}], #image{}) -> #image{}.
fill_image_extra([], Image) ->
Image;
fill_image_extra([{<<"status">>, Value} | T], Image) ->
fill_image_extra(T, wm_entity:set({status, binary_to_list(Value)}, Image));
fill_image_extra([{<<"created">>, Value} | T], Image) ->
fill_image_extra(T, wm_entity:set({created, binary_to_list(Value)}, Image));
fill_image_extra([{<<"updated">>, Value} | T], Image) ->
fill_image_extra(T, wm_entity:set({updated, binary_to_list(Value)}, Image));
fill_image_extra([{_, _} | T], Image) ->
fill_image_extra(T, Image).

%%
%% Parse flavors
%%
Expand Down Expand Up @@ -250,22 +258,11 @@ fill_partition_params([_ | T], Part) ->
parse_images_test() ->
Input =
<<"{\"images\":[",
"{\"id\":\"i1\",\"name\":\"image1\",\"status\""
":\"creating\",\"created\":null,\"updated\":nu"
"ll},",
"{\"id\":\"i2\",\"name\":\"cirros\",\"status\""
":\"created\",\"created\":null,\"updated\":nul"
"l}]}">>,
"{\"id\":\"i1\",\"name\":\"image1\",\"extra\":{\"status\":\"creating\"}},",
"{\"id\":\"i2\",\"name\":\"cirros\",\"extra\":{\"status\":\"created\"}}]}">>,
ExpectedImages =
[wm_entity:set([{id, "i1"},
{name, "image1"},
{status, "creating"},
{created, ""},
{updated, ""},
{kind, cloud}],
wm_entity:new(image)),
wm_entity:set([{id, "i2"}, {name, "cirros"}, {status, "created"}, {created, ""}, {updated, ""}, {kind, cloud}],
wm_entity:new(image))],
[wm_entity:set([{id, "i1"}, {name, "image1"}, {status, "creating"}, {kind, cloud}], wm_entity:new(image)),
wm_entity:set([{id, "i2"}, {name, "cirros"}, {status, "created"}, {kind, cloud}], wm_entity:new(image))],
?assertEqual({ok, ExpectedImages}, parse_images(Input)),
?assertMatch({ok, []}, parse_images(<<"{\"images\":[]}">>)),
?assertMatch({error, _}, parse_images(<<"foo">>)),
Expand Down Expand Up @@ -316,12 +313,12 @@ parse_partitions_test() ->
Input =
<<"{\"partitions\":[",
"{\"id\":\"p1\",\"name\":\"stack1\",\"status\""
":\"CREATE_IN_PROGRESS\",",
":\"creating\",",
"\"created\":\"2021-01-02T15:18:39\", "
"\"updated\":\"2021-01-02T16:18:40\",",
"\"description\":\"test stack 1\"},",
"{\"id\":\"p2\",\"name\":\"stack2\",\"status\""
":\"CREATE_COMPLETE\",",
":\"succeeded\",",
"\"created\":\"2020-11-12T10:00:00\", "
"\"updated\":\"2021-01-02T11:18:38\",",
"\"description\":\"test stack 2\"}]}">>,
Expand Down
Loading

0 comments on commit 5b27970

Please sign in to comment.