TensorFlow Serving C++ API Documentation
model_service_impl.h
1 /* Copyright 2018 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_SERVICE_IMPL_H_
17 #define TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_SERVICE_IMPL_H_
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "grpcpp/server_context.h"
23 #include "grpcpp/support/status.h"
24 #include "absl/container/flat_hash_map.h"
25 #include "tensorflow_serving/apis/model_management.pb.h"
26 #include "tensorflow_serving/apis/model_service.grpc.pb.h"
27 #include "tensorflow_serving/apis/model_service.pb.h"
28 #include "tensorflow_serving/model_servers/server_core.h"
29 
30 namespace tensorflow {
31 namespace serving {
32 
33 class ModelServiceImpl final : public ModelService::Service {
34  public:
35  explicit ModelServiceImpl(ServerCore *core) : core_(core) {}
36 
37  ::grpc::Status GetModelStatus(::grpc::ServerContext *context,
38  const GetModelStatusRequest *request,
39  GetModelStatusResponse *response) override;
40 
41  ::grpc::Status HandleReloadConfigRequest(::grpc::ServerContext *context,
42  const ReloadConfigRequest *request,
43  ReloadConfigResponse *response);
44 
45  private:
46  ServerCore *core_;
47 
48  // Obtains values for metrics provided in request.
49  absl::flat_hash_map<std::string, int64_t> GetMetrics(
50  const ReloadConfigRequest *request);
51 
52  // Compares old_metric_values and new_metric_values, storing the increases in
53  // response
54  void RecordMetricsIncrease(
55  const absl::flat_hash_map<std::string, int64_t> &old_metric_values,
56  const absl::flat_hash_map<std::string, int64_t> &new_metric_values,
57  ReloadConfigResponse *response);
58 };
59 
60 } // namespace serving
61 } // namespace tensorflow
62 
63 #endif // TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_SERVICE_IMPL_H_