16 #ifndef TENSORFLOW_SERVING_CORE_MANAGER_H_
17 #define TENSORFLOW_SERVING_CORE_MANAGER_H_
25 #include "absl/types/optional.h"
26 #include "tensorflow/core/lib/core/errors.h"
27 #include "tensorflow/core/lib/core/status.h"
28 #include "tensorflow/core/lib/strings/strcat.h"
29 #include "tensorflow/core/platform/types.h"
30 #include "tensorflow_serving/core/servable_handle.h"
31 #include "tensorflow_serving/core/servable_id.h"
33 namespace tensorflow {
41 static ServableRequest Specific(
const string& name,
const int64_t version);
50 absl::optional<int64_t> version;
53 enum class AutoVersionPolicy {
60 AutoVersionPolicy auto_version_policy = AutoVersionPolicy::kLatest;
63 string DebugString()
const;
69 const absl::optional<int64_t>& version_in)
72 auto_version_policy(AutoVersionPolicy::kLatest) {}
109 virtual Status GetUntypedServableHandle(
111 std::unique_ptr<UntypedServableHandle>* untyped_handle) = 0;
115 virtual std::map<ServableId, std::unique_ptr<UntypedServableHandle>>
116 GetAvailableUntypedServableHandles()
const = 0;
124 const int64_t version) {
127 request.version = version;
131 inline ServableRequest ServableRequest::Earliest(
const string& name) {
132 ServableRequest request;
134 request.auto_version_policy = AutoVersionPolicy::kEarliest;
138 inline ServableRequest ServableRequest::Latest(
const string& name) {
139 ServableRequest request;
141 request.auto_version_policy = AutoVersionPolicy::kLatest;
145 inline ServableRequest ServableRequest::FromId(
const ServableId&
id) {
146 DCHECK_GE(
id.version, 0);
147 return Specific(
id.name,
id.version);
150 inline string ServableRequest::DebugString()
const {
152 return strings::StrCat(
"Specific(", name,
", ", version.value(),
")");
154 switch (auto_version_policy) {
155 case AutoVersionPolicy::kEarliest:
156 return strings::StrCat(
"Earliest(", name,
")");
157 case AutoVersionPolicy::kLatest:
158 return strings::StrCat(
"Latest(", name,
")");
163 template <
typename T>
166 std::unique_ptr<UntypedServableHandle> untyped_handle;
167 TF_RETURN_IF_ERROR(GetUntypedServableHandle(request, &untyped_handle));
168 if (untyped_handle ==
nullptr) {
169 return errors::Internal(
"Manager returned a null handle with OK status.");
172 if (handle->get() ==
nullptr) {
173 return errors::InvalidArgument(
174 "Servable type doesn't match the asked for type.");
179 template <
typename T>
182 std::map<ServableId, ServableHandle<T>> id_and_handles;
183 std::map<ServableId, std::unique_ptr<UntypedServableHandle>>
184 id_and_untyped_handles = GetAvailableUntypedServableHandles();
185 for (
auto& id_and_untyped_handle : id_and_untyped_handles) {
187 if (handle.get() !=
nullptr) {
188 id_and_handles.emplace(id_and_untyped_handle.first, std::move(handle));
191 return id_and_handles;
virtual std::vector< ServableId > ListAvailableServableIds() const =0
std::map< ServableId, ServableHandle< T > > GetAvailableServableHandles() const
Status GetServableHandle(const ServableRequest &request, ServableHandle< T > *const handle)