TensorFlow Serving C++ API Documentation
aspired_version_policy.h
1 /* Copyright 2016 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_CORE_ASPIRED_VERSION_POLICY_H_
17 #define TENSORFLOW_SERVING_CORE_ASPIRED_VERSION_POLICY_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "absl/types/optional.h"
23 #include "tensorflow/core/lib/strings/strcat.h"
24 #include "tensorflow/core/platform/types.h"
25 #include "tensorflow_serving/core/loader_harness.h"
26 #include "tensorflow_serving/core/servable_id.h"
27 namespace tensorflow {
28 namespace serving {
29 
32  ServableId id;
34  bool is_aspired;
35 };
36 
49  public:
51  enum class Action : int {
53  kLoad,
55  kUnload,
56  };
57 
58  virtual ~AspiredVersionPolicy() = default;
59 
61  struct ServableAction final {
62  Action action;
63  ServableId id;
64 
65  string DebugString() const {
66  return strings::StrCat("{ action: ", static_cast<int>(action),
67  " id: ", id.DebugString(), " }");
68  }
69  };
70 
77  virtual absl::optional<ServableAction> GetNextAction(
78  const std::vector<AspiredServableStateSnapshot>& all_versions) const = 0;
79 
80  protected:
83  static absl::optional<ServableId> GetHighestAspiredNewServableId(
84  const std::vector<AspiredServableStateSnapshot>& all_versions);
85 
86  private:
87  friend class AspiredVersionPolicyTest;
88 };
89 
90 inline bool operator==(const AspiredVersionPolicy::ServableAction& lhs,
92  return lhs.action == rhs.action && lhs.id == rhs.id;
93 }
94 
95 } // namespace serving
96 } // namespace tensorflow
97 
98 #endif // TENSORFLOW_SERVING_CORE_ASPIRED_VERSION_POLICY_H_
Action
The different actions that could be recommended by a policy.
static absl::optional< ServableId > GetHighestAspiredNewServableId(const std::vector< AspiredServableStateSnapshot > &all_versions)
virtual absl::optional< ServableAction > GetNextAction(const std::vector< AspiredServableStateSnapshot > &all_versions) const =0
A snapshot of a servable's state and aspiredness.
Action and the id of the servable associated with it.