-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix curl error #7
base: master
Are you sure you want to change the base?
Changes from 10 commits
7ad27f3
75086e4
392ff94
c8a2043
f4f3269
2d9f74c
c6ff4f6
69cf7c0
2bdb859
063c418
2249c64
e8ad6eb
948ecc4
38d7238
f193110
2cb8dfb
4d3de18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,8 +184,7 @@ module Aws : Provider_template.Provider = struct | |
Lwt.return None | ||
|
||
(*TODO Please no more string types.*) | ||
let send_command box s ~expire_time : (string, [> R.msg] * string) result Lwt.t = | ||
let uri = Uri.of_string ("http://" ^ box ^ ":8000/command") in | ||
let send_command cmd_uri s ~expire_time : (string, [> R.msg] * string) result Lwt.t = | ||
let headers = Cohttp.Header.init_with "ApiKey" (Sys.getenv "MC_KEY") in | ||
let rec repeat_until_ok f c = | ||
match c with | ||
|
@@ -209,7 +208,7 @@ module Aws : Provider_template.Provider = struct | |
in | ||
let send_command () = | ||
let body = Cohttp_lwt.Body.of_string s in | ||
let%lwt resp, body = Cohttp_lwt_unix.Client.put uri ~headers ~body in | ||
let%lwt resp, body = Cohttp_lwt_unix.Client.put cmd_uri ~headers ~body in | ||
let%lwt body = Cohttp_lwt.Body.to_string body in | ||
let process_response x = | ||
match Cohttp.Response.status x with | ||
|
@@ -230,18 +229,19 @@ module Aws : Provider_template.Provider = struct | |
process_response resp | ||
in | ||
let%lwt _resp, body = | ||
match%lwt repeat_until_ok send_command 10 with | ||
match%lwt repeat_until_ok send_command 60 with | ||
| Ok (r, b) -> | ||
Lwt.return (r, b) | ||
| Error _ -> | ||
failwith | ||
| Error (`Msg message, note) -> | ||
Lwt.fail_with (Fmt.str | ||
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. Should we leave this as 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. Fair question. In theory using the Lwt ppx should give decent backtraces. But that's not happening here so something is missing somewhere. |
||
"Can't talk to an agent, this probably means the agent failed to \ | ||
install." | ||
install. Error: %s - %s" | ||
message note) | ||
in | ||
(*TODO cohttp_retry*) | ||
let poll_agent () = | ||
let check_uri = | ||
Uri.of_string ("http://" ^ box ^ ":8000/check_command") | ||
Uri.with_path cmd_uri ("/check_command") | ||
in | ||
let check_uri = Uri.add_query_param' check_uri ("id", body) in | ||
match%lwt Cohttp_lwt_unix.Client.get check_uri ~headers with | ||
|
@@ -332,19 +332,33 @@ module Aws : Provider_template.Provider = struct | |
let%bind _store_result = store_ami ?profile ~settings ~n ~guid waiting_image in | ||
Lwt.return_ok waiting_image | ||
|
||
let runcmd transfer t (params : Lib.run_parameters) (settings : Settings.t) (n : Node.real_node) guid (cmd : Command.t) : | ||
let make_file_transfer_payload src dst = | ||
let json : Yojson.Safe.t = `Assoc [("src", `String src); ("dst", `String dst)] in | ||
Yojson.Safe.to_string json | ||
|
||
let runcmd transfer_fn t (params : Lib.run_parameters) (settings : Settings.t) (n : Node.real_node) guid (cmd : Command.t) : | ||
(string, [> R.msg] * string) result Lwt.t = | ||
let%lwt () = Node.node_log n (Command.to_string cmd) in | ||
let expire_time = 12 * Node.rnode_get_expire_time n in | ||
let base_uri = Uri.make ~scheme:"http" ~port:8000 ~host:t.ip_address () in | ||
match cmd with | ||
| Command.(Run shell_cmd) -> | ||
send_command t.ip_address ~expire_time shell_cmd | ||
let u = Uri.with_path base_uri "/command" in | ||
send_command u ~expire_time shell_cmd | ||
| Upload (first_arg, second_arg) -> | ||
send_command t.ip_address ~expire_time | ||
@@ transfer ~first_arg ~second_arg ~verb:`Put | ||
let u = Uri.with_path base_uri "/upload" in | ||
let uri = Uri.to_string (transfer_fn (sprintf "/%s/%s/%s" guid n.name second_arg) `Put) in | ||
let payload = make_file_transfer_payload first_arg uri in | ||
send_command u ~expire_time payload | ||
| Download (first_arg, second_arg) -> | ||
send_command t.ip_address ~expire_time | ||
@@ transfer ~first_arg ~second_arg ~verb:`Get | ||
let u = Uri.with_path base_uri "/download" in | ||
let uri = if Uri.of_string first_arg |> Uri.scheme |> Option.is_none then | ||
Uri.to_string (transfer_fn (sprintf "/%s/%s" guid first_arg) `Get) | ||
else | ||
first_arg | ||
in | ||
let payload = make_file_transfer_payload uri second_arg in | ||
send_command u ~expire_time payload | ||
| Publish -> | ||
let%lwt image_id = publish_image ?profile:params.aws_profile ~t ~settings ~n ~guid in | ||
(match image_id with | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good!