-
Notifications
You must be signed in to change notification settings - Fork 214
/
Copy pathhttp_rest_api_handler.cpp
1180 lines (1076 loc) · 53.7 KB
/
http_rest_api_handler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//*****************************************************************************
// Copyright 2020 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "http_rest_api_handler.hpp"
#include <cctype>
#include <iomanip>
#include <memory>
#include <mutex>
#include <optional>
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <utility>
#include <vector>
#ifndef _WIN32
#include <curl/curl.h>
#endif
#pragma warning(push)
#pragma warning(disable : 6313)
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#pragma warning(pop)
#include "config.hpp"
#include "dags/pipeline.hpp"
#include "dags/pipelinedefinition.hpp"
#include "dags/pipelinedefinitionunloadguard.hpp"
#include "execution_context.hpp"
#include "filesystem.hpp"
#include "get_model_metadata_impl.hpp"
#include "grpcservermodule.hpp"
#include "kfs_frontend/kfs_grpc_inference_service.hpp"
#include "kfs_frontend/kfs_utils.hpp"
#include "metric_module.hpp"
#include "metric_registry.hpp"
#include "model_metric_reporter.hpp"
#include "model_service.hpp"
#include "modelinstance.hpp"
#include "modelinstanceunloadguard.hpp"
#include "modelmanager.hpp"
#include "prediction_service_utils.hpp"
#include "profiler.hpp"
#include "rest_parser.hpp"
#include "rest_utils.hpp"
#include "servablemanagermodule.hpp"
#include "server.hpp"
#include "status.hpp"
#include "stringutils.hpp"
#include "timer.hpp"
#if (MEDIAPIPE_DISABLE == 0)
#include "http_frontend/http_client_connection.hpp"
#include "http_frontend/http_graph_executor_impl.hpp"
#include "mediapipe_internal/mediapipegraphexecutor.hpp"
#endif
#include "tfs_frontend/tfs_utils.hpp"
#include "tfs_frontend/deserialization.hpp"
#include "deserialization_main.hpp"
#include "inference_executor.hpp"
using tensorflow::serving::PredictRequest;
using tensorflow::serving::PredictResponse;
using rapidjson::Document;
using rapidjson::SizeType;
using rapidjson::Value;
namespace {
enum : unsigned int {
TOTAL,
PREPARE_GRPC_REQUEST,
TIMER_END
};
const std::string DEFAULT_VERSION = "DEFAULT";
} // namespace
namespace ovms {
const std::string HttpRestApiHandler::predictionRegexExp =
R"((.?)\/v1\/models\/([^\/:]+)(?:(?:\/versions\/(\d+))|(?:\/labels\/(\w+)))?:(classify|regress|predict))";
const std::string HttpRestApiHandler::modelstatusRegexExp =
R"((.?)\/v1\/models(?:\/([^\/:]+))?(?:(?:\/versions\/(\d+))|(?:\/labels\/(\w+)))?(?:\/(metadata))?)";
const std::string HttpRestApiHandler::configReloadRegexExp = R"((.?)\/v1\/config\/reload)";
const std::string HttpRestApiHandler::configStatusRegexExp = R"((.?)\/v1\/config)";
const std::string HttpRestApiHandler::kfs_modelreadyRegexExp =
R"(/v2/models/([^/]+)(?:/versions/([0-9]+))?(?:/(ready)))";
const std::string HttpRestApiHandler::kfs_modelmetadataRegexExp =
R"(/v2/models/([^/]+)(?:/versions/([0-9]+))?(?:/)?)";
const std::string HttpRestApiHandler::kfs_inferRegexExp =
R"(/v2/models/([^/]+)(?:/versions/([0-9]+))?(?:/(infer)))";
const std::string HttpRestApiHandler::kfs_serverreadyRegexExp =
R"(/v2/health/ready)";
const std::string HttpRestApiHandler::kfs_serverliveRegexExp =
R"(/v2/health/live)";
const std::string HttpRestApiHandler::kfs_servermetadataRegexExp =
R"(/v2)";
const std::string HttpRestApiHandler::v3_RegexExp =
R"(/v3/.*?(/|$))";
const std::string HttpRestApiHandler::metricsRegexExp = R"((.?)\/metrics(\?(.*))?)";
HttpRestApiHandler::HttpRestApiHandler(ovms::Server& ovmsServer, int timeout_in_ms) :
predictionRegex(predictionRegexExp),
modelstatusRegex(modelstatusRegexExp),
configReloadRegex(configReloadRegexExp),
configStatusRegex(configStatusRegexExp),
kfs_modelreadyRegex(kfs_modelreadyRegexExp),
kfs_modelmetadataRegex(kfs_modelmetadataRegexExp),
kfs_inferRegex(kfs_inferRegexExp),
kfs_serverreadyRegex(kfs_serverreadyRegexExp),
kfs_serverliveRegex(kfs_serverliveRegexExp),
kfs_servermetadataRegex(kfs_servermetadataRegexExp),
v3_Regex(v3_RegexExp),
metricsRegex(metricsRegexExp),
timeout_in_ms(timeout_in_ms),
ovmsServer(ovmsServer),
kfsGrpcImpl(dynamic_cast<const GRPCServerModule*>(this->ovmsServer.getModule(GRPC_SERVER_MODULE_NAME))->getKFSGrpcImpl()),
grpcGetModelMetadataImpl(dynamic_cast<const GRPCServerModule*>(this->ovmsServer.getModule(GRPC_SERVER_MODULE_NAME))->getTFSModelMetadataImpl()),
modelManager(dynamic_cast<const ServableManagerModule*>(this->ovmsServer.getModule(SERVABLE_MANAGER_MODULE_NAME))->getServableManager()) {
if (nullptr == this->ovmsServer.getModule(GRPC_SERVER_MODULE_NAME))
throw std::logic_error("Tried to create http rest api handler without grpc server module");
if (nullptr == this->ovmsServer.getModule(SERVABLE_MANAGER_MODULE_NAME))
throw std::logic_error("Tried to create http rest api handler without servable manager module");
registerAll();
}
Status HttpRestApiHandler::parseModelVersion(std::string& model_version_str, std::optional<int64_t>& model_version) {
if (!model_version_str.empty()) {
try {
model_version = std::stoll(model_version_str.c_str());
} catch (std::out_of_range const&) {
return StatusCode::MODEL_VERSION_MISSING;
} catch (std::exception&) {
SPDLOG_DEBUG("Couldn't parse model version {}", model_version_str);
return StatusCode::REST_COULD_NOT_PARSE_VERSION;
}
}
return StatusCode::OK;
}
void HttpRestApiHandler::registerHandler(RequestType type, HandlerCallbackFn f) {
handlers[type] = std::move(f);
}
void HttpRestApiHandler::registerAll() {
registerHandler(Predict, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
if (request_components.processing_method == "predict") {
return processPredictRequest(request_components.model_name, request_components.model_version,
request_components.model_version_label, request_body, &response);
} else {
SPDLOG_DEBUG("Requested REST resource not found");
return StatusCode::REST_NOT_FOUND;
}
});
registerHandler(GetModelMetadata, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) {
return processModelMetadataRequest(request_components.model_name, request_components.model_version,
request_components.model_version_label, &response);
});
registerHandler(GetModelStatus, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) {
return processModelStatusRequest(request_components.model_name, request_components.model_version,
request_components.model_version_label, &response);
});
registerHandler(ConfigReload, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processConfigReloadRequest(response, this->modelManager);
});
registerHandler(ConfigStatus, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processConfigStatusRequest(response, this->modelManager);
});
registerHandler(KFS_GetModelReady, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processModelReadyKFSRequest(request_components, response, request_body);
});
registerHandler(KFS_GetModelMetadata, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processModelMetadataKFSRequest(request_components, response, request_body);
});
registerHandler(KFS_Infer, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processInferKFSRequest(request_components, response, request_body, response_components.inferenceHeaderContentLength);
});
registerHandler(KFS_GetServerReady, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processServerReadyKFSRequest(request_components, response, request_body);
});
registerHandler(KFS_GetServerLive, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processServerLiveKFSRequest(request_components, response, request_body);
});
registerHandler(KFS_GetServerMetadata, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processServerMetadataKFSRequest(request_components, response, request_body);
});
registerHandler(V3, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
OVMS_PROFILE_FUNCTION();
return processV3(uri, request_components, response, request_body, std::move(serverReaderWriter));
});
registerHandler(Metrics, [this](const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, HttpResponseComponents& response_components, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) -> Status {
return processMetrics(request_components, response, request_body);
});
}
Status HttpRestApiHandler::processServerReadyKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
bool isReady = this->ovmsServer.isReady();
SPDLOG_DEBUG("Requested Server readiness state: {}", isReady);
if (isReady) {
return StatusCode::OK;
}
return StatusCode::MODEL_NOT_LOADED;
}
Status HttpRestApiHandler::processServerLiveKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
bool isLive = this->ovmsServer.isLive(HTTP_SERVER_MODULE_NAME);
SPDLOG_DEBUG("Requested Server liveness state: {}", isLive);
if (isLive) {
return StatusCode::OK;
}
return StatusCode::INTERNAL_ERROR;
}
Status HttpRestApiHandler::processServerMetadataKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
::KFSServerMetadataRequest grpc_request;
::KFSServerMetadataResponse grpc_response;
Status gstatus = kfsGrpcImpl.ServerMetadataImpl(nullptr, &grpc_request, &grpc_response);
if (!gstatus.ok()) {
return gstatus;
}
std::string output;
google::protobuf::util::JsonPrintOptions opts;
google::protobuf::util::Status status = google::protobuf::util::MessageToJsonString(grpc_response, &output, opts);
if (!status.ok()) {
return StatusCode::INTERNAL_ERROR;
}
response = std::move(output);
return StatusCode::OK;
}
static bool isInputEmpty(const ::KFSRequest::InferInputTensor& input) {
if (input.datatype() == "FP32")
return input.contents().fp32_contents_size() == 0;
if (input.datatype() == "INT64")
return input.contents().int64_contents_size() == 0;
if (input.datatype() == "INT32")
return input.contents().int_contents_size() == 0;
if (input.datatype() == "INT16")
return input.contents().int_contents_size() == 0;
if (input.datatype() == "INT8")
return input.contents().int_contents_size() == 0;
if (input.datatype() == "UINT64")
return input.contents().uint64_contents_size() == 0;
if (input.datatype() == "UINT32")
return input.contents().uint_contents_size() == 0;
if (input.datatype() == "UINT16")
return input.contents().uint_contents_size() == 0;
if (input.datatype() == "UINT8")
return input.contents().uint_contents_size() == 0;
if (input.datatype() == "FP64")
return input.contents().fp64_contents_size() == 0;
if (input.datatype() == "BYTES")
return input.contents().bytes_contents_size() == 0;
if (input.datatype() == "BOOL")
return input.contents().bool_contents_size() == 0;
return true;
}
static Status handleBinaryInput(const int binary_input_size, size_t& binary_input_offset, const size_t binary_buffer_size, const char* binary_inputs_buffer, ::KFSRequest::InferInputTensor& input, std::string* rawInputContentsBuffer) {
if (binary_input_offset + binary_input_size > binary_buffer_size) {
SPDLOG_DEBUG("Binary inputs size exceeds provided buffer size {}, binary input offset {}, binary_input size {}",
binary_buffer_size,
binary_input_offset,
binary_input_size);
return StatusCode::REST_BINARY_BUFFER_EXCEEDED;
}
rawInputContentsBuffer->assign(binary_inputs_buffer + binary_input_offset, binary_input_size);
binary_input_offset += binary_input_size;
return StatusCode::OK;
}
static size_t calculateBinaryDataSize(::KFSRequest::InferInputTensor& input) {
auto element_size = KFSDataTypeSize(input.datatype());
size_t elements_number = std::accumulate(std::begin(input.shape()), std::end(input.shape()), 1, std::multiplies<size_t>());
size_t binary_data_size = elements_number * element_size;
return binary_data_size;
}
static Status handleBinaryInputs(::KFSRequest& grpc_request, const std::string& request_body, size_t endOfJson) {
const char* binary_inputs_buffer = &(request_body[endOfJson]);
size_t binary_buffer_size = request_body.length() - endOfJson;
size_t binary_input_offset = 0;
for (int i = 0; i < grpc_request.mutable_inputs()->size(); i++) {
auto input = grpc_request.mutable_inputs()->Mutable(i);
auto binary_data_size_parameter = input->parameters().find("binary_data_size");
size_t binary_input_size = 0;
if (binary_data_size_parameter != input->parameters().end()) {
if (!isInputEmpty(*input)) {
SPDLOG_DEBUG("Request contains both data in json and binary inputs");
return StatusCode::REST_CONTENTS_FIELD_NOT_EMPTY;
}
if (binary_data_size_parameter->second.parameter_choice_case() == inference::InferParameter::ParameterChoiceCase::kInt64Param) {
binary_input_size = binary_data_size_parameter->second.int64_param();
} else {
SPDLOG_DEBUG("binary_data_size parameter type should be int64");
return StatusCode::REST_BINARY_DATA_SIZE_PARAMETER_INVALID;
}
} else {
if (!isInputEmpty(*input))
continue;
if (grpc_request.mutable_inputs()->size() == 1 && input->datatype() == "BYTES") {
binary_input_size = binary_buffer_size;
} else {
binary_input_size = calculateBinaryDataSize(*input);
}
}
auto status = handleBinaryInput(binary_input_size, binary_input_offset, binary_buffer_size, binary_inputs_buffer, *input, grpc_request.add_raw_input_contents());
if (!status.ok()) {
SPDLOG_DEBUG("Error handling binary input");
return status;
}
}
return StatusCode::OK;
}
Status HttpRestApiHandler::prepareGrpcRequest(const std::string modelName, const std::optional<int64_t>& modelVersion, const std::string& request_body, ::KFSRequest& grpc_request, const std::optional<int>& inferenceHeaderContentLength) {
KFSRestParser requestParser;
size_t endOfJson = inferenceHeaderContentLength.value_or(request_body.length());
if (endOfJson > request_body.length()) {
SPDLOG_DEBUG("Inference header content length exceeded JSON size");
return StatusCode::REST_INFERENCE_HEADER_CONTENT_LENGTH_EXCEEDED;
}
auto status = requestParser.parse(request_body.substr(0, endOfJson).c_str());
if (!status.ok()) {
SPDLOG_DEBUG("Parsing http request failed");
return status;
}
grpc_request = requestParser.getProto();
status = handleBinaryInputs(grpc_request, request_body, endOfJson);
if (!status.ok()) {
SPDLOG_DEBUG("Error handling binary inputs");
return status;
}
grpc_request.set_model_name(modelName);
if (modelVersion.has_value()) {
grpc_request.set_model_version(std::to_string(modelVersion.value()));
}
return StatusCode::OK;
}
static std::set<std::string> getRequestedBinaryOutputsNames(::KFSRequest& grpc_request) {
std::set<std::string> binaryOutputs;
bool byDefaultBinaryOutpuRequested = false;
for (auto& parameter : grpc_request.parameters()) {
if (parameter.second.parameter_choice_case() == inference::InferParameter::ParameterChoiceCase::kBoolParam) {
if (parameter.first == "binary_data_output") {
byDefaultBinaryOutpuRequested = parameter.second.bool_param();
break;
}
}
}
for (const inference::ModelInferRequest_InferRequestedOutputTensor& output : grpc_request.outputs()) {
bool specificBinaryOutputRequested = byDefaultBinaryOutpuRequested;
for (auto& parameter : output.parameters()) {
if ((parameter.second.parameter_choice_case() == inference::InferParameter::ParameterChoiceCase::kBoolParam) &&
(parameter.first == "binary_data")) {
specificBinaryOutputRequested = parameter.second.bool_param();
break;
}
}
if (specificBinaryOutputRequested) {
binaryOutputs.insert(output.name());
}
}
return binaryOutputs;
}
Status HttpRestApiHandler::processInferKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, std::optional<int>& inferenceHeaderContentLength) {
Timer<TIMER_END> timer;
timer.start(TOTAL);
ServableMetricReporter* reporter = nullptr;
std::string modelName(request_components.model_name);
std::string modelVersionLog = request_components.model_version.has_value() ? std::to_string(request_components.model_version.value()) : DEFAULT_VERSION;
SPDLOG_DEBUG("Processing REST request for model: {}; version: {}", modelName, modelVersionLog);
::KFSRequest grpc_request;
timer.start(PREPARE_GRPC_REQUEST);
using std::chrono::microseconds;
auto status = prepareGrpcRequest(modelName, request_components.model_version, request_body, grpc_request, request_components.inferenceHeaderContentLength);
ExecutionContext executionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::ModelInfer};
if (!status.ok()) {
auto pstatus = this->getReporter(request_components, reporter);
if (pstatus.ok()) {
INCREMENT_IF_ENABLED(reporter->getInferRequestMetric(executionContext, status.ok()));
}
SPDLOG_DEBUG("REST to GRPC request conversion failed for model: {}", modelName);
return status;
}
timer.stop(PREPARE_GRPC_REQUEST);
SPDLOG_DEBUG("Preparing grpc request time: {} ms", timer.elapsed<std::chrono::microseconds>(PREPARE_GRPC_REQUEST) / 1000);
::KFSResponse grpc_response;
const Status gstatus = kfsGrpcImpl.ModelInferImpl(nullptr, &grpc_request, &grpc_response, executionContext, reporter);
if (!gstatus.ok()) {
return gstatus;
}
std::set<std::string> requestedBinaryOutputsNames = getRequestedBinaryOutputsNames(grpc_request);
std::string output;
status = ovms::makeJsonFromPredictResponse(grpc_response, &output, inferenceHeaderContentLength, requestedBinaryOutputsNames);
if (!status.ok()) {
return status;
}
response = std::move(output);
timer.stop(TOTAL);
double totalTime = timer.elapsed<std::chrono::microseconds>(TOTAL);
SPDLOG_DEBUG("Total REST request processing time: {} ms", totalTime / 1000);
if (!reporter) {
return StatusCode::OK;
// There is no request time metric for MediaPipe endpoints
}
OBSERVE_IF_ENABLED(reporter->requestTimeRest, totalTime);
return StatusCode::OK;
}
Status HttpRestApiHandler::dispatchToProcessor(
const std::string_view uri,
const std::string& request_body,
std::string* response,
const HttpRequestComponents& request_components,
HttpResponseComponents& response_components,
std::shared_ptr<HttpAsyncWriter> serverReaderWriter) {
auto handler = handlers.find(request_components.type);
if (handler != handlers.end()) {
return handler->second(uri, request_components, *response, request_body, response_components, std::move(serverReaderWriter));
} else {
return StatusCode::UNKNOWN_REQUEST_COMPONENTS_TYPE;
}
return StatusCode::UNKNOWN_REQUEST_COMPONENTS_TYPE;
}
Status HttpRestApiHandler::processV3(const std::string_view uri, const HttpRequestComponents& request_components, std::string& response, const std::string& request_body, std::shared_ptr<HttpAsyncWriter> serverReaderWriter) {
#if (MEDIAPIPE_DISABLE == 0)
OVMS_PROFILE_FUNCTION();
HttpPayload request;
std::shared_ptr<Document> doc = std::make_shared<Document>();
std::shared_ptr<MediapipeGraphExecutor> executor;
bool streamFieldVal = false;
{
OVMS_PROFILE_SCOPE("rapidjson parse body");
doc->Parse(request_body.c_str());
}
{
OVMS_PROFILE_SCOPE("rapidjson validate");
if (doc->HasParseError()) {
return Status(StatusCode::JSON_INVALID, "Cannot parse JSON body");
}
if (!doc->IsObject()) {
return Status(StatusCode::JSON_INVALID, "JSON body must be an object");
}
auto modelNameIt = doc->FindMember("model");
if (modelNameIt == doc->MemberEnd()) {
return Status(StatusCode::JSON_INVALID, "model field is missing in JSON body");
}
if (!modelNameIt->value.IsString()) {
return Status(StatusCode::JSON_INVALID, "model field is not a string");
}
const std::string model_name = modelNameIt->value.GetString();
bool isTextGenerationEndpoint = uri.find("completions") != std::string_view::npos;
if (isTextGenerationEndpoint) {
auto streamIt = doc->FindMember("stream");
if (streamIt != doc->MemberEnd()) {
if (!streamIt->value.IsBool()) {
return Status(StatusCode::JSON_INVALID, "stream field is not a boolean");
}
streamFieldVal = streamIt->value.GetBool();
}
}
auto status = this->modelManager.createPipeline(executor, model_name);
if (!status.ok()) {
return status;
}
// TODO: Possibly avoid making copy
request.headers = request_components.headers;
request.body = request_body;
request.parsedJson = std::move(doc);
request.uri = std::string(uri);
request.client = std::make_shared<HttpClientConnection>(serverReaderWriter);
}
if (streamFieldVal == false) {
ExecutionContext executionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::V3Unary};
return executor->infer(&request, &response, executionContext);
} else {
serverReaderWriter->OverwriteResponseHeader("Content-Type", "text/event-stream");
serverReaderWriter->OverwriteResponseHeader("Cache-Control", "no-cache");
serverReaderWriter->OverwriteResponseHeader("Connection", "keep-alive");
serverReaderWriter->PartialReplyBegin([executor = std::move(executor), serverReaderWriter, request = std::move(request)] {
ExecutionContext executionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::V3Stream};
auto status = executor->inferStream(request, *serverReaderWriter, executionContext);
if (!status.ok()) {
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject();
writer.String("error");
writer.String(status.string().c_str());
writer.EndObject();
serverReaderWriter->PartialReplyWithStatus(buffer.GetString(), HTTPStatusCode::BAD_REQUEST);
}
serverReaderWriter->PartialReplyEnd();
});
return StatusCode::PARTIAL_END;
}
#else
SPDLOG_DEBUG("Mediapipe support was disabled during build process...");
return StatusCode::NOT_IMPLEMENTED;
#endif
}
Status HttpRestApiHandler::processMetrics(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
auto module = this->ovmsServer.getModule(METRICS_MODULE_NAME);
if (nullptr == module) {
SPDLOG_ERROR("Failed to process metrics - metrics module is missing");
return StatusCode::INTERNAL_ERROR;
}
auto& metricConfig = this->modelManager.getMetricConfig();
if (!metricConfig.metricsEnabled) {
return StatusCode::REST_INVALID_URL;
}
auto metricModule = dynamic_cast<const MetricModule*>(module);
response = metricModule->getRegistry().collect();
return StatusCode::OK;
}
Status HttpRestApiHandler::processModelReadyKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
::KFSGetModelStatusRequest grpc_request;
::KFSGetModelStatusResponse grpc_response;
std::string modelName(request_components.model_name);
grpc_request.set_name(modelName);
if (request_components.model_version.has_value()) {
grpc_request.set_version(std::to_string(request_components.model_version.value()));
}
std::string modelVersionLog = request_components.model_version.has_value() ? std::to_string(request_components.model_version.value()) : DEFAULT_VERSION;
SPDLOG_DEBUG("Processing REST request for model: {}; version: {}", modelName, modelVersionLog);
Status status = kfsGrpcImpl.ModelReadyImpl(nullptr, &grpc_request, &grpc_response, ExecutionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::ModelReady});
if (!status.ok()) {
return status;
}
if (grpc_response.ready()) {
return StatusCode::OK;
}
return StatusCode::MODEL_VERSION_NOT_LOADED_YET;
}
void HttpRestApiHandler::convertShapeType(Value& scope, Document& doc) {
for (SizeType i = 0; i < scope.Size(); i++) {
Value data = scope[i].GetObject()["shape"].GetArray();
Value shape(rapidjson::kArrayType);
for (SizeType j = 0; j < data.Size(); j++) {
shape.PushBack(atoi(data[j].GetString()), doc.GetAllocator());
}
scope[i].GetObject()["shape"] = shape;
}
}
void HttpRestApiHandler::convertRTInfo(Value& scope, Document& doc, ov::AnyMap& rtInfo) {
scope.SetObject();
for (auto& [key, value] : rtInfo) {
SPDLOG_DEBUG("building rest response: rt_info: key: {}; value: {}", key, value.as<std::string>());
rapidjson::Value rtInfoKey, rtInfoValue, subScope;
rtInfoKey.SetString(key.c_str(), doc.GetAllocator());
if (value.is<ov::AnyMap>()) {
SPDLOG_DEBUG("building submap rest response : key: {};", key);
subScope.SetObject();
convertRTInfo(subScope, doc, value.as<ov::AnyMap>());
scope.AddMember(rtInfoKey, subScope, doc.GetAllocator());
} else {
try {
rtInfoValue.SetString(value.as<std::string>().c_str(), doc.GetAllocator());
} catch (const std::exception& e) {
SPDLOG_ERROR("Error converting RT info value to string: {}", e.what());
rtInfoValue.SetString("Error converting value", doc.GetAllocator());
}
scope.AddMember(rtInfoKey, rtInfoValue, doc.GetAllocator());
}
}
}
Status HttpRestApiHandler::processModelMetadataKFSRequest(const HttpRequestComponents& request_components, std::string& response, const std::string& request_body) {
::KFSModelMetadataRequest grpc_request;
::KFSModelMetadataResponse grpc_response;
std::string modelName(request_components.model_name);
grpc_request.set_name(modelName);
if (request_components.model_version.has_value()) {
grpc_request.set_version(std::to_string(request_components.model_version.value()));
}
std::string modelVersionLog = request_components.model_version.has_value() ? std::to_string(request_components.model_version.value()) : DEFAULT_VERSION;
SPDLOG_DEBUG("Processing REST request for model: {}; version: {}", modelName, modelVersionLog);
KFSModelExtraMetadata extraMetadata;
Status gstatus = kfsGrpcImpl.ModelMetadataImpl(nullptr, &grpc_request, &grpc_response, ExecutionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::ModelMetadata}, extraMetadata);
if (!gstatus.ok()) {
return gstatus;
}
std::string output;
google::protobuf::util::JsonPrintOptions opts;
// This parameter forces JSON writer to not omit empty shape in case of scalar tensor
opts.always_print_primitive_fields = true;
google::protobuf::util::Status status = google::protobuf::util::MessageToJsonString(grpc_response, &output, opts);
if (!status.ok()) {
return StatusCode::JSON_SERIALIZATION_ERROR;
}
Document doc;
doc.Parse(output.c_str());
convertShapeType(doc["inputs"], doc);
convertShapeType(doc["outputs"], doc);
if (extraMetadata.rt_info.count("model_info")) {
rapidjson::Value modelInfoScope, rtInfoScope;
modelInfoScope.SetObject();
rtInfoScope.SetObject();
try {
convertRTInfo(modelInfoScope, doc, extraMetadata.rt_info["model_info"].as<ov::AnyMap>());
} catch (const std::exception& e) {
SPDLOG_DEBUG("Error converting RT info: {}", e.what());
return StatusCode::INTERNAL_ERROR;
}
rtInfoScope.AddMember("model_info", modelInfoScope, doc.GetAllocator());
doc.AddMember("rt_info", rtInfoScope, doc.GetAllocator());
}
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
doc.Accept(writer);
response = buffer.GetString();
return StatusCode::OK;
}
static Status parseInferenceHeaderContentLength(HttpRequestComponents& requestComponents,
const std::vector<std::pair<std::string, std::string>>& headers) {
for (auto& header : headers) {
if (toLower(header.first) == "inference-header-content-length") { // drogon automatically converts all headers to lowercase, net_http does not
requestComponents.inferenceHeaderContentLength = stoi32(header.second);
if (!requestComponents.inferenceHeaderContentLength.has_value() || requestComponents.inferenceHeaderContentLength.value() < 0) {
return StatusCode::REST_INFERENCE_HEADER_CONTENT_LENGTH_INVALID;
}
}
}
return StatusCode::OK;
}
Status HttpRestApiHandler::parseRequestComponents(HttpRequestComponents& requestComponents,
const std::string_view http_method,
const std::string& request_path,
const std::vector<std::pair<std::string, std::string>>& headers) {
std::smatch sm;
requestComponents.http_method = http_method;
if (http_method != "POST" && http_method != "GET") {
return StatusCode::REST_UNSUPPORTED_METHOD;
}
if (FileSystem::isPathEscaped(request_path)) {
SPDLOG_DEBUG("Path {} escape with .. is forbidden.", request_path);
return StatusCode::PATH_INVALID;
}
if (http_method == "POST") {
if (std::regex_match(request_path, sm, predictionRegex)) {
requestComponents.type = Predict;
requestComponents.model_name = urlDecode(sm[2]);
std::string model_version_str = sm[3];
auto status = parseModelVersion(model_version_str, requestComponents.model_version);
if (!status.ok())
return status;
std::string model_version_label_str = sm[4];
if (!model_version_label_str.empty()) {
requestComponents.model_version_label = model_version_label_str;
}
requestComponents.processing_method = sm[5];
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_inferRegex, std::regex_constants::match_any)) {
requestComponents.type = KFS_Infer;
requestComponents.model_name = urlDecode(sm[1]);
std::string model_version_str = sm[2];
auto status = parseModelVersion(model_version_str, requestComponents.model_version);
if (!status.ok())
return status;
status = parseInferenceHeaderContentLength(requestComponents, headers);
if (!status.ok())
return status;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, v3_Regex)) {
requestComponents.type = V3;
auto status = parseInferenceHeaderContentLength(requestComponents, headers);
if (!status.ok())
return status;
requestComponents.headers = headers;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, configReloadRegex)) {
requestComponents.type = ConfigReload;
return StatusCode::OK;
}
return (std::regex_match(request_path, sm, modelstatusRegex) ||
std::regex_match(request_path, sm, kfs_serverliveRegex) ||
std::regex_match(request_path, sm, configStatusRegex) ||
std::regex_match(request_path, sm, kfs_serverreadyRegex) ||
std::regex_match(request_path, sm, kfs_servermetadataRegex) ||
std::regex_match(request_path, sm, kfs_modelmetadataRegex) ||
std::regex_match(request_path, sm, kfs_modelreadyRegex) ||
std::regex_match(request_path, sm, metricsRegex))
? StatusCode::REST_UNSUPPORTED_METHOD
: StatusCode::REST_INVALID_URL;
} else if (http_method == "GET") {
if (std::regex_match(request_path, sm, modelstatusRegex)) {
requestComponents.model_name = urlDecode(sm[2]);
std::string model_version_str = sm[3];
auto status = parseModelVersion(model_version_str, requestComponents.model_version);
if (!status.ok())
return status;
std::string model_version_label_str = sm[4];
if (!model_version_label_str.empty()) {
requestComponents.model_version_label = model_version_label_str;
}
requestComponents.model_subresource = sm[5];
if (!requestComponents.model_subresource.empty() && requestComponents.model_subresource == "metadata") {
requestComponents.type = GetModelMetadata;
} else {
requestComponents.type = GetModelStatus;
}
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, configStatusRegex)) {
requestComponents.type = ConfigStatus;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_serverliveRegex)) {
requestComponents.type = KFS_GetServerLive;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_serverreadyRegex)) {
requestComponents.type = KFS_GetServerReady;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_servermetadataRegex)) {
requestComponents.type = KFS_GetServerMetadata;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_modelmetadataRegex)) {
requestComponents.model_name = urlDecode(sm[1]);
std::string model_version_str = sm[2];
auto status = parseModelVersion(model_version_str, requestComponents.model_version);
if (!status.ok())
return status;
requestComponents.type = KFS_GetModelMetadata;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, kfs_modelreadyRegex)) {
requestComponents.model_name = urlDecode(sm[1]);
std::string model_version_str = sm[2];
auto status = parseModelVersion(model_version_str, requestComponents.model_version);
if (!status.ok())
return status;
requestComponents.type = KFS_GetModelReady;
return StatusCode::OK;
}
if (std::regex_match(request_path, sm, predictionRegex))
return StatusCode::REST_UNSUPPORTED_METHOD;
if (std::regex_match(request_path, sm, metricsRegex)) {
std::string params = sm[3];
if (!params.empty()) {
SPDLOG_DEBUG("Discarded following url parameters: {}", params);
}
requestComponents.type = Metrics;
return StatusCode::OK;
}
return (std::regex_match(request_path, sm, predictionRegex) ||
std::regex_match(request_path, sm, kfs_inferRegex, std::regex_constants::match_any) ||
std::regex_match(request_path, sm, configReloadRegex))
? StatusCode::REST_UNSUPPORTED_METHOD
: StatusCode::REST_INVALID_URL;
}
return StatusCode::REST_INVALID_URL;
}
Status HttpRestApiHandler::processRequest(
const std::string_view http_method,
const std::string_view request_path,
const std::string& request_body,
std::vector<std::pair<std::string, std::string>>* headers,
std::string* response,
HttpResponseComponents& responseComponents,
std::shared_ptr<HttpAsyncWriter> serverReaderWriter) {
std::smatch sm;
std::string request_path_str(request_path);
if (FileSystem::isPathEscaped(request_path_str)) {
SPDLOG_DEBUG("Path {} escape with .. is forbidden.", request_path);
return StatusCode::PATH_INVALID;
}
HttpRequestComponents requestComponents;
auto status = parseRequestComponents(requestComponents, http_method, request_path_str, *headers);
headers->clear();
response->clear();
headers->push_back({"Content-Type", "application/json"});
if (!status.ok())
return status;
return dispatchToProcessor(request_path, request_body, response, requestComponents, responseComponents, std::move(serverReaderWriter));
}
Status HttpRestApiHandler::processPredictRequest(
const std::string& modelName,
const std::optional<int64_t>& modelVersion,
const std::optional<std::string_view>& modelVersionLabel,
const std::string& request,
std::string* response) {
// model_version_label currently is not in use
Timer<TIMER_END> timer;
timer.start(TOTAL);
using std::chrono::microseconds;
std::string modelVersionLog = modelVersion.has_value() ? std::to_string(modelVersion.value()) : DEFAULT_VERSION;
SPDLOG_DEBUG("Processing REST request for model: {}; version: {}",
modelName, modelVersionLog);
Order requestOrder = Order::UNKNOWN;
tensorflow::serving::PredictResponse responseProto;
Status status;
ServableMetricReporter* reporterOut = nullptr;
if (this->modelManager.modelExists(modelName)) {
SPDLOG_DEBUG("Found model with name: {}. Searching for requested version...", modelName);
status = processSingleModelRequest(modelName, modelVersion, request, requestOrder, responseProto, reporterOut);
} else if (this->modelManager.pipelineDefinitionExists(modelName)) {
SPDLOG_DEBUG("Found pipeline with name: {}", modelName);
status = processPipelineRequest(modelName, request, requestOrder, responseProto, reporterOut);
} else {
SPDLOG_DEBUG("Model or pipeline matching request parameters not found - name: {}, version: {}", modelName, modelVersionLog);
status = StatusCode::MODEL_NAME_MISSING;
}
if (!status.ok())
return status;
status = makeJsonFromPredictResponse(responseProto, response, requestOrder);
if (!status.ok())
return status;
timer.stop(TOTAL);
double requestTime = timer.elapsed<std::chrono::microseconds>(TOTAL);
SPDLOG_DEBUG("Total REST request processing time: {} ms", requestTime / 1000);
if (!reporterOut) {
return StatusCode::OK;
// There is no request time metric for MediaPipe endpoints
}
OBSERVE_IF_ENABLED(reporterOut->requestTimeRest, requestTime);
return StatusCode::OK;
}
Status HttpRestApiHandler::processSingleModelRequest(const std::string& modelName,
const std::optional<int64_t>& modelVersion,
const std::string& request,
Order& requestOrder,
tensorflow::serving::PredictResponse& responseProto,
ServableMetricReporter*& reporterOut) {
std::shared_ptr<ModelInstance> modelInstance;
std::unique_ptr<ModelInstanceUnloadGuard> modelInstanceUnloadGuard;
auto status = this->modelManager.getModelInstance(
modelName,
modelVersion.value_or(0),
modelInstance,
modelInstanceUnloadGuard);
if (!status.ok()) {
if (modelInstance) {
INCREMENT_IF_ENABLED(modelInstance->getMetricReporter().requestFailRestPredict);
}
std::string modelVersionLog = modelVersion.has_value() ? std::to_string(modelVersion.value()) : DEFAULT_VERSION;
SPDLOG_DEBUG("Requested model instance - name: {}, version: {} - does not exist.", modelName, modelVersionLog);
return status;
}
reporterOut = &modelInstance->getMetricReporter();
Timer<TIMER_END> timer;
timer.start(TOTAL);
TFSRestParser requestParser(modelInstance->getInputsInfo());
status = requestParser.parse(request.c_str());
if (!status.ok()) {
INCREMENT_IF_ENABLED(modelInstance->getMetricReporter().requestFailRestPredict);
return status;
}
requestOrder = requestParser.getOrder();
timer.stop(TOTAL);
SPDLOG_DEBUG("JSON request parsing time: {} ms", timer.elapsed<std::chrono::microseconds>(TOTAL) / 1000);
tensorflow::serving::PredictRequest& requestProto = requestParser.getProto();
requestProto.mutable_model_spec()->set_name(modelName);
if (modelVersion.has_value()) {
requestProto.mutable_model_spec()->mutable_version()->set_value(modelVersion.value());
}
status = infer(*modelInstance, &requestProto, &responseProto, modelInstanceUnloadGuard);
INCREMENT_IF_ENABLED(modelInstance->getMetricReporter().getInferRequestMetric(ExecutionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::Predict}, status.ok()));
return status;
}
Status HttpRestApiHandler::getReporter(const HttpRequestComponents& components, ovms::ServableMetricReporter*& reporter) {
std::shared_ptr<ovms::ModelInstance> modelInstance;
std::unique_ptr<ovms::Pipeline> pipelinePtr;
std::unique_ptr<ModelInstanceUnloadGuard> modelInstanceUnloadGuard;
auto status = this->modelManager.getModelInstance(components.model_name, components.model_version.value_or(0), modelInstance, modelInstanceUnloadGuard);
if (status == StatusCode::MODEL_NAME_MISSING) {
auto pipelineDefinition = this->modelManager.getPipelineFactory().findDefinitionByName(components.model_name);
if (!pipelineDefinition) {
return StatusCode::MODEL_MISSING;
}
reporter = &pipelineDefinition->getMetricReporter();
} else if (status.ok()) {
reporter = &modelInstance->getMetricReporter();
} else {
return StatusCode::MODEL_MISSING;
}
return StatusCode::OK;
}
Status HttpRestApiHandler::getPipelineInputsAndReporter(const std::string& modelName, ovms::tensor_map_t& inputs, ovms::ServableMetricReporter*& reporter) {
auto pipelineDefinition = this->modelManager.getPipelineFactory().findDefinitionByName(modelName);
if (!pipelineDefinition) {
return StatusCode::MODEL_MISSING;
}
std::unique_ptr<PipelineDefinitionUnloadGuard> unloadGuard;
Status status = pipelineDefinition->waitForLoaded(unloadGuard);
if (!status.ok()) {
return status;
}
reporter = &pipelineDefinition->getMetricReporter();
inputs = pipelineDefinition->getInputsInfo();
return StatusCode::OK;
}
Status HttpRestApiHandler::processPipelineRequest(const std::string& modelName,
const std::string& request,
Order& requestOrder,
tensorflow::serving::PredictResponse& responseProto,
ServableMetricReporter*& reporterOut) {
ExecutionContext executionContext{ExecutionContext::Interface::REST, ExecutionContext::Method::Predict};
std::unique_ptr<Pipeline> pipelinePtr;
Timer<TIMER_END> timer;
timer.start(TOTAL);
ovms::tensor_map_t inputs;
auto status = getPipelineInputsAndReporter(modelName, inputs, reporterOut);
if (!status.ok()) {
if (reporterOut) {
INCREMENT_IF_ENABLED(reporterOut->getInferRequestMetric(executionContext, false));
}
return status;
}
TFSRestParser requestParser(inputs);
status = requestParser.parse(request.c_str());
if (!status.ok()) {
INCREMENT_IF_ENABLED(reporterOut->getInferRequestMetric(executionContext, false));
return status;
}
requestOrder = requestParser.getOrder();