1 /* Copyright 2015 The TensorFlow Authors. 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_CONTRIB_S3_S3_FILE_SYSTEM_H_ 17 #define TENSORFLOW_CONTRIB_S3_S3_FILE_SYSTEM_H_ 18 19 #include <aws/s3/S3Client.h> 20 #include "tensorflow/core/platform/env.h" 21 #include "tensorflow/core/platform/mutex.h" 22 23 namespace tensorflow { 24 25 class S3FileSystem : public FileSystem { 26 public: 27 S3FileSystem(); 28 ~S3FileSystem(); 29 30 Status NewRandomAccessFile( 31 const string& fname, std::unique_ptr<RandomAccessFile>* result) override; 32 33 Status NewWritableFile(const string& fname, 34 std::unique_ptr<WritableFile>* result) override; 35 36 Status NewAppendableFile(const string& fname, 37 std::unique_ptr<WritableFile>* result) override; 38 39 Status NewReadOnlyMemoryRegionFromFile( 40 const string& fname, 41 std::unique_ptr<ReadOnlyMemoryRegion>* result) override; 42 43 Status FileExists(const string& fname) override; 44 45 Status GetChildren(const string& dir, std::vector<string>* result) override; 46 47 Status Stat(const string& fname, FileStatistics* stat) override; 48 49 Status GetMatchingPaths(const string& pattern, 50 std::vector<string>* results) override; 51 52 Status DeleteFile(const string& fname) override; 53 54 Status CreateDir(const string& name) override; 55 56 Status DeleteDir(const string& name) override; 57 58 Status GetFileSize(const string& fname, uint64* size) override; 59 60 Status RenameFile(const string& src, const string& target) override; 61 62 private: 63 // Returns the member S3 client, initializing as-needed. 64 // When the client tries to access the object in S3, e.g., 65 // s3://bucket-name/path/to/object 66 // the behavior could be controlled by various environmental 67 // variables. 68 // By default S3 access regional endpoint, with region 69 // controlled by `AWS_REGION`. The endpoint could be overridden 70 // explicitly with `S3_ENDPOINT`. S3 uses HTTPS by default. 71 // If S3_USE_HTTPS=0 is specified, HTTP is used. Also, 72 // S3_VERIFY_SSL=0 could disable SSL verification in case 73 // HTTPS is used. 74 // This S3 Client does not support Virtual Hosted–Style Method 75 // for a bucket. 76 std::shared_ptr<Aws::S3::S3Client> GetS3Client(); 77 78 std::shared_ptr<Aws::S3::S3Client> s3_client_; 79 // Lock held when checking for s3_client_ initialization. 80 mutex client_lock_; 81 }; 82 83 } // namespace tensorflow 84 85 #endif // TENSORFLOW_CONTRIB_S3_S3_FILE_SYSTEM_H_ 86