16 #include "tensorflow_serving/servables/tensorflow/simple_servers.h"
23 #include "tensorflow/core/lib/core/errors.h"
24 #include "tensorflow/core/lib/core/status.h"
25 #include "tensorflow_serving/config/file_system_storage_path_source.pb.h"
26 #include "tensorflow_serving/core/aspired_versions_manager_builder.h"
27 #include "tensorflow_serving/core/availability_preserving_policy.h"
28 #include "tensorflow_serving/core/loader.h"
29 #include "tensorflow_serving/core/source.h"
30 #include "tensorflow_serving/core/source_adapter.h"
31 #include "tensorflow_serving/core/storage_path.h"
32 #include "tensorflow_serving/core/target.h"
33 #include "tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.h"
34 #include "tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.pb.h"
35 #include "tensorflow_serving/sources/storage_path/file_system_storage_path_source.h"
37 namespace tensorflow {
39 namespace simple_servers {
47 Status CreateStoragePathSource(
48 const string& base_path,
const string& servable_name,
49 std::unique_ptr<Source<StoragePath>>* path_source) {
50 FileSystemStoragePathSourceConfig config;
51 config.set_file_system_poll_wait_seconds(1);
52 auto* servable = config.add_servables();
53 servable->set_servable_name(servable_name);
54 servable->set_base_path(base_path);
56 std::unique_ptr<FileSystemStoragePathSource> file_system_source;
58 FileSystemStoragePathSource::Create(config, &file_system_source));
60 *path_source = std::move(file_system_source);
61 return absl::OkStatus();
69 Status CreateSavedModelBundleSource(
70 std::unique_ptr<SavedModelBundleSourceAdapter>* source) {
71 SavedModelBundleSourceAdapterConfig config;
72 TF_RETURN_IF_ERROR(SavedModelBundleSourceAdapter::Create(config, source));
74 return absl::OkStatus();
79 Status CreateSingleTFModelManagerFromBasePath(
80 const string& base_path, std::unique_ptr<Manager>*
const manager) {
81 std::unique_ptr<SavedModelBundleSourceAdapter> bundle_source;
82 TF_RETURN_IF_ERROR(CreateSavedModelBundleSource(&bundle_source));
83 std::unique_ptr<Source<StoragePath>> path_source;
85 CreateStoragePathSource(base_path,
"default", &path_source));
87 AspiredVersionsManagerBuilder::Options manager_options;
88 manager_options.aspired_version_policy.reset(
89 new AvailabilityPreservingPolicy);
90 std::unique_ptr<AspiredVersionsManagerBuilder> builder;
91 TF_CHECK_OK(AspiredVersionsManagerBuilder::Create(std::move(manager_options),
93 builder->AddSourceChain(std::move(path_source), std::move(bundle_source));
94 *manager = builder->Build();
96 return absl::OkStatus();