| 3868 | |
| 3869 | |
| 3870 | Future<Response> Http::_attachContainerInput( |
| 3871 | const mesos::agent::Call& call, |
| 3872 | Owned<Reader<mesos::agent::Call>>&& decoder, |
| 3873 | const RequestMediaTypes& mediaTypes) const |
| 3874 | { |
| 3875 | const ContainerID& containerId = call.attach_container_input().container_id(); |
| 3876 | |
| 3877 | Pipe pipe; |
| 3878 | Pipe::Reader reader = pipe.reader(); |
| 3879 | Pipe::Writer writer = pipe.writer(); |
| 3880 | |
| 3881 | CHECK_SOME(mediaTypes.messageContent); |
| 3882 | auto encoder = [mediaTypes](const mesos::agent::Call& call) { |
| 3883 | string record = serialize(mediaTypes.messageContent.get(), call); |
| 3884 | return ::recordio::encode(record); |
| 3885 | }; |
| 3886 | |
| 3887 | // Write the first record. We had extracted it from the `decoder` |
| 3888 | // in the `api()` handler to identify the call type earlier. |
| 3889 | pipe.writer().write(encoder(call)); |
| 3890 | |
| 3891 | // We create this here since C++11 does not support move capture of `reader`. |
| 3892 | Future<Nothing> transform = recordio::transform<mesos::agent::Call>( |
| 3893 | std::move(decoder), encoder, writer); |
| 3894 | |
| 3895 | return slave->containerizer->attach(containerId) |
| 3896 | .then(defer(slave->self(), [=]( |
| 3897 | Connection connection) mutable -> Future<Response> { |
| 3898 | Request request; |
| 3899 | request.method = "POST"; |
| 3900 | request.type = Request::PIPE; |
| 3901 | request.reader = reader; |
| 3902 | request.headers = {{"Content-Type", stringify(mediaTypes.content)}, |
| 3903 | {MESSAGE_CONTENT_TYPE, |
| 3904 | stringify(mediaTypes.messageContent.get())}, |
| 3905 | {"Accept", stringify(mediaTypes.accept)}}; |
| 3906 | |
| 3907 | // See comments in `attachContainerOutput()` for the reasoning |
| 3908 | // behind these values. |
| 3909 | request.url.domain = ""; |
| 3910 | request.url.path = "/"; |
| 3911 | |
| 3912 | transform |
| 3913 | .onAny([writer]( |
| 3914 | const Future<Nothing>& future) mutable { |
| 3915 | CHECK(!future.isDiscarded()); |
| 3916 | |
| 3917 | if (future.isFailed()) { |
| 3918 | writer.fail(future.failure()); |
| 3919 | return; |
| 3920 | } |
| 3921 | |
| 3922 | writer.close(); |
| 3923 | }); |
| 3924 | |
| 3925 | // This is a non Keep-Alive request which means the connection |
| 3926 | // will be closed when the response is received. Since the |
| 3927 | // 'Connection' is reference-counted, we must maintain a copy |
nothing calls this directly
no test coverage detected